forked from aosapps/drone-sonar-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
executable file
·57 lines (50 loc) · 1.2 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"strings"
"fmt"
"os/exec"
)
type (
Config struct {
Key string
Name string
Host string
Token string
Version string
Sources string
Timeout string
Inclusions string
Exclusions string
Level string
showProfiling string
}
Plugin struct {
Config Config
}
)
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,
"-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.scm.provider=git",
}
cmd := exec.Command("sonar-scanner", args...)
// fmt.Printf("==> Executing: %s\n", strings.Join(cmd.Args, " "))
output, err := cmd.CombinedOutput()
if len(output) > 0 {
fmt.Printf("==> Code Analysis Result: %s\n", string(output))
}
if err != nil {
return err
}
return nil
}