Search in sources :

Example 11 with ArtifactHandler

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

the class TestDefaultMarkerFileHandler 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);
    outputFolder = new File("target/markers/");
    DependencyTestUtils.removeDirectory(this.outputFolder);
    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) 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)

Example 12 with ArtifactHandler

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

the class ShadeMojoTest method testShadeWithFilter.

/**
     * Tests if a Filter is installed correctly, also if createSourcesJar is set to true.
     *
     * @throws Exception
     */
public void testShadeWithFilter() throws Exception {
    ShadeMojo mojo = new ShadeMojo();
    // set createSourcesJar = true
    Field createSourcesJar = ShadeMojo.class.getDeclaredField("createSourcesJar");
    createSourcesJar.setAccessible(true);
    createSourcesJar.set(mojo, Boolean.TRUE);
    // configure artifactResolver (mocked) for mojo
    ArtifactResolver mockArtifactResolver = new ArtifactResolver() {

        @Override
        public ArtifactResult resolveArtifact(ProjectBuildingRequest req, final Artifact art) throws ArtifactResolverException {
            return new ArtifactResult() {

                @Override
                public Artifact getArtifact() {
                    art.setResolved(true);
                    String fileName = art.getArtifactId() + "-" + art.getVersion() + (art.getClassifier() != null ? "-" + art.getClassifier() : "") + ".jar";
                    art.setFile(new File(fileName));
                    return art;
                }
            };
        }

        @Override
        public ArtifactResult resolveArtifact(ProjectBuildingRequest req, final ArtifactCoordinate coordinate) throws ArtifactResolverException {
            return new ArtifactResult() {

                @Override
                public Artifact getArtifact() {
                    Artifact art = mock(Artifact.class);
                    when(art.getGroupId()).thenReturn(coordinate.getGroupId());
                    when(art.getArtifactId()).thenReturn(coordinate.getArtifactId());
                    when(art.getType()).thenReturn(coordinate.getExtension());
                    when(art.getClassifier()).thenReturn(coordinate.getClassifier());
                    when(art.isResolved()).thenReturn(true);
                    String fileName = coordinate.getArtifactId() + "-" + coordinate.getVersion() + (coordinate.getClassifier() != null ? "-" + coordinate.getClassifier() : "") + ".jar";
                    when(art.getFile()).thenReturn(new File(fileName));
                    return art;
                }
            };
        }
    };
    Field artifactResolverField = ShadeMojo.class.getDeclaredField("artifactResolver");
    artifactResolverField.setAccessible(true);
    artifactResolverField.set(mojo, mockArtifactResolver);
    // create and configure MavenProject
    MavenProject project = new MavenProject();
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE);
    Artifact artifact = new DefaultArtifact("org.apache.myfaces.core", "myfaces-impl", VersionRange.createFromVersion("2.0.1-SNAPSHOT"), "compile", "jar", null, artifactHandler);
    // setFile and setResolved
    artifact = mockArtifactResolver.resolveArtifact(null, artifact).getArtifact();
    project.setArtifact(artifact);
    Field projectField = ShadeMojo.class.getDeclaredField("project");
    projectField.setAccessible(true);
    projectField.set(mojo, project);
    // create and configure the ArchiveFilter
    ArchiveFilter archiveFilter = new ArchiveFilter();
    Field archiveFilterArtifact = ArchiveFilter.class.getDeclaredField("artifact");
    archiveFilterArtifact.setAccessible(true);
    archiveFilterArtifact.set(archiveFilter, "org.apache.myfaces.core:myfaces-impl");
    // add ArchiveFilter to mojo
    Field filtersField = ShadeMojo.class.getDeclaredField("filters");
    filtersField.setAccessible(true);
    filtersField.set(mojo, new ArchiveFilter[] { archiveFilter });
    Field sessionField = ShadeMojo.class.getDeclaredField("session");
    sessionField.setAccessible(true);
    sessionField.set(mojo, mock(MavenSession.class));
    // invoke getFilters()
    Method getFilters = ShadeMojo.class.getDeclaredMethod("getFilters", new Class[0]);
    getFilters.setAccessible(true);
    List<Filter> filters = (List<Filter>) getFilters.invoke(mojo);
    // assertions - there must be one filter
    assertEquals(1, filters.size());
    // the filter must be able to filter the binary and the sources jar
    Filter filter = filters.get(0);
    // binary jar
    assertTrue(filter.canFilter(new File("myfaces-impl-2.0.1-SNAPSHOT.jar")));
    // sources jar
    assertTrue(filter.canFilter(new File("myfaces-impl-2.0.1-SNAPSHOT-sources.jar")));
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) Method(java.lang.reflect.Method) ArtifactResolver(org.apache.maven.shared.artifact.resolve.ArtifactResolver) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) Field(java.lang.reflect.Field) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) Filter(org.apache.maven.plugins.shade.filter.Filter) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 13 with ArtifactHandler

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

the class WarExplodedMojoTest method testExplodedWarWithOutputFileNameMapping.

/**
     * @throws Exception in case of an error.
     */
public void testExplodedWarWithOutputFileNameMapping() throws Exception {
    // setup test data
    String testId = "ExplodedWarWithFileNameMapping";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
    File jarFile = jarArtifact.getFile();
    assertTrue("jar not found: " + jarFile.toString(), jarFile.exists());
    // configure mojo
    project.addArtifact(jarArtifact);
    mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@");
    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/lib/jarartifact.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) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) 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 14 with ArtifactHandler

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

the class WarExplodedMojoTest method testExplodedWarWithAar.

/**
     * @throws Exception in case of an error.
     */
public void testExplodedWarWithAar() throws Exception {
    // setup test data
    String testId = "ExplodedWarWithAar";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    // Fake here since the aar artifact handler does not exist: no biggie
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), artifactHandler);
    File aarFile = aarArtifact.getFile();
    assertTrue("jar not found: " + aarFile.toString(), aarFile.exists());
    // configure mojo
    project.addArtifact(aarArtifact);
    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/services/aarartifact-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) AarArtifactStub(org.apache.maven.plugins.war.stub.AarArtifactStub) 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 15 with ArtifactHandler

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

the class WarExplodedMojoTest method testExplodedWarWithXar.

/**
     * @throws Exception in case of an error.
     */
public void testExplodedWarWithXar() throws Exception {
    // setup test data
    String testId = "ExplodedWarWithXar";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    // Fake here since the xar artifact handler does not exist: no biggie
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler);
    File xarFile = xarArtifact.getFile();
    assertTrue("jar not found: " + xarFile.toString(), xarFile.exists());
    // configure mojo
    project.addArtifact(xarArtifact);
    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/extensions/xarartifact-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 : XarArtifactStub(org.apache.maven.plugins.war.stub.XarArtifactStub) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) 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)

Aggregations

ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)35 File (java.io.File)17 Artifact (org.apache.maven.artifact.Artifact)14 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)12 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)10 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)9 VersionRange (org.apache.maven.artifact.versioning.VersionRange)7 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)5 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)5 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)5 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)5 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)5 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)5 PARArtifactStub (org.apache.maven.plugins.war.stub.PARArtifactStub)5 TLDArtifactStub (org.apache.maven.plugins.war.stub.TLDArtifactStub)5 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)5 XarArtifactStub (org.apache.maven.plugins.war.stub.XarArtifactStub)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 MavenProject (org.apache.maven.project.MavenProject)4