Search in sources :

Example 6 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class NPERepair method businessExecute.

@Override
protected void businessExecute() {
    this.getLogger().debug("Entrance in NPERepair step...");
    if (isThereNPE()) {
        this.getLogger().info("NPE found, start NPEFix");
        MavenHelper mavenHelper = new MavenHelper(this.getPom(), NPEFIX_GOAL, null, this.getName(), this.getInspector(), true);
        int status = MavenHelper.MAVEN_ERROR;
        try {
            status = mavenHelper.run();
        } catch (InterruptedException e) {
            this.addStepError("Error while executing Maven goal", e);
        }
        if (status == MavenHelper.MAVEN_ERROR) {
            this.addStepError("Error while running NPE fix: maybe the project does not contain a NPE?");
            this.setPipelineState(PipelineState.NPEFIX_NOTPATCHED);
        } else {
            Collection<File> files = FileUtils.listFiles(new File(this.getInspector().getJobStatus().getPomDirPath() + "/target/npefix"), new String[] { "json" }, false);
            if (!files.isEmpty()) {
                File patchesFiles = files.iterator().next();
                try {
                    FileUtils.copyFile(patchesFiles, new File(this.getInspector().getRepoLocalPath() + "/repairnator.npefix.results"));
                } catch (IOException e) {
                    this.addStepError("Error while moving NPE fix results", e);
                }
                this.getInspector().getJobStatus().addFileToPush("repairnator.npefix.results");
                boolean effectivelyPatched = false;
                File patchDir = new File(this.getInspector().getRepoLocalPath() + "/repairnatorPatches");
                patchDir.mkdir();
                try {
                    JsonParser jsonParser = new JsonParser();
                    JsonElement root = jsonParser.parse(new FileReader(patchesFiles));
                    this.getInspector().getJobStatus().setNpeFixResults(root);
                    List<String> npePatches = new ArrayList<String>();
                    JsonArray executions = root.getAsJsonObject().getAsJsonArray("executions");
                    if (executions != null) {
                        for (JsonElement execution : executions) {
                            JsonObject result = execution.getAsJsonObject().getAsJsonObject("result");
                            boolean success = result.get("success").getAsBoolean() && execution.getAsJsonObject().has("decisions");
                            if (success) {
                                effectivelyPatched = true;
                                String testName = execution.getAsJsonObject().getAsJsonObject("test").get("name").getAsString();
                                long startDate = execution.getAsJsonObject().get("startDate").getAsLong();
                                String filename = "npefix_" + testName + "_" + startDate + ".patch";
                                String content = execution.getAsJsonObject().get("diff").getAsString();
                                File patchFile = new File(patchDir.getPath() + "/" + filename);
                                BufferedWriter patchWriter = new BufferedWriter(new FileWriter(patchFile));
                                patchWriter.write(content);
                                patchWriter.flush();
                                patchWriter.close();
                                npePatches.add(content);
                            }
                        }
                    }
                    this.getInspector().getJobStatus().setNpeFixPatches(npePatches);
                } catch (IOException e) {
                    this.addStepError("Error while parsing JSON patch files");
                }
                if (effectivelyPatched) {
                    this.setPipelineState(PipelineState.NPEFIX_PATCHED);
                    this.getInspector().getJobStatus().setHasBeenPatched(true);
                } else {
                    this.setPipelineState(PipelineState.NPEFIX_NOTPATCHED);
                }
            } else {
                this.addStepError("Error while getting the patch json file: no file found.");
                this.setPipelineState(PipelineState.NPEFIX_NOTPATCHED);
            }
        }
    } else {
        this.getLogger().info("No NPE found, this step will be skipped.");
        this.setPipelineState(PipelineState.NPEFIX_NOTPATCHED);
    }
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) JsonArray(com.google.gson.JsonArray) MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) JsonElement(com.google.gson.JsonElement) FileReader(java.io.FileReader) File(java.io.File) JsonParser(com.google.gson.JsonParser)

Example 7 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class ResolveDependency method businessExecute.

@Override
protected void businessExecute() {
    this.getLogger().debug("Resolve dependencies with maven (skip tests)...");
    this.getLogger().debug("Installing artifacts without test execution...");
    MavenHelper helper = new MavenHelper(this.getPom(), "dependency:resolve", null, this.getClass().getSimpleName(), this.inspector, true);
    int result = MavenHelper.MAVEN_ERROR;
    try {
        result = helper.run();
    } catch (InterruptedException e) {
        this.addStepError("Error while executing Maven goal", e);
    }
    if (result == MavenHelper.MAVEN_SUCCESS) {
        this.setPipelineState(PipelineState.DEPENDENCY_RESOLVED);
    } else {
        this.getLogger().warn("Repository " + this.inspector.getRepoSlug() + " may have unresolvable dependencies.");
        this.setPipelineState(PipelineState.DEPENDENCY_UNRESOLVABLE);
    }
}
Also used : MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper)

Aggregations

MavenHelper (fr.inria.spirals.repairnator.process.maven.MavenHelper)7 File (java.io.File)4 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)2 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 MavenFilterTestOutputHandler (fr.inria.spirals.repairnator.process.maven.output.MavenFilterTestOutputHandler)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1