public void initPatchDir() { this.patchDir = new File(this.getInspector().getRepoLocalPath()+"/"+this.getToolResultsFolderName()); this.patchDir.mkdirs(); }
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); } }
private void testPomLocation() { this.pomLocationTested = true; File defaultPomFile = new File(this.inspector.getRepoLocalPath() + File.separator + Utils.POM_FILE); this.getLogger().info("The pom.xml file is not at the root of the repository. Start to search it in folders..."); File rootRepo = new File(this.inspector.getRepoLocalPath());
protected void cleanMavenArtifactsAndLocalRepo() { if (this.inspector.getM2LocalPath() != null) { try { FileUtils.deleteDirectory(this.inspector.getM2LocalPath()); } catch (IOException e) { getLogger().warn( "Error while deleting the M2 local directory (" + this.inspector.getM2LocalPath() + "): " + e); } } File repoDir = new File(this.inspector.getRepoLocalPath(), Utils.REMOTE_REPO_EXT); if (repoDir.exists() && this.getConfig().isClean()) { try { FileUtils.deleteDirectory(this.inspector.getRepoLocalPath()); } catch (IOException e) { getLogger().warn("Error while deleting the workspace directory (" + this.inspector.getRepoLocalPath() + "): " + e); } } }
private void computeMetricsOnCompleteRepo() { this.getLogger().debug("Compute the line of code of the project"); ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh","-c",COMPUTE_TOTAL_CLOC) .directory(new File(this.getInspector().getRepoLocalPath())); try { Process p = processBuilder.start(); BufferedReader stdin = new BufferedReader(new InputStreamReader(p.getInputStream())); p.waitFor(); this.getLogger().debug("Get result from cloc process..."); String processReturn = ""; String line; while (stdin.ready() && (line = stdin.readLine()) != null) { processReturn += line; } Gson gson = new GsonBuilder().create(); JsonObject json = gson.fromJson(processReturn, JsonObject.class); int numberLines = 0; if (json != null && json.getAsJsonObject("Java") != null) { JsonObject java = json.getAsJsonObject("Java"); if (java.getAsJsonPrimitive("code") != null) { numberLines = java.getAsJsonPrimitive("code").getAsInt(); } } this.getInspector().getJobStatus().getProperties().getProjectMetrics().setNumberLines(numberLines); } catch (IOException | InterruptedException e) { this.getLogger().error("Error while computing metrics on source code of the whole repo.", e); } }
@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 StepStatus recordResults() { File nopolLog = new File(System.getProperty("user.dir"), "debug.log"); if (nopolLog.exists()) { String nopolDestName = "repairnator.nopol.log"; File nopolDest = new File(this.getInspector().getRepoLocalPath(), nopolDestName); try { Files.move(nopolLog.toPath(), nopolDest.toPath()); this.getInspector().getJobStatus().addFileToPush(nopolDestName); } catch (IOException e) { getLogger().error("Error while renaming nopol log", e); } } this.recordPatches(repairPatches); this.recordToolDiagnostic(toolDiag); try { FileHelper.deleteFile(patchDir); } catch (IOException e) { getLogger().error("Error while removing the temp folder containing Nopol output", e); } if (!patchCreated) { this.addStepError("No patch has been generated by Nopol. Look at the trace to get more information."); return StepStatus.buildSkipped(this,"No patch has been found."); } return StepStatus.buildSuccess(this); }
FileUtils.copyFile(patchesFiles, new File(this.getInspector().getRepoLocalPath()+"/repairnator.npefix.results")); } catch (IOException e) { this.addStepError("Error while moving NPE fix results", e); File patchDir = new File(this.getInspector().getRepoLocalPath()+"/repairnatorPatches");
astorArgs.add("timezone:Europe/Paris:maxnumbersolutions:3:limitbysuspicious:false:maxmodificationpoints:1000:javacompliancelevel:8:logfilepath:"+this.getInspector().getRepoLocalPath()+"/repairnator.astor." + this.getAstorMode() + ".log"); FileUtils.copyFile(jsonResultFile, new File(this.getInspector().getRepoLocalPath()+"/repairnator.astor." + this.getAstorMode() + ".results.json")); } catch (IOException e) { this.addStepError("Error while moving " + this.getRepairToolName() + " JSON results", e);
@Override protected StepStatus businessExecute() { String repoSlug = this.build.getRepository().getSlug(); String repoRemotePath = Utils.getCompleteGithubRepoUrl(repoSlug); String repoLocalPath = this.getInspector().getRepoLocalPath(); try { this.getLogger().debug("Cloning repository " + repoSlug + " in the following directory: " + repoLocalPath); Git.cloneRepository().setCloneSubmodules(true).setURI(repoRemotePath).setDirectory(new File(repoLocalPath)).call(); return StepStatus.buildSuccess(this); } catch (Exception e) { this.addStepError("Repository " + repoSlug + " cannot be cloned.", e); return StepStatus.buildError(this, PipelineState.NOTCLONABLE); } }
@Override protected StepStatus businessExecute() { this.getLogger().debug("Computing the test directory ..."); super.setComputeDirType(ComputeDirType.COMPUTE_TEST_DIR); super.setRootDirPath(this.getInspector().getRepoLocalPath()); StepStatus superStepStatus = super.businessExecute(); if (superStepStatus.isSuccess()) { File[] testDirs = super.getResultDirs(); this.computeMetricsOnTestDirs(testDirs); this.getInspector().getJobStatus().setTestDir(testDirs); return StepStatus.buildSuccess(this); } else { return StepStatus.buildError(this, PipelineState.TESTDIRNOTCOMPUTED); } }
nopolContext.setOutputFolder(patchDir.getAbsolutePath()); String repoLocalPath = this.getInspector().getRepoLocalPath(); if (repoLocalPath.startsWith("./")) { repoLocalPath = repoLocalPath.substring(2);
.directory(new File(this.getInspector().getRepoLocalPath())); return StepStatus.buildSuccess(this); } catch (IOException e) { this.addStepError("Error while reading git directory at the following location: " + this.getInspector().getRepoLocalPath() + ".", e); } catch (URISyntaxException e) { this.addStepError("Error while setting remote repository with the following URL: " + remoteRepo + ".", e);
Git git = Git.open(new File(this.getInspector().getRepoLocalPath())); int status = GitHelper.gitCreateNewBranchAndCheckoutIt(this.getInspector().getRepoLocalPath(), branchName); if (status == 0) { ProcessBuilder processBuilder = new ProcessBuilder("git", "apply", patch.getAbsolutePath()) .directory(new File(this.getInspector().getRepoLocalPath())).inheritIO();
@Override protected StepStatus businessExecute() { this.getLogger().debug("Computing the source directory ..."); String dirPath = (this.allModules) ? this.getInspector().getRepoLocalPath() : this.getInspector().getJobStatus().getFailingModulePath(); super.setComputeDirType(ComputeDirType.COMPUTE_SOURCE_DIR); super.setRootDirPath(dirPath); super.setAllModules(this.allModules); StepStatus superStepStatus = super.businessExecute(); if (superStepStatus.isSuccess()) { File[] sourceDirs = super.getResultDirs(); if (allModules) { this.computeMetricsOnSourceDirs(sourceDirs); this.computeMetricsOnCompleteRepo(); } this.getInspector().getJobStatus().setRepairSourceDir(sourceDirs); return StepStatus.buildSuccess(this); } else { this.getInspector().getJobStatus().setRepairSourceDir(null); return StepStatus.buildError(this, PipelineState.SOURCEDIRNOTCOMPUTED); } }
if (this.getConfig().isPush()) { File sourceDir = new File(this.getInspector().getRepoLocalPath()); File targetDir = new File(this.getInspector().getRepoToPushLocalPath());
try { git = Git.open(new File(this.getInspector().getRepoLocalPath())); GitHelper gitHelper = this.getInspector().getGitHelper(); Build build;