1 package org.apache.maven.plugins.enforcer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.lang.reflect.Field;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34
35 import org.apache.maven.BuildFailureException;
36 import org.apache.maven.artifact.Artifact;
37 import org.apache.maven.artifact.factory.ArtifactFactory;
38 import org.apache.maven.artifact.repository.ArtifactRepository;
39 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
40 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
41 import org.apache.maven.artifact.resolver.ArtifactResolver;
42 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
43 import org.apache.maven.artifact.versioning.VersionRange;
44 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
45 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
46 import org.apache.maven.execution.MavenSession;
47 import org.apache.maven.lifecycle.Lifecycle;
48 import org.apache.maven.lifecycle.LifecycleExecutionException;
49 import org.apache.maven.lifecycle.LifecycleExecutor;
50 import org.apache.maven.lifecycle.mapping.LifecycleMapping;
51 import org.apache.maven.model.BuildBase;
52 import org.apache.maven.model.Model;
53 import org.apache.maven.model.Plugin;
54 import org.apache.maven.model.Profile;
55 import org.apache.maven.model.ReportPlugin;
56 import org.apache.maven.plugin.InvalidPluginException;
57 import org.apache.maven.plugin.MojoExecutionException;
58 import org.apache.maven.plugin.PluginManager;
59 import org.apache.maven.plugin.PluginManagerException;
60 import org.apache.maven.plugin.PluginNotFoundException;
61 import org.apache.maven.plugin.descriptor.PluginDescriptor;
62 import org.apache.maven.plugin.logging.Log;
63 import org.apache.maven.plugin.version.PluginVersionNotFoundException;
64 import org.apache.maven.plugin.version.PluginVersionResolutionException;
65 import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils;
66 import org.apache.maven.plugins.enforcer.utils.PluginWrapper;
67 import org.apache.maven.project.MavenProject;
68 import org.apache.maven.settings.Settings;
69 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
70 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
71 import org.codehaus.plexus.util.ReflectionUtils;
72 import org.codehaus.plexus.util.StringUtils;
73 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
74
75
76
77
78
79
80
81 public class RequirePluginVersions
82 extends AbstractNonCacheableEnforcerRule
83 {
84
85 private EnforcerRuleHelper helper;
86
87
88
89
90
91
92
93 private boolean banLatest = true;
94
95
96
97
98
99
100
101 private boolean banRelease = true;
102
103
104
105
106
107
108
109 private boolean banSnapshots = true;
110
111
112
113
114
115
116
117 private boolean banTimestamps = true;
118
119
120
121
122
123
124
125
126 private String phases = "clean,deploy,site";
127
128
129
130
131
132
133
134
135
136 private List<String> additionalPlugins;
137
138
139
140
141
142
143
144
145 private List<String> unCheckedPlugins;
146
147
148
149
150
151
152
153
154
155 private String unCheckedPluginList;
156
157
158 private PluginManager pluginManager;
159
160
161 private Map<String, Lifecycle> phaseToLifecycleMap;
162
163
164 private Collection<Lifecycle> lifecycles;
165
166
167 ArtifactFactory factory;
168
169
170 ArtifactResolver resolver;
171
172
173 ArtifactRepository local;
174
175
176 List<ArtifactRepository> remoteRepositories;
177
178
179 Log log;
180
181
182 MavenSession session;
183
184
185 EnforcerRuleUtils utils;
186
187 @Override
188 public void execute( EnforcerRuleHelper helper )
189 throws EnforcerRuleException
190 {
191 this.log = helper.getLog();
192 this.helper = helper;
193
194 MavenProject project;
195 try
196 {
197
198
199 project = (MavenProject) helper.evaluate( "${project}" );
200 LifecycleExecutor life;
201 life = (LifecycleExecutor) helper.getComponent( LifecycleExecutor.class );
202
203
204
205 Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( "defaultLifeCycles", life.getClass() );
206 if ( field != null )
207 {
208 Object defaultLifeCycles = ReflectionUtils.getValueIncludingSuperclasses( "defaultLifeCycles", life );
209 Map lifecyclesMap =
210 (Map) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", defaultLifeCycles );
211 lifecycles = lifecyclesMap.values();
212 }
213 else
214
215 {
216 lifecycles = (Collection) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", life );
217 }
218
219 session = (MavenSession) helper.evaluate( "${session}" );
220 pluginManager = (PluginManager) helper.getComponent( PluginManager.class );
221 factory = (ArtifactFactory) helper.getComponent( ArtifactFactory.class );
222 resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class );
223 local = (ArtifactRepository) helper.evaluate( "${localRepository}" );
224 remoteRepositories = project.getRemoteArtifactRepositories();
225
226 utils = new EnforcerRuleUtils( helper );
227
228
229 Set<Plugin> allPlugins = getBoundPlugins( life, project, phases );
230
231
232 allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins );
233 allPlugins.addAll( getProfilePlugins( project ) );
234
235
236 allPlugins =
237 removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins );
238
239
240 if ( allPlugins.isEmpty() )
241 {
242 log.info( "No plugin bindings found." );
243 return;
244 }
245 else
246 {
247 log.debug( "All Plugins in use: " + allPlugins );
248 }
249
250
251 List<PluginWrapper> pluginWrappers = getAllPluginEntries( project );
252
253
254 List<Plugin> failures = new ArrayList<Plugin>();
255 for ( Plugin plugin : allPlugins )
256 {
257 if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) )
258 {
259 failures.add( plugin );
260 }
261 }
262
263
264 if ( !failures.isEmpty() )
265 {
266 StringBuilder newMsg = new StringBuilder();
267 newMsg.append( "Some plugins are missing valid versions:" );
268 if ( banLatest || banRelease || banSnapshots || banTimestamps )
269 {
270 newMsg.append( "(" );
271 if ( banLatest )
272 {
273 newMsg.append( "LATEST " );
274 }
275 if ( banRelease )
276 {
277 newMsg.append( "RELEASE " );
278 }
279 if ( banSnapshots || banTimestamps )
280 {
281 newMsg.append( "SNAPSHOT " );
282 }
283 newMsg.append( "are not allowed )\n" );
284 }
285 for ( Plugin plugin : failures )
286 {
287 newMsg.append( plugin.getGroupId() );
288 newMsg.append( ":" );
289 newMsg.append( plugin.getArtifactId() );
290
291 try
292 {
293 newMsg.append( ". \tThe version currently in use is " );
294
295 Plugin currentPlugin = findCurrentPlugin( plugin, project );
296
297 if ( currentPlugin != null )
298 {
299 newMsg.append( currentPlugin.getVersion() );
300 }
301 else
302 {
303 newMsg.append( "unknown" );
304 }
305 }
306 catch ( Exception e )
307 {
308
309
310 log.debug( "Exception while determining plugin Version.", e );
311 newMsg.append( ". Unable to determine the plugin version." );
312 }
313 newMsg.append( "\n" );
314 }
315 String message = getMessage();
316 if ( StringUtils.isNotEmpty( message ) )
317 {
318 newMsg.append( message );
319 }
320
321 throw new EnforcerRuleException( newMsg.toString() );
322 }
323 }
324 catch ( ExpressionEvaluationException e )
325 {
326 throw new EnforcerRuleException( "Unable to Evaluate an Expression:" + e.getLocalizedMessage() );
327 }
328 catch ( ComponentLookupException e )
329 {
330 throw new EnforcerRuleException( "Unable to lookup a component:" + e.getLocalizedMessage() );
331 }
332 catch ( IllegalAccessException e )
333 {
334 throw new EnforcerRuleException( e.getLocalizedMessage() );
335 }
336 catch ( LifecycleExecutionException e )
337 {
338 throw new EnforcerRuleException( e.getLocalizedMessage() );
339 }
340 catch ( PluginNotFoundException e )
341 {
342 throw new EnforcerRuleException( e.getLocalizedMessage() );
343 }
344 catch ( ArtifactResolutionException e )
345 {
346 throw new EnforcerRuleException( e.getLocalizedMessage() );
347 }
348 catch ( ArtifactNotFoundException e )
349 {
350 throw new EnforcerRuleException( e.getLocalizedMessage() );
351 }
352 catch ( IOException e )
353 {
354 throw new EnforcerRuleException( e.getLocalizedMessage() );
355 }
356 catch ( XmlPullParserException e )
357 {
358 throw new EnforcerRuleException( e.getLocalizedMessage() );
359 }
360 catch ( MojoExecutionException e )
361 {
362 throw new EnforcerRuleException( e.getLocalizedMessage() );
363 }
364 }
365
366
367
368
369
370
371
372
373
374 public Set<Plugin> removeUncheckedPlugins( Collection<String> uncheckedPlugins, Set<Plugin> plugins )
375 throws MojoExecutionException
376 {
377 if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() )
378 {
379 for ( String pluginKey : uncheckedPlugins )
380 {
381 Plugin plugin = parsePluginString( pluginKey, "UncheckedPlugins" );
382 plugins.remove( plugin );
383 }
384 }
385 return plugins;
386 }
387
388
389
390
391
392
393
394
395
396 public Collection<String> combineUncheckedPlugins( Collection<String> uncheckedPlugins, String uncheckedPluginsList )
397
398 {
399
400 if ( StringUtils.isNotEmpty( uncheckedPluginsList ) )
401 {
402
403 if ( uncheckedPlugins == null )
404 {
405 uncheckedPlugins = new HashSet<String>();
406 }
407 else if ( !uncheckedPlugins.isEmpty() && log != null )
408 {
409 log.warn( "The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead" );
410 }
411
412 uncheckedPlugins.addAll( Arrays.asList( uncheckedPluginsList.split( "," ) ) );
413 }
414 return uncheckedPlugins;
415 }
416
417
418
419
420
421
422
423
424
425 public Set<Plugin> addAdditionalPlugins( Set<Plugin> existing, List<String> additional )
426 throws MojoExecutionException
427 {
428 if ( additional != null )
429 {
430 for ( String pluginString : additional )
431 {
432 Plugin plugin = parsePluginString( pluginString, "AdditionalPlugins" );
433
434 if ( existing == null )
435 {
436 existing = new HashSet<Plugin>();
437 existing.add( plugin );
438 }
439 else if ( !existing.contains( plugin ) )
440 {
441 existing.add( plugin );
442 }
443 }
444 }
445 return existing;
446 }
447
448
449
450
451
452
453
454
455
456 protected Plugin parsePluginString( String pluginString, String field )
457 throws MojoExecutionException
458 {
459 if ( pluginString != null )
460 {
461 String[] pluginStrings = pluginString.split( ":" );
462 if ( pluginStrings.length == 2 )
463 {
464 Plugin plugin = new Plugin();
465 plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) );
466 plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) );
467
468 return plugin;
469 }
470 else
471 {
472 throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString );
473 }
474 }
475 else
476 {
477 throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString );
478 }
479
480 }
481
482
483
484
485
486
487
488 public Set<Plugin> getProfilePlugins( MavenProject project )
489 {
490 Set<Plugin> result = new HashSet<Plugin>();
491 List<Profile> profiles = project.getActiveProfiles();
492 if ( profiles != null && !profiles.isEmpty() )
493 {
494 for ( Profile p : profiles )
495 {
496 BuildBase b = p.getBuild();
497 if ( b != null )
498 {
499 List<Plugin> plugins = b.getPlugins();
500 if ( plugins != null )
501 {
502 result.addAll( plugins );
503 }
504 }
505 }
506 }
507 return result;
508 }
509
510
511
512
513
514
515
516
517 protected Plugin findCurrentPlugin( Plugin plugin, MavenProject project )
518 {
519 Plugin found = null;
520 try
521 {
522 Model model = project.getModel();
523 Map<String, Plugin> plugins = model.getBuild().getPluginsAsMap();
524 found = plugins.get( plugin.getKey() );
525 }
526 catch ( NullPointerException e )
527 {
528
529 }
530
531 if ( found == null )
532 {
533 found = resolvePlugin( plugin, project );
534 }
535
536 return found;
537 }
538
539
540
541
542
543
544
545
546 protected Plugin resolvePlugin( Plugin plugin, MavenProject project )
547 {
548
549 List<ArtifactRepository> pluginRepositories = project.getPluginArtifactRepositories();
550 Artifact artifact =
551 factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(),
552 VersionRange.createFromVersion( "LATEST" ) );
553
554 try
555 {
556 this.resolver.resolve( artifact, pluginRepositories, this.local );
557 plugin.setVersion( artifact.getVersion() );
558 }
559 catch ( ArtifactResolutionException e )
560 {
561
562 }
563 catch ( ArtifactNotFoundException e )
564 {
565
566 }
567
568 return plugin;
569 }
570
571
572
573
574
575
576
577
578
579
580
581
582
583 protected Set<Plugin> getBoundPlugins( LifecycleExecutor life, MavenProject project, String thePhases )
584 throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException
585 {
586
587 Set<Plugin> allPlugins = new HashSet<Plugin>();
588
589
590 String[] lifecyclePhases = thePhases.split( "," );
591 for ( int i = 0; i < lifecyclePhases.length; i++ )
592 {
593 String lifecyclePhase = lifecyclePhases[i];
594 if ( StringUtils.isNotEmpty( lifecyclePhase ) )
595 {
596 try
597 {
598 Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase );
599 allPlugins.addAll( getAllPlugins( project, lifecycle ) );
600 }
601 catch ( BuildFailureException e )
602 {
603
604
605
606 }
607 }
608 }
609 return allPlugins;
610 }
611
612
613
614
615
616
617
618
619
620
621
622
623
624 protected boolean hasValidVersionSpecified( EnforcerRuleHelper helper, Plugin source,
625 List<PluginWrapper> pluginWrappers )
626 {
627 boolean found = false;
628 boolean status = false;
629 for ( PluginWrapper plugin : pluginWrappers )
630 {
631
632 if ( source.getArtifactId().equals( plugin.getArtifactId() )
633 && source.getGroupId().equals( plugin.getGroupId() ) )
634 {
635 found = true;
636
637 String version = plugin.getVersion();
638 try
639 {
640 version = (String) helper.evaluate( version );
641 }
642 catch ( ExpressionEvaluationException e )
643 {
644 return false;
645 }
646
647 if ( StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ) )
648 {
649
650 if ( banRelease && version.equals( "RELEASE" ) )
651 {
652 return false;
653 }
654
655 if ( banLatest && version.equals( "LATEST" ) )
656 {
657 return false;
658 }
659
660 if ( banSnapshots && isSnapshot( version ) )
661 {
662 return false;
663 }
664
665
666
667
668 status = true;
669
670 if ( !banRelease && !banLatest && !banSnapshots )
671 {
672
673 break;
674 }
675 }
676 }
677 }
678 if ( !found )
679 {
680 log.debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" );
681 }
682 return status;
683 }
684
685
686
687
688
689
690
691 protected boolean isSnapshot( String baseVersion )
692 {
693 if ( banTimestamps )
694 {
695 return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches()
696 || baseVersion.endsWith( Artifact.SNAPSHOT_VERSION );
697 }
698 else
699 {
700 return baseVersion.endsWith( Artifact.SNAPSHOT_VERSION );
701 }
702 }
703
704
705
706
707
708
709
710
711
712
713
714
715
716 private Set<Plugin> getAllPlugins( MavenProject project, Lifecycle lifecycle )
717 throws PluginNotFoundException, LifecycleExecutionException
718
719 {
720 log.debug( "RequirePluginVersions.getAllPlugins:" );
721
722 Set<Plugin> plugins = new HashSet<Plugin>();
723
724 Map<String, String> mappings = findMappingsForLifecycle( project, lifecycle );
725
726 for ( Map.Entry<String, String> entry : mappings.entrySet() )
727 {
728 log.debug( " lifecycleMapping = " + entry.getKey() );
729 String pluginsForLifecycle = (String) entry.getValue();
730 log.debug( " plugins = " + pluginsForLifecycle );
731 if ( StringUtils.isNotEmpty( pluginsForLifecycle ) )
732 {
733 String pluginList[] = pluginsForLifecycle.split( "," );
734 for ( String plugin : pluginList )
735 {
736 plugin = StringUtils.strip( plugin );
737 log.debug( " plugin = " + plugin );
738 String tokens[] = plugin.split( ":" );
739 log.debug( " GAV = " + Arrays.asList( tokens ) );
740
741 Plugin p = new Plugin();
742 p.setGroupId( tokens[0] );
743 p.setArtifactId( tokens[1] );
744 plugins.add( p );
745 }
746 }
747 }
748
749 List<String> mojos = findOptionalMojosForLifecycle( project, lifecycle );
750 for ( String value : mojos )
751 {
752 String tokens[] = value.split( ":" );
753
754 Plugin plugin = new Plugin();
755 plugin.setGroupId( tokens[0] );
756 plugin.setArtifactId( tokens[1] );
757 plugins.add( plugin );
758 }
759
760 plugins.addAll( project.getBuildPlugins() );
761
762 return plugins;
763 }
764
765
766
767
768
769
770
771
772
773
774
775 public Map<String, Lifecycle> getPhaseToLifecycleMap()
776 throws LifecycleExecutionException
777 {
778 if ( phaseToLifecycleMap == null )
779 {
780 phaseToLifecycleMap = new HashMap<String, Lifecycle>();
781
782 for ( Lifecycle lifecycle : lifecycles )
783 {
784 List<String> phases = lifecycle.getPhases();
785 for ( String phase : phases )
786 {
787 if ( phaseToLifecycleMap.containsKey( phase ) )
788 {
789 Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase );
790 throw new LifecycleExecutionException( "Phase '" + phase
791 + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '"
792 + prevLifecycle.getId() + "'" );
793 }
794 else
795 {
796 phaseToLifecycleMap.put( phase, lifecycle );
797 }
798 }
799 }
800 }
801 return phaseToLifecycleMap;
802 }
803
804
805
806
807
808
809
810
811
812 private Lifecycle getLifecycleForPhase( String phase )
813 throws BuildFailureException, LifecycleExecutionException
814 {
815 Lifecycle lifecycle = (Lifecycle) getPhaseToLifecycleMap().get( phase );
816
817 if ( lifecycle == null )
818 {
819 throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" );
820 }
821 return lifecycle;
822 }
823
824
825
826
827
828
829
830
831
832
833 private Map<String, String> findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle )
834 throws LifecycleExecutionException, PluginNotFoundException
835 {
836 String packaging = project.getPackaging();
837 Map<String, String> mappings = null;
838
839 LifecycleMapping m =
840 (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(),
841 session.getLocalRepository() );
842 if ( m != null )
843 {
844 mappings = m.getPhases( lifecycle.getId() );
845 }
846
847 Map<String, String> defaultMappings = lifecycle.getDefaultPhases();
848
849 if ( mappings == null )
850 {
851 try
852 {
853 m = helper.getComponent( LifecycleMapping.class, packaging );
854 mappings = m.getPhases( lifecycle.getId() );
855 }
856 catch ( ComponentLookupException e )
857 {
858 if ( defaultMappings == null )
859 {
860 throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'"
861 + packaging + "\'.", e );
862 }
863 }
864 }
865
866 if ( mappings == null )
867 {
868 if ( defaultMappings == null )
869 {
870 throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging
871 + "\', and there is no default" );
872 }
873 else
874 {
875 mappings = defaultMappings;
876 }
877 }
878
879 return mappings;
880 }
881
882
883
884
885
886
887
888
889
890
891 private List<String> findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle )
892 throws LifecycleExecutionException, PluginNotFoundException
893 {
894 String packaging = project.getPackaging();
895 List<String> optionalMojos = null;
896
897 LifecycleMapping m =
898 (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(),
899 session.getLocalRepository() );
900
901 if ( m != null )
902 {
903 optionalMojos = m.getOptionalMojos( lifecycle.getId() );
904 }
905
906 if ( optionalMojos == null )
907 {
908 try
909 {
910 m = (LifecycleMapping) helper.getComponent( LifecycleMapping.class, packaging );
911 optionalMojos = m.getOptionalMojos( lifecycle.getId() );
912 }
913 catch ( ComponentLookupException e )
914 {
915 log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: "
916 + lifecycle.getId() + ". Error: " + e.getMessage(), e );
917 }
918 }
919
920 if ( optionalMojos == null )
921 {
922 optionalMojos = Collections.emptyList();
923 }
924
925 return optionalMojos;
926 }
927
928
929
930
931
932
933
934
935
936
937
938
939
940 private Object findExtension( MavenProject project, String role, String roleHint, Settings settings,
941 ArtifactRepository localRepository )
942 throws LifecycleExecutionException, PluginNotFoundException
943 {
944 Object pluginComponent = null;
945
946 List<Plugin> buildPlugins = project.getBuildPlugins();
947 for ( Plugin plugin : buildPlugins )
948 {
949 if ( plugin.isExtensions() )
950 {
951 verifyPlugin( plugin, project, settings, localRepository );
952
953
954
955
956
957 try
958 {
959 pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint );
960
961 if ( pluginComponent != null )
962 {
963 break;
964 }
965 }
966 catch ( ComponentLookupException e )
967 {
968 log.debug( "Unable to find the lifecycle component in the extension", e );
969 }
970 catch ( PluginManagerException e )
971 {
972 throw new LifecycleExecutionException( "Error getting extensions from the plugin '"
973 + plugin.getKey() + "': " + e.getMessage(), e );
974 }
975 }
976 }
977 return pluginComponent;
978 }
979
980
981
982
983
984
985
986
987
988
989
990
991 private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
992 ArtifactRepository localRepository )
993 throws LifecycleExecutionException, PluginNotFoundException
994 {
995 PluginDescriptor pluginDescriptor;
996 try
997 {
998 pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository );
999 }
1000 catch ( PluginManagerException e )
1001 {
1002 throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '"
1003 + plugin.getKey() + "': " + e.getMessage(), e );
1004 }
1005 catch ( PluginVersionResolutionException e )
1006 {
1007 throw new LifecycleExecutionException( e.getMessage(), e );
1008 }
1009 catch ( InvalidVersionSpecificationException e )
1010 {
1011 throw new LifecycleExecutionException( e.getMessage(), e );
1012 }
1013 catch ( InvalidPluginException e )
1014 {
1015 throw new LifecycleExecutionException( e.getMessage(), e );
1016 }
1017 catch ( ArtifactNotFoundException e )
1018 {
1019 throw new LifecycleExecutionException( e.getMessage(), e );
1020 }
1021 catch ( ArtifactResolutionException e )
1022 {
1023 throw new LifecycleExecutionException( e.getMessage(), e );
1024 }
1025 catch ( PluginVersionNotFoundException e )
1026 {
1027 throw new LifecycleExecutionException( e.getMessage(), e );
1028 }
1029 return pluginDescriptor;
1030 }
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043 protected List<PluginWrapper> getAllPluginEntries( MavenProject project )
1044 throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
1045 {
1046 List<PluginWrapper> plugins = new ArrayList<PluginWrapper>();
1047
1048
1049 String pomName = null;
1050 try
1051 {
1052 pomName = project.getFile().getName();
1053 }
1054 catch ( Exception e )
1055 {
1056 pomName = "pom.xml";
1057 }
1058 List<Model> models =
1059 utils.getModelsRecursively( project.getGroupId(), project.getArtifactId(), project.getVersion(),
1060 new File( project.getBasedir(), pomName ) );
1061
1062
1063
1064 for ( Model model : models )
1065 {
1066 try
1067 {
1068 List<Plugin> modelPlugins = model.getBuild().getPlugins();
1069 plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
1070 + ".build.plugins" ) );
1071 }
1072 catch ( NullPointerException e )
1073 {
1074
1075 }
1076
1077 try
1078 {
1079 List<ReportPlugin> modelReportPlugins = model.getReporting().getPlugins();
1080
1081 plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId()
1082 + ".reporting" ) );
1083 }
1084 catch ( NullPointerException e )
1085 {
1086
1087 }
1088
1089 try
1090 {
1091 List<Plugin> modelPlugins = model.getBuild().getPluginManagement().getPlugins();
1092 plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
1093 + ".build.pluginManagement.plugins" ) );
1094 }
1095 catch ( NullPointerException e )
1096 {
1097
1098 }
1099
1100
1101 List<Profile> profiles = model.getProfiles();
1102 for ( Profile profile : profiles )
1103 {
1104 try
1105 {
1106 List<Plugin> modelPlugins = profile.getBuild().getPlugins();
1107 plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
1108 + ".profiles.profile[" + profile.getId() + "].build.plugins" ) );
1109 }
1110 catch ( NullPointerException e )
1111 {
1112
1113 }
1114
1115 try
1116 {
1117 List<ReportPlugin> modelReportPlugins = profile.getReporting().getPlugins();
1118
1119 plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ),
1120 model.getId() + "profile[" + profile.getId()
1121 + "].reporting.plugins" ) );
1122 }
1123 catch ( NullPointerException e )
1124 {
1125
1126 }
1127 try
1128 {
1129 List<Plugin> modelPlugins = profile.getBuild().getPluginManagement().getPlugins();
1130 plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
1131 + "profile[" + profile.getId() + "].build.pluginManagement.plugins" ) );
1132 }
1133 catch ( NullPointerException e )
1134 {
1135
1136 }
1137 }
1138 }
1139
1140 return plugins;
1141 }
1142
1143
1144
1145
1146
1147
1148 protected boolean isBanLatest()
1149 {
1150 return this.banLatest;
1151 }
1152
1153
1154
1155
1156
1157
1158 protected void setBanLatest( boolean theBanLatest )
1159 {
1160 this.banLatest = theBanLatest;
1161 }
1162
1163
1164
1165
1166
1167
1168 protected boolean isBanRelease()
1169 {
1170 return this.banRelease;
1171 }
1172
1173
1174
1175
1176
1177
1178 protected void setBanRelease( boolean theBanRelease )
1179 {
1180 this.banRelease = theBanRelease;
1181 }
1182
1183
1184
1185
1186
1187
1188 protected EnforcerRuleUtils getUtils()
1189 {
1190 return this.utils;
1191 }
1192
1193
1194
1195
1196
1197
1198 protected void setUtils( EnforcerRuleUtils theUtils )
1199 {
1200 this.utils = theUtils;
1201 }
1202
1203
1204
1205
1206
1207
1208 public boolean isBanSnapshots()
1209 {
1210 return this.banSnapshots;
1211 }
1212
1213
1214
1215
1216
1217
1218 public void setBanSnapshots( boolean theBanSnapshots )
1219 {
1220 this.banSnapshots = theBanSnapshots;
1221 }
1222
1223
1224
1225
1226
1227
1228 public boolean isBanTimestamps()
1229 {
1230 return this.banTimestamps;
1231 }
1232
1233
1234
1235
1236
1237
1238 public void setBanTimestamps( boolean theBanTimestamps )
1239 {
1240 this.banTimestamps = theBanTimestamps;
1241 }
1242
1243 public List<String> getUnCheckedPlugins()
1244 {
1245 return unCheckedPlugins;
1246 }
1247
1248 public void setUnCheckedPlugins( List<String> unCheckedPlugins )
1249 {
1250 this.unCheckedPlugins = unCheckedPlugins;
1251 }
1252
1253 public final void setPhases( String phases )
1254 {
1255 this.phases = phases;
1256 }
1257
1258 public final String getPhases()
1259 {
1260 return phases;
1261 }
1262
1263 public final void setAdditionalPlugins( List<String> additionalPlugins )
1264 {
1265 this.additionalPlugins = additionalPlugins;
1266 }
1267
1268 public final List<String> getAdditionalPlugins()
1269 {
1270 return additionalPlugins;
1271 }
1272 }