Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,6 @@ public abstract class AbstractWarMojo extends AbstractMojo {
@Parameter
private List<String> nonFilteredFileExtensions;

/**
* @since 2.1-alpha-2
*/
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;

/**
* To filter deployment descriptors. <b>Disabled by default.</b>
*
Expand Down Expand Up @@ -379,15 +373,19 @@ public abstract class AbstractWarMojo extends AbstractMojo {

private final MavenResourcesFiltering mavenResourcesFiltering;

private final MavenSession session;

protected AbstractWarMojo(
ArtifactHandlerManager artifactHandlerManager,
ArchiverManager archiverManager,
MavenFileFilter mavenFileFilter,
MavenResourcesFiltering mavenResourcesFiltering) {
MavenResourcesFiltering mavenResourcesFiltering,
MavenSession session) {
this.artifactHandlerManager = artifactHandlerManager;
this.archiverManager = archiverManager;
this.mavenFileFilter = mavenFileFilter;
this.mavenResourcesFiltering = mavenResourcesFiltering;
this.session = session;
try {
this.jarArchiver = (JarArchiver) archiverManager.getArchiver("jar");
} catch (NoSuchArchiverException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.inject.Inject;

import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -44,8 +45,9 @@ public WarExplodedMojo(
ArtifactHandlerManager artifactHandlerManager,
ArchiverManager archiverManager,
MavenFileFilter mavenFileFilter,
MavenResourcesFiltering mavenResourcesFiltering) {
super(artifactHandlerManager, archiverManager, mavenFileFilter, mavenResourcesFiltering);
MavenResourcesFiltering mavenResourcesFiltering,
MavenSession session) {
super(artifactHandlerManager, archiverManager, mavenFileFilter, mavenResourcesFiltering, session);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.inject.Inject;

import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -40,8 +41,9 @@ public WarInPlaceMojo(
ArtifactHandlerManager artifactHandlerManager,
ArchiverManager archiverManager,
MavenFileFilter mavenFileFilter,
MavenResourcesFiltering mavenResourcesFiltering) {
super(artifactHandlerManager, archiverManager, mavenFileFilter, mavenResourcesFiltering);
MavenResourcesFiltering mavenResourcesFiltering,
MavenSession session) {
super(artifactHandlerManager, archiverManager, mavenFileFilter, mavenResourcesFiltering, session);
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/apache/maven/plugins/war/WarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand Down Expand Up @@ -136,8 +137,9 @@ public WarMojo(
ArchiverManager archiverManager,
MavenFileFilter mavenFileFilter,
MavenResourcesFiltering mavenResourcesFiltering,
MavenProjectHelper projectHelper) {
super(artifactHandlerManager, archiverManager, mavenFileFilter, mavenResourcesFiltering);
MavenProjectHelper projectHelper,
MavenSession session) {
super(artifactHandlerManager, archiverManager, mavenFileFilter, mavenResourcesFiltering, session);
this.projectHelper = projectHelper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.apache.maven.plugin.testing.stubs.ArtifactStub;
Expand Down Expand Up @@ -94,7 +93,7 @@ protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, Stri
}
}

configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "workDirectory", workDirectory);

return webAppDirectory;
Expand Down
31 changes: 12 additions & 19 deletions src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;

import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
Expand All @@ -30,7 +29,6 @@
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
import org.apache.maven.plugins.war.stub.WarOverlayStub;
import org.apache.maven.shared.filtering.MavenFileFilter;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
Expand All @@ -47,35 +45,30 @@ public abstract class AbstractWarMojoTest extends AbstractMojoTestCase {

protected abstract File getTestDirectory() throws Exception;

protected void setUp() throws Exception {
super.setUp();

MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setSystemProperties(System.getProperties())
.setStartTime(new Date());

MavenSession mavenSession =
new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null);
getContainer().addComponent(mavenSession, MavenSession.class.getName());
}
/**
* initialize required parameters
*
* @param mojo The mojo to be tested.
* @param filters The list of filters.
* @param classesDir The classes' directory.
* @param webAppSource The webAppSource.
* @param webAppDir The webAppDir folder.
* @param project The Maven project.
* @throws Exception in case of errors
*/
protected void configureMojo(
AbstractWarMojo mojo,
List<String> filters,
File classesDir,
File webAppSource,
File webAppDir,
MavenProjectBasicStub project)
AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project)
throws Exception {
setVariableValueToObject(mojo, "filters", filters);
setVariableValueToObject(mojo, "mavenFileFilter", lookup(MavenFileFilter.class.getName()));

MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setSystemProperties(System.getProperties())
.setStartTime(new Date());

MavenSession mavenSession =
new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null);
setVariableValueToObject(mojo, "session", mavenSession);
setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/");
mojo.setClassesDirectory(classesDir);
mojo.setWarSourceDirectory(webAppSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.LinkedList;
import java.util.List;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
import org.apache.maven.plugins.war.stub.ResourceStub;
import org.codehaus.plexus.util.FileUtils;
Expand Down Expand Up @@ -96,14 +97,16 @@ public void testExplodedWarWithResourceFiltering() throws Exception {
FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content);
FileUtils.fileWrite(sampleResource.getAbsolutePath(), content);

System.setProperty("system.property", "system-property-value");
lookup(MavenSession.class).getSystemProperties().setProperty("system.property", "system-property-value");

// configure mojo
project.addProperty("is_this_simple", "i_think_so");
resources[0].setDirectory(webAppResource.getAbsolutePath());
resources[0].setFiltering(true);
this.configureMojo(mojo, filterList, classesDir, webAppSource, webAppDirectory, project);
this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "webResources", resources);
setVariableValueToObject(mojo, "filters", filterList);

mojo.execute();

// validate operation
Expand Down Expand Up @@ -151,8 +154,8 @@ public void testExplodedWarWithResourceFiltering() throws Exception {
reader.readLine());

// update property, and generate again
System.setProperty("system.property", "new-system-property-value");
this.configureMojo(mojo, filterList, classesDir, webAppSource, webAppDirectory, project);
lookup(MavenSession.class).getSystemProperties().setProperty("system.property", "new-system-property-value");
this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project);

mojo.execute();

Expand Down
Loading