You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2024/12/26 12:45:13 UTC
(maven-war-plugin) branch master updated: Prefer Guice injection (#79)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 1e267a6 Prefer Guice injection (#79)
1e267a6 is described below
commit 1e267a60af197cb0704508e7b38bbde95629c1fd
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Thu Dec 26 12:45:08 2024 +0000
Prefer Guice injection (#79)
* Prefer Guice injection
* Remove plexus components.xml
---
.../apache/maven/plugins/war/AbstractWarMojo.java | 116 ++++++---------------
.../apache/maven/plugins/war/WarExplodedMojo.java | 19 +++-
.../apache/maven/plugins/war/WarInPlaceMojo.java | 20 +++-
.../java/org/apache/maven/plugins/war/WarMojo.java | 18 ++++
.../META-INF/plexus/components.xml | 89 ----------------
.../apache/maven/plugins/war/WarOverlaysTest.java | 6 +-
6 files changed, 86 insertions(+), 182 deletions(-)
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.AbstractMojo;
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.MavenFilteringException;
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 <code>web.xml</code> file is missing. Set to <code>false</code> if you
+ * Whether to fail the build if the <code>web.xml</code> file is missing. Set to <code>false</code> if you
* want your WAR built without a <code>web.xml</code> file. This may be useful if you are building an overlay that
* has no web.xml file.
* <p>
@@ -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 abstract class AbstractWarMojo extends AbstractMojo {
return archiveClasses;
}
- /**
- * @param archiveClasses {@link #archiveClasses}
- */
- public void setArchiveClasses(boolean archiveClasses) {
- this.archiveClasses = archiveClasses;
- }
-
/**
* @return {@link JarArchiver}
*/
@@ -967,13 +960,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
return jarArchiver;
}
- /**
- * @param jarArchiver {@link JarArchiver}
- */
- public void setJarArchiver(JarArchiver jarArchiver) {
- this.jarArchiver = jarArchiver;
- }
-
/**
* @return {@link #webResources}.
*/
@@ -995,13 +981,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
return filters;
}
- /**
- * @param filters {@link #filters}
- */
- public void setFilters(List<String> filters) {
- this.filters = filters;
- }
-
/**
* @return {@link #workDirectory}
*/
@@ -1009,13 +988,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
return workDirectory;
}
- /**
- * @param workDirectory {@link #workDirectory}
- */
- public void setWorkDirectory(File workDirectory) {
- this.workDirectory = workDirectory;
- }
-
/**
* @return {@link #warSourceIncludes}
*/
@@ -1023,13 +995,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
return warSourceIncludes;
}
- /**
- * @param warSourceIncludes {@link #warSourceIncludes}
- */
- public void setWarSourceIncludes(String warSourceIncludes) {
- this.warSourceIncludes = warSourceIncludes;
- }
-
/**
* @return {@link #warSourceExcludes}
*/
@@ -1037,13 +1002,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
return warSourceExcludes;
}
- /**
- * @param warSourceExcludes {@link #warSourceExcludes}
- */
- public void setWarSourceExcludes(String warSourceExcludes) {
- this.warSourceExcludes = warSourceExcludes;
- }
-
/**
* @return {@link #archive}
*/
@@ -1058,13 +1016,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
return nonFilteredFileExtensions;
}
- /**
- * @param nonFilteredFileExtensions {@link #nonFilteredFileExtensions}
- */
- public void setNonFilteredFileExtensions(List<String> nonFilteredFileExtensions) {
- this.nonFilteredFileExtensions = nonFilteredFileExtensions;
- }
-
/**
* @return {@link #artifactFactory}
*/
@@ -1072,13 +1023,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
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 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
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 java.util.List;
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.Parameter;
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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-
-<component-set>
- <components>
- <!--
- | WAR
- |-->
- <component>
- <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
- <role-hint>war</role-hint>
- <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
- <configuration>
- <type>war</type>
- <includesDependencies>true</includesDependencies>
- <language>java</language>
- <addedToClasspath>false</addedToClasspath>
- </configuration>
- </component>
-
- <!--
- | Defining the phases with their appropriate plugins
- ! and versions which will be executed during the 'default'
- ! life cycle.
- -->
- <!--
- | WAR
- |-->
- <component>
- <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
- <role-hint>war</role-hint>
- <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
- <configuration>
- <lifecycles>
- <lifecycle>
- <id>default</id>
- <!-- START SNIPPET: war-lifecycle -->
- <phases>
- <process-resources>
- org.apache.maven.plugins:maven-resources-plugin:3.3.1:resources
- </process-resources>
- <compile>
- org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile
- </compile>
- <process-test-resources>
- org.apache.maven.plugins:maven-resources-plugin:3.3.1:testResources
- </process-test-resources>
- <test-compile>
- org.apache.maven.plugins:maven-compiler-plugin:3.11.0:testCompile
- </test-compile>
- <test>
- org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test
- </test>
- <package>
- org.apache.maven.plugins:maven-war-plugin:${project.version}:war
- </package>
- <install>
- org.apache.maven.plugins:maven-install-plugin:3.1.1:install
- </install>
- <deploy>
- org.apache.maven.plugins:maven-deploy-plugin:3.1.1:deploy
- </deploy>
- </phases>
- <!-- END SNIPPET: war-lifecycle -->
- </lifecycle>
- </lifecycles>
- </configuration>
- </component>
-
- </components>
-</component-set>
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 @@ public class WarOverlaysTest extends AbstractWarExplodedMojoTest {
}
/**
- * 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 @@ public class WarOverlaysTest extends AbstractWarExplodedMojoTest {
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);
- }
}