From 65d95f08a6e86d6ce17edab7e20e741af7e1cc6f Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 3 Mar 2023 08:52:40 +0100 Subject: [PATCH] [MNG-7717] Maven warns wrongly about deprecated parameter (#1031) The implementation for MNG-7706 is wrong: it changes parameter NAME, where it should check type and defaultValue instead. --- https://issues.apache.org/jira/browse/MNG-7717 --- .../DeprecatedCoreExpressionValidator.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedCoreExpressionValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedCoreExpressionValidator.java index 0437b6252c..0eea6f92ab 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedCoreExpressionValidator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedCoreExpressionValidator.java @@ -22,6 +22,7 @@ import javax.inject.Named; import javax.inject.Singleton; import java.util.HashMap; +import java.util.Objects; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; @@ -43,14 +44,14 @@ class DeprecatedCoreExpressionValidator extends AbstractMavenPluginParametersVal static { HashMap deprecatedCoreParameters = new HashMap<>(); - deprecatedCoreParameters.put("localRepository", ARTIFACT_REPOSITORY_REASON); - deprecatedCoreParameters.put("session.localRepository", ARTIFACT_REPOSITORY_REASON); + deprecatedCoreParameters.put("${localRepository}", ARTIFACT_REPOSITORY_REASON); + deprecatedCoreParameters.put("${session.localRepository}", ARTIFACT_REPOSITORY_REASON); DEPRECATED_CORE_PARAMETERS = deprecatedCoreParameters; } @Override protected String getParameterLogReason(Parameter parameter) { - return "is deprecated core expression; " + DEPRECATED_CORE_PARAMETERS.get(parameter.getName()); + return "is deprecated core expression; " + DEPRECATED_CORE_PARAMETERS.get(parameter.getDefaultValue()); } @Override @@ -62,8 +63,12 @@ class DeprecatedCoreExpressionValidator extends AbstractMavenPluginParametersVal return; } - mojoDescriptor.getParameters().stream() - .filter(parameter -> DEPRECATED_CORE_PARAMETERS.containsKey(parameter.getName())) - .forEach(this::logParameter); + mojoDescriptor.getParameters().stream().filter(this::isDeprecated).forEach(this::logParameter); + } + + private boolean isDeprecated(Parameter parameter) { + return Objects.equals( + org.apache.maven.artifact.repository.ArtifactRepository.class.getName(), parameter.getType()) + && DEPRECATED_CORE_PARAMETERS.containsKey(parameter.getDefaultValue()); } }