[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
This commit is contained in:
Tamas Cservenak 2023-03-03 08:52:40 +01:00 committed by GitHub
parent 7967c204e4
commit 65d95f08a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -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<String, String> 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());
}
}