Search in sources :

Example 21 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class InspectorSerializer4Bears method serializeAsJson.

private JsonElement serializeAsJson(ProjectInspector inspector) {
    JobStatus jobStatus = inspector.getJobStatus();
    BuildToBeInspected buildToBeInspected = inspector.getBuildToBeInspected();
    Build build = inspector.getPatchedBuild();
    Build previousBuild = inspector.getBuggyBuild();
    int previousBuildId = (previousBuild != null) ? previousBuild.getId() : -1;
    String state = this.getPrettyPrintState(inspector);
    String realState = (jobStatus.getPipelineState() != null) ? jobStatus.getPipelineState().name() : "null";
    String typeOfFailures = StringUtils.join(jobStatus.getMetrics().getFailureNames(), ",");
    String previousBuildSlug = (previousBuild != null) ? previousBuild.getRepository().getSlug() : "";
    String committerEmail = (build.getCommit().getCommitterEmail() != null) ? build.getCommit().getCommitterEmail() : "-";
    JsonObject result = new JsonObject();
    result.addProperty("buildId", build.getId());
    result.addProperty("previousBuildId", previousBuildId);
    result.addProperty("scannedBuildStatus", buildToBeInspected.getStatus().name());
    result.addProperty("status", state);
    result.addProperty("realStatus", realState);
    result.addProperty("checkoutType", inspector.getCheckoutType().name());
    result.addProperty("typeOfFailures", typeOfFailures);
    result.addProperty("repositoryName", build.getRepository().getSlug());
    result.addProperty("prNumber", build.getPullRequestNumber());
    result.addProperty("buildFinishedDateStr", Utils.formatCompleteDate(build.getFinishedAt()));
    this.addDate(result, "buildFinishedDate", build.getFinishedAt());
    result.addProperty("buildFinishedDay", Utils.formatOnlyDay(build.getFinishedAt()));
    result.addProperty("hostname", Utils.getHostname());
    result.addProperty("buildReproductionDateStr", Utils.formatCompleteDate(new Date()));
    this.addDate(result, "buildReproductionDate", new Date());
    result.addProperty("buildTravisUrl", Utils.getTravisUrl(build.getId(), build.getRepository().getSlug()));
    result.addProperty("previousBuildTravisUrl", Utils.getTravisUrl(previousBuildId, previousBuildSlug));
    result.addProperty("committerEmail", committerEmail);
    result.addProperty("runId", buildToBeInspected.getRunId());
    return result;
}
Also used : JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) Build(fr.inria.jtravis.entities.Build) JsonObject(com.google.gson.JsonObject) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Date(java.util.Date)

Example 22 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class InspectorSerializer4Bears method serializeAsList.

private List<Object> serializeAsList(ProjectInspector inspector) {
    JobStatus jobStatus = inspector.getJobStatus();
    BuildToBeInspected buildToBeInspected = inspector.getBuildToBeInspected();
    Build build = inspector.getPatchedBuild();
    Build previousBuild = inspector.getBuggyBuild();
    int previousBuildId = (previousBuild != null) ? previousBuild.getId() : -1;
    String state = this.getPrettyPrintState(inspector);
    String realState = (jobStatus.getPipelineState() != null) ? jobStatus.getPipelineState().name() : "null";
    String typeOfFailures = StringUtils.join(jobStatus.getMetrics().getFailureNames(), ",") + "";
    String previousBuildSlug = (previousBuild != null) ? previousBuild.getRepository().getSlug() : "";
    String committerEmail = (build.getCommit().getCommitterEmail() != null) ? build.getCommit().getCommitterEmail() : "-";
    List<Object> dataCol = new ArrayList<Object>();
    dataCol.add(build.getId() + "");
    dataCol.add(previousBuildId + "");
    dataCol.add(buildToBeInspected.getStatus().name());
    dataCol.add(state);
    dataCol.add(realState);
    dataCol.add(inspector.getCheckoutType().name());
    dataCol.add(typeOfFailures);
    dataCol.add(build.getRepository().getSlug());
    dataCol.add(build.getPullRequestNumber() + "");
    dataCol.add(Utils.formatCompleteDate(build.getFinishedAt()));
    dataCol.add(Utils.formatOnlyDay(build.getFinishedAt()));
    dataCol.add(Utils.getHostname());
    dataCol.add(Utils.formatCompleteDate(new Date()));
    dataCol.add(Utils.getTravisUrl(build.getId(), build.getRepository().getSlug()));
    dataCol.add(Utils.getTravisUrl(previousBuildId, previousBuildSlug));
    dataCol.add(committerEmail);
    dataCol.add(buildToBeInspected.getRunId());
    return dataCol;
}
Also used : JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) Build(fr.inria.jtravis.entities.Build) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Date(java.util.Date)

