Skip to content

Commit

Permalink
Prefer Guice injection (#79)
Browse files Browse the repository at this point in the history
* Prefer Guice injection
* Remove plexus components.xml
  • Loading branch information
elharo authored Dec 26, 2024
1 parent c3ac8db commit 1e267a6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 182 deletions.
116 changes: 30 additions & 86 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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>
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -953,27 +953,13 @@ public boolean isArchiveClasses() {
return archiveClasses;
}

/**
* @param archiveClasses {@link #archiveClasses}
*/
public void setArchiveClasses(boolean archiveClasses) {
this.archiveClasses = archiveClasses;
}

/**
* @return {@link JarArchiver}
*/
public JarArchiver getJarArchiver() {
return jarArchiver;
}

/**
* @param jarArchiver {@link JarArchiver}
*/
public void setJarArchiver(JarArchiver jarArchiver) {
this.jarArchiver = jarArchiver;
}

/**
* @return {@link #webResources}.
*/
Expand All @@ -995,55 +981,27 @@ public List<String> getFilters() {
return filters;
}

/**
* @param filters {@link #filters}
*/
public void setFilters(List<String> filters) {
this.filters = filters;
}

/**
* @return {@link #workDirectory}
*/
public File getWorkDirectory() {
return workDirectory;
}

/**
* @param workDirectory {@link #workDirectory}
*/
public void setWorkDirectory(File workDirectory) {
this.workDirectory = workDirectory;
}

/**
* @return {@link #warSourceIncludes}
*/
public String getWarSourceIncludes() {
return warSourceIncludes;
}

/**
* @param warSourceIncludes {@link #warSourceIncludes}
*/
public void setWarSourceIncludes(String warSourceIncludes) {
this.warSourceIncludes = warSourceIncludes;
}

/**
* @return {@link #warSourceExcludes}
*/
public String getWarSourceExcludes() {
return warSourceExcludes;
}

/**
* @param warSourceExcludes {@link #warSourceExcludes}
*/
public void setWarSourceExcludes(String warSourceExcludes) {
this.warSourceExcludes = warSourceExcludes;
}

/**
* @return {@link #archive}
*/
Expand All @@ -1058,27 +1016,13 @@ public List<String> getNonFilteredFileExtensions() {
return nonFilteredFileExtensions;
}

/**
* @param nonFilteredFileExtensions {@link #nonFilteredFileExtensions}
*/
public void setNonFilteredFileExtensions(List<String> nonFilteredFileExtensions) {
this.nonFilteredFileExtensions = nonFilteredFileExtensions;
}

/**
* @return {@link #artifactFactory}
*/
public ArtifactFactory getArtifactFactory() {
return this.artifactFactory;
}

/**
* @param artifactFactory {@link #artifactFactory}
*/
public void setArtifactFactory(ArtifactFactory artifactFactory) {
this.artifactFactory = artifactFactory;
}

/**
* @return {@link #session}
*/
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,39 @@
*/
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",
defaultPhase = LifecyclePhase.PACKAGE,
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");
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() + "]");
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/apache/maven/plugins/war/WarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
// ----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 1e267a6

Please sign in to comment.