Search in sources :

Example 1 with WebappStructure

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

the class WebappStructureTest method testDependencyAnalysisNoChange.

public void testDependencyAnalysisNoChange() {
    final List<Dependency> dependencies = new ArrayList<Dependency>();
    dependencies.add(createDependency("groupTest", "artifactTest", "1.0"));
    final WebappStructure cache = new WebappStructure(dependencies);
    final WebappStructure webappStructure = new WebappStructure(dependencies, cache);
    webappStructure.analyseDependencies(new WebappStructure.DependenciesAnalysisCallback() {

        int count = 0;

        public void unchangedDependency(Dependency dependency) {
            if (count == 0) {
                count++;
            } else {
                fail("Should have called unchanged dependency only once");
            }
        }

        public void newDependency(Dependency dependency) {
            fail("Should have failed to trigger this callback");
        }

        public void removedDependency(Dependency dependency) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedVersion(Dependency dependency, String previousVersion) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedScope(Dependency dependency, String previousScope) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedOptionalFlag(Dependency dependency, boolean previousOptional) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedUnknown(Dependency dependency, Dependency previousDep) {
            fail("Should have failed to trigger this callback");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure)

Example 2 with WebappStructure

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

the class WebappStructureTest method testUnknownFileNotAvailable.

public void testUnknownFileNotAvailable() {
    final WebappStructure structure = new WebappStructure(new ArrayList<Dependency>());
    assertFalse(structure.isRegistered("/foo/bar.txt"));
}
Also used : Dependency(org.apache.maven.model.Dependency) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure)

Example 3 with WebappStructure

use of org.apache.maven.plugins.war.util.WebappStructure 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 WebappStructure

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

the class WebappStructureTest method testDependencyAnalysisWithRemovedDependency.

public void testDependencyAnalysisWithRemovedDependency() {
    final List<Dependency> dependencies = new ArrayList<Dependency>();
    dependencies.add(createDependency("groupTest", "artifactTest", "1.0"));
    final Dependency removedDependency = createDependency("groupTest", "removedDep", "5.2");
    dependencies.add(removedDependency);
    final WebappStructure cache = new WebappStructure(dependencies);
    final List<Dependency> newDependencies = new ArrayList<Dependency>(dependencies);
    newDependencies.remove(removedDependency);
    final WebappStructure webappStructure = new WebappStructure(newDependencies, cache);
    webappStructure.analyseDependencies(new WebappStructure.DependenciesAnalysisCallback() {

        int count = 0;

        public void unchangedDependency(Dependency dependency) {
            if (count == 0) {
                count++;
            } else {
                fail("Should have called unchanged dependency only once");
            }
        }

        public void newDependency(Dependency dependency) {
            fail("Should have failed to trigger this callback");
        }

        public void removedDependency(Dependency dependency) {
            if (!removedDependency.equals(dependency)) {
                fail("Called removed dependency with an unexpected dependency " + dependency);
            }
        }

        public void updatedVersion(Dependency dependency, String previousVersion) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedScope(Dependency dependency, String previousScope) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedOptionalFlag(Dependency dependency, boolean previousOptional) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedUnknown(Dependency dependency, Dependency previousDep) {
            fail("Should have failed to trigger this callback");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure)

Example 5 with WebappStructure

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

the class WebappStructureTest method testRegisterForced.

public void testRegisterForced() {
    final String path = "WEB-INF/web.xml";
    final WebappStructure structure = new WebappStructure(new ArrayList<Dependency>());
    assertFalse("New file should return false", structure.registerFileForced("overlay1", path));
    assertEquals("overlay1", structure.getOwner(path));
}
Also used : Dependency(org.apache.maven.model.Dependency) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure)

Aggregations

WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)8 Dependency (org.apache.maven.model.Dependency)7 ArrayList (java.util.ArrayList)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)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 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1 MavenResourcesExecution (org.apache.maven.shared.filtering.MavenResourcesExecution)1