use of org.apache.maven.plugins.war.stub.WarArtifactStub in project maven-plugins by apache.
the class WarExplodedMojoTest method testExplodedWarMergeWarLocalFileOverride.
/**
* Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
* @throws Exception in case of an error.
*/
public void testExplodedWarMergeWarLocalFileOverride() throws Exception {
// setup test data
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
WarArtifactStub warArtifact = new WarArtifactStub(getBasedir());
String testId = "testExplodedWarMergeWarLocalFileOverride";
File webAppDirectory = new File(getTestDirectory(), testId);
File webAppSource = getWebAppSource(testId);
File simpleJSP = new File(webAppSource, "org/sample/company/test.jsp");
createFile(simpleJSP);
File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
createDir(workDirectory);
File classesDir = createClassesDir(testId, true);
// configure mojo
project.addArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
// validate operation
File expectedFile = new File(webAppDirectory, "/org/sample/company/test.jsp");
assertTrue("file not found: " + expectedFile.toString(), expectedFile.exists());
assertEquals("file incorrect", simpleJSP.toString(), FileUtils.fileRead(expectedFile));
// check when the merged war file is newer - so set an old time on the local file
long time = new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2005-1-1").getTime();
simpleJSP.setLastModified(time);
expectedFile.setLastModified(time);
project.addArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
assertTrue("file not found: " + expectedFile.toString(), expectedFile.exists());
assertEquals("file incorrect", simpleJSP.toString(), FileUtils.fileRead(expectedFile));
// house keeping
expectedFile.delete();
}
use of org.apache.maven.plugins.war.stub.WarArtifactStub in project maven-plugins by apache.
the class WarZipTest method configureMojo.
private File configureMojo(String testId) throws Exception {
MavenZipProject project = new MavenZipProject();
String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + testId + "-output";
// clean up
File outputDirFile = new File(outputDir);
if (outputDirFile.exists()) {
FileUtils.deleteDirectory(outputDirFile);
}
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifactStub warArtifact = new WarArtifactStub(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);
setVariableValueToObject(mojo, "workDirectory", new File(getTestDirectory(), "work"));
mojo.setWebXml(new File(xmlSource, "web.xml"));
project.getArtifacts().add(buildZipArtifact());
return webAppDirectory;
}
use of org.apache.maven.plugins.war.stub.WarArtifactStub in project maven-plugins by apache.
the class WarExplodedMojoTest method testExplodedWar_WithSimpleExternalWARFile.
/**
* @throws Exception in case of an error.
*/
public void testExplodedWar_WithSimpleExternalWARFile() throws Exception {
// setup test data
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
WarArtifactStub warArtifact = new WarArtifactStub(getBasedir());
String testId = "ExplodedWar_WithSimpleExternalWARFile";
File webAppDirectory = new File(getTestDirectory(), testId);
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
File simpleWarFile = warArtifact.getFile();
assertTrue("simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists());
createDir(workDirectory);
// configure mojo
project.addArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
// validate operation - META-INF is automatically excluded so remove the file from the list
File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml");
File expectedWARFile = new File(webAppDirectory, "/org/sample/company/test.jsp");
assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
// check simple.war in the unit test dir under resources to verify the list of files
assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists());
assertTrue("war file not found: " + expectedWARFile.toString(), expectedWARFile.exists());
// house keeping
expectedWebSourceFile.delete();
expectedWebSource2File.delete();
expectedWEBXMLFile.delete();
expectedWARFile.delete();
}
use of org.apache.maven.plugins.war.stub.WarArtifactStub in project maven-plugins by apache.
the class OverlayManagerTest method newWarArtifact.
protected ArtifactStub newWarArtifact(String groupId, String artifactId, String classifier) {
final WarArtifactStub a = new WarArtifactStub(getBasedir());
a.setGroupId(groupId);
a.setArtifactId(artifactId);
if (classifier != null) {
a.setClassifier(classifier);
}
return a;
}
Aggregations