Skip to content

Commit

Permalink
[MRESOURCES-295] Drop Plexus legacy code (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 21, 2023
1 parent df7e172 commit 6bb3e1f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 65 deletions.
21 changes: 4 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ under the License.
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interpolation</artifactId>
Expand Down Expand Up @@ -208,6 +203,10 @@ under the License.
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
<!--
! The following is used within the src/it/user-filters test.
-->
Expand All @@ -222,18 +221,6 @@ under the License.
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<goals>
<goal>generate-test-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
85 changes: 39 additions & 46 deletions src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -40,12 +41,6 @@
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;

/**
* Copy resources for the main source code to the main output directory. Always uses the project.build.resources element
Expand All @@ -58,8 +53,7 @@
*/
@Mojo( name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresProject = true, threadSafe = true )
public class ResourcesMojo
extends AbstractMojo
implements Contextualizable
extends AbstractMojo
{

/**
Expand Down Expand Up @@ -98,8 +92,8 @@ public class ResourcesMojo
/**
* The list of additional filter properties files to be used along with System and project properties, which would
* be used for the filtering.
* @see ResourcesMojo#filters
*
* @see ResourcesMojo#filters
* @since 2.4
*/
@Parameter( defaultValue = "${project.build.filters}", readonly = true )
Expand All @@ -123,9 +117,9 @@ public class ResourcesMojo
/**
* If false, don't use the filters specified in the build/filters section of the POM when processing resources in
* this mojo execution.
* @see ResourcesMojo#buildFilters
* @see ResourcesMojo#filters
*
* @see ResourcesMojo#buildFilters
* @see ResourcesMojo#filters
* @since 2.4
*/
@Parameter( defaultValue = "true" )
Expand All @@ -137,6 +131,12 @@ public class ResourcesMojo
@Component( role = MavenResourcesFiltering.class, hint = "default" )
protected MavenResourcesFiltering mavenResourcesFiltering;

/**
*
*/
@Component( role = MavenResourcesFiltering.class )
protected Map<String, MavenResourcesFiltering> mavenResourcesFilteringMap;

/**
*
*/
Expand All @@ -147,6 +147,7 @@ public class ResourcesMojo
* Expressions preceded with this string won't be interpolated. Anything else preceded with this string will be
* passed through unchanged. For example {@code \${foo}} will be replaced with {@code ${foo}} but {@code \\${foo}}
* will be replaced with {@code \\value of foo}, if this parameter has been set to the backslash.
*
* @since 2.3
*/
@Parameter
Expand Down Expand Up @@ -192,7 +193,7 @@ public class ResourcesMojo
* <p>
* So, the default filtering delimiters might be specified as:
* </p>
*
*
* <pre>
* &lt;delimiters&gt;
* &lt;delimiter&gt;${*}&lt;/delimiter&gt;
Expand Down Expand Up @@ -258,11 +259,6 @@ public class ResourcesMojo
@Parameter
private List<String> mavenFilteringHints;

/**
* @since 2.4
*/
private PlexusContainer plexusContainer;

/**
* @since 2.4
*/
Expand All @@ -278,7 +274,7 @@ public class ResourcesMojo

/**
* Support filtering of filenames folders etc.
*
*
* @since 3.0.0
*/
@Parameter( defaultValue = "false" )
Expand All @@ -287,22 +283,17 @@ public class ResourcesMojo
/**
* You can skip the execution of the plugin if you need to. Its use is NOT RECOMMENDED, but quite convenient on
* occasion.
*
*
* @since 3.0.0
*/
@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 );
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
public void execute()
throws MojoExecutionException
throws MojoExecutionException
{
if ( isSkip() )
{
Expand All @@ -313,8 +304,8 @@ public void execute()
if ( StringUtils.isBlank( encoding ) && isFilteringEnabled( getResources() ) )
{
getLog().warn( "File encoding has not been set, using platform encoding "
+ System.getProperty( "file.encoding" )
+ ". Build is platform dependent!" );
+ System.getProperty( "file.encoding" )
+ ". Build is platform dependent!" );
getLog().warn( "See https://maven.apache.org/general.html#encoding-warning" );
}

Expand All @@ -323,8 +314,9 @@ public void execute()
List<String> combinedFilters = getCombinedFiltersList();

MavenResourcesExecution mavenResourcesExecution =
new MavenResourcesExecution( getResources(), getOutputDirectory(), project, encoding, combinedFilters,
Collections.emptyList(), session );
new MavenResourcesExecution( getResources(), getOutputDirectory(), project, encoding,
combinedFilters,
Collections.emptyList(), session );

mavenResourcesExecution.setEscapeWindowsPaths( escapeWindowsPaths );

Expand Down Expand Up @@ -371,10 +363,10 @@ public void execute()
* can't be found in the context which can be got from the maven core.<br/>
* A solution could be to put those values into the context by Maven core so they are accessible everywhere. (I'm
* not sure if this is a good idea). Better ideas are always welcome.
*
* The problem at the moment is that maven core handles usage of properties and replacements in
* <p>
* The problem at the moment is that maven core handles usage of properties and replacements in
* the model, but does not the resource filtering which needed some of the properties.
*
*
* @return the new instance with those properties.
*/
private Properties addSeveralSpecialProperties()
Expand All @@ -391,35 +383,36 @@ private Properties addSeveralSpecialProperties()
}

/**
* @param mavenResourcesExecution {@link MavenResourcesExecution}
* @throws MojoExecutionException in case of wrong lookup.
* @param mavenResourcesExecution {@link MavenResourcesExecution}
* @throws MojoExecutionException in case of wrong lookup.
* @throws MavenFilteringException in case of failure.
* @since 2.5
*/
protected void executeUserFilterComponents( MavenResourcesExecution mavenResourcesExecution )
throws MojoExecutionException, MavenFilteringException
throws MojoExecutionException, MavenFilteringException
{

if ( mavenFilteringHints != null )
{
for ( String hint : mavenFilteringHints )
{
try
MavenResourcesFiltering userFilterComponent = mavenResourcesFilteringMap.get( hint );
if ( userFilterComponent != null )
{
// CHECKSTYLE_OFF: LineLength
mavenFilteringComponents.add( (MavenResourcesFiltering) plexusContainer.lookup( MavenResourcesFiltering.class.getName(),
hint ) );
// CHECKSTYLE_ON: LineLength
getLog().debug( "added user filter component with hint: " + hint );
mavenFilteringComponents.add( userFilterComponent );
}
catch ( ComponentLookupException e )
else
{
throw new MojoExecutionException( e.getMessage(), e );
throw new MojoExecutionException(
"User filter with hint `" + hint + "` requested, but not present. Discovered filters are: "
+ mavenResourcesFilteringMap.keySet() );
}
}
}
else
{
getLog().debug( "no use filter components" );
getLog().debug( "no user filter components" );
}

if ( mavenFilteringComponents != null && !mavenFilteringComponents.isEmpty() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.apache.maven.plugins.resources.filters;

import javax.inject.Named;
import javax.inject.Singleton;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -28,14 +31,14 @@
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.component.annotations.Component;

/**
* @author Olivier Lamy
* @since 2.5
* @version $Id$
*/
@Component(role = org.apache.maven.shared.filtering.MavenResourcesFiltering.class, hint = "itFilter")
@Singleton
@Named("itFilter")
public class ItFilter
implements MavenResourcesFiltering
{
Expand Down

0 comments on commit 6bb3e1f

Please sign in to comment.