Search in sources :

Example 1 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class TestMavenFilterTestOutputHandler method testFilterLogWillWork.

@Test
public void testFilterLogWillWork() throws IOException {
    String resourcePath = "./src/test/resources/build-logs/log-test-failures.txt";
    List<String> lines = Files.readAllLines(new File(resourcePath).toPath());
    ProjectInspector inspector = mock(ProjectInspector.class);
    Path tmp = Files.createTempDirectory("test-filter");
    when(inspector.getRepoLocalPath()).thenReturn(tmp.toAbsolutePath().toString());
    JobStatus jobStatus = new JobStatus(tmp.toAbsolutePath().toString());
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    MavenHelper mavenHelper = mock(MavenHelper.class);
    when(mavenHelper.getInspector()).thenReturn(inspector);
    when(mavenHelper.getName()).thenReturn("test");
    MavenFilterTestOutputHandler filterTest = new MavenFilterTestOutputHandler(mavenHelper);
    for (String s : lines) {
        filterTest.consumeLine(s);
    }
    assertTrue(filterTest.isFailingWithTest());
    assertEquals(40, filterTest.getRunningTests());
    assertEquals(0, filterTest.getFailingTests());
    assertEquals(9, filterTest.getErroringTests());
    assertEquals(3, filterTest.getSkippingTests());
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) Test(org.junit.Test)

Example 2 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class TestMavenFilterTestOutputHandler method testFilterLogWillWork2.

@Test
public void testFilterLogWillWork2() throws IOException {
    String resourcePath = "./src/test/resources/build-logs/log-test-druidio.txt";
    List<String> lines = Files.readAllLines(new File(resourcePath).toPath());
    ProjectInspector inspector = mock(ProjectInspector.class);
    Path tmp = Files.createTempDirectory("test-filter");
    when(inspector.getRepoLocalPath()).thenReturn(tmp.toAbsolutePath().toString());
    JobStatus jobStatus = new JobStatus(tmp.toAbsolutePath().toString());
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    MavenHelper mavenHelper = mock(MavenHelper.class);
    when(mavenHelper.getInspector()).thenReturn(inspector);
    when(mavenHelper.getName()).thenReturn("test");
    MavenFilterTestOutputHandler filterTest = new MavenFilterTestOutputHandler(mavenHelper);
    for (String s : lines) {
        filterTest.consumeLine(s);
    }
    assertFalse(filterTest.isFailingWithTest());
    assertEquals(77351 * 2, filterTest.getRunningTests());
    assertEquals(0, filterTest.getFailingTests());
    assertEquals(0, filterTest.getErroringTests());
    assertEquals((52 + 6 + 1) * 2, filterTest.getSkippingTests());
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) Test(org.junit.Test)

Example 3 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class ComputeClasspath method businessExecute.

@Override
protected void businessExecute() {
    this.getLogger().debug("Computing classpath from incriminated module...");
    String incriminatedModule = this.getInspector().getJobStatus().getFailingModulePath();
    File defaultClassDir = new File(incriminatedModule + File.separator + DEFAULT_CLASSES_DIR + File.separator);
    this.addFileToClassPath(defaultClassDir);
    File defaultTestClassDir = new File(incriminatedModule + File.separator + DEFAULT_TEST_CLASSES_DIR + File.separator);
    this.addFileToClassPath(defaultTestClassDir);
    Properties properties = new Properties();
    properties.setProperty("mdep.outputFile", CLASSPATH_FILENAME);
    String goal = "dependency:build-classpath";
    String pomModule = incriminatedModule + File.separator + "pom.xml";
    MavenHelper helper = new MavenHelper(pomModule, goal, properties, this.getClass().getSimpleName(), this.inspector, true);
    int result = MavenHelper.MAVEN_ERROR;
    try {
        result = helper.run();
    } catch (InterruptedException e) {
        this.addStepError("Error with maven goal", e);
    }
    if (result != MavenHelper.MAVEN_SUCCESS) {
        this.getLogger().debug("Error while computing classpath maven");
        this.setPipelineState(PipelineState.CLASSPATHNOTCOMPUTED);
        return;
    }
    String classpathPath = incriminatedModule + File.separator + CLASSPATH_FILENAME;
    try {
        BufferedReader reader = new BufferedReader(new FileReader(new File(classpathPath)));
        String classpathLine = reader.readLine();
        String[] allJars = classpathLine.split(":");
        for (String jar : allJars) {
            File f = new File(jar);
            this.addFileToClassPath(f);
        }
    } catch (IOException e) {
        this.addStepError("Problem while getting classpath: " + e);
        this.setPipelineState(PipelineState.CLASSPATHNOTCOMPUTED);
    // return ?
    }
    boolean containJunit = false;
    for (URL url : classPath) {
        if (url.toString().contains("junit")) {
            containJunit = true;
            break;
        }
    }
    if (!containJunit) {
        this.addStepError("The classpath seems not to contain JUnit, maybe this project does not use junit for testing.");
    }
    this.inspector.getJobStatus().setRepairClassPath(this.classPath);
    this.inspector.getJobStatus().getMetrics().setNbLibraries(this.classPath.size() - 2);
    this.setPipelineState(PipelineState.CLASSPATHCOMPUTED);
}
Also used : MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL)

