Search in sources :

Example 1 with RepairnatorConfig

use of fr.inria.spirals.repairnator.config.RepairnatorConfig 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);
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) Test(org.junit.Test)

Example 2 with RepairnatorConfig

use of fr.inria.spirals.repairnator.config.RepairnatorConfig 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));
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with RepairnatorConfig

use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.

the class LauncherUtils method initSpreadsheetSerializerEngineWithAccessToken.

public static SerializerEngine initSpreadsheetSerializerEngineWithAccessToken(Logger logger) {
    RepairnatorConfig config = RepairnatorConfig.getInstance();
    if (config.getSpreadsheetId() != null && config.getGoogleAccessToken() != null) {
        logger.info("Initialize Google spreadsheet serializer engine.");
        GoogleSpreadSheetFactory.setSpreadsheetId(config.getSpreadsheetId());
        try {
            if (GoogleSpreadSheetFactory.initWithAccessToken(config.getGoogleAccessToken())) {
                return new GoogleSpreadsheetSerializerEngine();
            } else {
                logger.error("Error while initializing Google Spreadsheet, no information will be serialized in spreadsheets.");
            }
        } catch (IOException | GeneralSecurityException e) {
            logger.error("Error while initializing Google Spreadsheet, no information will be serialized in spreadsheets.", e);
        }
    } else {
        logger.info("Google Spreadsheet won't be used for serialization.");
    }
    return null;
}
Also used : RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GeneralSecurityException(java.security.GeneralSecurityException) GoogleSpreadsheetSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.table.GoogleSpreadsheetSerializerEngine) IOException(java.io.IOException)

Example 4 with RepairnatorConfig

use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.

the class LauncherUtils method initNotifierEngines.

public static List<NotifierEngine> initNotifierEngines(Logger logger) {
    List<NotifierEngine> notifierEngines = new ArrayList<>();
    RepairnatorConfig config = RepairnatorConfig.getInstance();
    if (config.getSmtpServer() != null && config.getNotifyTo() != null) {
        logger.info("The email notifier engine will be used.");
        notifierEngines.add(new EmailNotifierEngine(config.getNotifyTo(), config.getSmtpServer()));
    } else {
        logger.info("The email notifier engine won't be used.");
    }
    return notifierEngines;
}
Also used : NotifierEngine(fr.inria.spirals.repairnator.notifier.engines.NotifierEngine) EmailNotifierEngine(fr.inria.spirals.repairnator.notifier.engines.EmailNotifierEngine) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) ArrayList(java.util.ArrayList) EmailNotifierEngine(fr.inria.spirals.repairnator.notifier.engines.EmailNotifierEngine)

Example 5 with RepairnatorConfig

use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.

the class LauncherUtils method initFileSerializerEngines.

public static List<SerializerEngine> initFileSerializerEngines(Logger logger) {
    List<SerializerEngine> fileSerializerEngines = new ArrayList<>();
    RepairnatorConfig config = RepairnatorConfig.getInstance();
    if (config.getOutputPath() != null) {
        logger.info("Initialize file serializer engines.");
        String path = config.getOutputPath();
        path += config.getBuildId() > 0 ? "/" + config.getBuildId() : "";
        fileSerializerEngines.add(new CSVSerializerEngine(path));
        fileSerializerEngines.add(new JSONFileSerializerEngine(path));
    } else {
        logger.info("File serializers won't be used.");
    }
    return fileSerializerEngines;
}
Also used : JSONFileSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.JSONFileSerializerEngine) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) ArrayList(java.util.ArrayList) CSVSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.table.CSVSerializerEngine) CSVSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.table.CSVSerializerEngine) SerializerEngine(fr.inria.spirals.repairnator.serializer.engines.SerializerEngine) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) JSONFileSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.JSONFileSerializerEngine) GoogleSpreadsheetSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.table.GoogleSpreadsheetSerializerEngine)

Aggregations

RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)19 File (java.io.File)12 Build (fr.inria.jtravis.entities.Build)11 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)11 Path (java.nio.file.Path)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 SerializerEngine (fr.inria.spirals.repairnator.serializer.engines.SerializerEngine)8 Git (org.eclipse.jgit.api.Git)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 AbstractNotifier (fr.inria.spirals.repairnator.notifier.AbstractNotifier)7 AbstractDataSerializer (fr.inria.spirals.repairnator.serializer.AbstractDataSerializer)7 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)7 NotifierEngine (fr.inria.spirals.repairnator.notifier.engines.NotifierEngine)6 InspectorSerializer (fr.inria.spirals.repairnator.serializer.InspectorSerializer)5 NopolSerializer (fr.inria.spirals.repairnator.serializer.NopolSerializer)5 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)4 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)4 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)4 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)4