1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.internal;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.HashMap;
25 import java.util.Objects;
26
27 import org.apache.maven.plugin.descriptor.MojoDescriptor;
28 import org.apache.maven.plugin.descriptor.Parameter;
29 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
30 import org.codehaus.plexus.configuration.PlexusConfiguration;
31
32
33
34
35
36
37 @Singleton
38 @Named
39 class DeprecatedCoreExpressionValidator extends AbstractMavenPluginParametersValidator {
40 private static final HashMap<String, String> DEPRECATED_CORE_PARAMETERS;
41
42 private static final String ARTIFACT_REPOSITORY_REASON =
43 "Avoid use of ArtifactRepository type. If you need access to local repository, switch to '${repositorySystemSession}' expression and get LRM from it instead.";
44
45 static {
46 HashMap<String, String> deprecatedCoreParameters = new HashMap<>();
47 deprecatedCoreParameters.put("${localRepository}", ARTIFACT_REPOSITORY_REASON);
48 deprecatedCoreParameters.put("${session.localRepository}", ARTIFACT_REPOSITORY_REASON);
49 DEPRECATED_CORE_PARAMETERS = deprecatedCoreParameters;
50 }
51
52 @Override
53 protected String getParameterLogReason(Parameter parameter) {
54 return "is deprecated core expression; " + DEPRECATED_CORE_PARAMETERS.get(parameter.getDefaultValue());
55 }
56
57 @Override
58 protected void doValidate(
59 MojoDescriptor mojoDescriptor,
60 PlexusConfiguration pomConfiguration,
61 ExpressionEvaluator expressionEvaluator) {
62 if (mojoDescriptor.getParameters() == null) {
63 return;
64 }
65
66 mojoDescriptor.getParameters().stream().filter(this::isDeprecated).forEach(this::logParameter);
67 }
68
69 private boolean isDeprecated(Parameter parameter) {
70 return Objects.equals(
71 org.apache.maven.artifact.repository.ArtifactRepository.class.getName(), parameter.getType())
72 && DEPRECATED_CORE_PARAMETERS.containsKey(parameter.getDefaultValue());
73 }
74 }