Search in sources :

Example 41 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarExplodedMojoTest method testExplodedWarWithMar.

/**
 * @throws Exception in case of an error.
 */
public void testExplodedWarWithMar() throws Exception {
    // setup test data
    String testId = "ExplodedWarWithMar";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    // Fake here since the mar artifact handler does not exist: no biggie
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler);
    File marFile = marArtifact.getFile();
    assertTrue("jar not found: " + marFile.toString(), marFile.exists());
    // configure mojo
    project.addArtifact(marArtifact);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    mojo.execute();
    // validate operation
    File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
    File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
    // final name form is <artifactId>-<version>.<type>
    File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar");
    assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
    assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
    assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
    // house keeping
    expectedWebSourceFile.delete();
    expectedWebSource2File.delete();
    expectedJarArtifact.delete();
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MarArtifactStub(org.apache.maven.plugins.war.stub.MarArtifactStub) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) XarArtifactStub(org.apache.maven.plugins.war.stub.XarArtifactStub) MarArtifactStub(org.apache.maven.plugins.war.stub.MarArtifactStub) EJBArtifactStub(org.apache.maven.plugins.war.stub.EJBArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) PARArtifactStub(org.apache.maven.plugins.war.stub.PARArtifactStub) TLDArtifactStub(org.apache.maven.plugins.war.stub.TLDArtifactStub) IncludeExcludeWarArtifactStub(org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) EJBClientArtifactStub(org.apache.maven.plugins.war.stub.EJBClientArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) AarArtifactStub(org.apache.maven.plugins.war.stub.AarArtifactStub) File(java.io.File)

Example 42 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarMojoTest method testFailOnMissingWebXmlNotSpecifiedAndServlet30Used.

public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception {
    String testId = "SimpleWarUnderServlet30";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
    File webAppDirectory = new File(getTestDirectory(), testId);
    WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
    String warName = "simple";
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifactStub.setFile(new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar"));
    jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED);
    project.addArtifact(jarArtifactStub);
    project.setArtifact(warArtifact);
    project.setFile(warArtifact.getFile());
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "outputDirectory", outputDir);
    setVariableValueToObject(mojo, "warName", warName);
    mojo.execute();
    // validate war file
    File expectedWarFile = new File(outputDir, "simple.war");
    final Map<String, JarEntry> jarContent = assertJarContent(expectedWarFile, new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, null, null, null });
    assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml"));
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) WarArtifact4CCStub(org.apache.maven.plugins.war.stub.WarArtifact4CCStub) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 43 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarZipTest method buildZipArtifact.

private Artifact buildZipArtifact() throws Exception {
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    File zipFile = new File(getTestDirectory(), "foobar.zip");
    return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) ZipArtifactStub(org.apache.maven.plugins.war.stub.ZipArtifactStub) File(java.io.File)

Example 44 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class AbstractCompilerMojo method resolveProcessorPathEntries.

private List<String> resolveProcessorPathEntries() throws MojoExecutionException {
    if (annotationProcessorPaths == null || annotationProcessorPaths.isEmpty()) {
        return null;
    }
    try {
        Set<Artifact> requiredArtifacts = new LinkedHashSet<Artifact>();
        for (DependencyCoordinate coord : annotationProcessorPaths) {
            ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(coord.getType());
            Artifact artifact = new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(), VersionRange.createFromVersionSpec(coord.getVersion()), Artifact.SCOPE_RUNTIME, coord.getType(), coord.getClassifier(), handler, false);
            requiredArtifacts.add(artifact);
        }
        ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(requiredArtifacts.iterator().next()).setResolveRoot(true).setResolveTransitively(true).setArtifactDependencies(requiredArtifacts).setLocalRepository(session.getLocalRepository()).setRemoteRepositories(project.getRemoteArtifactRepositories());
        ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request);
        resolutionErrorHandler.throwErrors(request, resolutionResult);
        List<String> elements = new ArrayList<String>(resolutionResult.getArtifacts().size());
        for (Object resolved : resolutionResult.getArtifacts()) {
            elements.add(((Artifact) resolved).getFile().getAbsolutePath());
        }
        return elements;
    } catch (Exception e) {
        throw new MojoExecutionException("Resolution of annotationProcessorPath dependencies failed: " + e.getLocalizedMessage(), e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) CompilerException(org.codehaus.plexus.compiler.CompilerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompilerNotImplementedException(org.codehaus.plexus.compiler.CompilerNotImplementedException) NoSuchCompilerException(org.codehaus.plexus.compiler.manager.NoSuchCompilerException) IOException(java.io.IOException) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 45 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class TestSourcesMarkerFileHandler method setUp.

protected void setUp() throws Exception {
    super.setUp();
    ArtifactHandler ah = new DefaultArtifactHandler();
    VersionRange vr = VersionRange.createFromVersion("1.1");
    Artifact artifact = new DefaultArtifact("test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false);
    artifacts.add(artifact);
    // pick random output location
    Random a = new Random();
    outputFolder = new File("target/markers" + a.nextLong() + "/");
    outputFolder.delete();
    assertFalse(outputFolder.exists());
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) Random(java.util.Random) VersionRange(org.apache.maven.artifact.versioning.VersionRange) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)51 File (java.io.File)26 Artifact (org.apache.maven.artifact.Artifact)26 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)23 VersionRange (org.apache.maven.artifact.versioning.VersionRange)17 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)10 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)10 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 MavenProject (org.apache.maven.project.MavenProject)6 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)6 ArrayList (java.util.ArrayList)5 Random (java.util.Random)4 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)4 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)4 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)4 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)4 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)4