Search in sources :

Example 1 with WarArtifact4CCStub

use of org.apache.maven.plugins.war.stub.WarArtifact4CCStub 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 2 with WarArtifact4CCStub

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

the class WarMojoTest method testFailOnMissingWebXmlFalse.

public void testFailOnMissingWebXmlFalse() throws Exception {
    String testId = "SimpleWarMissingWebXmlFalse";
    MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
    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);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "outputDirectory", outputDir);
    setVariableValueToObject(mojo, "warName", warName);
    mojo.setFailOnMissingWebXml(false);
    mojo.execute();
    // validate jar file
    File expectedJarFile = new File(outputDir, "simple.war");
    final Map<String, JarEntry> jarContent = assertJarContent(expectedJarFile, 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 : MavenProject4CopyConstructor(org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor) WarArtifact4CCStub(org.apache.maven.plugins.war.stub.WarArtifact4CCStub) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 3 with WarArtifact4CCStub

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

the class WarMojoTest method testFailOnMissingWebXmlTrue.

public void testFailOnMissingWebXmlTrue() throws Exception {
    String testId = "SimpleWarMissingWebXmlTrue";
    MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
    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);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "outputDirectory", outputDir);
    setVariableValueToObject(mojo, "warName", warName);
    mojo.setFailOnMissingWebXml(true);
    try {
        mojo.execute();
        fail("Building of the war isn't possible because web.xml is missing");
    } catch (MojoExecutionException e) {
    // expected behaviour
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject4CopyConstructor(org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor) WarArtifact4CCStub(org.apache.maven.plugins.war.stub.WarArtifact4CCStub) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with WarArtifact4CCStub

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

the class WarMojoTest method testSimpleWarPackagingExcludeWithIncludesRegEx.

public void testSimpleWarPackagingExcludeWithIncludesRegEx() throws Exception {
    String testId = "SimpleWarPackagingExcludeWithIncludesRegEx";
    MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
    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);
    File xmlSource = createXMLConfigDir(testId, new String[] { "web.xml" });
    project.setArtifact(warArtifact);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "outputDirectory", outputDir);
    setVariableValueToObject(mojo, "warName", warName);
    mojo.setWebXml(new File(xmlSource, "web.xml"));
    setVariableValueToObject(mojo, "packagingIncludes", "%regex[(.(?!exile))+]");
    mojo.execute();
    // validate jar file
    File expectedJarFile = new File(outputDir, "simple.war");
    assertJarContent(expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.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, mojo.getWebXml().toString(), null, null, null }, new String[] { "org/web/app/last-exile.jsp" });
}
Also used : MavenProject4CopyConstructor(org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor) WarArtifact4CCStub(org.apache.maven.plugins.war.stub.WarArtifact4CCStub) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 5 with WarArtifact4CCStub

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

the class WarMojoTest method testAttachClassesWithCustomClassifier.

public void testAttachClassesWithCustomClassifier() throws Exception {
    String testId = "AttachClassesCustomClassifier";
    MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
    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, false);
    File xmlSource = createXMLConfigDir(testId, new String[] { "web.xml" });
    project.setArtifact(warArtifact);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "outputDirectory", outputDir);
    setVariableValueToObject(mojo, "warName", warName);
    mojo.setWebXml(new File(xmlSource, "web.xml"));
    mojo.setAttachClasses(true);
    mojo.setClassesClassifier("mystuff");
    mojo.execute();
    // validate jar file
    File expectedJarFile = new File(outputDir, "simple-mystuff.jar");
    assertJarContent(expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" }, new String[] { null, null });
}
Also used : MavenProject4CopyConstructor(org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor) WarArtifact4CCStub(org.apache.maven.plugins.war.stub.WarArtifact4CCStub) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

File (java.io.File)13 JarFile (java.util.jar.JarFile)13 WarArtifact4CCStub (org.apache.maven.plugins.war.stub.WarArtifact4CCStub)13 MavenProject4CopyConstructor (org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor)11 ProjectHelperStub (org.apache.maven.plugins.war.stub.ProjectHelperStub)3 JarEntry (java.util.jar.JarEntry)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)2 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)1 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)1