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 org.apache.maven.enforcer.rule.api.EnforcerRuleException;
23 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
24 import org.apache.maven.plugin.logging.Log;
25 import org.apache.maven.plugins.enforcer.utils.DistributionManagementCheck;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
28
29
30
31
32
33
34
35
36
37 public class BanDistributionManagement
38 extends AbstractNonCacheableEnforcerRule
39 {
40
41
42
43
44 private boolean allowRepository = false;
45
46
47
48
49 private boolean allowSnapshotRepository = false;
50
51
52
53
54 private boolean allowSite = false;
55
56 private Log logger;
57
58 @Override
59 public void execute( EnforcerRuleHelper helper )
60 throws EnforcerRuleException
61 {
62 logger = helper.getLog();
63
64 try
65 {
66 MavenProject project = (MavenProject) helper.evaluate( "${project}" );
67
68 if ( project.isExecutionRoot() )
69 {
70 if ( project.getParent() == null )
71 {
72
73 logger.debug( "We have no parent and in the root of a build we don't check anything," );
74 logger.debug( "because that is the location where we defined maven-enforcer-plugin." );
75 }
76 else
77 {
78 logger.debug( "We are in the root of the execution and we have a parent." );
79
80 DistributionManagementCheck check = new DistributionManagementCheck( project );
81 check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() );
82 }
83 }
84 else
85 {
86 logger.debug( "We are in a deeper level." );
87 DistributionManagementCheck check = new DistributionManagementCheck( project );
88 check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() );
89
90 }
91 }
92 catch ( ExpressionEvaluationException e )
93 {
94 throw new EnforcerRuleException( e.getMessage(), e );
95 }
96 }
97
98 public boolean isAllowRepository()
99 {
100 return allowRepository;
101 }
102
103 public void setAllowRepository( boolean allowRepository )
104 {
105 this.allowRepository = allowRepository;
106 }
107
108 public boolean isAllowSnapshotRepository()
109 {
110 return allowSnapshotRepository;
111 }
112
113 public void setAllowSnapshotRepository( boolean allowSnapshotRepository )
114 {
115 this.allowSnapshotRepository = allowSnapshotRepository;
116 }
117
118 public boolean isAllowSite()
119 {
120 return allowSite;
121 }
122
123 public void setAllowSite( boolean allowSite )
124 {
125 this.allowSite = allowSite;
126 }
127
128 }