use of org.apache.maven.plugins.war.util.PathSet in project maven-plugins by apache.
the class WarProjectPackagingTask method performPackaging.
/**
* {@inheritDoc}
*/
public void performPackaging(WarPackagingContext context) throws MojoExecutionException, MojoFailureException {
context.getLog().info("Processing war project");
// Prepare the INF directories
File webinfDir = new File(context.getWebappDirectory(), WEB_INF_PATH);
webinfDir.mkdirs();
File metainfDir = new File(context.getWebappDirectory(), META_INF_PATH);
metainfDir.mkdirs();
handleWebResources(context);
handeWebAppSourceDirectory(context);
// Debug mode: dump the path set for the current build
PathSet pathSet = context.getWebappStructure().getStructure("currentBuild");
context.getLog().debug("Dump of the current build pathSet content -->");
for (String path : pathSet) {
context.getLog().debug(path);
}
context.getLog().debug("-- end of dump --");
handleDeploymentDescriptors(context, webinfDir, metainfDir);
handleClassesDirectory(context);
handleArtifacts(context);
}
use of org.apache.maven.plugins.war.util.PathSet in project maven-plugins by apache.
the class PathSetTest method testAddAllFilesInDirectory.
/**
* Test method for 'org.apache.maven.plugin.war.PathSet.addAllFilesInDirectory(File, String)'
*
* @throws IOException if an io error occurred
*/
public void testAddAllFilesInDirectory() throws IOException {
PathSet ps = new PathSet();
/* Preparing directory structure*/
File testDir = new File("target/testAddAllFilesInDirectory");
testDir.mkdirs();
File f1 = new File(testDir, "f1");
f1.createNewFile();
File f2 = new File(testDir, "f2");
f2.createNewFile();
File d1 = new File(testDir, "d1");
File d1d2 = new File(testDir, "d1/d2");
d1d2.mkdirs();
File d1d2f1 = new File(d1d2, "f1");
d1d2f1.createNewFile();
File d1d2f2 = new File(d1d2, "f2");
d1d2f2.createNewFile();
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
assertEquals("Unexpected PathSet size", 4, ps.size());
/*No changes after adding duplicates*/
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
assertEquals("Unexpected PathSet size", 4, ps.size());
/*Cleanup*/
f1.delete();
f2.delete();
/*No changes after adding a subset of files*/
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
assertEquals("Unexpected PathSet size", 4, ps.size());
d1d2f1.delete();
d1d2f2.delete();
d1d2.delete();
d1.delete();
testDir.delete();
assertTrue(ps.contains("123/f1"));
assertTrue(ps.contains("/123/f1"));
assertTrue(ps.contains("123\\f1"));
assertTrue(ps.contains("123\\f2"));
assertTrue(ps.contains("\\123/d1\\d2/f1"));
assertTrue(ps.contains("123\\d1/d2\\f2"));
assertFalse(ps.contains("123\\f3"));
}
use of org.apache.maven.plugins.war.util.PathSet in project maven-plugins by apache.
the class PathSetTest method testPathsSetAddAlls.
/**
* Test method for:
* <ul>
* <li>org.apache.maven.plugin.war.PathSet.PathSet(Collection)</li>
* <li>org.apache.maven.plugin.war.PathSet.PathSet(String[])</li>
* <li>org.apache.maven.plugin.war.PathSet.Add</li>
* <li>org.apache.maven.plugin.war.PathSet.AddAll(String[],String)</li>
* <li>org.apache.maven.plugin.war.PathSet.AddAll(Collection,String)</li>
* </ul>
*/
public void testPathsSetAddAlls() {
Set<String> s1set = new HashSet<String>();
s1set.add("/a/b");
s1set.add("a/b/c");
s1set.add("a\\b/c");
s1set.add("//1//2\3a");
String[] s2ar = new String[] { "/a/b", "a2/b2/c2", "a2\\b2/c2", "//21//22\23a" };
PathSet ps1 = new PathSet(s1set);
assertEquals("Unexpected PathSet size", 3, ps1.size());
PathSet ps2 = new PathSet(s2ar);
assertEquals("Unexpected PathSet size", 3, ps2.size());
ps1.addAll(s2ar);
assertEquals("Unexpected PathSet size", 5, ps1.size());
ps2.addAll(s1set);
assertEquals("Unexpected PathSet size", 5, ps2.size());
for (String str : ps1) {
assertTrue(str, ps2.contains(str));
assertTrue(ps2.contains("/" + str));
assertTrue(ps1.contains(str));
assertTrue(ps1.contains("/" + str));
}
for (String str : ps2) {
assertTrue(ps1.contains(str));
assertTrue(ps1.contains("/" + str));
assertTrue(ps2.contains(str));
assertTrue(ps2.contains("/" + str));
}
ps1.addAll(s2ar, "/pref/");
assertEquals("Unexpected PathSet size", 8, ps1.size());
ps2.addAll(s2ar, "/pref/");
assertEquals("Unexpected PathSet size", 8, ps2.size());
for (String str : ps1) {
assertTrue(str, ps2.contains(str));
assertTrue(ps2.contains("/" + str));
assertTrue(ps1.contains(str));
assertTrue(ps1.contains("/" + str));
}
for (String str : ps2) {
assertTrue(ps1.contains(str));
assertTrue(ps1.contains("/" + str));
assertTrue(ps2.contains(str));
assertTrue(ps2.contains("/" + str));
}
}
use of org.apache.maven.plugins.war.util.PathSet in project maven-plugins by apache.
the class OverlayPackagingTask method performPackaging.
/**
* {@inheritDoc}
*/
public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
context.getLog().debug("OverlayPackagingTask performPackaging overlay.getTargetPath() " + overlay.getTargetPath());
if (overlay.shouldSkip()) {
context.getLog().info("Skipping overlay [" + overlay + "]");
} else {
try {
context.getLog().info("Processing overlay [" + overlay + "]");
// Step1: Extract if necessary
final File tmpDir = unpackOverlay(context, overlay);
// Step2: setup
final PathSet includes = getFilesToIncludes(tmpDir, overlay.getIncludes(), overlay.getExcludes());
// Copy
if (null == overlay.getTargetPath()) {
copyFiles(overlay.getId(), context, tmpDir, includes, overlay.isFiltered());
} else {
// overlay.getTargetPath() must ended with /
// if not we add it
String targetPath = overlay.getTargetPath();
if (!targetPath.endsWith("/")) {
targetPath = targetPath + "/";
}
copyFiles(overlay.getId(), context, tmpDir, includes, targetPath, overlay.isFiltered());
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy file for overlay [" + overlay + "]", e);
}
}
}
use of org.apache.maven.plugins.war.util.PathSet in project maven-plugins by apache.
the class AbstractWarPackagingTask method getFilesToIncludes.
/**
* Returns the file to copy. If the includes are <tt>null</tt> or empty, the default includes are used.
*
* @param baseDir the base directory to start from
* @param includes the includes
* @param excludes the excludes
* @param includeDirectories include directories yes or not.
* @return the files to copy
*/
// CHECKSTYLE_OFF: LineLength
protected PathSet getFilesToIncludes(File baseDir, String[] includes, String[] excludes, boolean includeDirectories) // CHECKSTYLE_ON: LineLength
{
final DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
if (excludes != null) {
scanner.setExcludes(excludes);
}
scanner.addDefaultExcludes();
if (includes != null && includes.length > 0) {
scanner.setIncludes(includes);
} else {
scanner.setIncludes(DEFAULT_INCLUDES);
}
scanner.scan();
PathSet pathSet = new PathSet(scanner.getIncludedFiles());
if (includeDirectories) {
pathSet.addAll(scanner.getIncludedDirectories());
}
return pathSet;
}
Aggregations