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();
}
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();
}
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
}
}
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;
}
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();
}
Aggregations