public ProjectInspector(BuildToBeInspected buildToBeInspected, String workspace, List<AbstractDataSerializer> serializers, List<AbstractNotifier> notifiers) { this.buildToBeInspected = buildToBeInspected; this.workspace = workspace; this.repoLocalPath = workspace + File.separator + getRepoSlug() + File.separator + buildToBeInspected.getBuggyBuild().getId(); this.repoToPushLocalPath = repoLocalPath+"_topush"; this.m2LocalPath = new File(this.repoLocalPath + File.separator + ".m2").getAbsolutePath(); this.serializers = serializers; this.gitHelper = new GitHelper(); this.jobStatus = new JobStatus(repoLocalPath); this.notifiers = notifiers; this.checkoutType = CheckoutType.NO_CHECKOUT; this.steps = new ArrayList<>(); this.initProperties(); }
@Override protected StepStatus businessExecute() { this.getLogger().debug("Writing file with properties..."); String filePath; if (this.getConfig().getLauncherMode() == LauncherMode.REPAIR) { filePath = this.getInspector().getRepoLocalPath() + File.separator + PROPERTY_FILENAME; } else { filePath = this.getInspector().getRepoLocalPath() + File.separator + PROPERTY_FILENAME_BEARS; } Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Properties.class, new PropertiesSerializerAdapter()).create(); String jsonString = gson.toJson(this.getInspector().getJobStatus().getProperties()); File file = new File(filePath); try { if (!file.exists()) { file.createNewFile(); } OutputStreamWriter outputStream = new OutputStreamWriter(new FileOutputStream(file)); outputStream.write(jsonString); outputStream.flush(); outputStream.close(); this.getInspector().getJobStatus().addFileToPush(file.getName()); return StepStatus.buildSuccess(this); } catch (IOException e) { this.addStepError("An exception occurred when writing the following property file: " + file.getPath(), e); } return StepStatus.buildError(this, PipelineState.PROPERTY_FILE_NOT_WRITTEN); }
protected void setPushState(PushState pushState) { if (pushState != null) { this.inspector.getJobStatus().addPushState(pushState); if (this.nextStep != null) { this.nextStep.setPushState(pushState); } } }
List<RepairPatch> astorPatches = new ArrayList<>(); List<URL> classPath = this.getInspector().getJobStatus().getRepairClassPath(); File[] sources = this.getInspector().getJobStatus().getRepairSourceDir(); for (URL url : jobStatus.getRepairClassPath()) { if (url.getFile().endsWith(".jar")) { dependencies.add(url.getPath()); astorArgs.add(jobStatus.getFailingModulePath()); String relativeSourcePath = new File(jobStatus.getFailingModulePath()).toURI().relativize(jobStatus.getRepairSourceDir()[0].toURI()).getPath(); astorArgs.add("-srcjavafolder"); astorArgs.add(relativeSourcePath); jobStatus.addFileToPush("repairnator.astor." + this.getAstorMode() + ".log"); jobStatus.addFileToPush("repairnator.astor." + this.getAstorMode() + ".results.json"); return StepStatus.buildSkipped(this,"No patch found."); } else { this.getInspector().getJobStatus().setHasBeenPatched(true); this.recordPatches(astorPatches); return StepStatus.buildSuccess(this);
public void execute() { List<AbstractStep> steps = this.inspector.getSteps(); this.getLogger().debug("----------------------------------------------------------------------"); this.getLogger().debug("STEP "+ (steps.indexOf(this) + 1)+"/"+ steps.size() +": "+this.name); this.getLogger().debug("----------------------------------------------------------------------"); this.dateBegin = new Date(); this.stepStatus = this.businessExecute(); this.dateEnd = new Date(); this.getLogger().debug("STEP STATUS: "+this.stepStatus); this.getLogger().debug("STEP DURATION: "+getDuration()+"s"); this.inspector.getJobStatus().addStepDuration(this.name, getDuration()); this.inspector.getJobStatus().addFreeMemoryByStep(this.name, Runtime.getRuntime().freeMemory()); ReproductionBuggyBuild reproductionBuggyBuild = this.inspector.getJobStatus().getProperties().getReproductionBuggyBuild(); reproductionBuggyBuild.addStep(this); this.inspector.getJobStatus().addStepStatus(this.stepStatus); this.shouldStop = this.shouldStop || (this.isBlockingStep() && !this.stepStatus.isSuccess()); if (!this.shouldStop) { this.getLogger().debug("EXECUTE NEXT STEP"); this.executeNextStep(); } else { this.getLogger().debug("TERMINATE PIPELINE"); this.terminatePipeline(); } }
if (!this.getInspector().getJobStatus().isHasBeenForked()) { this.getLogger().info("The project has not been forked. The PR won't be created."); return; String forkedRepo = this.getInspector().getJobStatus().getForkURL(); String prURL = "https://github.com/" + this.getInspector().getRepoSlug() + "/pull/" + pullRequest.getNumber(); this.getLogger().info("Pull request created on: " + prURL); this.getInspector().getJobStatus().addPRCreated(prURL); } else { this.addStepError("Error while creating a dedicated branch for the patch.");
public void addStepError(String error, Throwable exception) { getLogger().error(error, exception); this.inspector.getJobStatus().addStepError(this.name, error + " Original msg: " + exception.getMessage()); }
return StepStatus.buildSkipped(this,"Error while running maven goal for NPEFix."); } else { Collection<File> files = FileUtils.listFiles(new File(this.getInspector().getJobStatus().getPomDirPath()+"/target/npefix"), new String[] { "json"}, false); if (!files.isEmpty()) { this.getInspector().getJobStatus().addFileToPush("repairnator.npefix.results");
protected void recordPatches(List<RepairPatch> patchList) { this.getInspector().getJobStatus().addPatches(this.getRepairToolName(), patchList); if (!patchList.isEmpty()) { this.getInspector().getJobStatus().setHasBeenPatched(true); List<File> serializedPatches = null; try { serializedPatches = this.serializePatches(patchList); } catch (IOException e) { this.addStepError("Error while serializing patches", e); } if (this.getConfig().isCreatePR()) { if (serializedPatches != null) { try { this.createPullRequest(serializedPatches, MAX_PATCH_PER_TOOL); } catch (IOException | GitAPIException | URISyntaxException e) { this.addStepError("Error while creating the PR", e); } } else { this.addStepError("No file has been serialized, so no PR will be created"); } } this.notify(patchList); } }
private void initFileWriter() { String filename = "repairnator.maven." + name.toLowerCase() + ".log"; String filePath = inspector.getRepoLocalPath() + "/" + filename; inspector.getJobStatus().addFileToPush(filename); try { this.fileWriter = new FileWriter(filePath); } catch (IOException e) { this.getLogger().error("Cannot create file writer for file " + filePath + ".", e); } }
cloneRepo.execute(); } catch (Exception e) { this.jobStatus.addStepError("Unknown", e.getMessage()); this.logger.error("Exception catch while executing steps: ", e); this.jobStatus.setFatalError(e);
protected void recordToolDiagnostic(JsonElement element) { this.getInspector().getJobStatus().addToolDiagnostic(this.getRepairToolName(), element); }
@Override public void execute() { if (this.getConfig().getRepairTools().contains(this.getRepairToolName())) { super.execute(); } else { this.getLogger().warn("Skipping repair step "+this.getRepairToolName()); this.getInspector().getJobStatus().addStepStatus(StepStatus.buildSkipped(this,"Not configured to run.")); super.executeNextStep(); } }
public void addStepError(String error) { getLogger().error(error); this.inspector.getJobStatus().addStepError(this.name, error); }
private void addJarFilesToClassPath(String classpathFilePath) { try { BufferedReader reader = new BufferedReader(new FileReader(new File(classpathFilePath))); String classpathLine = reader.readLine(); if (classpathLine != null && !classpathLine.isEmpty()) { String[] allJars = classpathLine.split(":"); for (String jar : allJars) { File jarFile = new File(jar); this.addFileToClassPath(jarFile); } this.getInspector().getJobStatus().addFileToPush(CLASSPATH_FILENAME); } else { this.addStepError("The classpath file is empty."); } } catch (IOException e) { this.addStepError("Problem while getting classpath file.", e); } }
@Override public void consumeLine(String s) { super.consumeLine(s); this.getLogger().debug(s); if (s.contains("[ERROR]")) { this.inspector.getJobStatus().addStepError(name, s); } } }
private List<File> serializePatches(List<RepairPatch> patchList) throws IOException { File parentDirectory = new File(this.getInspector().getRepoToPushLocalPath(), DEFAULT_DIR_PATCHES); if (!parentDirectory.exists()) { parentDirectory.mkdirs(); } File toolDirectory = new File(parentDirectory, this.getRepairToolName()); toolDirectory.mkdirs(); List<File> serializedPatches = new ArrayList<>(); int i = 1; String dirPath = DEFAULT_DIR_PATCHES + "/" + this.getRepairToolName() + "/"; for (RepairPatch repairPatch : patchList) { File patchFile = new File(toolDirectory, "patch_" + (i++) + ".patch"); BufferedWriter bufferedWriter = Files.newBufferedWriter(patchFile.toPath()); bufferedWriter.write(repairPatch.getDiff()); bufferedWriter.close(); this.getInspector().getJobStatus().addFileToPush(dirPath + patchFile.getName()); serializedPatches.add(patchFile); } return serializedPatches; }
@Override public void consumeLine(String s) { super.consumeLine(s); this.getLogger().error(s); this.inspector.getJobStatus().addStepError(name, s); } }
step.getInspector().getJobStatus().addFileToPush(Utils.TRAVIS_FILE); step.getInspector().getJobStatus().addFileToPush("bak" + Utils.TRAVIS_FILE);
@Override public void run() { InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(new File(this.mavenHelper.getPomFile())); request.setGoals(Arrays.asList(this.mavenHelper.getGoal())); request.setProperties(this.mavenHelper.getProperties()); request.setBatchMode(true); Invoker invoker = new DefaultInvoker(); if (this.mavenHelper.getErrorHandler() != null) { invoker.setErrorHandler(this.mavenHelper.getErrorHandler()); } invoker.setOutputHandler(this.mavenHelper.getOutputHandler()); try { InvocationResult result = invoker.execute(request); this.exitCode = result.getExitCode(); } catch (MavenInvocationException e) { this.logger.error("Error while executing goal " + this.mavenHelper.getGoal() + " on the following pom file: " + this.mavenHelper.getPomFile() + ". Properties: " + this.mavenHelper.getProperties()); this.logger.debug(e.getMessage()); this.mavenHelper.getInspector().getJobStatus().addStepError(this.mavenHelper.getName(), e.getMessage()); this.exitCode = MavenHelper.MAVEN_ERROR; } }