25
25
import java .util .Collections ;
26
26
import java .util .LinkedHashSet ;
27
27
import java .util .List ;
28
+ import java .util .Map ;
28
29
import java .util .Properties ;
29
30
30
31
import org .apache .commons .lang3 .StringUtils ;
40
41
import org .apache .maven .shared .filtering .MavenFilteringException ;
41
42
import org .apache .maven .shared .filtering .MavenResourcesExecution ;
42
43
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 ;
49
44
50
45
/**
51
46
* Copy resources for the main source code to the main output directory. Always uses the project.build.resources element
58
53
*/
59
54
@ Mojo ( name = "resources" , defaultPhase = LifecyclePhase .PROCESS_RESOURCES , requiresProject = true , threadSafe = true )
60
55
public class ResourcesMojo
61
- extends AbstractMojo
62
- implements Contextualizable
56
+ extends AbstractMojo
63
57
{
64
58
65
59
/**
@@ -98,8 +92,8 @@ public class ResourcesMojo
98
92
/**
99
93
* The list of additional filter properties files to be used along with System and project properties, which would
100
94
* be used for the filtering.
101
- * @see ResourcesMojo#filters
102
95
*
96
+ * @see ResourcesMojo#filters
103
97
* @since 2.4
104
98
*/
105
99
@ Parameter ( defaultValue = "${project.build.filters}" , readonly = true )
@@ -123,9 +117,9 @@ public class ResourcesMojo
123
117
/**
124
118
* If false, don't use the filters specified in the build/filters section of the POM when processing resources in
125
119
* this mojo execution.
126
- * @see ResourcesMojo#buildFilters
127
- * @see ResourcesMojo#filters
128
120
*
121
+ * @see ResourcesMojo#buildFilters
122
+ * @see ResourcesMojo#filters
129
123
* @since 2.4
130
124
*/
131
125
@ Parameter ( defaultValue = "true" )
@@ -137,6 +131,12 @@ public class ResourcesMojo
137
131
@ Component ( role = MavenResourcesFiltering .class , hint = "default" )
138
132
protected MavenResourcesFiltering mavenResourcesFiltering ;
139
133
134
+ /**
135
+ *
136
+ */
137
+ @ Component ( role = MavenResourcesFiltering .class )
138
+ protected Map <String , MavenResourcesFiltering > mavenResourcesFilteringMap ;
139
+
140
140
/**
141
141
*
142
142
*/
@@ -147,6 +147,7 @@ public class ResourcesMojo
147
147
* Expressions preceded with this string won't be interpolated. Anything else preceded with this string will be
148
148
* passed through unchanged. For example {@code \${foo}} will be replaced with {@code ${foo}} but {@code \\${foo}}
149
149
* will be replaced with {@code \\value of foo}, if this parameter has been set to the backslash.
150
+ *
150
151
* @since 2.3
151
152
*/
152
153
@ Parameter
@@ -192,7 +193,7 @@ public class ResourcesMojo
192
193
* <p>
193
194
* So, the default filtering delimiters might be specified as:
194
195
* </p>
195
- *
196
+ *
196
197
* <pre>
197
198
* <delimiters>
198
199
* <delimiter>${*}</delimiter>
@@ -258,11 +259,6 @@ public class ResourcesMojo
258
259
@ Parameter
259
260
private List <String > mavenFilteringHints ;
260
261
261
- /**
262
- * @since 2.4
263
- */
264
- private PlexusContainer plexusContainer ;
265
-
266
262
/**
267
263
* @since 2.4
268
264
*/
@@ -278,7 +274,7 @@ public class ResourcesMojo
278
274
279
275
/**
280
276
* Support filtering of filenames folders etc.
281
- *
277
+ *
282
278
* @since 3.0.0
283
279
*/
284
280
@ Parameter ( defaultValue = "false" )
@@ -287,22 +283,17 @@ public class ResourcesMojo
287
283
/**
288
284
* You can skip the execution of the plugin if you need to. Its use is NOT RECOMMENDED, but quite convenient on
289
285
* occasion.
290
- *
286
+ *
291
287
* @since 3.0.0
292
288
*/
293
289
@ Parameter ( property = "maven.resources.skip" , defaultValue = "false" )
294
290
private boolean skip ;
295
291
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
+ */
304
295
public void execute ()
305
- throws MojoExecutionException
296
+ throws MojoExecutionException
306
297
{
307
298
if ( isSkip () )
308
299
{
@@ -313,8 +304,8 @@ public void execute()
313
304
if ( StringUtils .isBlank ( encoding ) && isFilteringEnabled ( getResources () ) )
314
305
{
315
306
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!" );
318
309
getLog ().warn ( "See https://maven.apache.org/general.html#encoding-warning" );
319
310
}
320
311
@@ -323,8 +314,9 @@ public void execute()
323
314
List <String > combinedFilters = getCombinedFiltersList ();
324
315
325
316
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 );
328
320
329
321
mavenResourcesExecution .setEscapeWindowsPaths ( escapeWindowsPaths );
330
322
@@ -371,10 +363,10 @@ public void execute()
371
363
* can't be found in the context which can be got from the maven core.<br/>
372
364
* A solution could be to put those values into the context by Maven core so they are accessible everywhere. (I'm
373
365
* 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
376
368
* the model, but does not the resource filtering which needed some of the properties.
377
- *
369
+ *
378
370
* @return the new instance with those properties.
379
371
*/
380
372
private Properties addSeveralSpecialProperties ()
@@ -391,35 +383,36 @@ private Properties addSeveralSpecialProperties()
391
383
}
392
384
393
385
/**
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.
396
388
* @throws MavenFilteringException in case of failure.
397
389
* @since 2.5
398
390
*/
399
391
protected void executeUserFilterComponents ( MavenResourcesExecution mavenResourcesExecution )
400
- throws MojoExecutionException , MavenFilteringException
392
+ throws MojoExecutionException , MavenFilteringException
401
393
{
402
394
403
395
if ( mavenFilteringHints != null )
404
396
{
405
397
for ( String hint : mavenFilteringHints )
406
398
{
407
- try
399
+ MavenResourcesFiltering userFilterComponent = mavenResourcesFilteringMap .get ( hint );
400
+ if ( userFilterComponent != null )
408
401
{
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 );
413
404
}
414
- catch ( ComponentLookupException e )
405
+ else
415
406
{
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 () );
417
410
}
418
411
}
419
412
}
420
413
else
421
414
{
422
- getLog ().debug ( "no use filter components" );
415
+ getLog ().debug ( "no user filter components" );
423
416
}
424
417
425
418
if ( mavenFilteringComponents != null && !mavenFilteringComponents .isEmpty () )
0 commit comments