fix: support sonar-project.Properties

This commit is contained in:
Rogan 2020-02-08 02:04:04 +08:00
parent 15157105c5
commit c0971c7f44
4 changed files with 54 additions and 34 deletions

2
.gitignore vendored
View File

@ -14,4 +14,4 @@
.history
.vscode
.scannerwork
.idea

10
DOCS.md
View File

@ -13,7 +13,7 @@ This plugin can scan your code quality and post the analysis report to your Sona
The below pipeline configuration demonstrates simple usage:
```yaml
steps
steps:
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
@ -26,7 +26,7 @@ steps
Customized parameters could be specified:
```diff
steps
steps:
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
@ -40,6 +40,7 @@ Customized parameters could be specified:
+ level: DEBUG
+ showProfiling: true
+ exclusions: **/static/**/*,**/dist/**/*.js
+ usingProperties: false
```
# Secret Reference
@ -62,6 +63,11 @@ Safety first, the host and token are stored in Drone Secrets.
* `showProfiling`: Display logs to see where the analyzer spends time. Default value `false`
* `branchAnalysis`: Pass currently analysed branch to SonarQube. (Must not be active for initial scan!) Default value `false`
* `usingProperties`: Using the `sonar-project.properties` file in root directory as sonar parameters. (Not include `sonar_host` and
`sonar_token`.) Default value `false`
# Notes
* projectKey: `DRONE_REPO`

11
main.go
View File

@ -87,6 +87,11 @@ func main() {
Usage: "execute branchAnalysis",
EnvVar: "PLUGIN_BRANCHANALYSIS",
},
cli.BoolFlag{
Name: "usingProperties",
Usage: "using sonar-project.properties",
EnvVar: "PLUGIN_USINGPROPERTIES",
},
}
app.Run(os.Args)
@ -107,8 +112,10 @@ func run(c *cli.Context) {
Inclusions: c.String("inclusions"),
Exclusions: c.String("exclusions"),
Level: c.String("level"),
showProfiling: c.String("showProfiling"),
branchAnalysis: c.Bool("branchAnalysis"),
ShowProfiling: c.String("showProfiling"),
BranchAnalysis: c.Bool("branchAnalysis"),
UsingProperties: c.Bool("usingProperties"),
},
}

View File

@ -20,8 +20,9 @@ type (
Inclusions string
Exclusions string
Level string
showProfiling string
branchAnalysis bool
ShowProfiling string
BranchAnalysis bool
UsingProperties bool
}
Plugin struct {
Config Config
@ -30,22 +31,28 @@ type (
func (p Plugin) Exec() error {
args := []string{
"-Dsonar.projectKey=" + strings.Replace(p.Config.Key, "/", ":", -1),
"-Dsonar.projectName=" + p.Config.Name,
"-Dsonar.host.url=" + p.Config.Host,
"-Dsonar.login=" + p.Config.Token,
}
if !p.Config.UsingProperties {
argsParameter := []string{
"-Dsonar.projectKey=" + strings.Replace(p.Config.Key, "/", ":", -1),
"-Dsonar.projectName=" + p.Config.Name,
"-Dsonar.projectVersion=" + p.Config.Version,
"-Dsonar.sources=" + p.Config.Sources,
"-Dsonar.ws.timeout=" + p.Config.Timeout,
"-Dsonar.inclusions=" + p.Config.Inclusions,
"-Dsonar.exclusions=" + p.Config.Exclusions,
"-Dsonar.log.level=" + p.Config.Level,
"-Dsonar.showProfiling=" + p.Config.showProfiling,
"-Dsonar.showProfiling=" + p.Config.ShowProfiling,
"-Dsonar.scm.provider=git",
}
args = append(args, argsParameter)
}
if p.Config.branchAnalysis {
if p.Config.BranchAnalysis {
args = append(args, "-Dsonar.branch.name=" + p.Config.Branch)
}