Search in sources :

Example 1 with AstorMain

use of fr.inria.main.evolution.AstorMain in project repairnator by Spirals-Team.

the class AstorRepair method businessExecute.

@Override
protected void businessExecute() {
    this.getLogger().info("Start to repair using Astor");
    JobStatus jobStatus = this.getInspector().getJobStatus();
    List<String> astorPatches = new ArrayList<>();
    List<URL> classPath = this.inspector.getJobStatus().getRepairClassPath();
    File[] sources = this.inspector.getJobStatus().getRepairSourceDir();
    if (classPath != null && sources != null) {
        List<String> dependencies = new ArrayList<>();
        for (URL url : jobStatus.getRepairClassPath()) {
            if (url.getFile().endsWith(".jar")) {
                dependencies.add(url.getPath());
            }
        }
        final List<String> astorArgs = new ArrayList<>();
        astorArgs.add("-dependencies");
        astorArgs.add(StringUtils.join(dependencies, ":"));
        astorArgs.add("-mode");
        astorArgs.add("jgenprog");
        astorArgs.add("-location");
        astorArgs.add(jobStatus.getFailingModulePath());
        String relativeSourcePath = new File(jobStatus.getFailingModulePath()).toURI().relativize(jobStatus.getRepairSourceDir()[0].toURI()).getPath();
        astorArgs.add("-srcjavafolder");
        astorArgs.add(relativeSourcePath);
        astorArgs.add("-stopfirst");
        astorArgs.add("true");
        astorArgs.add("-population");
        astorArgs.add("1");
        // astorArgs.add("-loglevel");
        // astorArgs.add("DEBUG");
        astorArgs.add("-parameters");
        astorArgs.add("timezone:Europe/Paris:maxnumbersolutions:3:limitbysuspicious:false:maxmodificationpoints:1000:javacompliancelevel:8:logfilepath:" + this.getInspector().getRepoLocalPath() + "/repairnator.astor.log");
        astorArgs.add("-maxtime");
        astorArgs.add(MAX_TIME_EXECUTION + "");
        astorArgs.add("-seed");
        astorArgs.add("1");
        final AstorMain astorMain = new AstorMain();
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        final Future<AstorOutputStatus> astorExecution = executor.submit(new Callable<AstorOutputStatus>() {

            @Override
            public AstorOutputStatus call() throws Exception {
                AstorOutputStatus status = null;
                try {
                    astorMain.execute(astorArgs.toArray(new String[0]));
                    if (astorMain.getEngine() != null) {
                        status = astorMain.getEngine().getOutputStatus();
                    } else {
                        status = AstorOutputStatus.ERROR;
                    }
                } catch (SpoonException e) {
                    status = AstorOutputStatus.ERROR;
                    addStepError("Got SpoonException while running Astor", e);
                } catch (RuntimeException e) {
                    addStepError("Got runtime exception while running Astor", e);
                    status = AstorOutputStatus.ERROR;
                }
                return status;
            }
        });
        AstorOutputStatus status = null;
        try {
            executor.shutdown();
            status = astorExecution.get(MAX_TIME_EXECUTION, TimeUnit.MINUTES);
            if (astorMain.getEngine() != null) {
                List<ProgramVariant> solutions = astorMain.getEngine().getSolutions();
                if (solutions != null) {
                    for (ProgramVariant pv : solutions) {
                        if (pv.isSolution()) {
                            astorPatches.add(pv.getPatchDiff());
                        }
                    }
                }
            }
        } catch (Exception e) {
            status = AstorOutputStatus.ERROR;
            this.addStepError("Error while executing astor with args: " + StringUtils.join(astorArgs, ","), e);
        }
        jobStatus.addFileToPush("repairnator.astor.log");
        jobStatus.setAstorPatches(astorPatches);
        jobStatus.setAstorStatus(status);
        String jsonpath;
        try {
            jsonpath = astorMain.getEngine().getProjectFacade().getProperties().getWorkingDirRoot() + File.separator + ConfigurationProperties.getProperty("jsonoutputname") + ".json";
        } catch (NullPointerException e) {
            jsonpath = null;
        }
        if (jsonpath != null) {
            File jsonResultFile = new File(jsonpath);
            if (jsonResultFile.exists()) {
                try {
                    FileUtils.copyFile(jsonResultFile, new File(this.getInspector().getRepoLocalPath() + "/repairnator.astor.results.json"));
                } catch (IOException e) {
                    this.addStepError("Error while moving astor JSON results", e);
                }
                JsonParser jsonParser = new JsonParser();
                try {
                    JsonElement root = jsonParser.parse(new FileReader(jsonResultFile));
                    this.getInspector().getJobStatus().setAstorResults(root);
                } catch (FileNotFoundException e) {
                    this.addStepError("Error while reading astor JSON results", e);
                }
                jobStatus.addFileToPush("repairnator.astor.results.json");
            }
        }
        if (astorPatches.isEmpty()) {
            this.setPipelineState(PipelineState.ASTOR_NOTPATCHED);
        } else {
            this.setPipelineState(PipelineState.ASTOR_PATCHED);
            this.getInspector().getJobStatus().setHasBeenPatched(true);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ProgramVariant(fr.inria.astor.core.entities.ProgramVariant) URL(java.net.URL) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) FileReader(java.io.FileReader) JsonParser(com.google.gson.JsonParser) SpoonException(spoon.SpoonException) IOException(java.io.IOException) AstorOutputStatus(fr.inria.main.AstorOutputStatus) SpoonException(spoon.SpoonException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AstorMain(fr.inria.main.evolution.AstorMain) JsonElement(com.google.gson.JsonElement) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File)

Aggregations

JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 ProgramVariant (fr.inria.astor.core.entities.ProgramVariant)1 AstorOutputStatus (fr.inria.main.AstorOutputStatus)1 AstorMain (fr.inria.main.evolution.AstorMain)1 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 SpoonException (spoon.SpoonException)1