use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class TestInitRepoToPush method testInitRepoShouldRemoveNotificationInTravisYML.
@Test
public void testInitRepoShouldRemoveNotificationInTravisYML() throws IOException {
int buildId = 331637757;
RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
repairnatorConfig.setClean(false);
repairnatorConfig.setPush(true);
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
ProjectInspector inspector = mock(ProjectInspector.class);
when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
when(inspector.getBuggyBuild()).thenReturn(build);
when(inspector.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
cloneStep.execute();
assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
File bak = new File(tmpDir.getAbsolutePath() + "/repotopush/bak.travis.yml");
File travis = new File(tmpDir.getAbsolutePath() + "/repotopush/.travis.yml");
assertTrue(bak.exists());
assertTrue(travis.exists());
boolean detected = false;
List<String> lines = Files.readAllLines(travis.toPath());
for (String l : lines) {
if (l.contains("notification")) {
assertTrue(l.trim().startsWith("#"));
detected = true;
}
if (l.contains("script")) {
assertFalse(l.trim().startsWith("#"));
}
}
assertTrue(detected);
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class TestInitRepoToPush method testInitRepoToPushSimpleCase.
@Test
public void testInitRepoToPushSimpleCase() throws IOException, GitAPIException, RepairnatorConfigException {
// surli/failingProject build
int buildId = 207924136;
RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
repairnatorConfig.setClean(false);
repairnatorConfig.setPush(true);
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
ProjectInspector inspector = mock(ProjectInspector.class);
when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
when(inspector.getBuggyBuild()).thenReturn(build);
when(inspector.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
cloneStep.execute();
assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
Git gitDir = Git.open(new File(tmpDir, "repotopush"));
Iterable<RevCommit> logs = gitDir.log().call();
Iterator<RevCommit> iterator = logs.iterator();
assertThat(iterator.hasNext(), is(true));
RevCommit commit = iterator.next();
assertThat(commit.getShortMessage(), containsString("End of the repairnator process"));
RevCommit firstCommit = iterator.next();
assertThat(firstCommit.getShortMessage(), containsString("Bug commit"));
assertThat(iterator.hasNext(), is(false));
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class Launcher method processOutput.
private void processOutput(List<BuildToBeInspected> listOfBuilds) {
if (this.config.isSerializeJson()) {
String outputPath = this.config.getOutputPath();
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath));
for (BuildToBeInspected buildToBeInspected : listOfBuilds) {
if (this.config.getLauncherMode() == LauncherMode.REPAIR) {
writer.write(buildToBeInspected.getBuggyBuild().getId() + "");
} else {
writer.write(buildToBeInspected.getBuggyBuild().getId() + Utils.COMMA + buildToBeInspected.getPatchedBuild().getId());
}
writer.newLine();
writer.flush();
}
writer.close();
return;
} catch (IOException e) {
LOGGER.error("Error while writing file " + outputPath + ". The content will be printed in the standard output.", e);
}
}
for (BuildToBeInspected buildToBeInspected : listOfBuilds) {
System.out.println(buildToBeInspected.getBuggyBuild().getId());
}
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class Launcher method runScanner.
private List<BuildToBeInspected> runScanner() throws IOException {
Launcher.LOGGER.info("Start to scan projects in travis...");
ProjectScanner scanner = new ProjectScanner(this.config.getLookFromDate(), this.config.getLookToDate(), this.config.getRunId());
List<BuildToBeInspected> buildsToBeInspected = scanner.getListOfBuildsToBeInspectedFromProjects(this.config.getInputPath());
ProcessSerializer scannerSerializer;
if (this.config.getLauncherMode() == LauncherMode.REPAIR) {
scannerSerializer = new ScannerSerializer(this.engines, scanner);
} else {
scannerSerializer = new ScannerSerializer4Bears(this.engines, scanner);
ScannerDetailedDataSerializer scannerDetailedDataSerializer = new ScannerDetailedDataSerializer(this.engines, buildsToBeInspected);
scannerDetailedDataSerializer.serialize();
}
scannerSerializer.serialize();
if (buildsToBeInspected.isEmpty()) {
Launcher.LOGGER.info("No build has been found (" + scanner.getTotalScannedBuilds() + " scanned builds.)");
}
return buildsToBeInspected;
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class ProjectScanner method getListOfBuildsFromRepo.
private List<BuildToBeInspected> getListOfBuildsFromRepo(List<Repository> repos) {
List<BuildToBeInspected> buildsToBeInspected = new ArrayList<BuildToBeInspected>();
for (Repository repo : repos) {
List<Build> repoBuilds = BuildHelper.getBuildsFromRepositoryInTimeInterval(repo, this.lookFromDate, this.lookToDate);
for (Build build : repoBuilds) {
this.totalScannedBuilds++;
BuildToBeInspected buildToBeInspected = getBuildToBeInspected(build);
if (buildToBeInspected != null) {
buildsToBeInspected.add(buildToBeInspected);
}
}
}
return buildsToBeInspected;
}
Aggregations