2525import java .util .Collections ;
2626import java .util .LinkedHashSet ;
2727import java .util .List ;
28+ import java .util .Map ;
2829import java .util .Properties ;
2930
3031import org .apache .commons .lang3 .StringUtils ;
4041import org .apache .maven .shared .filtering .MavenFilteringException ;
4142import org .apache .maven .shared .filtering .MavenResourcesExecution ;
4243import 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
5853 */
5954@ Mojo ( name = "resources" , defaultPhase = LifecyclePhase .PROCESS_RESOURCES , requiresProject = true , threadSafe = true )
6055public 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 * <delimiters>
198199 * <delimiter>${*}</delimiter>
@@ -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 () )
0 commit comments