Search in sources :

Example 1 with DebugEnabledLog

use of org.apache.maven.plugin.compiler.stubs.DebugEnabledLog in project maven-plugins by apache.

the class CompilerMojoTestCase method getCompilerMojo.

private CompilerMojo getCompilerMojo(String pomXml) throws Exception {
    File testPom = new File(getBasedir(), pomXml);
    CompilerMojo mojo = (CompilerMojo) lookupMojo("compile", testPom);
    setVariableValueToObject(mojo, "log", new DebugEnabledLog());
    setVariableValueToObject(mojo, "projectArtifact", new ArtifactStub());
    setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
    setVariableValueToObject(mojo, "session", getMockMavenSession());
    setVariableValueToObject(mojo, "project", getMockMavenProject());
    setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
    setVariableValueToObject(mojo, "source", source);
    setVariableValueToObject(mojo, "target", target);
    return mojo;
}
Also used : DebugEnabledLog(org.apache.maven.plugin.compiler.stubs.DebugEnabledLog) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) File(java.io.File)

Example 2 with DebugEnabledLog

use of org.apache.maven.plugin.compiler.stubs.DebugEnabledLog in project maven-plugins by apache.

the class CompilerMojoTestCase method getTestCompilerMojo.

private TestCompilerMojo getTestCompilerMojo(CompilerMojo compilerMojo, String pomXml) throws Exception {
    File testPom = new File(getBasedir(), pomXml);
    TestCompilerMojo mojo = (TestCompilerMojo) lookupMojo("testCompile", testPom);
    setVariableValueToObject(mojo, "log", new DebugEnabledLog());
    File buildDir = (File) getVariableValueFromObject(compilerMojo, "buildDirectory");
    File testClassesDir = new File(buildDir, "test-classes");
    setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
    List<String> testClasspathList = new ArrayList<String>();
    Artifact junitArtifact = mock(Artifact.class);
    ArtifactHandler handler = mock(ArtifactHandler.class);
    when(handler.isAddedToClasspath()).thenReturn(true);
    when(junitArtifact.getArtifactHandler()).thenReturn(handler);
    File artifactFile;
    String localRepository = System.getProperty("localRepository");
    if (localRepository != null) {
        artifactFile = new File(localRepository, "junit/junit/3.8.1/junit-3.8.1.jar");
    } else {
        // for IDE
        String junitURI = org.junit.Test.class.getResource("Test.class").toURI().toString();
        junitURI = junitURI.substring("jar:".length(), junitURI.indexOf('!'));
        artifactFile = new File(URI.create(junitURI));
    }
    when(junitArtifact.getFile()).thenReturn(artifactFile);
    testClasspathList.add(artifactFile.getAbsolutePath());
    testClasspathList.add(compilerMojo.getOutputDirectory().getPath());
    String testSourceRoot = testPom.getParent() + "/src/test/java";
    setVariableValueToObject(mojo, "compileSourceRoots", Collections.singletonList(testSourceRoot));
    MavenProject project = getMockMavenProject();
    project.setArtifacts(Collections.singleton(junitArtifact));
    project.getBuild().setOutputDirectory(new File(buildDir, "classes").getAbsolutePath());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
    setVariableValueToObject(mojo, "testPath", testClasspathList);
    setVariableValueToObject(mojo, "session", getMockMavenSession());
    setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
    setVariableValueToObject(mojo, "source", source);
    setVariableValueToObject(mojo, "target", target);
    return mojo;
}
Also used : DebugEnabledLog(org.apache.maven.plugin.compiler.stubs.DebugEnabledLog) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

File (java.io.File)2 DebugEnabledLog (org.apache.maven.plugin.compiler.stubs.DebugEnabledLog)2 ArrayList (java.util.ArrayList)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)1 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)1 MavenProject (org.apache.maven.project.MavenProject)1