diff --git a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java index fbee014..874ca2f 100644 --- a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java +++ b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java @@ -40,7 +40,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.war.overlay.OverlayManager; import org.apache.maven.plugins.war.packaging.CopyUserManifestTask; @@ -56,7 +55,6 @@ import org.apache.maven.shared.filtering.MavenResourcesExecution; import org.apache.maven.shared.filtering.MavenResourcesFiltering; import org.apache.maven.shared.utils.StringUtils; -import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.archiver.manager.ArchiverManager; @@ -68,7 +66,7 @@ public abstract class AbstractWarMojo extends AbstractMojo { private static final String WEB_INF = "WEB-INF"; /** - * Whether or not to fail the build if the web.xml file is missing. Set to false if you + * Whether to fail the build if the web.xml file is missing. Set to false if you * want your WAR built without a web.xml file. This may be useful if you are building an overlay that * has no web.xml file. *

@@ -119,12 +117,6 @@ public abstract class AbstractWarMojo extends AbstractMojo { @Parameter protected String propertiesEncoding; - /** - * The JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib. - */ - @Component(role = Archiver.class, hint = "jar") - private JarArchiver jarArchiver; - /** * The directory where the webapp is built. */ @@ -210,27 +202,6 @@ public abstract class AbstractWarMojo extends AbstractMojo { @Parameter private String outputFileNameMapping; - /** - */ - @Component(role = ArtifactFactory.class) - private ArtifactFactory artifactFactory; - - /** - * To look up Archiver/UnArchiver implementations. - */ - @Component(role = ArchiverManager.class) - private ArchiverManager archiverManager; - - /** - */ - @Component(role = MavenFileFilter.class, hint = "default") - private MavenFileFilter mavenFileFilter; - - /** - */ - @Component(role = MavenResourcesFiltering.class, hint = "default") - private MavenResourcesFiltering mavenResourcesFiltering; - /** * The comma separated list of tokens to include when copying the content of the warSourceDirectory. */ @@ -381,6 +352,35 @@ public abstract class AbstractWarMojo extends AbstractMojo { private final Overlay currentProjectOverlay = Overlay.createInstance(); + /** + * The JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib. + */ + private final JarArchiver jarArchiver; + + private final ArtifactFactory artifactFactory; + + /** + * To look up Archiver/UnArchiver implementations. + */ + private final ArchiverManager archiverManager; + + private final MavenFileFilter mavenFileFilter; + + private final MavenResourcesFiltering mavenResourcesFiltering; + + protected AbstractWarMojo( + JarArchiver jarArchiver, + ArtifactFactory artifactFactory, + ArchiverManager archiverManager, + MavenFileFilter mavenFileFilter, + MavenResourcesFiltering mavenResourcesFiltering) { + this.jarArchiver = jarArchiver; + this.artifactFactory = artifactFactory; + this.archiverManager = archiverManager; + this.mavenFileFilter = mavenFileFilter; + this.mavenResourcesFiltering = mavenResourcesFiltering; + } + /** * @return The current overlay. */ @@ -953,13 +953,6 @@ public boolean isArchiveClasses() { return archiveClasses; } - /** - * @param archiveClasses {@link #archiveClasses} - */ - public void setArchiveClasses(boolean archiveClasses) { - this.archiveClasses = archiveClasses; - } - /** * @return {@link JarArchiver} */ @@ -967,13 +960,6 @@ public JarArchiver getJarArchiver() { return jarArchiver; } - /** - * @param jarArchiver {@link JarArchiver} - */ - public void setJarArchiver(JarArchiver jarArchiver) { - this.jarArchiver = jarArchiver; - } - /** * @return {@link #webResources}. */ @@ -995,13 +981,6 @@ public List getFilters() { return filters; } - /** - * @param filters {@link #filters} - */ - public void setFilters(List filters) { - this.filters = filters; - } - /** * @return {@link #workDirectory} */ @@ -1009,13 +988,6 @@ public File getWorkDirectory() { return workDirectory; } - /** - * @param workDirectory {@link #workDirectory} - */ - public void setWorkDirectory(File workDirectory) { - this.workDirectory = workDirectory; - } - /** * @return {@link #warSourceIncludes} */ @@ -1023,13 +995,6 @@ public String getWarSourceIncludes() { return warSourceIncludes; } - /** - * @param warSourceIncludes {@link #warSourceIncludes} - */ - public void setWarSourceIncludes(String warSourceIncludes) { - this.warSourceIncludes = warSourceIncludes; - } - /** * @return {@link #warSourceExcludes} */ @@ -1037,13 +1002,6 @@ public String getWarSourceExcludes() { return warSourceExcludes; } - /** - * @param warSourceExcludes {@link #warSourceExcludes} - */ - public void setWarSourceExcludes(String warSourceExcludes) { - this.warSourceExcludes = warSourceExcludes; - } - /** * @return {@link #archive} */ @@ -1058,13 +1016,6 @@ public List getNonFilteredFileExtensions() { return nonFilteredFileExtensions; } - /** - * @param nonFilteredFileExtensions {@link #nonFilteredFileExtensions} - */ - public void setNonFilteredFileExtensions(List nonFilteredFileExtensions) { - this.nonFilteredFileExtensions = nonFilteredFileExtensions; - } - /** * @return {@link #artifactFactory} */ @@ -1072,13 +1023,6 @@ public ArtifactFactory getArtifactFactory() { return this.artifactFactory; } - /** - * @param artifactFactory {@link #artifactFactory} - */ - public void setArtifactFactory(ArtifactFactory artifactFactory) { - this.artifactFactory = artifactFactory; - } - /** * @return {@link #session} */ diff --git a/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java b/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java index 7e543ff..f2b999b 100644 --- a/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java +++ b/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java @@ -18,15 +18,22 @@ */ package org.apache.maven.plugins.war; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenResourcesFiltering; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; /** * Create an exploded webapp in a specified directory. - * */ @Mojo( name = "exploded", @@ -34,6 +41,16 @@ threadSafe = true, requiresDependencyResolution = ResolutionScope.RUNTIME) public class WarExplodedMojo extends AbstractWarMojo { + @Inject + public WarExplodedMojo( + JarArchiver jarArchiver, + ArtifactFactory artifactFactory, + ArchiverManager archiverManager, + @Named("default") MavenFileFilter mavenFileFilter, + @Named("default") MavenResourcesFiltering mavenResourcesFiltering) { + super(jarArchiver, artifactFactory, archiverManager, mavenFileFilter, mavenResourcesFiltering); + } + @Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Exploding webapp"); diff --git a/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java b/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java index 0190601..3951c7e 100644 --- a/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java +++ b/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java @@ -18,17 +18,35 @@ */ package org.apache.maven.plugins.war; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenResourcesFiltering; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; /** * Generate the webapp in the WAR source directory. - * */ @Mojo(name = "inplace", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true) public class WarInPlaceMojo extends AbstractWarMojo { + + @Inject + public WarInPlaceMojo( + JarArchiver jarArchiver, + ArtifactFactory artifactFactory, + ArchiverManager archiverManager, + @Named("default") MavenFileFilter mavenFileFilter, + @Named("default") MavenResourcesFiltering mavenResourcesFiltering) { + super(jarArchiver, artifactFactory, archiverManager, mavenFileFilter, mavenResourcesFiltering); + } + @Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Generating webapp in source directory [" + getWarSourceDirectory() + "]"); diff --git a/src/main/java/org/apache/maven/plugins/war/WarMojo.java b/src/main/java/org/apache/maven/plugins/war/WarMojo.java index 6b46c18..a42cc59 100644 --- a/src/main/java/org/apache/maven/plugins/war/WarMojo.java +++ b/src/main/java/org/apache/maven/plugins/war/WarMojo.java @@ -18,6 +18,9 @@ */ package org.apache.maven.plugins.war; +import javax.inject.Inject; +import javax.inject.Named; + import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -29,6 +32,7 @@ import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; @@ -38,9 +42,13 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.plugins.war.util.ClassesPackager; import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenResourcesFiltering; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.archiver.jar.ManifestException; +import org.codehaus.plexus.archiver.manager.ArchiverManager; import org.codehaus.plexus.archiver.war.WarArchiver; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; @@ -155,6 +163,16 @@ public class WarMojo extends AbstractWarMojo { @Parameter(property = "maven.war.skip", defaultValue = "false") private boolean skip; + @Inject + public WarMojo( + JarArchiver jarArchiver, + ArtifactFactory artifactFactory, + ArchiverManager archiverManager, + @Named("default") MavenFileFilter mavenFileFilter, + @Named("default") MavenResourcesFiltering mavenResourcesFiltering) { + super(jarArchiver, artifactFactory, archiverManager, mavenFileFilter, mavenResourcesFiltering); + } + // ---------------------------------------------------------------------- // Implementation // ---------------------------------------------------------------------- diff --git a/src/main/resources-filtered/META-INF/plexus/components.xml b/src/main/resources-filtered/META-INF/plexus/components.xml deleted file mode 100644 index c23b164..0000000 --- a/src/main/resources-filtered/META-INF/plexus/components.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - org.apache.maven.artifact.handler.ArtifactHandler - war - org.apache.maven.artifact.handler.DefaultArtifactHandler - - war - true - java - false - - - - - - - org.apache.maven.lifecycle.mapping.LifecycleMapping - war - org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - - default - - - - org.apache.maven.plugins:maven-resources-plugin:3.3.1:resources - - - org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile - - - org.apache.maven.plugins:maven-resources-plugin:3.3.1:testResources - - - org.apache.maven.plugins:maven-compiler-plugin:3.11.0:testCompile - - - org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test - - - org.apache.maven.plugins:maven-war-plugin:${project.version}:war - - - org.apache.maven.plugins:maven-install-plugin:3.1.1:install - - - org.apache.maven.plugins:maven-deploy-plugin:3.1.1:deploy - - - - - - - - - - diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index c049947..68540ca 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -461,7 +461,7 @@ protected void assertOverlayedFile(File webAppDirectory, String overlayId, Strin } /** - * Asserts that the content of an overlayed file is correct. + * Asserts that the content of an overlaid file is correct. * * Note that the {@code filePath} is relative to both the webapp directory and the overlayed directory, defined by * the {@code overlayId}. @@ -477,8 +477,4 @@ protected void assertDefaultFileContent(String testId, File webAppDirectory, Str final String expectedContent = sourceFile.toString(); assertEquals("Wrong content for file " + filePath, expectedContent, FileUtils.fileRead(webAppFile)); } - - protected ArtifactStub generateSimpleWarArtifactStub(String id) throws Exception { - return buildWarOverlayStub(id); - } }