-
Notifications
You must be signed in to change notification settings - Fork 0
/
scabov.go
126 lines (99 loc) · 3.31 KB
/
scabov.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"flag"
"github.com/jochil/scabov/analyzer"
"github.com/jochil/scabov/analyzer/classifier"
"github.com/jochil/scabov/export"
"github.com/jochil/scabov/vcs"
"io/ioutil"
"log"
"os"
"path"
)
var (
//parameters
repoPath = flag.String("p", "", "(remote) path to an vcs repository")
verbose = flag.Bool("v", false, "activate verbose output")
language = flag.String("l", "", "select programming language for analysis")
metrics = flag.Bool("m", false, "activate metrics calculation")
classification = flag.Bool("c", false, "activate developer classification")
outputFilename = flag.String("o", "", "select output file")
//local vars
repo *vcs.Repository
outputFile *os.File
styleGroups, contributionGroups []*classifier.Group
runStyleClassification, runContributionClassification bool
)
func main() {
flag.Parse()
// setup logging
log.SetFlags(0)
if !*verbose {
log.SetOutput(ioutil.Discard)
}
filter := vcs.NewLanguageFilter(*language)
vcs.Filter = filter
analyzer.Filter = filter
// load repo
if *repoPath == "" {
log.Fatal("repository path missing, e.g.: -p \"mypath/repo\"")
}
var err error
repo, err = vcs.NewRepository(*repoPath)
if err != nil {
log.Fatal(err)
}
//TODO path validation?
if *outputFilename == "" {
outputFile, _ = os.Create(path.Join(repo.Workspace, "result.xml"))
} else {
outputFile, _ = os.Create(*outputFilename)
}
runStyleClassification = true
runContributionClassification = true
if *classification {
executeCompleteClassification()
}
if *metrics {
executeMetricsCalculation()
}
log.Printf("saved results to %s", outputFile.Name())
export.SaveFile(outputFile)
//TODO clean up (delete workspace, ...)
}
func executeMetricsCalculation() {
if runStyleClassification == true {
executeStyleClassification()
}
if runContributionClassification == true {
executeContributionClassification()
}
log.Println("started metric extraction")
styleHomogeneity := analyzer.CalcHomogeneity(styleGroups)
log.Printf("\t style homogeneity: %.2f", styleHomogeneity)
contributionHomogeneity := analyzer.CalcHomogeneity(contributionGroups)
log.Printf("\t contribution homogeneity: %.2f", contributionHomogeneity)
analyzer.LoadHistory(repo)
stability := analyzer.CalcFunctionStability(repo)
log.Printf("\t overall function stability: %.2f", stability)
export.SaveMetricsResult(stability, styleHomogeneity, contributionHomogeneity)
export.SaveFunctions(analyzer.History)
}
func executeCompleteClassification() {
executeStyleClassification()
executeContributionClassification()
}
func executeStyleClassification() {
log.Println("started style classification")
styleRawMatrix := analyzer.StyleData(repo)
styleGroups = classifier.ClusterAnalysis(styleRawMatrix)
export.SaveClassificationResult("style", styleGroups, styleRawMatrix)
runStyleClassification = false
}
func executeContributionClassification() {
log.Println("started contribution classification")
contributionRawMatrix := analyzer.ContributionData(repo)
contributionGroups = classifier.ClusterAnalysis(contributionRawMatrix)
export.SaveClassificationResult("contribution", contributionGroups, contributionRawMatrix)
runContributionClassification = false
}