Skip to content

Commit

Permalink
[MNG-7717] Maven warns wrongly about deprecated parameter (#1030)
Browse files Browse the repository at this point in the history
The implementation for MNG-7706 is wrong: it checks parameter name where it should check type and defaultValue (expression) instead.

---

https://issues.apache.org/jira/browse/MNG-7717
  • Loading branch information
cstamas authored Mar 3, 2023
1 parent 7023ef7 commit 3d4fee3
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -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
Expand All @@ -62,8 +63,12 @@ protected void doValidate(
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());
}
}

0 comments on commit 3d4fee3

Please sign in to comment.