Java Code Examples for fr.inria.lille.repair.common.config.NopolContext#setProjectClasspath()

The following examples show how to use fr.inria.lille.repair.common.config.NopolContext#setProjectClasspath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalNopolActor.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onReceive(Object message) throws Exception {
	if (message instanceof ConfigActor) {

		ConfigActor configActor = (ConfigActor) message;

		NopolContext nopolContext = configActor.getNopolContext();
		File tempDirectory = Files.createTempDir();
		UnZiper.unZipIt(configActor.getContent(), tempDirectory.getAbsolutePath());
		ActorRef client = configActor.getClient();

		if (nopolContext.getSynthesis() == NopolContext.NopolSynthesis.SMT) {
			nopolContext.setSolverPath(pathToSolver);
		}

		String sourceFile = tempDirectory.toString() + "/src/";
		String classPath = getClasspathFromTargetFolder(new File(tempDirectory.getCanonicalPath() + "/target/"));

		System.out.println(tempDirectory);

		List<Patch> patches = Collections.EMPTY_LIST;
		nopolContext.setProjectSources(sourceFile);
		nopolContext.setProjectClasspath(JavaLibrary.classpathFrom(classPath));
		nopolContext.setComplianceLevel(8);

		try {
			NoPol noPol = new NoPol(nopolContext);
			NopolResult status = noPol.build();
			patches = status.getPatches();
		} catch (Exception e) {
			throw new RuntimeException("Error launch NoPol", e);
		} finally {
			getSender().tell(NoPolActor.Message.AVAILABLE, getSelf());
		}
		client.tell(patches, ActorRef.noSender());
	} else
		unhandled(message);//Unsupported message type
}
 
Example 2
Source File: AbstractRealBugsEvaluation.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private List<Patch> setupAndRun(String projectName, RepairType repairType, String[] tests, NopolContext nopolContext, String... dependencies) {
    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src";
    String binFolder = rootFolder + "target/classes/" + File.pathSeparatorChar + rootFolder + "target/test-classes/";
    String libFolder = realBugPath + "../data/lib/";
    String classpath = binFolder + File.pathSeparatorChar;
    for (int i = 0; i < dependencies.length; i++) {
        classpath += libFolder + dependencies[i];
        if (i < dependencies.length - 1) {
            classpath += File.pathSeparatorChar;
        }
    }
    nopolContext.setProjectSourcePath(new File[]{new File(srcFolder)});

    nopolContext.setSolverPath("lib/z3/z3_for_" + (isMac() ? "mac" : "linux"));
    nopolContext.setSolver(NopolContext.NopolSolver.Z3);
    nopolContext.setLocalizer(NopolContext.NopolLocalizer.GZOLTAR);
    nopolContext.setProjectTests(tests);
    nopolContext.setType(repairType);
    nopolContext.setProjectClasspath(JavaLibrary.classpathFrom(classpath));
    SolverFactory.setSolver(nopolContext.getSolver(), nopolContext.getSolverPath());
    switch (this.executionType) {
        case "symbolic":
            nopolContext.setOracle(NopolContext.NopolOracle.SYMBOLIC);
            break;
        case "nopol":
            nopolContext.setOracle(NopolContext.NopolOracle.ANGELIC);
            break;
        default:
            throw new RuntimeException("Execution type not found");
    }

    return new NoPol(nopolContext).build().getPatches();
}
 
Example 3
Source File: TseEvaluationTest.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public void testTSEBug(String bug_id) throws Exception {
	String folder = "unknown";
	if (bug_id.startsWith("cm") || bug_id.startsWith("pm")) {
		folder = "math";
	}
	if (bug_id.startsWith("cl") || bug_id.startsWith("pl")) {
		folder = "lang";
	}

	JSONTokener tokener = new JSONTokener(new File("../nopol-experiments/data/projects/"+folder+"/bugs/" + bug_id + ".json").toURL().openStream());
	JSONObject root = new JSONObject(tokener);

	//JSONArray s =
	NopolContext nopolContext = new NopolContext();
	String src = "../nopol-experiments/dataset/" + bug_id + "/" + root.getJSONObject("path").getString("source");
	nopolContext.setProjectSourcePath(new File[]{new File(src)});

	// setting the Java version of the project to repair, required for TSE_CL1 for instance
	if (root.has("java")) {
		nopolContext.setComplianceLevel(Integer.parseInt(root.getJSONObject("java").getString("version").substring(2)));
	}

	URL[] cp = new URL[root.getJSONArray("dependencies").length()+2];
	cp[0] = new File("../nopol-experiments/dataset/"+bug_id+"/"+"target/classes/").toURL();
	cp[1] = new File("../nopol-experiments/dataset/"+bug_id+"/"+"target/test-classes/").toURL();
	for (int i = 0; i <root.getJSONArray("dependencies").length(); i++)
	{
		cp[i+2] = new File("../nopol-experiments/data/lib/"+root.getJSONArray("dependencies").getString(i)).toURL();
	}

	if (root.has("tests")) {
		String[] tests = new String[root.getJSONArray("tests").length()];
		for (int i = 0; i <root.getJSONArray("tests").length(); i++)
		{
			tests[i] = root.getJSONArray("tests").getString(i);
		}				;
		nopolContext.setProjectTests(tests);
	}

	nopolContext.setProjectClasspath(cp);
	//nopolContext.setLocalizer(NopolContext.NopolLocalizer.COCOSPOON);
	nopolContext.setType(RepairType.PRECONDITION);
	if ("condition".equals(root.getString("type"))) {
			nopolContext.setType(RepairType.CONDITIONAL);
	}
	SolverFactory.setSolver("z3", TestUtility.solverPath);
	NoPol nopol = new NoPol(nopolContext);
	NopolResult result = nopol.build();

	assertEquals(1, result.getPatches().size());
}