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