Skip to content

Commit

Permalink
[MENFORCER-450] Code cleanup
Browse files Browse the repository at this point in the history
- isolate abstract class in api
- fix date format in documentation
- drop maven-shared-utils
- fix javadoc warnings
- drop old classes
  • Loading branch information
slawekjaranowski committed Jan 20, 2023
1 parent 8cdd8d0 commit 26697b1
Show file tree
Hide file tree
Showing 66 changed files with 161 additions and 2,063 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String getCacheId() {
*/
@Override
public String toString() {
return String.format("MyCustomRule[level=%s, shouldIfail=%b]", getLevel(), shouldIfail);
return String.format("MyCustomRule[shouldIfail=%b]", shouldIfail);
}
}
// END SNIPPET: rule-implementation
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class AbstractEnforcerRule extends AbstractEnforcerRuleBase {
*
* @return an Enforcer execution level
*/
@Override
public EnforcerLevel getLevel() {
return level;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author Slawomir Jaranowski
* @since 3.2.0
*/
public abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase {
abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase {

/**
* EnforcerLogger instance
Expand All @@ -38,12 +38,15 @@ public abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase {
*
* @param log an {@link EnforcerLogger} instance
*/
@Override
public void setLog(EnforcerLogger log) {
this.log = log;
}

/**
* Provide an {@link EnforcerLogger} instance for Rule
* <p>
* <b>NOTICE</b> A logger is not available in constructors.
*
* @return an {@link EnforcerLogger} instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.maven.enforcer.rule.api;

import javax.annotation.Nonnull;

/**
* Interface to be implemented by any rules as of version 2.0 executed by the enforcer.
*
Expand All @@ -29,12 +27,4 @@
* <a href="https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html">Writing a custom rule</a>
*/
@Deprecated
public interface EnforcerRule2 extends EnforcerRule {
/**
* Returns the level of enforcement.
*
* @return level
*/
@Nonnull
EnforcerLevel getLevel();
}
public interface EnforcerRule2 extends EnforcerRule {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,21 @@
* @author Slawomir Jaranowski
* @since 3.2.0
*/
public interface EnforcerRuleBase {}
public interface EnforcerRuleBase {

/**
* Current Enforcer execution level
*
* @return an Enforcer execution level
*/
default EnforcerLevel getLevel() {
return EnforcerLevel.ERROR;
}

/**
* Used by {@code EnforcerMojo} to inject logger instance
*
* @param log an {@link EnforcerLogger} instance
*/
default void setLog(EnforcerLogger log) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public interface EnforcerRuleHelper extends ExpressionEvaluator {
* Gets the component.
*
* @param clazz the clazz
* @param <T> a class type
* @return the component
* @throws ComponentLookupException the component lookup exception
*/
Expand Down Expand Up @@ -84,6 +85,7 @@ public interface EnforcerRuleHelper extends ExpressionEvaluator {
*
* @param clazz the clazz
* @param roleHint the role hint
* @param <T> a class type
* @return the component
* @throws ComponentLookupException the component lookup exception
*/
Expand Down
2 changes: 1 addition & 1 deletion enforcer-api/src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
------
Brian Fox
------
Mar 2007
2007-09-01
------

Maven Enforcer Rule API - Extending The Loving Iron Fist of Maven\x99
Expand Down
2 changes: 1 addition & 1 deletion enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
------
Brian Fox
------
Nov 2007
2007-09-01
------

Writing a custom rule
Expand Down
4 changes: 0 additions & 4 deletions enforcer-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import org.apache.maven.enforcer.rules.utils.ArtifactUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
Expand Down Expand Up @@ -185,13 +183,12 @@ public boolean visitEnter(DependencyNode node) {
} else {
getLog().debug("Found node " + node + " with version constraint " + node.getVersionConstraint());
if (predicate.test(node) && isBannedDynamicVersion(node.getVersionConstraint())) {
MessageBuilder msgBuilder = MessageUtils.buffer();
getLog().warn(msgBuilder
.a("Dependency ")
.strong(node.getDependency())
.mojo(dumpIntermediatePath(nodeStack))
.a(" is referenced with a banned dynamic version " + node.getVersionConstraint())
.toString());
getLog().warnOrError(() -> new StringBuilder()
.append("Dependency ")
.append(node.getDependency())
.append(dumpIntermediatePath(nodeStack))
.append(" is referenced with a banned dynamic version ")
.append(node.getVersionConstraint()));
numViolations++;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.apache.maven.shared.utils.logging.MessageUtils;

/**
* Checks that all dependencies have an explicitly declared scope in the non-effective pom (i.e. without taking
Expand All @@ -57,19 +55,12 @@ public void execute() throws EnforcerRuleException {
for (Dependency dependency : dependencies) {
getLog().debug("Found dependency " + dependency);
if (dependency.getScope() == null) {
MessageBuilder msgBuilder = MessageUtils.buffer();
msgBuilder
.a("Dependency ")
.strong(dependency.getManagementKey())
.a(" @ ")
.strong(formatLocation(project, dependency.getLocation("")))
.a(" does not have an explicit scope defined!")
.toString();
if (getLevel() == EnforcerLevel.ERROR) {
getLog().error(msgBuilder.toString());
} else {
getLog().warn(msgBuilder.toString());
}
getLog().warnOrError(() -> new StringBuilder()
.append("Dependency ")
.append(dependency.getManagementKey())
.append(" @ ")
.append(formatLocation(project, dependency.getLocation("")))
.append(" does not have an explicit scope defined!"));
numMissingDependencyScopes++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void handleBanMessages(StringBuilder newMsg) {
* @return The plugins which have been removed.
* @throws MojoExecutionException
*/
public Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Set<Plugin> plugins)
Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Set<Plugin> plugins)
throws MojoExecutionException {
if (uncheckedPlugins != null && !uncheckedPlugins.isEmpty()) {
for (String pluginKey : uncheckedPlugins) {
Expand All @@ -328,8 +328,8 @@ public Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, S
/**
* Combines the old Collection with the new comma separated list.
*
* @param uncheckedPlugins
* @param uncheckedPluginsList
* @param uncheckedPlugins a new collections
* @param uncheckedPluginsList a list to merge
* @return List of unchecked plugins.
*/
public Collection<String> combineUncheckedPlugins(
Expand Down Expand Up @@ -376,12 +376,12 @@ public Set<Plugin> addAdditionalPlugins(Set<Plugin> existing, List<String> addit
/**
* Helper method to parse and inject a Plugin.
*
* @param pluginString
* @param field
* @return the plugin
* @throws MojoExecutionException
* @param pluginString a plugin description to parse
* @param field a source of pluginString
* @return the prepared plugin
* @throws MojoExecutionException in case of problems
*/
protected Plugin parsePluginString(String pluginString, String field) throws MojoExecutionException {
private Plugin parsePluginString(String pluginString, String field) throws MojoExecutionException {
if (pluginString != null) {
String[] pluginStrings = pluginString.split(":");
if (pluginStrings.length == 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.enforcer.rules.utils.ArtifactUtils;
import org.apache.maven.enforcer.rules.utils.ParentNodeProvider;
import org.apache.maven.enforcer.rules.utils.ParentsVisitor;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.DependencyVisitor;
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
Expand Down Expand Up @@ -79,16 +78,6 @@ public RequireUpperBoundDeps(ResolveUtil resolveUtil) {
this.resolveUtil = Objects.requireNonNull(resolveUtil);
}

/**
* Set to {@code true} if timestamped snapshots should be used.
*
* @param uniqueVersions
* @since 1.3
*/
public void setUniqueVersions(boolean uniqueVersions) {
this.uniqueVersions = uniqueVersions;
}

/**
* Sets dependencies to exclude.
* @param excludes a list of {@code groupId:artifactId} names
Expand Down Expand Up @@ -193,9 +182,7 @@ private String getFullArtifactName(DependencyNode node, boolean usePremanaged) {
}

String scope = artifact.getScope();
if ("compile".equals(scope)) {
result = MessageUtils.buffer().strong(result).toString();
} else if (scope != null) {
if (scope != null && !"compile".equals(scope)) {
result += " [" + scope + ']';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public void execute() throws EnforcerRuleException {
/**
* Resolves the property value
*
* @throws EnforcerRuleException
* @return a resolve value
* @throws EnforcerRuleException in case of problems
*/
protected abstract Object resolveValue() throws EnforcerRuleException;
}

This file was deleted.

Loading

0 comments on commit 26697b1

Please sign in to comment.