Skip to content

Commit 6bb3e1f

Browse files
authored
[MRESOURCES-295] Drop Plexus legacy code (#53)
Convert to modern stuff. --- https://issues.apache.org/jira/browse/MRESOURCES-295
1 parent df7e172 commit 6bb3e1f

File tree

3 files changed

+48
-65
lines changed

3 files changed

+48
-65
lines changed

pom.xml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ under the License.
111111
<artifactId>maven-plugin-annotations</artifactId>
112112
<scope>provided</scope>
113113
</dependency>
114-
<dependency>
115-
<groupId>org.codehaus.plexus</groupId>
116-
<artifactId>plexus-component-annotations</artifactId>
117-
<scope>provided</scope>
118-
</dependency>
119114
<dependency>
120115
<groupId>org.codehaus.plexus</groupId>
121116
<artifactId>plexus-interpolation</artifactId>
@@ -208,6 +203,10 @@ under the License.
208203
</plugins>
209204
</pluginManagement>
210205
<plugins>
206+
<plugin>
207+
<groupId>org.eclipse.sisu</groupId>
208+
<artifactId>sisu-maven-plugin</artifactId>
209+
</plugin>
211210
<!--
212211
! The following is used within the src/it/user-filters test.
213212
-->
@@ -222,18 +221,6 @@ under the License.
222221
</execution>
223222
</executions>
224223
</plugin>
225-
<plugin>
226-
<groupId>org.codehaus.plexus</groupId>
227-
<artifactId>plexus-component-metadata</artifactId>
228-
<version>2.1.1</version>
229-
<executions>
230-
<execution>
231-
<goals>
232-
<goal>generate-test-metadata</goal>
233-
</goals>
234-
</execution>
235-
</executions>
236-
</plugin>
237224
</plugins>
238225
</build>
239226
</profile>

src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Collections;
2626
import java.util.LinkedHashSet;
2727
import java.util.List;
28+
import java.util.Map;
2829
import java.util.Properties;
2930

3031
import org.apache.commons.lang3.StringUtils;
@@ -40,12 +41,6 @@
4041
import org.apache.maven.shared.filtering.MavenFilteringException;
4142
import org.apache.maven.shared.filtering.MavenResourcesExecution;
4243
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
43-
import org.codehaus.plexus.PlexusConstants;
44-
import org.codehaus.plexus.PlexusContainer;
45-
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
46-
import org.codehaus.plexus.context.Context;
47-
import org.codehaus.plexus.context.ContextException;
48-
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
4944

5045
/**
5146
* Copy resources for the main source code to the main output directory. Always uses the project.build.resources element
@@ -58,8 +53,7 @@
5853
*/
5954
@Mojo( name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresProject = true, threadSafe = true )
6055
public class ResourcesMojo
61-
extends AbstractMojo
62-
implements Contextualizable
56+
extends AbstractMojo
6357
{
6458

6559
/**
@@ -98,8 +92,8 @@ public class ResourcesMojo
9892
/**
9993
* The list of additional filter properties files to be used along with System and project properties, which would
10094
* be used for the filtering.
101-
* @see ResourcesMojo#filters
10295
*
96+
* @see ResourcesMojo#filters
10397
* @since 2.4
10498
*/
10599
@Parameter( defaultValue = "${project.build.filters}", readonly = true )
@@ -123,9 +117,9 @@ public class ResourcesMojo
123117
/**
124118
* If false, don't use the filters specified in the build/filters section of the POM when processing resources in
125119
* this mojo execution.
126-
* @see ResourcesMojo#buildFilters
127-
* @see ResourcesMojo#filters
128120
*
121+
* @see ResourcesMojo#buildFilters
122+
* @see ResourcesMojo#filters
129123
* @since 2.4
130124
*/
131125
@Parameter( defaultValue = "true" )
@@ -137,6 +131,12 @@ public class ResourcesMojo
137131
@Component( role = MavenResourcesFiltering.class, hint = "default" )
138132
protected MavenResourcesFiltering mavenResourcesFiltering;
139133

134+
/**
135+
*
136+
*/
137+
@Component( role = MavenResourcesFiltering.class )
138+
protected Map<String, MavenResourcesFiltering> mavenResourcesFilteringMap;
139+
140140
/**
141141
*
142142
*/
@@ -147,6 +147,7 @@ public class ResourcesMojo
147147
* Expressions preceded with this string won't be interpolated. Anything else preceded with this string will be
148148
* passed through unchanged. For example {@code \${foo}} will be replaced with {@code ${foo}} but {@code \\${foo}}
149149
* will be replaced with {@code \\value of foo}, if this parameter has been set to the backslash.
150+
*
150151
* @since 2.3
151152
*/
152153
@Parameter
@@ -192,7 +193,7 @@ public class ResourcesMojo
192193
* <p>
193194
* So, the default filtering delimiters might be specified as:
194195
* </p>
195-
*
196+
*
196197
* <pre>
197198
* &lt;delimiters&gt;
198199
* &lt;delimiter&gt;${*}&lt;/delimiter&gt;
@@ -258,11 +259,6 @@ public class ResourcesMojo
258259
@Parameter
259260
private List<String> mavenFilteringHints;
260261

261-
/**
262-
* @since 2.4
263-
*/
264-
private PlexusContainer plexusContainer;
265-
266262
/**
267263
* @since 2.4
268264
*/
@@ -278,7 +274,7 @@ public class ResourcesMojo
278274

279275
/**
280276
* Support filtering of filenames folders etc.
281-
*
277+
*
282278
* @since 3.0.0
283279
*/
284280
@Parameter( defaultValue = "false" )
@@ -287,22 +283,17 @@ public class ResourcesMojo
287283
/**
288284
* You can skip the execution of the plugin if you need to. Its use is NOT RECOMMENDED, but quite convenient on
289285
* occasion.
290-
*
286+
*
291287
* @since 3.0.0
292288
*/
293289
@Parameter( property = "maven.resources.skip", defaultValue = "false" )
294290
private boolean skip;
295291

296-
/** {@inheritDoc} */
297-
public void contextualize( Context context )
298-
throws ContextException
299-
{
300-
plexusContainer = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
301-
}
302-
303-
/** {@inheritDoc} */
292+
/**
293+
* {@inheritDoc}
294+
*/
304295
public void execute()
305-
throws MojoExecutionException
296+
throws MojoExecutionException
306297
{
307298
if ( isSkip() )
308299
{
@@ -313,8 +304,8 @@ public void execute()
313304
if ( StringUtils.isBlank( encoding ) && isFilteringEnabled( getResources() ) )
314305
{
315306
getLog().warn( "File encoding has not been set, using platform encoding "
316-
+ System.getProperty( "file.encoding" )
317-
+ ". Build is platform dependent!" );
307+
+ System.getProperty( "file.encoding" )
308+
+ ". Build is platform dependent!" );
318309
getLog().warn( "See https://maven.apache.org/general.html#encoding-warning" );
319310
}
320311

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

325316
MavenResourcesExecution mavenResourcesExecution =
326-
new MavenResourcesExecution( getResources(), getOutputDirectory(), project, encoding, combinedFilters,
327-
Collections.emptyList(), session );
317+
new MavenResourcesExecution( getResources(), getOutputDirectory(), project, encoding,
318+
combinedFilters,
319+
Collections.emptyList(), session );
328320

329321
mavenResourcesExecution.setEscapeWindowsPaths( escapeWindowsPaths );
330322

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

393385
/**
394-
* @param mavenResourcesExecution {@link MavenResourcesExecution}
395-
* @throws MojoExecutionException in case of wrong lookup.
386+
* @param mavenResourcesExecution {@link MavenResourcesExecution}
387+
* @throws MojoExecutionException in case of wrong lookup.
396388
* @throws MavenFilteringException in case of failure.
397389
* @since 2.5
398390
*/
399391
protected void executeUserFilterComponents( MavenResourcesExecution mavenResourcesExecution )
400-
throws MojoExecutionException, MavenFilteringException
392+
throws MojoExecutionException, MavenFilteringException
401393
{
402394

403395
if ( mavenFilteringHints != null )
404396
{
405397
for ( String hint : mavenFilteringHints )
406398
{
407-
try
399+
MavenResourcesFiltering userFilterComponent = mavenResourcesFilteringMap.get( hint );
400+
if ( userFilterComponent != null )
408401
{
409-
// CHECKSTYLE_OFF: LineLength
410-
mavenFilteringComponents.add( (MavenResourcesFiltering) plexusContainer.lookup( MavenResourcesFiltering.class.getName(),
411-
hint ) );
412-
// CHECKSTYLE_ON: LineLength
402+
getLog().debug( "added user filter component with hint: " + hint );
403+
mavenFilteringComponents.add( userFilterComponent );
413404
}
414-
catch ( ComponentLookupException e )
405+
else
415406
{
416-
throw new MojoExecutionException( e.getMessage(), e );
407+
throw new MojoExecutionException(
408+
"User filter with hint `" + hint + "` requested, but not present. Discovered filters are: "
409+
+ mavenResourcesFilteringMap.keySet() );
417410
}
418411
}
419412
}
420413
else
421414
{
422-
getLog().debug( "no use filter components" );
415+
getLog().debug( "no user filter components" );
423416
}
424417

425418
if ( mavenFilteringComponents != null && !mavenFilteringComponents.isEmpty() )

src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package org.apache.maven.plugins.resources.filters;
2020

21+
import javax.inject.Named;
22+
import javax.inject.Singleton;
23+
2124
import java.io.File;
2225
import java.io.IOException;
2326
import java.util.ArrayList;
@@ -28,14 +31,14 @@
2831
import org.apache.maven.shared.filtering.MavenFilteringException;
2932
import org.apache.maven.shared.filtering.MavenResourcesExecution;
3033
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
31-
import org.codehaus.plexus.component.annotations.Component;
3234

3335
/**
3436
* @author Olivier Lamy
3537
* @since 2.5
3638
* @version $Id$
3739
*/
38-
@Component(role = org.apache.maven.shared.filtering.MavenResourcesFiltering.class, hint = "itFilter")
40+
@Singleton
41+
@Named("itFilter")
3942
public class ItFilter
4043
implements MavenResourcesFiltering
4144
{

0 commit comments

Comments
 (0)