Search in sources :

Example 6 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class WarExplodedMojoTest method testExplodedWar_WithWarDependencyIncludeExclude.

/**
 * @throws Exception in case of an error.
 */
public void testExplodedWar_WithWarDependencyIncludeExclude() throws Exception {
    // setup test data
    String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir());
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
    File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
    assertTrue("war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists());
    createDir(workDirectory);
    // configure mojo
    project.addArtifact(includeexcludeWarArtifact);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml");
    setVariableValueToObject(mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF");
    setVariableValueToObject(mojo, "workDirectory", workDirectory);
    mojo.execute();
    // validate operation
    File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
    File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
    File expectedManifestFile = new File(webAppDirectory, "META-INF/MANIFEST.MF");
    File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml");
    File expectedIncludedWARFile = new File(webAppDirectory, "/org/sample/company/testInclude.jsp");
    File expectedExcludedWarfile = new File(webAppDirectory, "/org/sample/companyExclude/test.jsp");
    assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
    assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
    // check include-exclude.war in the unit test dir under resources to verify the list of files
    assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists());
    assertFalse("manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists());
    assertTrue("war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists());
    assertFalse("war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists());
    // house keeping
    expectedWebSourceFile.delete();
    expectedWebSource2File.delete();
    expectedManifestFile.delete();
    expectedWEBXMLFile.delete();
    expectedIncludedWARFile.delete();
    expectedExcludedWarfile.delete();
}
Also used : MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) File(java.io.File) IncludeExcludeWarArtifactStub(org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)

Example 7 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class WarExplodedMojoTest method testExplodedWar_WithEJBClient.

/**
 * @throws Exception in case of an error.
 */
public void testExplodedWar_WithEJBClient() throws Exception {
    // setup test data
    String testId = "ExplodedWar_WithEJB";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir());
    File ejbFile = ejbArtifact.getFile();
    assertTrue("ejb jar not found: " + ejbFile.toString(), ejbFile.exists());
    // configure mojo
    project.addArtifact(ejbArtifact);
    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 expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar");
    assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
    assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
    assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
    // house keeping
    expectedWebSourceFile.delete();
    expectedWebSource2File.delete();
    expectedEJBArtifact.delete();
}
Also used : MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) EJBClientArtifactStub(org.apache.maven.plugins.war.stub.EJBClientArtifactStub) File(java.io.File)

Example 8 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class WarMojoTest method testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed.

public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed() throws Exception {
    String testId = "SimpleWarNotUnderServlet30";
    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);
    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);
    try {
        mojo.execute();
        fail("Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project " + "does not depend on Servlet 3.0");
    } catch (MojoExecutionException e) {
    // expected behaviour
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) WarArtifact4CCStub(org.apache.maven.plugins.war.stub.WarArtifact4CCStub) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 9 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class AbstractWarExplodedMojoTest method setUpMojo.

/**
 * Configures the exploded mojo for the specified test.
 *
 * If the <tt>sourceFiles</tt> parameter is <tt>null</tt>, sample JSPs are created by default.
 *
 * @param testId the id of the test
 * @param artifactStubs the dependencies (may be null)
 * @param sourceFiles the source files to create (may be null)
 * @return the webapp directory
 * @throws Exception if an error occurs while configuring the mojo
 */
protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final File webAppDirectory = new File(getTestDirectory(), testId);
    // Create the webapp sources
    File webAppSource;
    if (sourceFiles == null) {
        webAppSource = createWebAppSource(testId);
    } else {
        webAppSource = createWebAppSource(testId, false);
        for (String sourceFile : sourceFiles) {
            File sample = new File(webAppSource, sourceFile);
            createFile(sample);
        }
    }
    final File classesDir = createClassesDir(testId, true);
    final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
    createDir(workDirectory);
    if (artifactStubs != null) {
        for (ArtifactStub artifactStub : artifactStubs) {
            project.addArtifact(artifactStub);
        }
    }
    configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "workDirectory", workDirectory);
    return webAppDirectory;
}
Also used : MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) File(java.io.File)

Example 10 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub 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)

Aggregations

MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)24 File (java.io.File)18 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)12 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)11 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)9 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)8 ArrayList (java.util.ArrayList)6 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)6 Overlay (org.apache.maven.plugins.war.Overlay)6 DefaultOverlay (org.apache.maven.plugins.war.overlay.DefaultOverlay)6 InvalidOverlayConfigurationException (org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)6 OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)6 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)6 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)6 PARArtifactStub (org.apache.maven.plugins.war.stub.PARArtifactStub)6 TLDArtifactStub (org.apache.maven.plugins.war.stub.TLDArtifactStub)6 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)5 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)5 XarArtifactStub (org.apache.maven.plugins.war.stub.XarArtifactStub)5 JarFile (java.util.jar.JarFile)2