Skip to content

Commit

Permalink
fix isValidTest method
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Feb 20, 2019
1 parent 138a080 commit 19b180e
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/main/java/fr/inria/spirals/npefix/main/run/Main.java
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.FileWriter;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand All @@ -37,26 +38,33 @@ public class Main {
private RepairStrategy repairStrategy;
private String[] tests;
private int nbIteration;
private String repairStrategyClassname = "fr.inria.spirals.npefix.main.all.DefaultRepairStrategy";

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
Main main = new Main();
try {
main.initJSAP();
if (!main.parseArguments(args)) {
return;
}
main.run();
} catch (JSAPException e) {
e.printStackTrace();
} catch (Exception e) {
main.showUsage();
throw e;
} finally {

}
System.exit(0);
}

private NPEOutput run() {
repairStrategy = new DefaultRepairStrategy(sources.toArray(new String[]{}));

private RepairStrategy getRepairStrategy() throws Exception {
Class<RepairStrategy> aClass = (Class<RepairStrategy>) this.getClass().getClassLoader().loadClass(this.repairStrategyClassname);
Constructor<RepairStrategy> constructor = aClass.getConstructor(String[].class);
return constructor.newInstance(new Object[]{sources.toArray(new String[]{})});
}

private NPEOutput run() throws Exception {
repairStrategy = getRepairStrategy();
Launcher npefix = new Launcher(sources.toArray(new String[]{}), workingDirectory + "/npefix-src", workingDirectory + "/npefix-bin", classpath, complianceLevel, repairStrategy);
if (!new File(workingDirectory + "/npefix-bin").exists()) {
npefix.instrument();
Expand Down Expand Up @@ -184,6 +192,7 @@ private boolean parseArguments(String[] args) {
this.tests = jsapConfig.getStringArray("test");
this.nbIteration = jsapConfig.getInt("iteration");
this.complianceLevel = jsapConfig.getInt("complianceLevel");
this.repairStrategyClassname = jsapConfig.getString("repairStrategy");

return true;
}
Expand Down Expand Up @@ -246,5 +255,14 @@ private void initJSAP() throws JSAPException {
outputFolder.setDefault(".");
outputFolder.setHelp("Define the location where npefix will put its files.");
jsap.registerParameter(outputFolder);

FlaggedOption repairStrategy = new FlaggedOption("repairStrategy");
repairStrategy.setRequired(false);
repairStrategy.setAllowMultipleDeclarations(false);
repairStrategy.setLongFlag("repairStrategy");
repairStrategy.setStringParser(JSAP.STRING_PARSER);
repairStrategy.setDefault(DefaultRepairStrategy.class.getCanonicalName());
repairStrategy.setHelp("Define the repair strategy used by NPEFix.");
jsap.registerParameter(repairStrategy);
}
}

0 comments on commit 19b180e

Please sign in to comment.