Skip to content

Commit 004b70d

Browse files
authored
Merge pull request #208 from leonardoAnjos16/fixes-and-improvements
Ajuste no Formato de Data Esperado e Novas Opções
2 parents 8711c8e + bfd1bbf commit 004b70d

7 files changed

Lines changed: 181 additions & 46 deletions

File tree

README.md

Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,107 @@ usage: miningframework [options] [input] [output]
8585
the Mining Framework take an input csv file and a name for the output dir
8686
(default: output)
8787
Options:
88-
-a,--access-key <access key> Specify the access key of the git account
89-
for when the analysis needs user access to
90-
GitHub
91-
-e, --extension <extension> Specify the file extension that should be
92-
used in the analysis (e.g. .rb, .ts, .java,
93-
.cpp. Default: .java)
94-
-h,--help Show help for executing commands
95-
-i,--injector <class> Specify the class of the dependency
96-
injector (Must provide full name, default
97-
injectors.StaticAnalysisConflictsDetection
98-
Module)
99-
-k,--keep-projects Specify that cloned projects must be kept
100-
after the analysis (those are kept in
101-
clonedRepositories/ )
102-
-l,--language-separators <'separators'> Specify the language separators that should
103-
be used in the analysis. Required for (and
104-
only considered when) running studies with
105-
the CSDiff tool. Default: '{ } ( ) ; ,'
106-
-log,--log-level <log level Specify the minimum log level: (OFF, FATAL,
107-
ERROR, WARN, INFO, DEBUG, TRACE, ALL).
108-
Default: "INFO"
109-
-p,--push <link> Specify a git repository to upload the
110-
output in the end of the analysis (format
111-
https://github.com/<owner>/<name>
112-
-s,--since <date> Use commits more recent than a specific
113-
date (format DD/MM/YYY)
114-
-t,--threads <threads> Number of cores used in analysis (default:
115-
1)
116-
-u,--until <date> Use commits older than a specific
117-
date(format DD/MM/YYYY)
88+
-a,--access-key <access key> Specify the
89+
access key of
90+
the git
91+
account for
92+
when the
93+
analysis needs
94+
user access to
95+
GitHub
96+
-e,--extension <file extenson> Specify the
97+
file extension
98+
that should be
99+
used in the
100+
analysis (e.g.
101+
.rb, .ts,
102+
.java, .cpp.
103+
Default:
104+
.java)
105+
-h,--help Show help for
106+
executing
107+
commands
108+
-i,--injector <class> Specify the
109+
class of the
110+
dependency
111+
injector (Must
112+
provide full
113+
name, default
114+
injectors.Stat
115+
icAnalysisConf
116+
lictsDetection
117+
Module)
118+
-k,--keep-projects Specify that
119+
cloned
120+
projects must
121+
be kept after
122+
the analysis
123+
(those are
124+
kept in
125+
clonedReposito
126+
ries/ )
127+
-l,--language-separators <language syntactic separators> Specify the
128+
language
129+
separators
130+
that should be
131+
used in the
132+
analysis.
133+
Required for
134+
(and only
135+
considered
136+
when) running
137+
studies with
138+
the CSDiff
139+
tool. Default:
140+
"{ } ( ) ; ,"
141+
-log,--log-level <log level> Specify the
142+
minimum log
143+
level: (OFF,
144+
FATAL, ERROR,
145+
WARN, INFO,
146+
DEBUG, TRACE,
147+
ALL). Default:
148+
"INFO"
149+
-m,--max-commits-per-project <commits> Maximum number
150+
of commits to
151+
use for each
152+
project.
153+
Commits will
154+
be selected
155+
randomly,
156+
according to
157+
provided
158+
random seed
159+
-p,--push <link> Specify a git
160+
repository to
161+
upload the
162+
output in the
163+
end of the
164+
analysis
165+
(format
166+
https://github
167+
.com/<owner>/<
168+
name>
169+
-r,--random-seed <seed> Random seed
170+
used for
171+
shuffling
172+
merge commits
173+
array
174+
-s,--since <date> Use commits
175+
more recent
176+
than a
177+
specific date
178+
(format
179+
YYYY-MM-DD)
180+
-t,--threads <threads> Number of
181+
cores used in
182+
analysis
183+
(default: 1)
184+
-u,--until <date> Use commits
185+
older than a
186+
specific
187+
date(format
188+
YYYY-MM-DD)
118189
```
119190

120191

build.gradle

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
apply plugin: 'groovy'
1+
plugins {
2+
id 'groovy'
3+
id 'application'
4+
}
25

3-
apply plugin: 'application'
6+
group = 'app'
7+
version = '1.0.0'
48

59
mainClassName = System.getProperty("mainClass") ?: "app.Main"
610

11+
ext {
12+
groovyVersion = '3.0.23'
13+
}
14+
715
repositories {
8-
mavenCentral()
16+
mavenCentral()
917
}
1018

1119
sourceSets {
@@ -22,24 +30,33 @@ sourceSets {
2230
}
2331
}
2432

33+
java {
34+
toolchain {
35+
languageVersion = JavaLanguageVersion.of(17)
36+
}
37+
}
38+
2539
test {
40+
useJUnitPlatform()
2641
filter {
2742
includeTestsMatching '*TestSuite'
2843
}
2944
}
3045

3146
dependencies {
32-
implementation 'com.google.inject:guice:4.2.2'
47+
implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
48+
implementation "org.codehaus.groovy:groovy-cli-commons:${groovyVersion}"
49+
implementation 'com.google.inject:guice:5.1.0'
3350
implementation 'commons-io:commons-io:2.6'
3451
implementation 'com.xlson.groovycsv:groovycsv:1.3'
35-
implementation 'org.codehaus.groovy:groovy-cli-commons:3.0.0'
36-
implementation 'org.codehaus.groovy:groovy-all:3.0.0'
3752
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.22.1'
53+
implementation 'com.github.javaparser:javaparser-core:3.25.5'
54+
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
55+
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
56+
implementation 'org.json:json:20210307'
57+
3858
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
3959
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
4060
testCompileOnly 'junit:junit:4.12'
4161
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.3.1'
42-
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
43-
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
44-
implementation 'org.json:json:20210307'
4562
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/app/MiningWorker.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package app
22

3+
import java.util.Collections
4+
import java.util.Random
35
import java.text.SimpleDateFormat
46

57
import static app.MiningFramework.arguments
@@ -40,12 +42,22 @@ class MiningWorker implements Runnable {
4042
}
4143

4244
def (mergeCommits, skipped) = project.getMergeCommits(arguments.getSinceDate(), arguments.getUntilDate())
45+
46+
Random random = new Random(arguments.getRandomSeed())
47+
Collections.shuffle(mergeCommits, random)
48+
49+
int collectedMergeCommits = 0
4350
for (mergeCommit in mergeCommits) {
51+
if (collectedMergeCommits >= arguments.getMaxCommitsPerProject()) {
52+
break
53+
}
54+
4455
try {
4556
if (commitFilter.applyFilter(project, mergeCommit)) {
4657
println "${project.getName()} - Merge commit: ${mergeCommit.getSHA()}"
4758

4859
runDataCollectors(project, mergeCommit)
60+
collectedMergeCommits++
4961
}
5062
} catch (Exception e) {
5163
println "${project.getName()} - ${mergeCommit.getSHA()} - ERROR"

src/main/arguments/ArgsParser.groovy

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ class ArgsParser {
2222

2323
private defParameters() {
2424
this.cli.h(longOpt: 'help', 'Show help for executing commands')
25+
this.cli.r(longOpt: 'random-seed', args: 1,
26+
argName: 'seed', 'Random seed used for shuffling merge commits array')
2527
this.cli.s(longOpt: 'since', args: 1,
26-
argName: 'date', 'Use commits more recent than a specific date (format DD/MM/YYY)')
28+
argName: 'date', 'Use commits more recent than a specific date (format YYYY-MM-DD)')
2729
this.cli.u(longOpt: 'until', args: 1,
28-
argName: 'date', 'Use commits older than a specific date(format DD/MM/YYYY)')
30+
argName: 'date', 'Use commits older than a specific date(format YYYY-MM-DD)')
31+
this.cli.m(longOpt: 'max-commits-per-project', args: 1,
32+
argName: 'commits', 'Maximum number of commits to use for each project. Commits will be selected randomly, according to provided random seed')
2933
this.cli.i(longOpt: 'injector', args: 1,
3034
argName: 'class', 'Specify the class of the dependency injector (Must provide full name, default injectors.StaticAnalysisConflictsDetectionModule)')
3135
this.cli.p(longOpt: 'push', args: 1, argName: 'link', 'Specify a git repository to upload the output in the end of the analysis (format https://github.com/<owner>/<name>')
@@ -78,20 +82,28 @@ class ArgsParser {
7882
}
7983

8084
private void parseOptions(Arguments args) {
85+
if (this.options.r) {
86+
args.setRandomSeed(this.options.r.toInteger())
87+
}
88+
8189
if (this.options.since) {
8290
if (!validDate(this.options.since))
83-
throw new InvalidArgsException('Invalid since date. You must specify it with the format DD/MM/YYYY')
91+
throw new InvalidArgsException('Invalid since date. You must specify it with the format YYYY-MM-DD')
8492

8593
args.setSinceDate(this.options.since)
8694
}
8795

8896
if (this.options.until) {
8997
if (!validDate(this.options.until))
90-
throw new InvalidArgsException('Invalid since date. You must specify it with the format DD/MM/YYYY')
98+
throw new InvalidArgsException('Invalid until date. You must specify it with the format YYYY-MM-DD')
9199

92100
args.setUntilDate(this.options.until)
93101
}
94102

103+
if (this.options.m) {
104+
args.setMaxCommitsPerProject(this.options.m.toInteger())
105+
}
106+
95107
if (this.options.injector) {
96108
try {
97109
args.setInjector(Class.forName(this.options.injector));
@@ -144,7 +156,7 @@ class ArgsParser {
144156
}
145157

146158
private boolean validDate(String value) {
147-
SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy")
159+
SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd")
148160
try {
149161
format.setLenient(false)
150162
format.parse(value)

src/main/arguments/Arguments.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import org.apache.logging.log4j.core.config.Configurator
66

77
class Arguments {
88

9+
private int randomSeed
910
private String inputPath
1011
private String outputPath
1112
private String sinceDate
1213
private String untilDate
14+
private int maxCommitsPerProject
1315
private Class injector
1416
private boolean isHelp
1517
private String resultsRemoteRepositoryURL
@@ -21,9 +23,11 @@ class Arguments {
2123
private Level logLevel
2224

2325
Arguments() { // set the default values for all parameters
26+
randomSeed = 1
2427
isHelp = false
2528
sinceDate = ''
2629
untilDate = ''
30+
maxCommitsPerProject = 100000
2731
outputPath = 'output'
2832
injector = StaticAnalysisConflictsDetectionModule
2933
resultsRemoteRepositoryURL = ''
@@ -35,6 +39,10 @@ class Arguments {
3539
logLevel = Level.INFO
3640
}
3741

42+
void setRandomSeed(int randomSeed) {
43+
this.randomSeed = randomSeed
44+
}
45+
3846
void setNumOfThreads(int numOfThreads) {
3947
this.numOfThreads = numOfThreads
4048
}
@@ -55,6 +63,10 @@ class Arguments {
5563
this.untilDate = untilDate
5664
}
5765

66+
void setMaxCommitsPerProject(int maxCommitsPerProject) {
67+
this.maxCommitsPerProject = maxCommitsPerProject
68+
}
69+
5870
Class setInjector(Class injector) {
5971
this.injector = injector
6072
}
@@ -83,6 +95,10 @@ class Arguments {
8395
this.syntacticSeparators = separators
8496
}
8597

98+
int getRandomSeed() {
99+
return this.randomSeed
100+
}
101+
86102
int getNumOfThreads() {
87103
return this.numOfThreads
88104
}
@@ -103,6 +119,10 @@ class Arguments {
103119
return untilDate
104120
}
105121

122+
int getMaxCommitsPerProject() {
123+
return this.maxCommitsPerProject
124+
}
125+
106126
Class getInjector() {
107127
return injector
108128
}

src/main/project/Project.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package project
33
import util.ProcessRunner
44
import exception.UnexpectedOutputException
55

6+
import java.util.Collections
7+
import java.util.Random
68
import java.util.regex.Pattern
79
import java.util.regex.Matcher
810

@@ -71,6 +73,7 @@ class Project {
7173

7274
if(mergeCommits.isEmpty())
7375
println "No merge commits."
76+
7477
return [mergeCommits, skipped]
7578
}
7679

@@ -103,7 +106,7 @@ class Project {
103106
}
104107

105108
private Process constructAndRunGitLog(String sinceDate, String untilDate) {
106-
ProcessBuilder gitLogBuilder = ProcessRunner.buildProcess(path, 'git', '--no-pager', 'log', '--merges', '--pretty=%H-%p', '--date=format:\'%d/%m/%Y\'')
109+
ProcessBuilder gitLogBuilder = ProcessRunner.buildProcess(path, 'git', '--no-pager', 'log', '--merges', '--pretty=%H-%p')
107110
if(!sinceDate.equals(''))
108111
ProcessRunner.addCommand(gitLogBuilder, "--since=\"${sinceDate}\"")
109112
if(!untilDate.equals(''))

0 commit comments

Comments
 (0)