com.lewisd.maven.lint.rules.basic.RedundantPluginVersionsRule Maven / Gradle / Ivy
package com.lewisd.maven.lint.rules.basic;
import com.lewisd.maven.lint.ResultCollector;
import com.lewisd.maven.lint.model.ExtPlugin;
import com.lewisd.maven.lint.model.ObjectWithPath;
import com.lewisd.maven.lint.rules.AbstractReduntantVersionRule;
import com.lewisd.maven.lint.util.ExpressionEvaluator;
import com.lewisd.maven.lint.util.ModelUtil;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
import org.apache.maven.project.MavenProject;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class RedundantPluginVersionsRule extends AbstractReduntantVersionRule {
@Autowired
public RedundantPluginVersionsRule(ExpressionEvaluator expressionEvaluator,
ModelUtil modelUtil,
PluginParameterExpressionEvaluator pluginParameterExpressionEvaluator) {
super(expressionEvaluator, modelUtil, pluginParameterExpressionEvaluator);
}
@Override
public String getIdentifier() {
return "RedundantPluginVersion";
}
@Override
public String getDescription() {
return "Plugin versions should be set in one place, and not overridden without changing the version. " +
"If, for example, sets a version, and somewhere overrides it, " +
"but with the same version, this can make version upgrades more difficult, due to the repetition.";
}
@Override
public void invoke(final MavenProject mavenProject, final Map models, final ResultCollector resultCollector) {
final Model originalModel = mavenProject.getOriginalModel();
final Collection plugins = expressionEvaluator.getPath(originalModel, "build/plugins");
final Collection managedPlugins = expressionEvaluator.getPath(originalModel, "build/pluginManagement/plugins");
final Map managedPluginsByManagementKey = modelUtil.mapById(managedPlugins);
for (final Plugin plugin : plugins) {
final Plugin managedDependency = managedPluginsByManagementKey.get(plugin.getId());
if (managedDependency != null) {
checkForRedundantVersions(mavenProject, resultCollector,
new ObjectWithPath
© 2015 - 2025 Weber Informatics LLC | Privacy Policy