This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch mvn4
in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git
The following commit(s) were added to refs/heads/mvn4 by this push:
new aae810e Switch a few core plugins to the new api
aae810e is described below
commit aae810ee5a212f2effac3053810992a178b1d895
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Feb 24 17:00:56 2022 +0100
Switch a few core plugins to the new api
---
pom.xml | 19 +---
.../maven/plugins/resources/CopyResourcesMojo.java | 6 +-
.../maven/plugins/resources/ResourcesMojo.java | 117 ++++++++-------------
.../maven/plugins/resources/TestResourcesMojo.java | 6 +-
.../maven/plugins/resources/filters/ItFilter.java | 2 +-
5 files changed, 54 insertions(+), 96 deletions(-)
diff --git a/pom.xml b/pom.xml
index c34eb9c..48d0212 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@ under the License.
<parent>
<artifactId>maven-plugins</artifactId>
<groupId>org.apache.maven.plugins</groupId>
- <version>34</version>
+ <version>35-SNAPSHOT</version>
</parent>
<artifactId>maven-resources-plugin</artifactId>
@@ -84,25 +84,10 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
+ <artifactId>maven-core-api</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>${mavenVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <version>${mavenVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-annotations</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
</dependency>
diff --git
a/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java
b/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java
index feee9d3..e3eb0fd 100644
--- a/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java
@@ -19,9 +19,9 @@ package org.apache.maven.plugins.resources;
* under the License.
*/
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.model.Resource;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
import java.io.File;
import java.util.List;
@@ -32,7 +32,7 @@ import java.util.List;
* @author Olivier Lamy
* @since 2.3
*/
-@Mojo( name = "copy-resources", threadSafe = true )
+@Mojo( name = "copy-resources" )
public class CopyResourcesMojo
extends ResourcesMojo
{
diff --git
a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
index a350a44..c438002 100644
--- a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
@@ -25,27 +25,23 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
-import org.apache.maven.execution.MavenSession;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Component;
+import org.apache.maven.api.plugin.annotations.LifecyclePhase;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.apache.maven.shared.filtering.MavenResourcesExecution;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import
org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Copy resources for the main source code to the main output directory.
Always uses the project.build.resources element
@@ -56,12 +52,13 @@ import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
* @author Andreas Hoheneder
* @author William Ferguson
*/
-@Mojo( name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES,
requiresProject = true, threadSafe = true )
+@Mojo( name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES )
public class ResourcesMojo
- extends AbstractMojo
- implements Contextualizable
+ implements org.apache.maven.api.plugin.Mojo
{
+ protected Logger logger = LoggerFactory.getLogger( getClass() );
+
/**
* The character encoding to use when reading and writing filtered
resources.
*/
@@ -93,7 +90,7 @@ public class ResourcesMojo
*
*/
@Parameter( defaultValue = "${project}", readonly = true, required = true )
- protected MavenProject project;
+ protected Project project;
/**
* The list of additional filter properties files to be used along with
System and project properties, which would
@@ -134,14 +131,8 @@ public class ResourcesMojo
/**
*
*/
- @Component( role = MavenResourcesFiltering.class, hint = "default" )
- protected MavenResourcesFiltering mavenResourcesFiltering;
-
- /**
- *
- */
@Parameter( defaultValue = "${session}", readonly = true, required = true )
- protected MavenSession session;
+ protected Session session;
/**
* Expressions preceded with this string won't be interpolated. Anything
else preceded with this string will be
@@ -259,16 +250,6 @@ public class ResourcesMojo
private List<String> mavenFilteringHints;
/**
- * @since 2.4
- */
- private PlexusContainer plexusContainer;
-
- /**
- * @since 2.4
- */
- private List<MavenResourcesFiltering> mavenFilteringComponents = new
ArrayList<MavenResourcesFiltering>();
-
- /**
* stop searching endToken at the end of line
*
* @since 2.5
@@ -293,29 +274,28 @@ public class ResourcesMojo
@Parameter( property = "maven.resources.skip", defaultValue = "false" )
private boolean skip;
- /** {@inheritDoc} */
- public void contextualize( Context context )
- throws ContextException
- {
- plexusContainer = (PlexusContainer) context.get(
PlexusConstants.PLEXUS_KEY );
- }
+ /**
+ * Map containing all MavenResourcesFiltering components
+ */
+ @Component
+ private Map<String, MavenResourcesFiltering> mavenResourcesFilteringMap;
/** {@inheritDoc} */
public void execute()
- throws MojoExecutionException
+ throws MojoException
{
if ( isSkip() )
{
- getLog().info( "Skipping the execution." );
+ logger.info( "Skipping the execution." );
return;
}
if ( StringUtils.isBlank( encoding ) && isFilteringEnabled(
getResources() ) )
{
- getLog().warn( "File encoding has not been set, using platform
encoding "
+ logger.warn( "File encoding has not been set, using platform
encoding "
+ System.getProperty( "file.encoding" )
+ ". Build is platform dependent!" );
- getLog().warn( "See
https://maven.apache.org/general.html#encoding-warning" );
+ logger.warn( "See
https://maven.apache.org/general.html#encoding-warning" );
}
try
@@ -323,8 +303,8 @@ public class ResourcesMojo
List<String> combinedFilters = getCombinedFiltersList();
MavenResourcesExecution mavenResourcesExecution =
- new MavenResourcesExecution( getResources(),
getOutputDirectory(), project, encoding, combinedFilters,
- Collections.<String>emptyList(),
session );
+ new MavenResourcesExecution( getResources(),
getOutputDirectory().toPath(), project, encoding,
+ combinedFilters,
Collections.emptyList(), session );
mavenResourcesExecution.setEscapeWindowsPaths( escapeWindowsPaths
);
@@ -353,13 +333,13 @@ public class ResourcesMojo
{
mavenResourcesExecution.setNonFilteredFileExtensions(
nonFilteredFileExtensions );
}
- mavenResourcesFiltering.filterResources( mavenResourcesExecution );
+ getFilter( "default" ).filterResources( mavenResourcesExecution );
executeUserFilterComponents( mavenResourcesExecution );
}
catch ( MavenFilteringException e )
{
- throw new MojoExecutionException( e.getMessage(), e );
+ throw new MojoException( e.getMessage(), e );
}
}
@@ -384,7 +364,8 @@ public class ResourcesMojo
additionalProperties.put( "maven.build.timestamp", timeStamp );
if ( project.getBasedir() != null )
{
- additionalProperties.put( "project.baseUri",
project.getBasedir().getAbsoluteFile().toURI().toString() );
+ additionalProperties.put( "project.baseUri",
+
project.getBasedir().toAbsolutePath().toFile().toURI().toString() );
}
return additionalProperties;
@@ -392,44 +373,36 @@ public class ResourcesMojo
/**
* @param mavenResourcesExecution {@link MavenResourcesExecution}
- * @throws MojoExecutionException in case of wrong lookup.
+ * @throws MojoException in case of wrong lookup.
* @throws MavenFilteringException in case of failure.
* @since 2.5
*/
protected void executeUserFilterComponents( MavenResourcesExecution
mavenResourcesExecution )
- throws MojoExecutionException, MavenFilteringException
+ throws MojoException, MavenFilteringException
{
-
- if ( mavenFilteringHints != null )
+ if ( mavenFilteringHints != null && !mavenFilteringHints.isEmpty() )
{
+ logger.debug( "execute user filters" );
for ( String hint : mavenFilteringHints )
{
- try
- {
- // CHECKSTYLE_OFF: LineLength
- mavenFilteringComponents.add( (MavenResourcesFiltering)
plexusContainer.lookup( MavenResourcesFiltering.class.getName(),
-
hint ) );
- // CHECKSTYLE_ON: LineLength
- }
- catch ( ComponentLookupException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
- }
+ MavenResourcesFiltering filter = getFilter( hint );
+ filter.filterResources( mavenResourcesExecution );
}
}
else
{
- getLog().debug( "no use filter components" );
+ logger.debug( "not using filter components" );
}
+ }
- if ( mavenFilteringComponents != null &&
!mavenFilteringComponents.isEmpty() )
+ protected MavenResourcesFiltering getFilter( String hint )
+ {
+ MavenResourcesFiltering filtering = mavenResourcesFilteringMap.get(
hint );
+ if ( filtering == null )
{
- getLog().debug( "execute user filters" );
- for ( MavenResourcesFiltering filter : mavenFilteringComponents )
- {
- filter.filterResources( mavenResourcesExecution );
- }
+ throw new MojoException( "Unable to find MavenResourcesFiltering
with hint '" + hint + "'" );
}
+ return filtering;
}
/**
diff --git
a/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java
b/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java
index b993126..72df179 100644
--- a/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java
@@ -19,8 +19,8 @@ package org.apache.maven.plugins.resources;
* under the License.
*/
+import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -64,11 +64,11 @@ public class TestResourcesMojo
* {@inheritDoc}
*/
public void execute()
- throws MojoExecutionException
+ throws MojoException
{
if ( skip )
{
- getLog().info( "Not copying test resources" );
+ logger.info( "Not copying test resources" );
}
else
{
diff --git
a/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java
b/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java
index 9fb95ae..a16350d 100644
--- a/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java
+++ b/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java
@@ -67,7 +67,7 @@ public class ItFilter
System.out.println("ItFilter filterResources");
try
{
- File f = new File( mavenResourcesExecution.getOutputDirectory(),
"foo.txt" );
+ File f = new File(
mavenResourcesExecution.getOutputDirectory().toFile(), "foo.txt" );
List<String> lines = new ArrayList<String>();
lines.add( "foo" );