Search in sources :

Example 1 with OverlayManager

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

the class OverlayManagerTest method testSimpleOverlay.

public void testSimpleOverlay() throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    project.addArtifact(first);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new DefaultOverlay(first));
    try {
        final Overlay currentProjectOverlay = Overlay.createInstance();
        OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay);
        assertNotNull(manager.getOverlays());
        assertEquals(2, manager.getOverlays().size());
        assertEquals(Overlay.createInstance(), manager.getOverlays().get(0));
        assertEquals(overlays.get(0), manager.getOverlays().get(1));
    } catch (InvalidOverlayConfigurationException e) {
        e.printStackTrace();
        fail("Should not have failed to validate a valid overlay config " + e.getMessage());
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Example 2 with OverlayManager

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

the class OverlayManagerTest method testOverlaysWithSameArtifactAndGroupId.

public void testOverlaysWithSameArtifactAndGroupId() throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    final ArtifactStub second = newWarArtifact("test", "test-webapp", "my-classifier");
    project.addArtifact(first);
    project.addArtifact(second);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new DefaultOverlay(first));
    overlays.add(new DefaultOverlay(second));
    try {
        final Overlay currentProjectOverlay = Overlay.createInstance();
        OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay);
        assertNotNull(manager.getOverlays());
        assertEquals(3, manager.getOverlays().size());
        assertEquals(currentProjectOverlay, manager.getOverlays().get(0));
        assertEquals(overlays.get(0), manager.getOverlays().get(1));
        assertEquals(overlays.get(1), manager.getOverlays().get(2));
    } catch (InvalidOverlayConfigurationException e) {
        e.printStackTrace();
        fail("Should not have failed to validate a valid overlay config " + e.getMessage());
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Example 3 with OverlayManager

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

the class AbstractWarMojo method buildWebapp.

/**
     * Builds the webapp for the specified project with the new packaging task thingy.
     * Classes, libraries and tld files are copied to the <tt>webappDirectory</tt> during this phase.
     *
     * @param mavenProject the maven project
     * @param webapplicationDirectory the target directory
     * @throws MojoExecutionException if an error occurred while packaging the webapp
     * @throws MojoFailureException if an unexpected error occurred while packaging the webapp
     * @throws IOException if an error occurred while copying the files
     */
public void buildWebapp(MavenProject mavenProject, File webapplicationDirectory) throws MojoExecutionException, MojoFailureException, IOException {
    WebappStructure cache;
    if (useCache && cacheFile.exists()) {
        // CHECKSTYLE_OFF: LineLength
        cache = new WebappStructure(mavenProject.getDependencies(), webappStructureSerialier.fromXml(cacheFile));
    // CHECKSTYLE_ON: LineLength
    } else {
        cache = new WebappStructure(mavenProject.getDependencies(), null);
    }
    // CHECKSTYLE_OFF: LineLength
    final long startTime = System.currentTimeMillis();
    getLog().info("Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]");
    final OverlayManager overlayManager = new OverlayManager(overlays, mavenProject, getDependentWarIncludes(), getDependentWarExcludes(), currentProjectOverlay);
    final List<WarPackagingTask> packagingTasks = getPackagingTasks(overlayManager);
    // CHECKSTYLE_ON: LineLength
    List<FileUtils.FilterWrapper> defaultFilterWrappers;
    try {
        MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
        mavenResourcesExecution.setEscapeString(escapeString);
        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
        mavenResourcesExecution.setMavenProject(mavenProject);
        // if these are NOT set, just use the defaults, which are '${*}' and '@'.
        mavenResourcesExecution.setDelimiters(delimiters, useDefaultDelimiters);
        if (nonFilteredFileExtensions != null) {
            mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
        }
        if (filters == null) {
            filters = getProject().getBuild().getFilters();
        }
        mavenResourcesExecution.setFilters(filters);
        mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath);
        mavenResourcesExecution.setMavenSession(this.session);
        mavenResourcesExecution.setEscapeString(this.escapeString);
        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
        defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution);
    } catch (MavenFilteringException e) {
        getLog().error("fail to build filering wrappers " + e.getMessage());
        throw new MojoExecutionException(e.getMessage(), e);
    }
    final WarPackagingContext context = new DefaultWarPackagingContext(webapplicationDirectory, cache, overlayManager, defaultFilterWrappers, getNonFilteredFileExtensions(), filteringDeploymentDescriptors, this.artifactFactory, resourceEncoding, useJvmChmod);
    for (WarPackagingTask warPackagingTask : packagingTasks) {
        warPackagingTask.performPackaging(context);
    }
    // Post packaging
    final List<WarPostPackagingTask> postPackagingTasks = getPostPackagingTasks();
    for (WarPostPackagingTask task : postPackagingTasks) {
        task.performPostPackaging(context);
    }
    getLog().info("Webapp assembled in [" + (System.currentTimeMillis() - startTime) + " msecs]");
}
Also used : OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) WarPackagingContext(org.apache.maven.plugins.war.packaging.WarPackagingContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) WarPostPackagingTask(org.apache.maven.plugins.war.packaging.WarPostPackagingTask) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure) WarPackagingTask(org.apache.maven.plugins.war.packaging.WarPackagingTask)

Example 4 with OverlayManager

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

the class OverlayManagerTest method testUnknonwnOverlay.

public void testUnknonwnOverlay() throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    project.addArtifact(first);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new Overlay("test", "test-webapp-2"));
    try {
        final Overlay currentProjectOVerlay = Overlay.createInstance();
        new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOVerlay);
        fail("Should have failed to validate an unknown overlay");
    } catch (InvalidOverlayConfigurationException e) {
    // OK
    }
}
Also used : OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Example 5 with OverlayManager

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

the class OverlayManagerTest method testAutodetectSimpleOverlay.

public void testAutodetectSimpleOverlay(Overlay currentProjectOverlay) throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    project.addArtifact(first);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    try {
        final Overlay overlay = currentProjectOverlay;
        OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, overlay);
        assertNotNull(manager.getOverlays());
        assertEquals(2, manager.getOverlays().size());
        assertEquals(overlay, manager.getOverlays().get(0));
        assertEquals(new DefaultOverlay(first), manager.getOverlays().get(1));
    } catch (InvalidOverlayConfigurationException e) {
        e.printStackTrace();
        fail("Should not have failed to validate a valid overlay config " + e.getMessage());
    }
}
Also used : OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Aggregations

OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)7 ArrayList (java.util.ArrayList)6 Overlay (org.apache.maven.plugins.war.Overlay)6 DefaultOverlay (org.apache.maven.plugins.war.overlay.DefaultOverlay)6 InvalidOverlayConfigurationException (org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)6 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)5 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 WarPackagingContext (org.apache.maven.plugins.war.packaging.WarPackagingContext)1 WarPackagingTask (org.apache.maven.plugins.war.packaging.WarPackagingTask)1 WarPostPackagingTask (org.apache.maven.plugins.war.packaging.WarPostPackagingTask)1 WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1 MavenResourcesExecution (org.apache.maven.shared.filtering.MavenResourcesExecution)1