Search in sources :

Example 6 with Overlay

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

the class WarOverlaysTest method testScenarioOneWithOverlaySettings.

/**
     * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc).
     * 
     * The default project is not specified in this case so it is processed first by default
     *
     * @throws Exception if an error occurs
     */
public void testScenarioOneWithOverlaySettings() throws Exception {
    // setup test data
    final String testId = "scenario-one-overlay-settings";
    // Add an overlay
    final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
    final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { "org/sample/company/test.jsp", "jsp/b.jsp" });
    // Add the tags
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new DefaultOverlay(overlay1));
    overlays.add(new DefaultOverlay(overlay2));
    overlays.add(new DefaultOverlay(overlay3));
    mojo.setOverlays(overlays);
    // current project ignored. Should be on top of the list
    assertScenariOne(testId, webAppDirectory);
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) File(java.io.File)

Example 7 with Overlay

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

the class WarOverlaysTest method testOverlaysIncludesExcludesWithMultipleDefinitions2.

public void testOverlaysIncludesExcludesWithMultipleDefinitions2() throws Exception {
    // setup test data
    final String testId = "overlays-includes-excludes-multiple-defs2";
    // Add an overlay
    final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
    final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { "org/sample/company/test.jsp", "jsp/b.jsp" });
    Overlay over1 = new DefaultOverlay(overlay3);
    over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp");
    Overlay over2 = new DefaultOverlay(overlay1);
    over2.setIncludes("jsp/d/*");
    over2.setExcludes("jsp/d/a.jsp");
    Overlay over3 = new DefaultOverlay(overlay3);
    over3.setIncludes("**/*.jsp");
    over3.setExcludes("jsp/b.jsp");
    Overlay over4 = new DefaultOverlay(overlay2);
    mojo.setOverlays(new LinkedList<Overlay>());
    mojo.addOverlay(over1);
    mojo.addOverlay(over2);
    mojo.addOverlay(over3);
    mojo.addOverlay(mojo.getCurrentProjectOverlay());
    mojo.addOverlay(over4);
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        mojo.execute();
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found"));
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp");
        assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
        assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) FileFilter(java.io.FileFilter) File(java.io.File)

Example 8 with Overlay

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

the class OverlayManager method initialize.

/**
     * Initializes the manager and validates the overlays configuration.
     *
     * @param defaultIncludes the default includes to use
     * @param defaultExcludes the default excludes to use
     * @param currentProjectOverlay the overlay for the current project
     * @throws InvalidOverlayConfigurationException if the configuration is invalid
     */
void initialize(String[] defaultIncludes, String[] defaultExcludes, Overlay currentProjectOverlay) throws InvalidOverlayConfigurationException {
    // Build the list of configured artifacts and makes sure that each overlay
    // refer to a valid artifact
    final List<Artifact> configuredWarArtifacts = new ArrayList<Artifact>();
    final ListIterator<Overlay> it = overlays.listIterator();
    while (it.hasNext()) {
        Overlay overlay = it.next();
        if (overlay == null) {
            throw new InvalidOverlayConfigurationException("overlay could not be null.");
        }
        // If it's the current project, return the project instance
        if (overlay.isCurrentProject()) {
            overlay = currentProjectOverlay;
            it.set(overlay);
        }
        // default includes/excludes - only if the overlay uses the default settings
        if (Arrays.equals(Overlay.DEFAULT_INCLUDES, overlay.getIncludes()) && Arrays.equals(Overlay.DEFAULT_EXCLUDES, overlay.getExcludes())) {
            overlay.setIncludes(defaultIncludes);
            overlay.setExcludes(defaultExcludes);
        }
        final Artifact artifact = getAssociatedArtifact(overlay);
        if (artifact != null) {
            configuredWarArtifacts.add(artifact);
            overlay.setArtifact(artifact);
        }
    }
    // Build the list of missing overlays
    for (Artifact artifact : artifactsOverlays) {
        if (!configuredWarArtifacts.contains(artifact)) {
            // Add a default overlay for the given artifact which will be applied after
            // the ones that have been configured
            overlays.add(new DefaultOverlay(artifact, defaultIncludes, defaultExcludes));
        }
    }
    // Final validation, make sure that the current project is in there. Otherwise add it first
    for (Overlay overlay : overlays) {
        if (overlay.equals(currentProjectOverlay)) {
            return;
        }
    }
    overlays.add(0, currentProjectOverlay);
}
Also used : ArrayList(java.util.ArrayList) Overlay(org.apache.maven.plugins.war.Overlay) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with Overlay

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

the class WarOverlaysTest method testCacheWithUpdatedOverlay.

public void testCacheWithUpdatedOverlay() throws Exception {
    // setup test data
    final String testId = "cache-updated-overlay";
    // Add an overlay
    final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay, overlay2 });
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        // Use the cache
        setVariableValueToObject(mojo, "useCache", Boolean.TRUE);
        setVariableValueToObject(mojo, "cacheFile", new File(mojo.getWorkDirectory(), "cache.xml"));
        final LinkedList<Overlay> overlays = new LinkedList<Overlay>();
        overlays.add(new DefaultOverlay(overlay));
        overlays.add(new DefaultOverlay(overlay2));
        mojo.setOverlays(overlays);
        mojo.execute();
        // Now change the overlay order and make sure the right file is overwritten
        final LinkedList<Overlay> updatedOverlays = new LinkedList<Overlay>();
        updatedOverlays.add(new DefaultOverlay(overlay2));
        updatedOverlays.add(new DefaultOverlay(overlay));
        mojo.setOverlays(updatedOverlays);
        mojo.execute();
        assertedFiles.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "index.jsp", "login.jsp", "admin.jsp" }, "overlay file not found"));
        // index and login come from overlay2 now
        assertOverlayedFile(webAppDirectory, "overlay-two", "index.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-two", "admin.jsp");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) FileFilter(java.io.FileFilter) File(java.io.File) LinkedList(java.util.LinkedList)

Example 10 with Overlay

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

the class WarOverlaysTest method testOverlaysIncludesExcludesWithMultipleDefinitions.

public void testOverlaysIncludesExcludesWithMultipleDefinitions() throws Exception {
    // setup test data
    final String testId = "overlays-includes-excludes-multiple-defs";
    // Add an overlay
    final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
    final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { "org/sample/company/test.jsp", "jsp/b.jsp" });
    Overlay over1 = new DefaultOverlay(overlay3);
    over1.setExcludes("**/a.*,**/c.*,**/*.xml");
    Overlay over2 = new DefaultOverlay(overlay1);
    over2.setIncludes("jsp/d/*");
    over2.setExcludes("jsp/d/a.jsp");
    Overlay over3 = new DefaultOverlay(overlay3);
    over3.setIncludes("**/*.jsp");
    Overlay over4 = new DefaultOverlay(overlay2);
    mojo.setOverlays(new LinkedList<Overlay>());
    mojo.addOverlay(over1);
    mojo.addOverlay(over2);
    mojo.addOverlay(over3);
    mojo.addOverlay(mojo.getCurrentProjectOverlay());
    mojo.addOverlay(over4);
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        mojo.execute();
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found"));
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
        assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

Overlay (org.apache.maven.plugins.war.Overlay)16 DefaultOverlay (org.apache.maven.plugins.war.overlay.DefaultOverlay)15 ArrayList (java.util.ArrayList)13 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)11 File (java.io.File)9 InvalidOverlayConfigurationException (org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)6 OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)6 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)5 FileFilter (java.io.FileFilter)4 LinkedList (java.util.LinkedList)2 Artifact (org.apache.maven.artifact.Artifact)1