diff --git a/enforcer-api/src/custom-rule-sample/src/main/java/org/example/custom/rule/MyCustomRule.java b/enforcer-api/src/custom-rule-sample/src/main/java/org/example/custom/rule/MyCustomRule.java index d7a36ea0..16a809df 100644 --- a/enforcer-api/src/custom-rule-sample/src/main/java/org/example/custom/rule/MyCustomRule.java +++ b/enforcer-api/src/custom-rule-sample/src/main/java/org/example/custom/rule/MyCustomRule.java @@ -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 diff --git a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRule.java b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRule.java index f6d6b05f..d9f9ef8d 100644 --- a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRule.java +++ b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRule.java @@ -39,6 +39,7 @@ public abstract class AbstractEnforcerRule extends AbstractEnforcerRuleBase { * * @return an Enforcer execution level */ + @Override public EnforcerLevel getLevel() { return level; } diff --git a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRuleBase.java b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRuleBase.java index 57ceb74b..a1856727 100644 --- a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRuleBase.java +++ b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/AbstractEnforcerRuleBase.java @@ -26,7 +26,7 @@ * @author Slawomir Jaranowski * @since 3.2.0 */ -public abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase { +abstract class AbstractEnforcerRuleBase implements EnforcerRuleBase { /** * EnforcerLogger instance @@ -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 + *

+ * NOTICE A logger is not available in constructors. * * @return an {@link EnforcerLogger} instance */ diff --git a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java index 335c4204..b9e05412 100644 --- a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java +++ b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java @@ -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. * @@ -29,12 +27,4 @@ * Writing a custom rule */ @Deprecated -public interface EnforcerRule2 extends EnforcerRule { - /** - * Returns the level of enforcement. - * - * @return level - */ - @Nonnull - EnforcerLevel getLevel(); -} +public interface EnforcerRule2 extends EnforcerRule {} diff --git a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleBase.java b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleBase.java index 328c307e..0b7ef0ed 100644 --- a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleBase.java +++ b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleBase.java @@ -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) {} +} diff --git a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java index 2c572632..eeaec78d 100644 --- a/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java +++ b/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java @@ -53,6 +53,7 @@ public interface EnforcerRuleHelper extends ExpressionEvaluator { * Gets the component. * * @param clazz the clazz + * @param a class type * @return the component * @throws ComponentLookupException the component lookup exception */ @@ -84,6 +85,7 @@ public interface EnforcerRuleHelper extends ExpressionEvaluator { * * @param clazz the clazz * @param roleHint the role hint + * @param a class type * @return the component * @throws ComponentLookupException the component lookup exception */ diff --git a/enforcer-api/src/site/apt/index.apt b/enforcer-api/src/site/apt/index.apt index 5454a6f5..d42abc0e 100644 --- a/enforcer-api/src/site/apt/index.apt +++ b/enforcer-api/src/site/apt/index.apt @@ -20,7 +20,7 @@ ------ Brian Fox ------ - Mar 2007 + 2007-09-01 ------ Maven Enforcer Rule API - Extending The Loving Iron Fist of Maven\x99 diff --git a/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm b/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm index 1216f4ed..416b5f42 100644 --- a/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm +++ b/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - Nov 2007 + 2007-09-01 ------ Writing a custom rule diff --git a/enforcer-rules/pom.xml b/enforcer-rules/pom.xml index 50dcac3a..9623032f 100644 --- a/enforcer-rules/pom.xml +++ b/enforcer-rules/pom.xml @@ -53,10 +53,6 @@ org.eclipse.aether aether-util - - org.apache.maven.shared - maven-shared-utils - org.codehaus.plexus plexus-utils diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/BanDynamicVersions.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/BanDynamicVersions.java index 6335f97d..d82aade3 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/BanDynamicVersions.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/BanDynamicVersions.java @@ -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; @@ -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; } diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireExplicitDependencyScope.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireExplicitDependencyScope.java index 11aeeb1c..24c87756 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireExplicitDependencyScope.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireExplicitDependencyScope.java @@ -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 @@ -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++; } } diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java index b7e50605..ad7baf57 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java @@ -314,7 +314,7 @@ private void handleBanMessages(StringBuilder newMsg) { * @return The plugins which have been removed. * @throws MojoExecutionException */ - public Set removeUncheckedPlugins(Collection uncheckedPlugins, Set plugins) + Set removeUncheckedPlugins(Collection uncheckedPlugins, Set plugins) throws MojoExecutionException { if (uncheckedPlugins != null && !uncheckedPlugins.isEmpty()) { for (String pluginKey : uncheckedPlugins) { @@ -328,8 +328,8 @@ public Set removeUncheckedPlugins(Collection 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 combineUncheckedPlugins( @@ -376,12 +376,12 @@ public Set addAdditionalPlugins(Set existing, List 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) { diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/RequireUpperBoundDeps.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/RequireUpperBoundDeps.java index c5c7a382..27f78899 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/RequireUpperBoundDeps.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/RequireUpperBoundDeps.java @@ -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; @@ -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 @@ -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 + ']'; } diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/property/AbstractPropertyEnforcerRule.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/property/AbstractPropertyEnforcerRule.java index 4fd10dd0..305a5e23 100755 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/property/AbstractPropertyEnforcerRule.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/property/AbstractPropertyEnforcerRule.java @@ -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; } diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java deleted file mode 100644 index be08cd45..00000000 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.plugins.enforcer; - -import org.apache.maven.enforcer.rule.api.EnforcerRule; - -/** - * The Class AbstractNonCacheableEnforcerRule. This is to be used by rules - * that don't need caching... it saves implementing a bunch of methods. - * - * @author Brian Fox - */ -public abstract class AbstractNonCacheableEnforcerRule extends AbstractStandardEnforcerRule { - @Override - public String getCacheId() { - return "0"; - } - - @Override - public boolean isCacheable() { - return false; - } - - @Override - public boolean isResultValid(EnforcerRule cachedRule) { - return false; - } -} diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractStandardEnforcerRule.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractStandardEnforcerRule.java deleted file mode 100644 index cffc0e30..00000000 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractStandardEnforcerRule.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.plugins.enforcer; - -import org.apache.maven.enforcer.rule.api.EnforcerLevel; -import org.apache.maven.enforcer.rule.api.EnforcerRule2; -import org.apache.maven.model.InputLocation; -import org.apache.maven.project.MavenProject; - -/** - * The Class AbstractStandardEnforcerRule. - */ -public abstract class AbstractStandardEnforcerRule implements EnforcerRule2 { - - /** - * Specify a friendly message if the rule fails. - * - * @see {@link #setMessage(String)} - * @see {@link #getMessage()} - */ - private String message; - - private EnforcerLevel level = EnforcerLevel.ERROR; - - public final void setMessage(String message) { - this.message = message; - } - - public final String getMessage() { - return message; - } - - @Override - public EnforcerLevel getLevel() { - return level; - } - - public void setLevel(EnforcerLevel level) { - this.level = level; - } - - /** - * Returns an identifier of a given project. - * @param project the project - * @return the identifier of the project in the format {@code ::} - */ - private static String getProjectId(MavenProject project) { - StringBuilder buffer = new StringBuilder(128); - - buffer.append( - (project.getGroupId() != null && project.getGroupId().length() > 0) - ? project.getGroupId() - : "[unknown-group-id]"); - buffer.append(':'); - buffer.append( - (project.getArtifactId() != null && project.getArtifactId().length() > 0) - ? project.getArtifactId() - : "[unknown-artifact-id]"); - buffer.append(':'); - buffer.append( - (project.getVersion() != null && project.getVersion().length() > 0) - ? project.getVersion() - : "[unknown-version]"); - - return buffer.toString(); - } - - /** - * Creates a string with line/column information for problems originating directly from this POM. Inspired by - * {@code o.a.m.model.building.ModelProblemUtils.formatLocation(...)}. - * - * @param project the current project. - * @param location The location which should be formatted, must not be {@code null}. - * @return The formatted problem location or an empty string if unknown, never {@code null}. - */ - protected static String formatLocation(MavenProject project, InputLocation location) { - StringBuilder buffer = new StringBuilder(); - - if (!location.getSource().getModelId().equals(getProjectId(project))) { - buffer.append(location.getSource().getModelId()); - - if (location.getSource().getLocation().length() > 0) { - if (buffer.length() > 0) { - buffer.append(", "); - } - buffer.append(location.getSource().getLocation()); - } - } - if (location.getLineNumber() > 0) { - if (buffer.length() > 0) { - buffer.append(", "); - } - buffer.append("line ").append(location.getLineNumber()); - } - if (location.getColumnNumber() > 0) { - if (buffer.length() > 0) { - buffer.append(", "); - } - buffer.append("column ").append(location.getColumnNumber()); - } - return buffer.toString(); - } -} diff --git a/enforcer-rules/src/site/apt/alwaysFail.apt.vm b/enforcer-rules/src/site/apt/alwaysFail.apt.vm index d00b9186..18ea993d 100644 --- a/enforcer-rules/src/site/apt/alwaysFail.apt.vm +++ b/enforcer-rules/src/site/apt/alwaysFail.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - August 2008 + 2008-08-06 ------ Always Fail @@ -47,7 +47,7 @@ Always Fail - + true diff --git a/enforcer-rules/src/site/apt/alwaysPass.apt.vm b/enforcer-rules/src/site/apt/alwaysPass.apt.vm index a422a115..e0bb3961 100644 --- a/enforcer-rules/src/site/apt/alwaysPass.apt.vm +++ b/enforcer-rules/src/site/apt/alwaysPass.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - August 2008 + 2008-08-06 ------ Always Pass diff --git a/enforcer-rules/src/site/apt/banDependencyManagementScope.apt.vm b/enforcer-rules/src/site/apt/banDependencyManagementScope.apt.vm index 6b00cf71..1d1a2ac3 100644 --- a/enforcer-rules/src/site/apt/banDependencyManagementScope.apt.vm +++ b/enforcer-rules/src/site/apt/banDependencyManagementScope.apt.vm @@ -20,7 +20,7 @@ ------ Konrad Windszus ------ - June 2022 + 2022-06-28 ------ Ban Dependency Management Scope diff --git a/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm b/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm index 4fc0a466..6dc2f7bd 100644 --- a/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm +++ b/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm @@ -20,7 +20,7 @@ ------ Karl-Heinz Marbaise ------ - June 2014 + 2014-06-28 ------ Ban Distribution Management diff --git a/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm b/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm index ccc9bc07..96e6782f 100644 --- a/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm +++ b/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm @@ -20,7 +20,7 @@ ------ Guillaume Boue ------ - November 2016 + 2016-11-30 ------ Ban Duplicate Pom Dependency Versions diff --git a/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm b/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm index d388183f..a71bff9d 100644 --- a/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm +++ b/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm @@ -19,7 +19,7 @@ Ban Transitive Dependencies ------ ------ - August 2012 + 2012-10-09 ------ Ban Transitive Dependencies diff --git a/enforcer-rules/src/site/apt/bannedDependencies.apt.vm b/enforcer-rules/src/site/apt/bannedDependencies.apt.vm index 5018647f..63ce4c46 100644 --- a/enforcer-rules/src/site/apt/bannedDependencies.apt.vm +++ b/enforcer-rules/src/site/apt/bannedDependencies.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - November 2007 + 2007-09-01 ------ Banned Dependencies diff --git a/enforcer-rules/src/site/apt/bannedPlugins.apt.vm b/enforcer-rules/src/site/apt/bannedPlugins.apt.vm index 028e2134..289fd75c 100644 --- a/enforcer-rules/src/site/apt/bannedPlugins.apt.vm +++ b/enforcer-rules/src/site/apt/bannedPlugins.apt.vm @@ -20,7 +20,7 @@ ------ Paul Gier ------ - November 2012 + 2012-11-23 ------ Banned Plugins diff --git a/enforcer-rules/src/site/apt/bannedRepositories.apt.vm b/enforcer-rules/src/site/apt/bannedRepositories.apt.vm index 7cd64c23..7d0734f9 100644 --- a/enforcer-rules/src/site/apt/bannedRepositories.apt.vm +++ b/enforcer-rules/src/site/apt/bannedRepositories.apt.vm @@ -20,7 +20,7 @@ ------ Simon Wang ------ - June 2014 + 2014-06-15 ------ Banned Specified Repositories diff --git a/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm b/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm index 8cf2e10f..74782757 100644 --- a/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm +++ b/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - June 2007 + 2007-09-01 ------ Beanshell diff --git a/enforcer-rules/src/site/apt/externalRules.apt.vm b/enforcer-rules/src/site/apt/externalRules.apt.vm index b5a256f0..fba231c6 100644 --- a/enforcer-rules/src/site/apt/externalRules.apt.vm +++ b/enforcer-rules/src/site/apt/externalRules.apt.vm @@ -64,7 +64,7 @@ External Rules - + src/build/rules.xml diff --git a/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm b/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm index 3bf2e5ad..63b5cfc0 100644 --- a/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm +++ b/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm @@ -20,7 +20,7 @@ ------ Karl-Heinz Marbaise ------ - March 2014 + 2014-03-14 ------ Reactor Module Convergence @@ -37,7 +37,7 @@ Reactor Module Convergence * <> - Ignore module dependencies which references modules within the the reactor (default: false). - Note: The current state does not correctly handle a situation like this {{mvn -pl subproject validate}}. + Note: The current state does not correctly handle a situation like this <<>>. This will be handled correctly with the next major release (2.X) of enforcer. [] diff --git a/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm b/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm index 307b6c92..e8007cf6 100644 --- a/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm +++ b/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm @@ -20,7 +20,7 @@ ------ Karl-Heinz Marbaise ------ - December 2013 + 2014-01-09 ------ Require Active Profile diff --git a/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm b/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm index 79e63b46..c05e8272 100644 --- a/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm +++ b/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm @@ -20,7 +20,7 @@ ------ Karl-Heinz Marbaise ------ - December 2013 + 2014-01-07 ------ Require Environment Variable diff --git a/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm b/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm index de4bd143..78b69099 100644 --- a/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm +++ b/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm @@ -20,7 +20,7 @@ ------ Edward Samson, Lyubomyr Shaydariv ------ - February 2016 + 2016-11-26 ------ Require Files Checksum diff --git a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm index 6d8b21d8..53b8ca68 100644 --- a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - August 2008 + 2008-08-06 ------ Require Files Don't Exist diff --git a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm index e314b07f..5a65f9ee 100644 --- a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - August 2008 + 2008-08-06 ------ Require Files Exist diff --git a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm index 7e7d7f0f..ed4fa0d8 100644 --- a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - August 2008 + 2008-08-06 ------ Require File Size diff --git a/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm b/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm index d7bf3bdc..a9b1fb6a 100644 --- a/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm +++ b/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm @@ -20,7 +20,7 @@ ------ Tim Sijstermans ------ - July 2020 + 2020-07-31 ------ Require Java Vendor @@ -29,11 +29,11 @@ Require Java Vendor The following parameters are supported by this rule: - * message - an optional message to the user if the rule fails. + * <> - an optional message to the user if the rule fails. - * includes - a list of allowed JDK vendors to include, by default all is included. + * <> - a list of allowed JDK vendors to include, by default all is included. - * excludes - a list of banned JDK vendors. These are exceptions to the includes. + * <> - a list of banned JDK vendors. These are exceptions to the includes. Sample Plugin Configuration: diff --git a/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm b/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm index f4acb712..4e82bf4a 100644 --- a/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm +++ b/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - June 2007 + 2007-09-01 ------ Require Java Version diff --git a/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm b/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm index bb17a2f6..e755536f 100644 --- a/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm +++ b/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - June 2007 + 2007-09-01 ------ Require Maven Version diff --git a/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm b/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm index 5976dbee..60874d72 100644 --- a/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm +++ b/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - November 2007 + 2007-09-01 ------ Require No Repositories diff --git a/enforcer-rules/src/site/apt/requireOS.apt.vm b/enforcer-rules/src/site/apt/requireOS.apt.vm index 8c66d4ca..1664f9df 100644 --- a/enforcer-rules/src/site/apt/requireOS.apt.vm +++ b/enforcer-rules/src/site/apt/requireOS.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - June 2007 + 2007-09-01 ------ Require OS Version diff --git a/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm b/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm index bd35874e..60bf472f 100644 --- a/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm +++ b/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - November 2009 + 2009-09-01 ------ Require Plugin Versions diff --git a/enforcer-rules/src/site/apt/requireProperty.apt.vm b/enforcer-rules/src/site/apt/requireProperty.apt.vm index 99393952..374ae42b 100644 --- a/enforcer-rules/src/site/apt/requireProperty.apt.vm +++ b/enforcer-rules/src/site/apt/requireProperty.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - June 2007 + 2007-09-01 ------ Require Property diff --git a/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm b/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm index 9311a005..dc577039 100644 --- a/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm +++ b/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - Auguest 2008 + 2008-09-01 ------ Require Release Dependencies diff --git a/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm b/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm index 738e4b06..7a82101a 100644 --- a/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm +++ b/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - August 2008 + 2008-08-06 ------ Require Release Version @@ -30,9 +30,9 @@ Require Release Version The following parameters are supported by this rule: - * message - an optional message to the user if the rule fails. + * <> - an optional message to the user if the rule fails. - * failWhenParentIsSnapshot - if the parent should be checked. Default: true + * <> - if the parent should be checked. Default: true [] diff --git a/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm b/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm index 03820f95..9f6d505f 100644 --- a/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm +++ b/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm @@ -20,7 +20,7 @@ ------ Guillaume Boue ------ - September 2016 + 2016-09-20 ------ Require Snapshot Version diff --git a/enforcer-rules/src/site/apt/requireTextFileChecksum.apt.vm b/enforcer-rules/src/site/apt/requireTextFileChecksum.apt.vm index f2101466..9f001bd3 100644 --- a/enforcer-rules/src/site/apt/requireTextFileChecksum.apt.vm +++ b/enforcer-rules/src/site/apt/requireTextFileChecksum.apt.vm @@ -20,7 +20,7 @@ ------ Konrad Windszus ------ - October 2020 + 2020-09-13 ------ Require Text Files Checksum diff --git a/enforcer-rules/src/site/apt/versionRanges.apt b/enforcer-rules/src/site/apt/versionRanges.apt index a27213b3..61159dfe 100644 --- a/enforcer-rules/src/site/apt/versionRanges.apt +++ b/enforcer-rules/src/site/apt/versionRanges.apt @@ -20,7 +20,7 @@ ------ Brian Fox ------ - May 2007 + 2007-09-01 ------ Version Range Specification diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/EnforcerTestUtils.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/EnforcerTestUtils.java similarity index 55% rename from enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/EnforcerTestUtils.java rename to enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/EnforcerTestUtils.java index cd4d953c..a4d4fa8a 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/EnforcerTestUtils.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/EnforcerTestUtils.java @@ -16,34 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugins.enforcer; +package org.apache.maven.enforcer.rules; import java.util.Properties; -import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.enforcer.rules.utils.DependencyNodeBuilder; -import org.apache.maven.enforcer.rules.utils.MockEnforcerExpressionEvaluator; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.InputLocation; import org.apache.maven.model.InputSource; import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.logging.SystemStreamLog; -import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.collection.CollectResult; -import org.eclipse.aether.collection.DependencyCollectionException; import org.eclipse.aether.graph.DependencyNode; import static org.apache.maven.artifact.Artifact.SCOPE_TEST; @@ -58,8 +46,6 @@ */ public final class EnforcerTestUtils { - private static RepositorySystem REPOSITORY_SYSTEM = mock(RepositorySystem.class); - /** * Gets the maven session. * @@ -83,93 +69,6 @@ public static MavenSession getMavenSession() { return new MavenSession(mock, new DefaultRepositorySystemSession(), mer, meResult); } - /** - * Gets the helper. - * - * @return the helper - */ - public static EnforcerRuleHelper getHelper() { - return getHelper(new MockProject(), false); - } - - /** - * Gets the helper. - * - * @param mockExpression the mock expression - * @return the helper - */ - public static EnforcerRuleHelper getHelper(boolean mockExpression) { - return getHelper(new MockProject(), mockExpression); - } - - /** - * Gets the helper. - * - * @param project the project - * @return the helper - */ - public static EnforcerRuleHelper getHelper(MavenProject project) { - return getHelper(project, false); - } - - public static void provideCollectDependencies(DependencyNode node) { - try { - when(REPOSITORY_SYSTEM.collectDependencies(any(), any(CollectRequest.class))) - .then(i -> new CollectResult(i.getArgument(1)).setRoot(node)); - } catch (DependencyCollectionException e) { - throw new RuntimeException(e); - } - } - - public static void provideCollectDependencies() { - provideCollectDependencies(getUniformDependencyNodeTree()); - } - - /** - * Gets the helper. - * - * @param project the project - * @param mockExpression the mock expression - * @return the helper - */ - public static EnforcerRuleHelper getHelper(MavenProject project, boolean mockExpression) { - try { - MavenSession session = getMavenSession(); - MojoExecution mockExecution = mock(MojoExecution.class); - ExpressionEvaluator eval; - if (mockExpression) { - eval = new MockEnforcerExpressionEvaluator(session); - } else { - session.setCurrentProject(project); - eval = new PluginParameterExpressionEvaluator(session, mockExecution); - } - - PlexusContainer container = mock(PlexusContainer.class); - when(container.lookup(RepositorySystem.class)).thenReturn(REPOSITORY_SYSTEM); - provideCollectDependencies(); - - MojoDescriptor mojoDescriptor = new MojoDescriptor(); - mojoDescriptor.setRealm(getTestClassRealm()); - when(mockExecution.getMojoDescriptor()).thenReturn(mojoDescriptor); - when(container.lookup(MojoExecution.class)).thenReturn(mockExecution); - return new DefaultEnforcementRuleHelper(session, eval, new SystemStreamLog(), container); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Gets the helper. - * - * @param project the project - * @param eval the expression evaluator to use - * @return the helper - */ - public static EnforcerRuleHelper getHelper(MavenProject project, ExpressionEvaluator eval) { - MavenSession session = getMavenSession(); - return new DefaultEnforcementRuleHelper(session, eval, new SystemStreamLog(), null); - } - /** * New plugin. * @@ -190,20 +89,6 @@ public static Plugin newPlugin(String groupId, String artifactId, String version return plugin; } - public static DependencyNode getUniformDependencyNodeTree() { - return new DependencyNodeBuilder() - .withType(DependencyNodeBuilder.Type.POM) - .withChildNode(new DependencyNodeBuilder() - .withArtifactId("childA") - .withVersion("1.0.0") - .build()) - .withChildNode(new DependencyNodeBuilder() - .withArtifactId("childB") - .withVersion("2.0.0") - .build()) - .build(); - } - public static DependencyNode getDependencyNodeWithMultipleSnapshots() { return new DependencyNodeBuilder() .withType(DependencyNodeBuilder.Type.POM) diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestBannedRepositories.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestBannedRepositories.java index 094a6143..bccddaf9 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestBannedRepositories.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestBannedRepositories.java @@ -25,32 +25,34 @@ import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.enforcer.rule.api.EnforcerLogger; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; -import org.apache.maven.plugins.enforcer.MockProject; +import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Test the "banned repositories" rule. * * @author Simon Wang */ +@ExtendWith(MockitoExtension.class) class TestBannedRepositories { - private BannedRepositories rule; + @Mock + private MavenProject project; - private MockProject project; + @InjectMocks + private BannedRepositories rule; @BeforeEach public void setUp() { - project = new MockProject(); - project.setGroupId("org.apache.maven.plugins.enforcer.test"); - project.setVersion("1.0-SNAPSHOT"); - - rule = new BannedRepositories(project); - rule.setMessage("my message"); rule.setLog(mock(EnforcerLogger.class)); } @@ -60,8 +62,8 @@ void testNoCheckRules() throws EnforcerRuleException { List repos = new ArrayList<>(); repos.add(repo1); - project.setRemoteArtifactRepositories(repos); - project.setPluginArtifactRepositories(repos); + when(project.getRemoteArtifactRepositories()).thenReturn(repos); + when(project.getPluginArtifactRepositories()).thenReturn(repos); rule.execute(); } @@ -76,8 +78,8 @@ void testBannedRepositories() { repos.add(repo2); repos.add(repo3); - project.setRemoteArtifactRepositories(repos); - project.setPluginArtifactRepositories(repos); + when(project.getRemoteArtifactRepositories()).thenReturn(repos); + when(project.getPluginArtifactRepositories()).thenReturn(repos); List bannedRepositories = new ArrayList<>(); String pattern1 = "http://repo1/*"; @@ -102,8 +104,8 @@ void testAllowedRepositoriesAllOK() throws EnforcerRuleException { repos.add(repo1); repos.add(repo2); - project.setRemoteArtifactRepositories(repos); - project.setPluginArtifactRepositories(repos); + when(project.getRemoteArtifactRepositories()).thenReturn(repos); + when(project.getPluginArtifactRepositories()).thenReturn(repos); List bannedRepositories = new ArrayList<>(); String pattern1 = "http://repo1/*"; @@ -126,8 +128,8 @@ void testAllowedRepositoriesException() { repos.add(repo2); repos.add(repo3); - project.setRemoteArtifactRepositories(repos); - project.setPluginArtifactRepositories(repos); + when(project.getRemoteArtifactRepositories()).thenReturn(repos); + when(project.getPluginArtifactRepositories()).thenReturn(repos); List patterns = new ArrayList<>(); String pattern1 = "http://repo1/*"; diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestExternalRules.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestExternalRules.java index ea6cf7b4..78af21ba 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestExternalRules.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestExternalRules.java @@ -23,7 +23,6 @@ import org.apache.maven.enforcer.rules.utils.ExpressionEvaluator; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugins.enforcer.EnforcerTestUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java index a410e263..49f63206 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java @@ -34,7 +34,6 @@ import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.PluginManager; -import org.apache.maven.plugins.enforcer.EnforcerTestUtils; import org.apache.maven.project.MavenProject; import org.apache.maven.rtinfo.RuntimeInformation; import org.codehaus.plexus.PlexusContainer; diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/RequireReleaseDepsTest.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/RequireReleaseDepsTest.java index 0f5f1df1..b1409a6d 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/RequireReleaseDepsTest.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/RequireReleaseDepsTest.java @@ -33,8 +33,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.apache.maven.plugins.enforcer.EnforcerTestUtils.getDependencyNodeWithMultipleSnapshots; -import static org.apache.maven.plugins.enforcer.EnforcerTestUtils.getDependencyNodeWithMultipleTestSnapshots; +import static org.apache.maven.enforcer.rules.EnforcerTestUtils.getDependencyNodeWithMultipleSnapshots; +import static org.apache.maven.enforcer.rules.EnforcerTestUtils.getDependencyNodeWithMultipleTestSnapshots; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.mockito.Mockito.verifyNoInteractions; diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/TestMockEnforcerExpressionEvaluator.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/TestMockEnforcerExpressionEvaluator.java index 7894b25b..21308185 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/TestMockEnforcerExpressionEvaluator.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/TestMockEnforcerExpressionEvaluator.java @@ -18,9 +18,9 @@ */ package org.apache.maven.enforcer.rules.utils; +import org.apache.maven.enforcer.rules.EnforcerTestUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.plugins.enforcer.EnforcerTestUtils; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.junit.jupiter.api.Test; diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java deleted file mode 100644 index 475ffa7a..00000000 --- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java +++ /dev/null @@ -1,1538 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.plugins.enforcer; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.model.Build; -import org.apache.maven.model.CiManagement; -import org.apache.maven.model.Contributor; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.Developer; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.IssueManagement; -import org.apache.maven.model.License; -import org.apache.maven.model.MailingList; -import org.apache.maven.model.Model; -import org.apache.maven.model.Organization; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.model.Prerequisites; -import org.apache.maven.model.Reporting; -import org.apache.maven.model.Resource; -import org.apache.maven.model.Scm; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -/** - * very simple stub of maven project, going to take a lot of work to make it useful as a stub though. - */ -public class MockProject extends MavenProject { - - /** The group id. */ - private String groupId; - - /** The artifact id. */ - private String artifactId; - - /** The name. */ - private String name; - - /** The model. */ - private Model model; - - /** The parent. */ - private MavenProject parent; - - /** The dependencies. */ - private List dependencies; - - /** The file. */ - private File file; - - /** The collected projects. */ - private List collectedProjects; - - /** The attached artifacts. */ - private List attachedArtifacts; - - /** The compile source roots. */ - private List compileSourceRoots; - - /** The test compile source roots. */ - private List testCompileSourceRoots; - - /** The script source roots. */ - private List scriptSourceRoots; - - /** The plugin artifact repositories. */ - private List pluginArtifactRepositories; - - /** The artifact repositories. */ - private List artifactRepositories; - - // private ArtifactRepository releaseArtifactRepository; - - // private ArtifactRepository snapshotArtifactRepository; - - /** The active profiles. */ - private List activeProfiles; - - /** The dependency artifacts. */ - private Set dependencyArtifacts; - - /** The dependency management. */ - private DependencyManagement dependencyManagement; - - /** The artifact. */ - private Artifact artifact; - - // private Map artifactMap; - - /** The original model. */ - private Model originalModel; - - // private Map pluginArtifactMap; - - // private Map reportArtifactMap; - - // private Map extensionArtifactMap; - - // private Map projectReferences; - - // private Build buildOverlay; - - /** The execution root. */ - private boolean executionRoot; - - /** The compile artifacts. */ - private List compileArtifacts; - - /** The compile dependencies. */ - private List compileDependencies; - - /** The system dependencies. */ - private List systemDependencies; - - /** The test classpath elements. */ - private List testClasspathElements; - - /** The test dependencies. */ - private List testDependencies; - - /** The system classpath elements. */ - private List systemClasspathElements; - - /** The system artifacts. */ - private List systemArtifacts; - - /** The test artifacts. */ - private List testArtifacts; - - /** The runtime artifacts. */ - private List runtimeArtifacts; - - /** The runtime dependencies. */ - private List runtimeDependencies; - - /** The runtime classpath elements. */ - private List runtimeClasspathElements; - - /** The model version. */ - private String modelVersion; - - /** The packaging. */ - private String packaging; - - /** The inception year. */ - private String inceptionYear; - - /** The url. */ - private String url; - - /** The description. */ - private String description; - - /** The version. */ - private String version; - - /** The default goal. */ - private String defaultGoal; - - /** The artifacts. */ - private Set artifacts; - - /** The properties. */ - private Properties properties = new Properties(); - - /** The base dir. */ - private File baseDir = null; - - /** - * Instantiates a new mock project. - */ - public MockProject() { - super((Model) null); - } - - // kinda dangerous... - /** - * Instantiates a new mock project. - * - * @param model the model - */ - public MockProject(Model model) { - // super(model); - super((Model) null); - } - - // kinda dangerous... - /** - * Instantiates a new mock project. - * - * @param project the project - */ - public MockProject(MavenProject project) { - // super(project); - super((Model) null); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getModulePathAdjustment(org.apache.maven.project.MavenProject) - */ - public String getModulePathAdjustment(MavenProject mavenProject) throws IOException { - return ""; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getArtifact() - */ - public Artifact getArtifact() { - return artifact; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setArtifact(org.apache.maven.artifact.Artifact) - */ - public void setArtifact(Artifact artifact) { - this.artifact = artifact; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getModel() - */ - public Model getModel() { - return model; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getParent() - */ - public MavenProject getParent() { - return parent; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setParent(org.apache.maven.project.MavenProject) - */ - public void setParent(MavenProject mavenProject) { - this.parent = mavenProject; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) - */ - public void setRemoteArtifactRepositories(List list) { - this.artifactRepositories = list; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() - */ - public List getRemoteArtifactRepositories() { - return artifactRepositories; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#hasParent() - */ - public boolean hasParent() { - if (parent != null) { - return true; - } else { - return false; - } - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getFile() - */ - public File getFile() { - return file; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setFile(java.io.File) - */ - public void setFile(File file) { - this.file = file; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getBasedir() - */ - public File getBasedir() { - if (baseDir == null) { - final String path = System.getProperty("basedir"); - baseDir = null != path ? new File(path) : new File(""); - } - return baseDir; - } - - /** - * Sets the base dir. - * - * @param base the new base dir - */ - public void setBaseDir(File base) { - baseDir = base; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) - */ - public void setDependencies(List list) { - dependencies = list; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDependencies() - */ - public List getDependencies() { - if (dependencies == null) { - dependencies = Collections.EMPTY_LIST; - } - return dependencies; - } - - /** - * Sets the dependency management. - * - * @param depMgt the new dependency management - */ - public void setDependencyManagement(DependencyManagement depMgt) { - this.dependencyManagement = depMgt; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDependencyManagement() - */ - public DependencyManagement getDependencyManagement() { - if (dependencyManagement == null) { - dependencyManagement = new DependencyManagement(); - } - - return dependencyManagement; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addCompileSourceRoot(java.lang.String) - */ - public void addCompileSourceRoot(String string) { - if (compileSourceRoots == null) { - compileSourceRoots = Collections.singletonList(string); - } else { - compileSourceRoots.add(string); - } - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addScriptSourceRoot(java.lang.String) - */ - public void addScriptSourceRoot(String string) { - if (scriptSourceRoots == null) { - scriptSourceRoots = Collections.singletonList(string); - } else { - scriptSourceRoots.add(string); - } - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addTestCompileSourceRoot(java.lang.String) - */ - public void addTestCompileSourceRoot(String string) { - if (testCompileSourceRoots == null) { - testCompileSourceRoots = Collections.singletonList(string); - } else { - testCompileSourceRoots.add(string); - } - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getCompileSourceRoots() - */ - public List getCompileSourceRoots() { - return compileSourceRoots; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getScriptSourceRoots() - */ - public List getScriptSourceRoots() { - return scriptSourceRoots; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getTestCompileSourceRoots() - */ - public List getTestCompileSourceRoots() { - return testCompileSourceRoots; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getCompileClasspathElements() - */ - public List getCompileClasspathElements() throws DependencyResolutionRequiredException { - return compileSourceRoots; - } - - /** - * Sets the compile artifacts. - * - * @param compileArtifacts the new compile artifacts - */ - public void setCompileArtifacts(List compileArtifacts) { - this.compileArtifacts = compileArtifacts; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getCompileArtifacts() - */ - public List getCompileArtifacts() { - return compileArtifacts; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getCompileDependencies() - */ - public List getCompileDependencies() { - return compileDependencies; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getTestClasspathElements() - */ - public List getTestClasspathElements() throws DependencyResolutionRequiredException { - return testClasspathElements; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getTestArtifacts() - */ - public List getTestArtifacts() { - return testArtifacts; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getTestDependencies() - */ - public List getTestDependencies() { - return testDependencies; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getRuntimeClasspathElements() - */ - public List getRuntimeClasspathElements() throws DependencyResolutionRequiredException { - return runtimeClasspathElements; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getRuntimeArtifacts() - */ - public List getRuntimeArtifacts() { - return runtimeArtifacts; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getRuntimeDependencies() - */ - public List getRuntimeDependencies() { - return runtimeDependencies; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getSystemClasspathElements() - */ - public List getSystemClasspathElements() throws DependencyResolutionRequiredException { - return systemClasspathElements; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getSystemArtifacts() - */ - public List getSystemArtifacts() { - return systemArtifacts; - } - - /** - * Sets the runtime classpath elements. - * - * @param runtimeClasspathElements the new runtime classpath elements - */ - public void setRuntimeClasspathElements(List runtimeClasspathElements) { - this.runtimeClasspathElements = runtimeClasspathElements; - } - - /** - * Sets the attached artifacts. - * - * @param attachedArtifacts the new attached artifacts - */ - public void setAttachedArtifacts(List attachedArtifacts) { - this.attachedArtifacts = attachedArtifacts; - } - - /** - * Sets the compile source roots. - * - * @param compileSourceRoots the new compile source roots - */ - public void setCompileSourceRoots(List compileSourceRoots) { - this.compileSourceRoots = compileSourceRoots; - } - - /** - * Sets the test compile source roots. - * - * @param testCompileSourceRoots the new test compile source roots - */ - public void setTestCompileSourceRoots(List testCompileSourceRoots) { - this.testCompileSourceRoots = testCompileSourceRoots; - } - - /** - * Sets the script source roots. - * - * @param scriptSourceRoots the new script source roots - */ - public void setScriptSourceRoots(List scriptSourceRoots) { - this.scriptSourceRoots = scriptSourceRoots; - } - - /** - * Sets the artifact map. - * - * @param artifactMap the new artifact map - */ - public void setArtifactMap(Map artifactMap) { - // this.artifactMap = artifactMap; - } - - /** - * Sets the plugin artifact map. - * - * @param pluginArtifactMap the new plugin artifact map - */ - public void setPluginArtifactMap(Map pluginArtifactMap) { - // this.pluginArtifactMap = pluginArtifactMap; - } - - /** - * Sets the report artifact map. - * - * @param reportArtifactMap the new report artifact map - */ - public void setReportArtifactMap(Map reportArtifactMap) { - // this.reportArtifactMap = reportArtifactMap; - } - - /** - * Sets the extension artifact map. - * - * @param extensionArtifactMap the new extension artifact map - */ - public void setExtensionArtifactMap(Map extensionArtifactMap) { - // this.extensionArtifactMap = extensionArtifactMap; - } - - /** - * Sets the project references. - * - * @param projectReferences the new project references - */ - public void setProjectReferences(Map projectReferences) { - // this.projectReferences = projectReferences; - } - - /** - * Sets the builds the overlay. - * - * @param buildOverlay the new builds the overlay - */ - public void setBuildOverlay(Build buildOverlay) { - // this.buildOverlay = buildOverlay; - } - - /** - * Sets the compile dependencies. - * - * @param compileDependencies the new compile dependencies - */ - public void setCompileDependencies(List compileDependencies) { - this.compileDependencies = compileDependencies; - } - - /** - * Sets the system dependencies. - * - * @param systemDependencies the new system dependencies - */ - public void setSystemDependencies(List systemDependencies) { - this.systemDependencies = systemDependencies; - } - - /** - * Sets the test classpath elements. - * - * @param testClasspathElements the new test classpath elements - */ - public void setTestClasspathElements(List testClasspathElements) { - this.testClasspathElements = testClasspathElements; - } - - /** - * Sets the test dependencies. - * - * @param testDependencies the new test dependencies - */ - public void setTestDependencies(List testDependencies) { - this.testDependencies = testDependencies; - } - - /** - * Sets the system classpath elements. - * - * @param systemClasspathElements the new system classpath elements - */ - public void setSystemClasspathElements(List systemClasspathElements) { - this.systemClasspathElements = systemClasspathElements; - } - - /** - * Sets the system artifacts. - * - * @param systemArtifacts the new system artifacts - */ - public void setSystemArtifacts(List systemArtifacts) { - this.systemArtifacts = systemArtifacts; - } - - /** - * Sets the test artifacts. - * - * @param testArtifacts the new test artifacts - */ - public void setTestArtifacts(List testArtifacts) { - this.testArtifacts = testArtifacts; - } - - /** - * Sets the runtime artifacts. - * - * @param runtimeArtifacts the new runtime artifacts - */ - public void setRuntimeArtifacts(List runtimeArtifacts) { - this.runtimeArtifacts = runtimeArtifacts; - } - - /** - * Sets the runtime dependencies. - * - * @param runtimeDependencies the new runtime dependencies - */ - public void setRuntimeDependencies(List runtimeDependencies) { - this.runtimeDependencies = runtimeDependencies; - } - - /** - * Sets the model. - * - * @param model the new model - */ - public void setModel(Model model) { - this.model = model; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getSystemDependencies() - */ - public List getSystemDependencies() { - return systemDependencies; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setModelVersion(java.lang.String) - */ - public void setModelVersion(String string) { - this.modelVersion = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getModelVersion() - */ - public String getModelVersion() { - return modelVersion; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getId() - */ - public String getId() { - return ""; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setGroupId(java.lang.String) - */ - public void setGroupId(String string) { - this.groupId = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getGroupId() - */ - public String getGroupId() { - return groupId; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setArtifactId(java.lang.String) - */ - public void setArtifactId(String string) { - this.artifactId = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getArtifactId() - */ - public String getArtifactId() { - return artifactId; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setName(java.lang.String) - */ - public void setName(String string) { - this.name = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getName() - */ - public String getName() { - return name; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setVersion(java.lang.String) - */ - public void setVersion(String string) { - this.version = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getVersion() - */ - public String getVersion() { - return version; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPackaging() - */ - public String getPackaging() { - return packaging; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setPackaging(java.lang.String) - */ - public void setPackaging(String string) { - this.packaging = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setInceptionYear(java.lang.String) - */ - public void setInceptionYear(String string) { - this.inceptionYear = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getInceptionYear() - */ - public String getInceptionYear() { - return inceptionYear; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setUrl(java.lang.String) - */ - public void setUrl(String string) { - this.url = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getUrl() - */ - public String getUrl() { - return url; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPrerequisites() - */ - public Prerequisites getPrerequisites() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) - */ - public void setIssueManagement(IssueManagement issueManagement) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getCiManagement() - */ - public CiManagement getCiManagement() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) - */ - public void setCiManagement(CiManagement ciManagement) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getIssueManagement() - */ - public IssueManagement getIssueManagement() { - return null; - } - - /* - * (non-Javadoc) - * @see - * org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) - */ - public void setDistributionManagement(DistributionManagement distributionManagement) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDistributionManagement() - */ - public DistributionManagement getDistributionManagement() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setDescription(java.lang.String) - */ - public void setDescription(String string) { - this.description = string; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDescription() - */ - public String getDescription() { - return description; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) - */ - public void setOrganization(Organization organization) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getOrganization() - */ - public Organization getOrganization() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) - */ - public void setScm(Scm scm) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getScm() - */ - public Scm getScm() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) - */ - public void setMailingLists(List list) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getMailingLists() - */ - public List getMailingLists() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) - */ - public void addMailingList(MailingList mailingList) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) - */ - public void setDevelopers(List list) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDevelopers() - */ - public List getDevelopers() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) - */ - public void addDeveloper(Developer developer) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) - */ - public void setContributors(List list) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getContributors() - */ - public List getContributors() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) - */ - public void addContributor(Contributor contributor) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setBuild(org.apache.maven.model.Build) - */ - public void setBuild(Build build) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getBuild() - */ - public Build getBuild() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getResources() - */ - public List getResources() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getTestResources() - */ - public List getTestResources() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) - */ - public void addResource(Resource resource) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) - */ - public void addTestResource(Resource resource) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) - */ - public void setReporting(Reporting reporting) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getReporting() - */ - public Reporting getReporting() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setLicenses(java.util.List) - */ - public void setLicenses(List list) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getLicenses() - */ - public List getLicenses() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) - */ - public void addLicense(License license) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) - */ - public void setArtifacts(Set set) { - this.artifacts = set; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getArtifacts() - */ - public Set getArtifacts() { - if (artifacts == null) { - return Collections.EMPTY_SET; - } else { - return artifacts; - } - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getArtifactMap() - */ - public Map getArtifactMap() { - return Collections.singletonMap("", ""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) - */ - public void setPluginArtifacts(Set set) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPluginArtifacts() - */ - public Set getPluginArtifacts() { - return Collections.singleton(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() - */ - public Map getPluginArtifactMap() { - return Collections.singletonMap("", ""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) - */ - public void setReportArtifacts(Set set) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getReportArtifacts() - */ - public Set getReportArtifacts() { - return Collections.singleton(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getReportArtifactMap() - */ - public Map getReportArtifactMap() { - return Collections.singletonMap("", ""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) - */ - public void setExtensionArtifacts(Set set) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() - */ - public Set getExtensionArtifacts() { - return Collections.singleton(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() - */ - public Map getExtensionArtifactMap() { - return Collections.singletonMap("", ""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) - */ - public void setParentArtifact(Artifact artifact) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getParentArtifact() - */ - public Artifact getParentArtifact() { - if (parent != null) { - return parent.getArtifact(); - } else return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getRepositories() - */ - public List getRepositories() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getReportPlugins() - */ - public List getReportPlugins() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getBuildPlugins() - */ - public List getBuildPlugins() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getModules() - */ - public List getModules() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPluginManagement() - */ - public PluginManagement getPluginManagement() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addPlugin(org.apache.maven.model.Plugin) - */ - public void addPlugin(Plugin plugin) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#injectPluginManagementInfo(org.apache.maven.model.Plugin) - */ - public void injectPluginManagementInfo(Plugin plugin) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getCollectedProjects() - */ - public List getCollectedProjects() { - return collectedProjects; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setCollectedProjects(java.util.List) - */ - public void setCollectedProjects(List list) { - this.collectedProjects = list; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setPluginArtifactRepositories(java.util.List) - */ - public void setPluginArtifactRepositories(List list) { - this.pluginArtifactRepositories = list; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPluginArtifactRepositories() - */ - public List getPluginArtifactRepositories() { - return pluginArtifactRepositories; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() - */ - public ArtifactRepository getDistributionManagementArtifactRepository() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getPluginRepositories() - */ - public List getPluginRepositories() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setActiveProfiles(java.util.List) - */ - public void setActiveProfiles(List list) { - activeProfiles = list; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getActiveProfiles() - */ - public List getActiveProfiles() { - return activeProfiles; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact) - */ - public void addAttachedArtifact(Artifact theArtifact) { - if (attachedArtifacts == null) { - this.attachedArtifacts = Collections.singletonList(theArtifact); - } else { - attachedArtifacts.add(theArtifact); - } - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getAttachedArtifacts() - */ - public List getAttachedArtifacts() { - return attachedArtifacts; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, - * java.lang.String, java.lang.String) - */ - public Xpp3Dom getGoalConfiguration(String string, String string1, String string2, String string3) { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, - * java.lang.String) - */ - public Xpp3Dom getReportConfiguration(String string, String string1, String string2) { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getExecutionProject() - */ - public MavenProject getExecutionProject() { - return null; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) - */ - public void setExecutionProject(MavenProject mavenProject) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) - */ - public void writeModel(Writer writer) throws IOException {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) - */ - public void writeOriginalModel(Writer writer) throws IOException {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDependencyArtifacts() - */ - public Set getDependencyArtifacts() { - return dependencyArtifacts; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setDependencyArtifacts(java.util.Set) - */ - public void setDependencyArtifacts(Set set) { - this.dependencyArtifacts = set; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setReleaseArtifactRepository(org.apache.maven.artifact.repository. - * ArtifactRepository) - */ - public void setReleaseArtifactRepository(ArtifactRepository artifactRepository) { - // this.releaseArtifactRepository = artifactRepository; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setSnapshotArtifactRepository(org.apache.maven.artifact.repository. - * ArtifactRepository) - */ - public void setSnapshotArtifactRepository(ArtifactRepository artifactRepository) { - // this.snapshotArtifactRepository = artifactRepository; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setOriginalModel(org.apache.maven.model.Model) - */ - public void setOriginalModel(Model model) { - this.originalModel = model; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getOriginalModel() - */ - public Model getOriginalModel() { - return originalModel; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getBuildExtensions() - */ - public List getBuildExtensions() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, - * java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) - */ - public Set createArtifacts(ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter) - throws InvalidDependencyVersionException { - return Collections.EMPTY_SET; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) - */ - public void addProjectReference(MavenProject mavenProject) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) - */ - public void attachArtifact(String string, String string1, File theFile) {} - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getProperties() - */ - public Properties getProperties() { - return this.properties; - } - - /** - * Sets the property. - * - * @param key the key - * @param value the value - */ - public void setProperty(String key, String value) { - properties.setProperty(key, value); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getFilters() - */ - public List getFilters() { - return Collections.singletonList(""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getProjectReferences() - */ - public Map getProjectReferences() { - return Collections.singletonMap("", ""); - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#isExecutionRoot() - */ - public boolean isExecutionRoot() { - return executionRoot; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#setExecutionRoot(boolean) - */ - public void setExecutionRoot(boolean b) { - this.executionRoot = b; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#getDefaultGoal() - */ - public String getDefaultGoal() { - return defaultGoal; - } - - /* - * (non-Javadoc) - * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) - */ - public Artifact replaceWithActiveArtifact(Artifact theArtifact) { - return null; - } -} diff --git a/maven-enforcer-extension/src/site/apt/index.apt b/maven-enforcer-extension/src/site/apt/index.apt index 1d00ac3a..c891e646 100644 --- a/maven-enforcer-extension/src/site/apt/index.apt +++ b/maven-enforcer-extension/src/site/apt/index.apt @@ -20,7 +20,7 @@ ------ Robert Scholte ------ - May 2021 + 2021-05-01 ------ Maven Enforcer Extension - The Extended Loving Iron Fist of Maven\x99 diff --git a/maven-enforcer-plugin/src/it/projects/ban-dynamic-versions/verify.groovy b/maven-enforcer-plugin/src/it/projects/ban-dynamic-versions/verify.groovy index 11abb380..cdf90a98 100644 --- a/maven-enforcer-plugin/src/it/projects/ban-dynamic-versions/verify.groovy +++ b/maven-enforcer-plugin/src/it/projects/ban-dynamic-versions/verify.groovy @@ -17,9 +17,9 @@ * under the License. */ File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( '[WARNING] Dependency org.apache.maven.plugins.enforcer.its:menforcer138_archiver:jar:2.1.1 (compile) is referenced with a banned dynamic version [1.3,2.1.1]' ) -assert buildLog.text.contains( '[WARNING] Dependency org.apache.maven.plugins.enforcer.its:menforcer138_io:jar:LATEST (compile) is referenced with a banned dynamic version LATEST' ) -assert buildLog.text.contains( '[WARNING] Dependency org.apache.maven.plugins.enforcer.its:menforcer134_model:jar:1.0-SNAPSHOT (compile) is referenced with a banned dynamic version 1.0-SNAPSHOT' ) -assert buildLog.text.contains( '[WARNING] Dependency org.apache.maven.plugins.enforcer.its:menforcer427-a:jar:1.0 (compile) via org.apache.maven.plugins.enforcer.its:menforcer427:jar:1.0 is referenced with a banned dynamic version [1.0,2)' ) +assert buildLog.text.contains( '[ERROR] Dependency org.apache.maven.plugins.enforcer.its:menforcer138_archiver:jar:2.1.1 (compile) is referenced with a banned dynamic version [1.3,2.1.1]' ) +assert buildLog.text.contains( '[ERROR] Dependency org.apache.maven.plugins.enforcer.its:menforcer138_io:jar:LATEST (compile) is referenced with a banned dynamic version LATEST' ) +assert buildLog.text.contains( '[ERROR] Dependency org.apache.maven.plugins.enforcer.its:menforcer134_model:jar:1.0-SNAPSHOT (compile) is referenced with a banned dynamic version 1.0-SNAPSHOT' ) +assert buildLog.text.contains( '[ERROR] Dependency org.apache.maven.plugins.enforcer.its:menforcer427-a:jar:1.0 (compile) via org.apache.maven.plugins.enforcer.its:menforcer427:jar:1.0 is referenced with a banned dynamic version [1.0,2)' ) assert buildLog.text.contains( '[ERROR] Rule 0: org.apache.maven.enforcer.rules.BanDynamicVersions failed with message' ) assert buildLog.text.contains( 'Found 4 dependencies with dynamic versions. Look at the warnings emitted above for the details.' ) diff --git a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java index e3b4113f..0694a7c0 100644 --- a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java +++ b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java @@ -45,6 +45,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.plugins.enforcer.internal.DefaultEnforcementRuleHelper; import org.apache.maven.plugins.enforcer.internal.EnforcerRuleCache; import org.apache.maven.plugins.enforcer.internal.EnforcerRuleDesc; import org.apache.maven.plugins.enforcer.internal.EnforcerRuleManager; @@ -54,6 +55,7 @@ import org.codehaus.plexus.configuration.DefaultPlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; +import org.codehaus.plexus.util.StringUtils; /** * This goal executes the defined enforcer-rules once per module. @@ -164,6 +166,8 @@ public class EnforceMojo extends AbstractMojo { /** * List of strings that matches the EnforcerRules to execute. Replacement for the rules property. * + * @param rulesToExecute a rules to execute + * @throws MojoExecutionException when values are incorrect * @since 3.2.0 */ @Parameter(required = false, property = "enforcer.rules") @@ -180,6 +184,8 @@ public void setRulesToExecute(List rulesToExecute) throws MojoExecutionE /** * List of strings that matches the EnforcerRules to execute. * + * @param rulesToExecute a rules to execute + * @throws MojoExecutionException when values are incorrect * @deprecated Use enforcer.rules property instead */ @Parameter(required = false, property = "rules") @@ -196,7 +202,7 @@ public void setCommandLineRules(List rulesToExecute) throws MojoExecutio public void execute() throws MojoExecutionException { Log log = this.getLog(); - if (isSkip()) { + if (skip) { log.info("Skipping Rule Enforcement."); return; } @@ -213,7 +219,7 @@ public void execute() throws MojoExecutionException { rulesList.addAll(additionalRules); if (rulesList.isEmpty()) { - if (isFailIfNoRules()) { + if (failIfNoRules) { throw new MojoExecutionException( "No rules are configured. Use the skip flag if you want to disable execution."); } else { @@ -417,10 +423,19 @@ protected boolean shouldExecute(EnforcerRule rule) { } /** - * @return the fail + * Set rule list to skip. + * + * @param rulesToSkip a rule list */ - public boolean isFail() { - return this.fail; + public void setRulesToSkip(List rulesToSkip) { + if (rulesToSkip == null) { + return; + } + // internally all rules begin from lowercase letter + this.rulesToSkip = rulesToSkip.stream() + .filter(Objects::nonNull) + .map(StringUtils::lowercaseFirstLetter) + .collect(Collectors.toList()); } /** @@ -437,10 +452,6 @@ public void setFailFast(boolean theFailFast) { this.failFast = theFailFast; } - public boolean isFailFast() { - return failFast; - } - private String createRuleMessage( int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerLevel level, EnforcerRuleException e) { @@ -475,59 +486,10 @@ private String getRuleName(EnforcerRuleDesc ruleDesc) { return ruleName; } - /** - * @return the skip - */ - public boolean isSkip() { - return this.skip; - } - - /** - * @param theSkip the skip to set - */ - public void setSkip(boolean theSkip) { - this.skip = theSkip; - } - - /** - * @return the failIfNoRules - */ - public boolean isFailIfNoRules() { - return this.failIfNoRules; - } - /** * @param thefailIfNoRules the failIfNoRules to set */ public void setFailIfNoRules(boolean thefailIfNoRules) { this.failIfNoRules = thefailIfNoRules; } - - /** - * @return the project - */ - public MavenProject getProject() { - return this.project; - } - - /** - * @param theProject the project to set - */ - public void setProject(MavenProject theProject) { - this.project = theProject; - } - - /** - * @return the session - */ - public MavenSession getSession() { - return this.session; - } - - /** - * @param theSession the session to set - */ - public void setSession(MavenSession theSession) { - this.session = theSession; - } } diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DefaultEnforcementRuleHelper.java b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/DefaultEnforcementRuleHelper.java similarity index 98% rename from enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DefaultEnforcementRuleHelper.java rename to maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/DefaultEnforcementRuleHelper.java index a9f79f12..51536d63 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DefaultEnforcementRuleHelper.java +++ b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/DefaultEnforcementRuleHelper.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugins.enforcer; +package org.apache.maven.plugins.enforcer.internal; import java.io.File; import java.util.HashMap; diff --git a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleDesc.java b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleDesc.java index cc3fccb5..c8cf16fd 100644 --- a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleDesc.java +++ b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleDesc.java @@ -27,14 +27,12 @@ * @author Slawomir Jaranowski * @since 3.2.0 */ -public class EnforcerRuleDesc { +public final class EnforcerRuleDesc { private final String name; private final EnforcerRuleBase rule; - private final EnforcerLevel level; - /** * Create a new Rule Description * @@ -44,20 +42,6 @@ public class EnforcerRuleDesc { public EnforcerRuleDesc(String name, EnforcerRuleBase rule) { this.name = name; this.rule = rule; - this.level = EnforcerLevel.ERROR; - } - - /** - * Create a new Rule Description - * - * @param name a rule name - * @param rule a rule instance - * @param level a rule level - */ - public EnforcerRuleDesc(String name, EnforcerRuleBase rule, EnforcerLevel level) { - this.name = name; - this.rule = rule; - this.level = level; } public String getName() { @@ -69,11 +53,11 @@ public EnforcerRuleBase getRule() { } public EnforcerLevel getLevel() { - return level; + return rule.getLevel(); } @Override public String toString() { - return String.format("EnforcerRuleDesc[name=%s, rule=%s, level=%s]", name, rule, level); + return String.format("EnforcerRuleDesc[name=%s, rule=%s, level=%s]", name, rule, getLevel()); } } diff --git a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManager.java b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManager.java index 2787e504..2d2c9b48 100644 --- a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManager.java +++ b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManager.java @@ -28,7 +28,6 @@ import java.util.Objects; import java.util.Optional; -import org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase; import org.apache.maven.enforcer.rule.api.EnforcerLevel; import org.apache.maven.enforcer.rule.api.EnforcerLogger; import org.apache.maven.enforcer.rule.api.EnforcerRuleBase; @@ -105,13 +104,12 @@ public List createRules(PlexusConfiguration rules, Log log) th EnforcerLogger enforcerLoggerWarn = new EnforcerLoggerWarn(log); for (PlexusConfiguration ruleConfig : rules.getChildren()) { - // we need rule level before configuration in order to proper set logger and RuleDesc + // we need rule level before configuration in order to proper set logger EnforcerLevel ruleLevel = getRuleLevelFromConfig(ruleConfig); - EnforcerRuleDesc ruleDesc = - createRuleDesc(ruleConfig.getName(), ruleConfig.getAttribute("implementation"), ruleLevel); + EnforcerRuleDesc ruleDesc = createRuleDesc(ruleConfig.getName(), ruleConfig.getAttribute("implementation")); // setup logger before rule configuration - setupLoggerForRule(ruleDesc, ruleLevel == EnforcerLevel.ERROR ? enforcerLoggerError : enforcerLoggerWarn); + ruleDesc.getRule().setLog(ruleLevel == EnforcerLevel.ERROR ? enforcerLoggerError : enforcerLoggerWarn); if (ruleConfig.getChildCount() > 0) { try { componentConfigurator.configureComponent(ruleDesc.getRule(), ruleConfig, evaluator, classRealm); @@ -132,24 +130,14 @@ private EnforcerLevel getRuleLevelFromConfig(PlexusConfiguration ruleConfig) { return EnforcerLevel.valueOf(level); } - private void setupLoggerForRule(EnforcerRuleDesc ruleDesc, EnforcerLogger logger) { - EnforcerRuleBase rule = ruleDesc.getRule(); - if (rule instanceof AbstractEnforcerRuleBase) { - AbstractEnforcerRuleBase ruleBase = (AbstractEnforcerRuleBase) rule; - ruleBase.setLog(logger); - } - } - - private EnforcerRuleDesc createRuleDesc(String name, String implementation, EnforcerLevel ruleLevel) - throws EnforcerRuleManagerException { + private EnforcerRuleDesc createRuleDesc(String name, String implementation) throws EnforcerRuleManagerException { // component name should always start at lowercase character String ruleName = Character.toLowerCase(name.charAt(0)) + name.substring(1); if (plexusContainer.hasComponent(EnforcerRuleBase.class, ruleName)) { try { - return new EnforcerRuleDesc( - ruleName, plexusContainer.lookup(EnforcerRuleBase.class, ruleName), ruleLevel); + return new EnforcerRuleDesc(ruleName, plexusContainer.lookup(EnforcerRuleBase.class, ruleName)); } catch (ComponentLookupException e) { throw new EnforcerRuleManagerException(e); } @@ -169,7 +157,7 @@ private EnforcerRuleDesc createRuleDesc(String name, String implementation, Enfo try { return new EnforcerRuleDesc( - ruleName, (EnforcerRuleBase) Class.forName(ruleClass).newInstance(), ruleLevel); + ruleName, (EnforcerRuleBase) Class.forName(ruleClass).newInstance()); } catch (Exception e) { throw new EnforcerRuleManagerException( "Failed to create enforcer rules with name: " + ruleName + " or for class: " + ruleClass, e); diff --git a/maven-enforcer-plugin/src/site/apt/index.apt b/maven-enforcer-plugin/src/site/apt/index.apt index c15c17bf..243d4efd 100644 --- a/maven-enforcer-plugin/src/site/apt/index.apt +++ b/maven-enforcer-plugin/src/site/apt/index.apt @@ -20,7 +20,7 @@ ------ Brian Fox ------ - Mar 2007 + 2007-03-01 ------ Maven Enforcer Plugin - The Loving Iron Fist of Maven\x99 diff --git a/maven-enforcer-plugin/src/site/apt/usage.apt.vm b/maven-enforcer-plugin/src/site/apt/usage.apt.vm index 5d050363..34ecdbe6 100644 --- a/maven-enforcer-plugin/src/site/apt/usage.apt.vm +++ b/maven-enforcer-plugin/src/site/apt/usage.apt.vm @@ -20,7 +20,7 @@ ------ Brian Fox ------ - Mar 2007 + 2007-03-01 ------ Usage diff --git a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java index 634b2ba3..2938a681 100644 --- a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java +++ b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; +import org.apache.maven.enforcer.rule.api.EnforcerLevel; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleError; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; @@ -299,6 +300,7 @@ void testLoggingOnEnforcerRuleExceptionWithMessage() throws Exception { EnforcerRuleException ruleException = new EnforcerRuleException("testMessage"); EnforcerRule ruleMock = Mockito.mock(EnforcerRule.class); + when(ruleMock.getLevel()).thenReturn(EnforcerLevel.ERROR); Mockito.doThrow(ruleException).when(ruleMock).execute(any(EnforcerRuleHelper.class)); when(ruleManager.createRules(any(), any())) .thenReturn(Collections.singletonList(new EnforcerRuleDesc("mock", ruleMock))); @@ -323,6 +325,7 @@ void testLoggingOnEnforcerRuleExceptionWithoutMessage() throws Exception { EnforcerRuleException enforcerRuleException = new EnforcerRuleException(npe.getLocalizedMessage(), npe); EnforcerRule ruleMock = Mockito.mock(EnforcerRule.class); + when(ruleMock.getLevel()).thenReturn(EnforcerLevel.ERROR); Mockito.doThrow(enforcerRuleException).when(ruleMock).execute(any(EnforcerRuleHelper.class)); when(ruleManager.createRules(any(), any())) diff --git a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule1.java b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule1.java index fdef9a2c..5d9bc684 100644 --- a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule1.java +++ b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule1.java @@ -18,11 +18,10 @@ */ package org.apache.maven.plugins.enforcer; -import org.apache.maven.enforcer.rule.api.EnforcerRuleException; -import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule; -public class TestRule1 extends AbstractNonCacheableEnforcerRule { +public class TestRule1 extends AbstractEnforcerRule { @Override - public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {} + public void execute() {} } diff --git a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule2.java b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule2.java index 4b2a2c57..adb19a05 100644 --- a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule2.java +++ b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestRule2.java @@ -18,11 +18,10 @@ */ package org.apache.maven.plugins.enforcer; -import org.apache.maven.enforcer.rule.api.EnforcerRuleException; -import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule; -public class TestRule2 extends AbstractNonCacheableEnforcerRule { +public class TestRule2 extends AbstractEnforcerRule { @Override - public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {} + public void execute() {} } diff --git a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManagerTest.java b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManagerTest.java index a31cca7d..106d7ed6 100644 --- a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManagerTest.java +++ b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManagerTest.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.maven.enforcer.rule.api.EnforcerLevel; -import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleBase; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; @@ -82,7 +81,7 @@ void setup() { new EnforcerRuleManager(sessionProvider, mojoExecutionProvider, componentConfigurator, plexusContainer); } - void setupMocks() throws Exception { + void setupMocks() { setupMocks(false); } @@ -236,7 +235,7 @@ void ruleShouldBeConfigured() throws Exception { List rules = enforcerRuleManager.createRules(configuration, mock(Log.class)); assertThat(rules).hasSize(1); - ArgumentCaptor ruleCaptor = ArgumentCaptor.forClass(EnforcerRule.class); + ArgumentCaptor ruleCaptor = ArgumentCaptor.forClass(EnforcerRuleBase.class); ArgumentCaptor configurationCaptor = ArgumentCaptor.forClass(PlexusConfiguration.class); verify(componentConfigurator) @@ -257,6 +256,6 @@ void ruleLevelShouldBeDisoveredFromConfigured() throws Exception { List rules = enforcerRuleManager.createRules(configuration, mock(Log.class)); assertThat(rules).hasSize(1); - assertThat(rules.get(0).getLevel()).isEqualTo(EnforcerLevel.WARN); + assertThat(rules.get(0).getLevel()).isEqualTo(EnforcerLevel.ERROR); } } diff --git a/pom.xml b/pom.xml index 721e9866..15e71731 100644 --- a/pom.xml +++ b/pom.xml @@ -154,11 +154,6 @@ commons-lang3 3.12.0 - - org.apache.maven.shared - maven-shared-utils - 3.3.4 - org.codehaus.plexus plexus-utils