Skip to content

Commit

Permalink
feat: add SoraldBot (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
khaes-kth committed Jun 17, 2021
1 parent 39e6a92 commit 4755881
Show file tree
Hide file tree
Showing 23 changed files with 628 additions and 425 deletions.
13 changes: 7 additions & 6 deletions doc/repair-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ It can be used [in the configuration](repairnator-config.md#REPAIR_TOOLS) with t

Currently this tool supports the following [rules](https://github.com/kth-tcs/sonarqube-repair/blob/master/docs/HANDLED_RULES.md) on SonarQube

It can be used [in the configuration](repairnator-config.md#REPAIR_TOOLS) with this value: `Sorald` with the corresponding handled rulenumber [in the configuration](repairnator-config.md#REPAIR_TOOLS). [Current supported ruleNumbers](https://github.com/kth-tcs/sonarqube-repair/blob/master/docs/HANDLED_RULES.md)
It can be used [in the configuration](repairnator-config.md#REPAIR_TOOLS) with this value: `SoraldBot` with the corresponding handled rulenumber [in the configuration](repairnator-config.md#REPAIR_TOOLS). [Current supported ruleNumbers](https://github.com/kth-tcs/sonarqube-repair/blob/master/docs/HANDLED_RULES.md)
Sorald resolves violations of `--sonarRules` in the files changed in a specified commit.

Moreover, Launcher choice need to be set with `--launcherChoice NEW` to use this tool.
Moreover, the launcher mode should be set to `--launcherMode GIT_REPOSITORY` to use this tool.

Additional parameters:
* `--sonarRules`: the rules Sorald should analyze for warnings after input. Input format: 2116,1656... . Default: 2116
* `--soraldRepairMode`: DEFAULT - the normal mode of Sorald, where the entire project is inputted. SEGMENT - the input project is sliced into smaller fixed-size segments.
* `--soraldMaxFixesPerRule`: specify the upper bound of the number of warning fixes.
* `--segmentSize`: the number of files per segment if Sorald runs in Segment mode.
* `--sonarRules`: the rules Sorald should analyze for warnings after input. Input format: 2116,1656... .
* `--gitrepo`: required only in the new version.
* `--gitrepourl`: the url of the target repo that should be fixed. Required only in the new version.
* `--gitcommithash`: the hash number of the commit that Sorald will fix its changed files. Required only in the new version.

## Sequencer

Expand Down
2 changes: 1 addition & 1 deletion src/maven-repair/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5</version>
<version>3.6.1</version>
<configuration>
<goalPrefix>repair</goalPrefix>
<skipErrorNoDescriptorsFound>true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ public static void registerCommonArgs(JSAP jsap) throws JSAPException {

// --sonarRules
jsap.registerParameter(LauncherUtils.defineArgSonarRules());
// --soraldRepairMode
jsap.registerParameter(LauncherUtils.defineArgSoraldRepairMode());
// --segmentSize
jsap.registerParameter(LauncherUtils.defineArgSegmentSize());
// --soraldMaxFixesPerRule
jsap.registerParameter(LauncherUtils.defineArgSoraldMaxFixesPerRule());

// --npeSelection
jsap.registerParameter(LauncherUtils.defineArgNPESelection());
Expand Down Expand Up @@ -231,9 +225,6 @@ public static void initCommonConfig(RepairnatorConfig config, JSAPResult argumen
}

config.setSonarRules(Arrays.stream(LauncherUtils.getArgSonarRules(arguments).split(",")).distinct().toArray(String[]::new));
config.setSegmentSize(LauncherUtils.getArgSegmentSize(arguments));
config.setSoraldRepairMode(RepairnatorConfig.SORALD_REPAIR_MODE.valueOf(LauncherUtils.getArgSoraldRepairMode(arguments)));
config.setSoraldMaxFixesPerRule(LauncherUtils.getArgSoraldMaxFixesPerRule(arguments));

config.setNPESelection(LauncherUtils.getArgNPESelection(arguments));
config.setNPENbIteration(LauncherUtils.getArgNPENbIteration(arguments));
Expand Down Expand Up @@ -822,7 +813,7 @@ public static String getArgGitBranch(JSAPResult arguments) {

public static FlaggedOption defineArgGitCommitHash() {
FlaggedOption opt = new FlaggedOption("gitcommithash");
opt.setLongFlag("gitcommit");
opt.setLongFlag("gitcommithash");
opt.setStringParser(JSAP.STRING_PARSER);
opt.setHelp("the hash of your git commit");
return opt;
Expand Down Expand Up @@ -872,45 +863,6 @@ public static String getArgSonarRules(JSAPResult arguments) {
return arguments.getString("sonarRules");
}

public static FlaggedOption defineArgSoraldRepairMode() {
FlaggedOption opt = new FlaggedOption("soraldRepairMode");
opt.setLongFlag("soraldRepairMode");
opt.setStringParser(JSAP.STRING_PARSER);
opt.setDefault(RepairnatorConfig.SORALD_REPAIR_MODE.DEFAULT.name());
opt.setHelp("DEFAULT - default mode , load everything in at once into Sorald. SEGMENT - repair segments of the projects instead, segmentsize can be specified.");
return opt;
}

public static String getArgSoraldRepairMode(JSAPResult arguments) {
return arguments.getString("soraldRepairMode");
}

public static FlaggedOption defineArgSegmentSize() {
FlaggedOption opt = new FlaggedOption("segmentSize");
opt.setLongFlag("segmentSize");
opt.setStringParser(JSAP.INTEGER_PARSER);
opt.setDefault("200");
opt.setHelp("Segment size for the segment repair.");
return opt;
}

public static Integer getArgSegmentSize(JSAPResult arguments) {
return arguments.getInt("segmentSize");
}

public static FlaggedOption defineArgSoraldMaxFixesPerRule() {
FlaggedOption opt = new FlaggedOption("soraldMaxFixesPerRule");
opt.setLongFlag("soraldMaxFixesPerRule");
opt.setStringParser(JSAP.INTEGER_PARSER);
opt.setDefault("2000");
opt.setHelp("Number of fixes per SonarQube rule.");
return opt;
}

public static Integer getArgSoraldMaxFixesPerRule(JSAPResult arguments) {
return arguments.getInt("soraldMaxFixesPerRule");
}

public static FlaggedOption defineArgNPESelection() {
FlaggedOption opt = new FlaggedOption("npeSelection");
opt.setLongFlag("npeSelection");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ public enum PATCH_FILTERING_MODE {
ODS_CORRECT
}

/**
* DEFAULT - the project files is scanned by Sorald as a single unit. If the repair fails then it fails completely and no fixes are produced if there could have been any
* SEGMENT - the project is sliced into fix-sized segments to be scanned one by one. If the repair fails for a segment, it will salvage the situation by continuing on with other segments
*/
public enum SORALD_REPAIR_MODE {
DEFAULT,
SEGMENT
}

private String runId;
private LauncherMode launcherMode = LauncherMode.REPAIR;

Expand Down Expand Up @@ -125,9 +116,6 @@ public enum SORALD_REPAIR_MODE {

private String[] sonarRules;
private boolean isStaticAnalysis;
private int soraldMaxFixesPerRule;
private int segmentSize;
private SORALD_REPAIR_MODE soraldRepairMode;
private boolean measureSoraldTime;

private String npeSelection;
Expand Down Expand Up @@ -753,30 +741,6 @@ public boolean isStaticAnalysis() {
return this.isStaticAnalysis;
}

public void setSegmentSize(int segmentSize) {
this.segmentSize = segmentSize;
}

public int getSegmentSize() {
return this.segmentSize;
}

public void setSoraldRepairMode(SORALD_REPAIR_MODE soraldRepairMode) {
this.soraldRepairMode = soraldRepairMode;
}

public SORALD_REPAIR_MODE getSoraldRepairMode() {
return this.soraldRepairMode;
}

public void setSoraldMaxFixesPerRule(int soraldMaxFixesPerRule) {
this.soraldMaxFixesPerRule = soraldMaxFixesPerRule;
}

public int getSoraldMaxFixesPerRule() {
return this.soraldMaxFixesPerRule;
}

public String getNPESelection() {
return npeSelection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public class Config {
private HashMap<String,String> stringConfig;
private String[] tools;
private String sonarRules;
private String soraldRepairMode;
private int soraldMaxFixesPerRule;
private int segmentSize;
private File workspaceDir;

public Config(){
Expand Down Expand Up @@ -151,30 +148,6 @@ public void switchQuiet() {
this.quiet = !this.quiet;
}

public void setSoraldRepairMode(String soraldRepairMode) {
this.soraldRepairMode = soraldRepairMode;
}

public String getSoraldRepairMode() {
return this.soraldRepairMode;
}

public void setSoraldMaxFixesPerRule(int soraldMaxFixesPerRule) {
this.soraldMaxFixesPerRule = soraldMaxFixesPerRule;
}

public int getSoraldMaxFixesPerRule() {
return this.soraldMaxFixesPerRule;
}

public void setSegmentSize(int segmentSize) {
this.segmentSize = segmentSize;
}

public int getSegmentSize() {
return this.segmentSize;
}

public void setWorkspaceDir(File workspaceDir) {
this.workspaceDir = workspaceDir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ public class RepairnatorPostBuild extends Recorder {
private boolean rule4973;

private SonarRulesBlock sonarRulesBlock;
private String soraldRepairMode;
private int soraldMaxFixesPerRule;
private int segmentSize;

@DataBoundConstructor
public RepairnatorPostBuild(String gitUrl,String gitOAuthToken,String gitBranch,String notifyTo, String soraldRepairMode, int segmentSize, int soraldMaxFixesPerRule,SonarRulesBlock sonarRulesBlock) {
public RepairnatorPostBuild(String gitUrl,String gitOAuthToken,String gitBranch,String notifyTo,SonarRulesBlock sonarRulesBlock) {
this.gitUrl = gitUrl;
this.gitOAuthToken = gitOAuthToken;
this.gitBranch = gitBranch;
Expand All @@ -126,23 +123,6 @@ public RepairnatorPostBuild(String gitUrl,String gitOAuthToken,String gitBranch,
sonarRulesBlock.rulesProvided = true;
}

if (soraldRepairMode == null) {
this.soraldRepairMode = "DEFAULT";
} else {
this.soraldRepairMode = soraldRepairMode;
}

if (soraldMaxFixesPerRule <= 0) {
this.soraldMaxFixesPerRule = 2000;
} else {
this.soraldMaxFixesPerRule = soraldMaxFixesPerRule;
}

if (segmentSize <= 0) {
this.segmentSize = 200;
} else {
this.segmentSize = segmentSize;
}
}

public RepairnatorPostBuild() {
Expand Down Expand Up @@ -247,30 +227,6 @@ public boolean getRule4973() {
return SonarRulesBlock.rule4973;
}

public void setSoraldRepairMode(String soraldRepairMode) {
this.soraldRepairMode = soraldRepairMode;
}

public String getSoraldRepairMode() {
return this.soraldRepairMode;
}

public void setSoraldMaxFixesPerRule(int soraldMaxFixesPerRule) {
this.soraldMaxFixesPerRule = soraldMaxFixesPerRule;
}

public int getSoraldMaxFixesPerRule() {
return this.soraldMaxFixesPerRule;
}

public void setSegmentSize(int segmentSize) {
this.segmentSize = segmentSize;
}

public int getSegmentSize() {
return this.segmentSize;
}

public void setGitUrl(String gitUrl) {
this.gitUrl = gitUrl;
}
Expand Down Expand Up @@ -402,10 +358,7 @@ public void runRepairnator(EnvVars env) throws IOException,InterruptedException{
.alsoCreatePR()
.withMavenHome(config.getMavenHome())
.atWorkSpace(config.getWorkspaceDir().getAbsolutePath())
.withOutputDir(config.getWorkspaceDir().getAbsolutePath())
.withSegmentSize(config.getSegmentSize())
.withSoraldRepairMode(config.getSoraldRepairMode())
.withSoraldMaxFixesPerRule(config.getSoraldMaxFixesPerRule());
.withOutputDir(config.getWorkspaceDir().getAbsolutePath());

ProcessBuilder builder = repProcBuilder.build().directory(config.getWorkspaceDir());
builder.redirectErrorStream(true);
Expand Down Expand Up @@ -522,9 +475,6 @@ public void configure(String url,String branch, EnvVars env) {
config.setTools(this.getTools());
config.setNotifyTo(this.notifyTo);
config.setSonarRules(SonarRulesBlock.constructCmdStr4Rules());
config.setSoraldRepairMode(this.soraldRepairMode);
config.setSoraldMaxFixesPerRule(this.soraldMaxFixesPerRule);
config.setSegmentSize(this.segmentSize);
config.setWorkspaceDir(workspaceDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class RepairnatorProcessBuilder {
private String mavenHome;
private String outputDir;
private String sonarRules;
private String segmentSize;
private String soraldMaxFixesPerRule;
private String soraldRepairMode;
private boolean createPR;
private boolean useSmtpTLS;
private boolean noTravisRepair;
Expand Down Expand Up @@ -127,21 +124,6 @@ public RepairnatorProcessBuilder withSonarRules(String sonarRules) {
}


public RepairnatorProcessBuilder withSegmentSize(int segmentSize) {
this.segmentSize = "" + segmentSize;
return this;
}

public RepairnatorProcessBuilder withSoraldRepairMode(String soraldRepairMode) {
this.soraldRepairMode = soraldRepairMode;
return this;
}

public RepairnatorProcessBuilder withSoraldMaxFixesPerRule(int soraldMaxFixesPerRule) {
this.soraldMaxFixesPerRule = "" + soraldMaxFixesPerRule;
return this;
}

public void checkValid() {
if (this.javaExec == null || this.javaExec.equals("")) {
throw new IllegalArgumentException("Repairnator Process building failed: java executable location is null");
Expand Down Expand Up @@ -176,13 +158,7 @@ public ProcessBuilder build() {
cmdList.add("NEW");
cmdList.add("--launcherMode");
cmdList.add("GIT_REPOSITORY");
cmdList.add("--soraldRepairMode");
cmdList.add(this.soraldRepairMode);
cmdList.add("--segmentSize");
cmdList.add(this.segmentSize);
cmdList.add("--soraldMaxFixesPerRule");
cmdList.add(this.soraldMaxFixesPerRule);


cmdList.add("--output");
cmdList.add(this.outputDir);
cmdList.add("--MavenHome");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,5 @@
<f:entry title="${%GitBranch}" field="gitBranch">
<f:textbox />
</f:entry>
<f:entry title="Sorald Repair Mode" field="soraldRepairMode" default="DEFAULT">
<f:radio name="soraldRepairMode" title="Default" value="DEFAULT" checked="${instance.soraldRepairMode == 'DEFAULT'}" />
<f:radio name="soraldRepairMode" title="Segment" value="SEGMENT" checked="${instance.soraldRepairMode == 'SEGMENT'}" />
</f:entry>
<f:entry title="${%SegmentSize}" field="segmentSize">
<f:number />
</f:entry>
<f:entry title="${%SoraldMaxFixesPerRule}" field="soraldMaxFixesPerRule">
<f:number/>
</f:entry>
</f:advanced>
</j:jelly>
2 changes: 1 addition & 1 deletion src/repairnator-pipeline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>se.kth.castor</groupId>
<artifactId>sorald</artifactId>
<version>17f106c8e7b3aea25542966410c0b26c2e6c2e43-SNAPSHOT</version>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>fr.inria.repairnator</groupId>
Expand Down
Loading

0 comments on commit 4755881

Please sign in to comment.