use of fr.inria.jtravis.entities.Build 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.jtravis.entities.Build 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.jtravis.entities.Build in project repairnator by Spirals-Team.
the class BuildRunner method submitBuild.
public void submitBuild(Build build) {
if (this.limitDateNextRetrieveDockerImage.before(new Date())) {
this.refreshDockerImage();
}
if (getRunning() < this.nbThreads) {
LOGGER.info("Build (id: " + build.getId() + ") immediately submitted for running.");
this.executorService.submit(this.submitBuild(this.dockerImageId, new InputBuildId(build.getId())));
} else {
LOGGER.info("All threads currently running (Limit: " + this.nbThreads + "). Add build (id: " + build.getId() + ") to list");
if (this.waitingBuilds.size() == this.nbThreads) {
Build b = this.waitingBuilds.removeLast();
LOGGER.debug("Remove oldest build (id: " + b.getId() + ")");
}
this.waitingBuilds.push(build);
}
}
use of fr.inria.jtravis.entities.Build in project repairnator by Spirals-Team.
the class RTScanner method isRepositoryInteresting.
public boolean isRepositoryInteresting(int repositoryId) {
if (this.blackListedRepository.contains(repositoryId)) {
// LOGGER.debug("Repo already blacklisted (id: "+repositoryId+")");
return false;
}
if (this.whiteListedRepository.contains(repositoryId)) {
// LOGGER.debug("Repo already whitelisted (id: "+repositoryId+")");
return true;
}
if (this.tempBlackList.containsKey(repositoryId)) {
if (this.tempBlackList.get(repositoryId).after(new Date())) {
return false;
} else {
this.tempBlackList.remove(repositoryId);
}
}
Repository repository = RepositoryHelper.getRepositoryFromId(repositoryId);
if (repository != null) {
Build masterBuild = BuildHelper.getLastSuccessfulBuildFromMaster(repository, false, 5);
if (masterBuild == null) {
this.addInTempBlackList(repository, "No successful build found.");
return false;
} else {
if (masterBuild.getConfig().getLanguage() == null || !masterBuild.getConfig().getLanguage().equals("java")) {
this.addInBlacklistRepository(repository, BlacklistedSerializer.Reason.OTHER_LANGUAGE, masterBuild.getConfig().getLanguage());
return false;
}
if (masterBuild.getBuildTool() == BuildTool.GRADLE) {
this.addInBlacklistRepository(repository, BlacklistedSerializer.Reason.USE_GRADLE, "");
return false;
} else if (masterBuild.getBuildTool() == BuildTool.UNKNOWN) {
this.addInBlacklistRepository(repository, BlacklistedSerializer.Reason.UNKNOWN_BUILD_TOOL, "");
return false;
}
if (!masterBuild.getJobs().isEmpty()) {
Job firstJob = masterBuild.getJobs().get(0);
Log jobLog = firstJob.getLog();
if (jobLog.getTestsInformation() != null && jobLog.getTestsInformation().getRunning() > 0) {
LOGGER.info("Tests has been found in repository " + repository.getSlug() + " (id: " + repositoryId + ") build (id: " + masterBuild.getId() + "). The repo is now whitelisted.");
this.addInWhitelistRepository(repository);
return true;
} else {
this.addInTempBlackList(repository, "No test found");
}
} else {
LOGGER.info("No job found in repository " + repository.getSlug() + " (id: " + repositoryId + ") build (id: " + masterBuild.getId() + "). It is not considered right now.");
}
}
} else {
LOGGER.info("Repository not found with the following id: " + repositoryId + " it will be temporary blacklisted");
Date expirationDate = new Date(new Date().toInstant().plusSeconds(DURATION_IN_TEMP_BLACKLIST).toEpochMilli());
this.tempBlackList.put(repositoryId, expirationDate);
}
return false;
}
use of fr.inria.jtravis.entities.Build in project repairnator by Spirals-Team.
the class TestProjectInspector method testRepairingWithNPEFix.
@Test
public void testRepairingWithNPEFix() throws IOException, GitAPIException {
// surli/failingProject npe
int buildId = 253130137;
Path tmpDirPath = Files.createTempDirectory("test_complete_npe");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
Build failingBuild = BuildHelper.getBuildFromId(buildId, null);
BuildToBeInspected buildToBeInspected = new BuildToBeInspected(failingBuild, null, ScannedBuildStatus.ONLY_FAIL, "testnpe");
List<AbstractDataSerializer> serializers = new ArrayList<>();
List<AbstractNotifier> notifiers = new ArrayList<>();
List<SerializerEngine> serializerEngines = new ArrayList<>();
SerializerEngine serializerEngine = mock(SerializerEngine.class);
serializerEngines.add(serializerEngine);
List<NotifierEngine> notifierEngines = new ArrayList<>();
NotifierEngine notifierEngine = mock(NotifierEngine.class);
notifierEngines.add(notifierEngine);
serializers.add(new InspectorSerializer(serializerEngines));
serializers.add(new NopolSerializer(serializerEngines));
notifiers.add(new PatchNotifier(notifierEngines));
RepairnatorConfig config = RepairnatorConfig.getInstance();
config.setLauncherMode(LauncherMode.REPAIR);
ProjectInspector inspector = new ProjectInspector(buildToBeInspected, tmpDir.getAbsolutePath(), serializers, notifiers);
inspector.run();
JobStatus jobStatus = inspector.getJobStatus();
assertThat(jobStatus.getAstorStatus(), is(AstorOutputStatus.MAX_GENERATION));
assertThat(jobStatus.getPipelineState(), is(PipelineState.NOPOL_PATCHED));
assertThat(jobStatus.getPushState(), is(PushState.REPAIR_INFO_COMMITTED));
assertThat(jobStatus.getFailureLocations().size(), is(1));
assertThat(jobStatus.getMetrics().getFailureNames().size(), is(1));
assertThat(jobStatus.isHasBeenPatched(), is(true));
assertThat(jobStatus.getNpeFixPatches().size(), is(6));
// Nopol and NPEFix
verify(notifierEngine, times(2)).notify(anyString(), anyString());
verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.INSPECTOR));
verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.NOPOL));
Git gitDir = Git.open(new File(inspector.getRepoToPushLocalPath()));
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"));
commit = iterator.next();
assertThat(commit.getShortMessage(), containsString("Automatic repair"));
commit = iterator.next();
assertThat(commit.getShortMessage(), containsString("Bug commit"));
assertThat(iterator.hasNext(), is(false));
}
Aggregations