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 ignoreParent = true;
45
46
47
48
49 private boolean allowRepository = false;
50
51
52
53
54 private boolean allowSnapshotRepository = false;
55
56
57
58
59 private boolean allowSite = false;
60
61
62
63
64 private boolean executeRootOnly = false;
65
66 private Log logger;
67
68
69
70
71 public void execute( EnforcerRuleHelper helper )
72 throws EnforcerRuleException
73 {
74 logger = helper.getLog();
75
76 try
77 {
78 MavenProject project = (MavenProject) helper.evaluate( "${project}" );
79
80 if ( !project.isExecutionRoot() && !executeRootOnly )
81 {
82
83 logger.debug( "distributionManagement: " + project.getDistributionManagement() );
84
85 DistributionManagementCheck check = new DistributionManagementCheck( project );
86
87 check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() );
88
89 if ( !isIgnoreParent() && ( project.getParent() != null ) )
90 {
91 DistributionManagementCheck checkParent = new DistributionManagementCheck( project.getParent() );
92 checkParent.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() );
93 }
94
95 }
96 }
97 catch ( ExpressionEvaluationException e )
98 {
99 throw new EnforcerRuleException( e.getMessage(), e );
100 }
101 }
102
103 public boolean isIgnoreParent()
104 {
105 return ignoreParent;
106 }
107
108 public void setIgnoreParent( boolean ignoreParent )
109 {
110 this.ignoreParent = ignoreParent;
111 }
112
113 public boolean isAllowRepository()
114 {
115 return allowRepository;
116 }
117
118 public void setAllowRepository( boolean allowRepository )
119 {
120 this.allowRepository = allowRepository;
121 }
122
123 public boolean isAllowSnapshotRepository()
124 {
125 return allowSnapshotRepository;
126 }
127
128 public void setAllowSnapshotRepository( boolean allowSnapshotRepository )
129 {
130 this.allowSnapshotRepository = allowSnapshotRepository;
131 }
132
133 public boolean isAllowSite()
134 {
135 return allowSite;
136 }
137
138 public void setAllowSite( boolean allowSite )
139 {
140 this.allowSite = allowSite;
141 }
142
143 }