Skip to content

Commit 26697b1

Browse files
[MENFORCER-450] Code cleanup
- isolate abstract class in api - fix date format in documentation - drop maven-shared-utils - fix javadoc warnings - drop old classes
1 parent 8cdd8d0 commit 26697b1

File tree

66 files changed

+161
-2063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+161
-2063
lines changed

enforcer-api/src/custom-rule-sample/src/main/java/org/example/custom/rule/MyCustomRule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public String getCacheId() {
9797
*/
9898
@Override
9999
public String toString() {
100-
return String.format("MyCustomRule[level=%s, shouldIfail=%b]", getLevel(), shouldIfail);
100+
return String.format("MyCustomRule[shouldIfail=%b]", shouldIfail);
101101
}
102102
}
103103
// END SNIPPET: rule-implementation

enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRule.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public abstract class AbstractEnforcerRule extends AbstractEnforcerRuleBase {
3939
*
4040
* @return an Enforcer execution level
4141
*/
42+
@Override
4243
public EnforcerLevel getLevel() {
4344
return level;
4445
}

enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRuleBase.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author Slawomir Jaranowski
2727
* @since 3.2.0
2828
*/
29-
public abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase {
29+
abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase {
3030

3131
/**
3232
* EnforcerLogger instance
@@ -38,12 +38,15 @@ public abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase {
3838
*
3939
* @param log an {@link EnforcerLogger} instance
4040
*/
41+
@Override
4142
public void setLog(EnforcerLogger log) {
4243
this.log = log;
4344
}
4445

4546
/**
4647
* Provide an {@link EnforcerLogger} instance for Rule
48+
* <p>
49+
* <b>NOTICE</b> A logger is not available in constructors.
4750
*
4851
* @return an {@link EnforcerLogger} instance
4952
*/

enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package org.apache.maven.enforcer.rule.api;
2020

21-
import javax.annotation.Nonnull;
22-
2321
/**
2422
* Interface to be implemented by any rules as of version 2.0 executed by the enforcer.
2523
*
@@ -29,12 +27,4 @@
2927
* <a href="https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html">Writing a custom rule</a>
3028
*/
3129
@Deprecated
32-
public interface EnforcerRule2 extends EnforcerRule {
33-
/**
34-
* Returns the level of enforcement.
35-
*
36-
* @return level
37-
*/
38-
@Nonnull
39-
EnforcerLevel getLevel();
40-
}
30+
public interface EnforcerRule2 extends EnforcerRule {}

enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleBase.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,21 @@
2626
* @author Slawomir Jaranowski
2727
* @since 3.2.0
2828
*/
29-
public interface EnforcerRuleBase {}
29+
public interface EnforcerRuleBase {
30+
31+
/**
32+
* Current Enforcer execution level
33+
*
34+
* @return an Enforcer execution level
35+
*/
36+
default EnforcerLevel getLevel() {
37+
return EnforcerLevel.ERROR;
38+
}
39+
40+
/**
41+
* Used by {@code EnforcerMojo} to inject logger instance
42+
*
43+
* @param log an {@link EnforcerLogger} instance
44+
*/
45+
default void setLog(EnforcerLogger log) {}
46+
}

enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public interface EnforcerRuleHelper extends ExpressionEvaluator {
5353
* Gets the component.
5454
*
5555
* @param clazz the clazz
56+
* @param <T> a class type
5657
* @return the component
5758
* @throws ComponentLookupException the component lookup exception
5859
*/
@@ -84,6 +85,7 @@ public interface EnforcerRuleHelper extends ExpressionEvaluator {
8485
*
8586
* @param clazz the clazz
8687
* @param roleHint the role hint
88+
* @param <T> a class type
8789
* @return the component
8890
* @throws ComponentLookupException the component lookup exception
8991
*/

enforcer-api/src/site/apt/index.apt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
------
2121
Brian Fox
2222
------
23-
Mar 2007
23+
2007-09-01
2424
------
2525

2626
Maven Enforcer Rule API - Extending The Loving Iron Fist of Maven\x99

enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
------
2121
Brian Fox
2222
------
23-
Nov 2007
23+
2007-09-01
2424
------
2525

2626
Writing a custom rule

enforcer-rules/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
<groupId>org.eclipse.aether</groupId>
5454
<artifactId>aether-util</artifactId>
5555
</dependency>
56-
<dependency>
57-
<groupId>org.apache.maven.shared</groupId>
58-
<artifactId>maven-shared-utils</artifactId>
59-
</dependency>
6056
<dependency>
6157
<groupId>org.codehaus.plexus</groupId>
6258
<artifactId>plexus-utils</artifactId>

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/BanDynamicVersions.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
import org.apache.maven.enforcer.rules.utils.ArtifactUtils;
3939
import org.apache.maven.execution.MavenSession;
4040
import org.apache.maven.project.MavenProject;
41-
import org.apache.maven.shared.utils.logging.MessageBuilder;
42-
import org.apache.maven.shared.utils.logging.MessageUtils;
4341
import org.eclipse.aether.DefaultRepositorySystemSession;
4442
import org.eclipse.aether.RepositorySystem;
4543
import org.eclipse.aether.RepositorySystemSession;
@@ -185,13 +183,12 @@ public boolean visitEnter(DependencyNode node) {
185183
} else {
186184
getLog().debug("Found node " + node + " with version constraint " + node.getVersionConstraint());
187185
if (predicate.test(node) && isBannedDynamicVersion(node.getVersionConstraint())) {
188-
MessageBuilder msgBuilder = MessageUtils.buffer();
189-
getLog().warn(msgBuilder
190-
.a("Dependency ")
191-
.strong(node.getDependency())
192-
.mojo(dumpIntermediatePath(nodeStack))
193-
.a(" is referenced with a banned dynamic version " + node.getVersionConstraint())
194-
.toString());
186+
getLog().warnOrError(() -> new StringBuilder()
187+
.append("Dependency ")
188+
.append(node.getDependency())
189+
.append(dumpIntermediatePath(nodeStack))
190+
.append(" is referenced with a banned dynamic version ")
191+
.append(node.getVersionConstraint()));
195192
numViolations++;
196193
return false;
197194
}

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireExplicitDependencyScope.java

+6-15
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
3030
import org.apache.maven.model.Dependency;
3131
import org.apache.maven.project.MavenProject;
32-
import org.apache.maven.shared.utils.logging.MessageBuilder;
33-
import org.apache.maven.shared.utils.logging.MessageUtils;
3432

3533
/**
3634
* Checks that all dependencies have an explicitly declared scope in the non-effective pom (i.e. without taking
@@ -57,19 +55,12 @@ public void execute() throws EnforcerRuleException {
5755
for (Dependency dependency : dependencies) {
5856
getLog().debug("Found dependency " + dependency);
5957
if (dependency.getScope() == null) {
60-
MessageBuilder msgBuilder = MessageUtils.buffer();
61-
msgBuilder
62-
.a("Dependency ")
63-
.strong(dependency.getManagementKey())
64-
.a(" @ ")
65-
.strong(formatLocation(project, dependency.getLocation("")))
66-
.a(" does not have an explicit scope defined!")
67-
.toString();
68-
if (getLevel() == EnforcerLevel.ERROR) {
69-
getLog().error(msgBuilder.toString());
70-
} else {
71-
getLog().warn(msgBuilder.toString());
72-
}
58+
getLog().warnOrError(() -> new StringBuilder()
59+
.append("Dependency ")
60+
.append(dependency.getManagementKey())
61+
.append(" @ ")
62+
.append(formatLocation(project, dependency.getLocation("")))
63+
.append(" does not have an explicit scope defined!"));
7364
numMissingDependencyScopes++;
7465
}
7566
}

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private void handleBanMessages(StringBuilder newMsg) {
314314
* @return The plugins which have been removed.
315315
* @throws MojoExecutionException
316316
*/
317-
public Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Set<Plugin> plugins)
317+
Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Set<Plugin> plugins)
318318
throws MojoExecutionException {
319319
if (uncheckedPlugins != null && !uncheckedPlugins.isEmpty()) {
320320
for (String pluginKey : uncheckedPlugins) {
@@ -328,8 +328,8 @@ public Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, S
328328
/**
329329
* Combines the old Collection with the new comma separated list.
330330
*
331-
* @param uncheckedPlugins
332-
* @param uncheckedPluginsList
331+
* @param uncheckedPlugins a new collections
332+
* @param uncheckedPluginsList a list to merge
333333
* @return List of unchecked plugins.
334334
*/
335335
public Collection<String> combineUncheckedPlugins(
@@ -376,12 +376,12 @@ public Set<Plugin> addAdditionalPlugins(Set<Plugin> existing, List<String> addit
376376
/**
377377
* Helper method to parse and inject a Plugin.
378378
*
379-
* @param pluginString
380-
* @param field
381-
* @return the plugin
382-
* @throws MojoExecutionException
379+
* @param pluginString a plugin description to parse
380+
* @param field a source of pluginString
381+
* @return the prepared plugin
382+
* @throws MojoExecutionException in case of problems
383383
*/
384-
protected Plugin parsePluginString(String pluginString, String field) throws MojoExecutionException {
384+
private Plugin parsePluginString(String pluginString, String field) throws MojoExecutionException {
385385
if (pluginString != null) {
386386
String[] pluginStrings = pluginString.split(":");
387387
if (pluginStrings.length == 2) {

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/RequireUpperBoundDeps.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.maven.enforcer.rules.utils.ArtifactUtils;
3838
import org.apache.maven.enforcer.rules.utils.ParentNodeProvider;
3939
import org.apache.maven.enforcer.rules.utils.ParentsVisitor;
40-
import org.apache.maven.shared.utils.logging.MessageUtils;
4140
import org.eclipse.aether.graph.DependencyNode;
4241
import org.eclipse.aether.graph.DependencyVisitor;
4342
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
@@ -79,16 +78,6 @@ public RequireUpperBoundDeps(ResolveUtil resolveUtil) {
7978
this.resolveUtil = Objects.requireNonNull(resolveUtil);
8079
}
8180

82-
/**
83-
* Set to {@code true} if timestamped snapshots should be used.
84-
*
85-
* @param uniqueVersions
86-
* @since 1.3
87-
*/
88-
public void setUniqueVersions(boolean uniqueVersions) {
89-
this.uniqueVersions = uniqueVersions;
90-
}
91-
9281
/**
9382
* Sets dependencies to exclude.
9483
* @param excludes a list of {@code groupId:artifactId} names
@@ -193,9 +182,7 @@ private String getFullArtifactName(DependencyNode node, boolean usePremanaged) {
193182
}
194183

195184
String scope = artifact.getScope();
196-
if ("compile".equals(scope)) {
197-
result = MessageUtils.buffer().strong(result).toString();
198-
} else if (scope != null) {
185+
if (scope != null && !"compile".equals(scope)) {
199186
result += " [" + scope + ']';
200187
}
201188

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/property/AbstractPropertyEnforcerRule.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public void execute() throws EnforcerRuleException {
119119
/**
120120
* Resolves the property value
121121
*
122-
* @throws EnforcerRuleException
122+
* @return a resolve value
123+
* @throws EnforcerRuleException in case of problems
123124
*/
124125
protected abstract Object resolveValue() throws EnforcerRuleException;
125126
}

enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java

-44
This file was deleted.

0 commit comments

Comments
 (0)