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
45 private boolean ignoreParent = true;
46
47
48
49
50 private boolean allowRepository = false;
51
52
53
54
55 private boolean allowSnapshotRepository = false;
56
57
58
59
60 private boolean allowSite = false;
61
62 private Log logger;
63
64
65
66
67 public void execute( EnforcerRuleHelper helper )
68 throws EnforcerRuleException
69 {
70 logger = helper.getLog();
71
72 try
73 {
74 MavenProject project = (MavenProject) helper.evaluate( "${project}" );
75
76 if ( project.isExecutionRoot() )
77 {
78 if ( project.getParent() == null )
79 {
80
81 logger.debug( "We have no parent and in the root of a build we don't check anything," );
82 logger.debug( "because that is the location where we defined maven-enforcer-plugin." );
83 }
84 else
85 {
86 logger.debug( "We are in the root of the execution and we have a parent." );
87
88 DistributionManagementCheck check = new DistributionManagementCheck( project );
89 check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() );
90 }
91 }
92 else
93 {
94 logger.debug( "We are in a deeper level." );
95 DistributionManagementCheck check = new DistributionManagementCheck( project );
96 check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() );
97
98 if ( !isIgnoreParent() )
99 {
100 logger.warn( "You have configured not to ignore the parent." );
101 logger.warn( "This configuration is deprecated and will be ignored." );
102 }
103 }
104 }
105 catch ( ExpressionEvaluationException e )
106 {
107 throw new EnforcerRuleException( e.getMessage(), e );
108 }
109 }
110
111 public boolean isIgnoreParent()
112 {
113 return ignoreParent;
114 }
115
116 public void setIgnoreParent( boolean ignoreParent )
117 {
118 this.ignoreParent = ignoreParent;
119 }
120
121 public boolean isAllowRepository()
122 {
123 return allowRepository;
124 }
125
126 public void setAllowRepository( boolean allowRepository )
127 {
128 this.allowRepository = allowRepository;
129 }
130
131 public boolean isAllowSnapshotRepository()
132 {
133 return allowSnapshotRepository;
134 }
135
136 public void setAllowSnapshotRepository( boolean allowSnapshotRepository )
137 {
138 this.allowSnapshotRepository = allowSnapshotRepository;
139 }
140
141 public boolean isAllowSite()
142 {
143 return allowSite;
144 }
145
146 public void setAllowSite( boolean allowSite )
147 {
148 this.allowSite = allowSite;
149 }
150
151 }