Example 23 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus 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)

Example 24 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class ErrorNotifier method observe.

@Override
public void observe(ProjectInspector inspector) {
    JobStatus status = inspector.getJobStatus();
    String subject = "URGENT! Error on buggy build " + inspector.getBuggyBuild().getId() + " on machine " + Utils.getHostname();
    String message = "The following error has been encountered: ";
    if (status.getFatalError() != null) {
        message += "\n" + status.getFatalError().toString();
    }
    this.notifyEngines(subject, message);
}
Also used : JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus)

Example 25 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class GitHelper method addAndCommitRepairnatorLogAndProperties.

public boolean addAndCommitRepairnatorLogAndProperties(JobStatus status, Git git, String commitMsg) {
    if (!RepairnatorConfig.getInstance().isPush()) {
        return false;
    }
    try {
        Status gitStatus = git.status().call();
        if (!gitStatus.isClean()) {
            this.getLogger().debug("Commit the logs and properties files");
            List<String> filesChanged = new ArrayList<>();
            filesChanged.addAll(gitStatus.getUncommittedChanges());
            filesChanged.addAll(gitStatus.getUntracked());
            filesChanged.addAll(gitStatus.getUntrackedFolders());
            List<String> filesToAdd = new ArrayList<>(status.getCreatedFilesToPush());
            List<String> filesToCheckout = new ArrayList<>();
            for (String fileName : filesChanged) {
                if (!fileName.contains("repairnator")) {
                    filesToCheckout.add(fileName);
                } else {
                    filesToAdd.add(fileName);
                }
            }
            if (filesToAdd.isEmpty()) {
                this.getLogger().info("No repairnator properties or log file to commit.");
                return false;
            }
            if (!filesToCheckout.isEmpty()) {
                this.getLogger().debug("Checkout " + filesToCheckout.size() + " files.");
                this.getLogger().info("Exec following command: git checkout -- " + StringUtils.join(filesToCheckout, " "));
                ProcessBuilder processBuilder = new ProcessBuilder("git", "checkout", "--", StringUtils.join(filesToCheckout, " ")).directory(git.getRepository().getDirectory().getParentFile()).inheritIO();
                try {
                    Process p = processBuilder.start();
                    p.waitFor();
                } catch (InterruptedException | IOException e) {
                    this.getLogger().error("Error while executing git command to checkout files: " + e);
                    return false;
                }
            // git.checkout().addPaths(filesToCheckout).call();
            }
            this.getLogger().info(filesToAdd.size() + " repairnators logs and/or properties file to commit.");
            for (String fileToAdd : filesToAdd) {
                // add force is not supported by JGit...
                ProcessBuilder processBuilder = new ProcessBuilder("git", "add", "-f", fileToAdd).directory(git.getRepository().getDirectory().getParentFile()).inheritIO();
                try {
                    Process p = processBuilder.start();
                    p.waitFor();
                } catch (InterruptedException | IOException e) {
                    this.getLogger().error("Error while executing git command to add files: " + e);
                    return false;
                }
            }
            PersonIdent personIdent = new PersonIdent("Luc Esape", "luc.esape@gmail.com");
            git.commit().setMessage("repairnator: add log and properties \n" + commitMsg).setCommitter(personIdent).setAuthor(personIdent).call();
            this.nbCommits++;
            return true;
        } else {
            return false;
        }
    } catch (GitAPIException e) {
        this.getLogger().error("Error while committing repairnator properties/log files ", e);
        return false;
    }
}
Also used : Status(org.eclipse.jgit.api.Status) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)48 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)39 Test (org.junit.Test)38 Build (fr.inria.jtravis.entities.Build)37 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)35 File (java.io.File)34 Path (java.nio.file.Path)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)22 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)10 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)8 Git (org.eclipse.jgit.api.Git)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)5 ArrayList (java.util.ArrayList)5 JsonObject (com.google.gson.JsonObject)4 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)4 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)4 Date (java.util.Date)4 ScannedBuildStatus (fr.inria.spirals.repairnator.states.ScannedBuildStatus)3