Example 4 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class TestProject method businessExecute.

protected void businessExecute() {
    this.getLogger().debug("Launching tests with maven...");
    MavenHelper helper = new MavenHelper(this.getPom(), "test", null, this.getClass().getSimpleName(), this.inspector, false);
    MavenFilterTestOutputHandler outputTestFilter = new MavenFilterTestOutputHandler(helper);
    helper.setOutputHandler(outputTestFilter);
    int result = MavenHelper.MAVEN_ERROR;
    try {
        result = helper.run();
    } catch (InterruptedException e) {
        this.addStepError("Error while executing maven goal", e);
    }
    if (result == MavenHelper.MAVEN_SUCCESS) {
        if (outputTestFilter.getRunningTests() > 0) {
            this.getLogger().debug(outputTestFilter.getRunningTests() + " tests has been launched but none failed.");
        } else {
            this.addStepError("No test recorded.");
        }
        this.setPipelineState(PipelineState.NOTFAILING);
    } else {
        if (outputTestFilter.isFailingWithTest()) {
            this.getLogger().debug(outputTestFilter.getFailingTests() + " tests failed, go to next step.");
            this.setPipelineState(PipelineState.TESTABLE);
        } else {
            this.addStepError("Error while testing the project.");
            this.setPipelineState(PipelineState.NOTTESTABLE);
            this.shouldStop = true;
        }
    }
}
Also used : MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) MavenFilterTestOutputHandler(fr.inria.spirals.repairnator.process.maven.output.MavenFilterTestOutputHandler)

Example 5 with MavenHelper

use of fr.inria.spirals.repairnator.process.maven.MavenHelper in project repairnator by Spirals-Team.

the class BuildProject method businessExecute.

protected void businessExecute() {
    this.getLogger().debug("Building project with maven (skip tests)...");
    Properties properties = new Properties();
    properties.setProperty(MavenHelper.SKIP_TEST_PROPERTY, "true");
    this.getLogger().debug("Installing artifacts without test execution...");
    MavenHelper helper = new MavenHelper(this.getPom(), "install", properties, this.getClass().getSimpleName(), this.inspector, true);
    int result;
    try {
        result = helper.run();
    } catch (InterruptedException e) {
        this.addStepError("Error while building", e);
        result = MavenHelper.MAVEN_ERROR;
    }
    if (result == MavenHelper.MAVEN_SUCCESS) {
        this.setPipelineState(PipelineState.BUILDABLE);
    } else {
        this.getLogger().warn("Repository " + this.inspector.getRepoSlug() + " cannot be built.");
        this.setPipelineState(PipelineState.NOTBUILDABLE);
        this.shouldStop = true;
    }
}
Also used : MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) Properties(java.util.Properties)

Aggregations

MavenHelper (fr.inria.spirals.repairnator.process.maven.MavenHelper)7 File (java.io.File)4 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)2 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 MavenFilterTestOutputHandler (fr.inria.spirals.repairnator.process.maven.output.MavenFilterTestOutputHandler)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1