Search in sources :

Example 31 with ArtifactHandler

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

the class WarDependenciesAnalysisTest method testDependencyNowProvided.

public void testDependencyNowProvided() throws Exception {
    // setup test data
    final String testId = "dependency-now-provided";
    final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact.setArtifactId("lib-test");
    jarArtifact.setVersion("1.0");
    ArtifactStub jarArtifact2 = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact2.setArtifactId("lib-test");
    jarArtifact2.setVersion("1.0");
    jarArtifact2.setScope(Artifact.SCOPE_PROVIDED);
    doTestTwiceWithUpdatedDependency(testId, new ArtifactStub[] { jarArtifact }, new ArtifactStub[] { jarArtifact2 }, new String[] { "WEB-INF/lib/lib-test-1.0.jar" }, null);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub)

Example 32 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 33 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 34 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 35 with ArtifactHandler

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

the class PreparePackageMojoTest method getMojoUnderTest.

private PreparePackageMojo getMojoUnderTest(String... knownArtifacts) throws Exception {
    File mrr = getMavenRepoRoot();
    ArtifactHandler ah = Mockito.mock(ArtifactHandler.class);
    ArtifactHandlerManager ahm = Mockito.mock(ArtifactHandlerManager.class);
    Mockito.when(ahm.getArtifactHandler(Mockito.anyString())).thenReturn(ah);
    Set<org.apache.maven.artifact.Artifact> artifacts = new HashSet<>();
    for (String s : knownArtifacts) {
        String[] parts = s.split("[/]");
        switch(parts.length) {
            case 3:
                artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2]));
                break;
            case 4:
                artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2], parts[3]));
                break;
            default:
                throw new IllegalStateException(s);
        }
    }
    MavenProject mavenPrj = new MavenProject();
    Build build = new Build();
    Path tempDir = Files.createTempDirectory(getClass().getSimpleName());
    build.setOutputDirectory(tempDir.toString());
    build.setDirectory(tempDir.toString());
    mavenPrj.setBuild(build);
    mavenPrj.setDependencyArtifacts(artifacts);
    PreparePackageMojo ppm = new PreparePackageMojo();
    ppm.mavenSession = Mockito.mock(MavenSession.class);
    ppm.project = mavenPrj;
    ArchiverManager am = Mockito.mock(ArchiverManager.class);
    UnArchiver ua = Mockito.mock(UnArchiver.class);
    Mockito.when(am.getUnArchiver(Mockito.isA(File.class))).thenReturn(ua);
    setPrivateField(ppm, "archiverManager", am);
    setPrivateField(ppm, "artifactHandlerManager", ahm);
    setPrivateField(ppm, "resolver", Mockito.mock(ArtifactResolver.class));
    return ppm;
}
Also used : Path(java.nio.file.Path) ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) MavenSession(org.apache.maven.execution.MavenSession) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) JarFile(java.util.jar.JarFile) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet)

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