-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…1012) This PR deprecates the 'localRepository' mojo parameter expression, and Core will emit warning if used by any Mojo. --- https://issues.apache.org/jira/browse/MNG-7706
- Loading branch information
Showing
9 changed files
with
175 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...apache/maven/plugin/internal/AbstractMavenPluginDescriptorSourcedParametersValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.plugin.internal; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Common implementations for plugin parameters configuration validation that relies on Mojo descriptor (leaves out | ||
* core parameters by default). | ||
* | ||
* @author Slawomir Jaranowski | ||
*/ | ||
abstract class AbstractMavenPluginDescriptorSourcedParametersValidator extends AbstractMavenPluginParametersValidator { | ||
|
||
// plugin author can provide @Parameter( property = "session" ) in this case property will always evaluate | ||
// so, we need ignore those | ||
|
||
// source org.apache.maven.plugin.PluginParameterExpressionEvaluator | ||
private static final List<String> IGNORED_PROPERTY_VALUES = Arrays.asList( | ||
"basedir", | ||
"executedProject", | ||
"localRepository", | ||
"mojo", | ||
"mojoExecution", | ||
"plugin", | ||
"project", | ||
"reactorProjects", | ||
"session", | ||
"settings"); | ||
|
||
private static final List<String> IGNORED_PROPERTY_PREFIX = | ||
Arrays.asList("mojo.", "pom.", "plugin.", "project.", "session.", "settings."); | ||
|
||
@Override | ||
protected boolean isIgnoredProperty(String strValue) { | ||
if (!strValue.startsWith("${")) { | ||
return false; | ||
} | ||
|
||
String propertyName = strValue.replace("${", "").replace("}", ""); | ||
|
||
if (IGNORED_PROPERTY_VALUES.contains(propertyName)) { | ||
return true; | ||
} | ||
|
||
return IGNORED_PROPERTY_PREFIX.stream().anyMatch(propertyName::startsWith); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ore/src/main/java/org/apache/maven/plugin/internal/DeprecatedCoreExpressionValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.plugin.internal; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.apache.maven.plugin.descriptor.MojoDescriptor; | ||
import org.apache.maven.plugin.descriptor.Parameter; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; | ||
import org.codehaus.plexus.configuration.PlexusConfiguration; | ||
|
||
/** | ||
* Print warnings if deprecated core parameters are used in mojo. | ||
* | ||
* @since 3.9.1 | ||
*/ | ||
@Singleton | ||
@Named | ||
class DeprecatedCoreExpressionValidator extends AbstractMavenPluginParametersValidator { | ||
private static final HashMap<String, String> DEPRECATED_CORE_PARAMETERS; | ||
|
||
private static final String ARTIFACT_REPOSITORY_REASON = | ||
"Avoid use of ArtifactRepository type. If you need access to local repository, switch to '${repositorySystemSession}' expression and get LRM from it instead."; | ||
|
||
static { | ||
HashMap<String, String> deprecatedCoreParameters = new HashMap<>(); | ||
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()); | ||
} | ||
|
||
@Override | ||
protected void doValidate( | ||
MojoDescriptor mojoDescriptor, | ||
PlexusConfiguration pomConfiguration, | ||
ExpressionEvaluator expressionEvaluator) { | ||
if (mojoDescriptor.getParameters() == null) { | ||
return; | ||
} | ||
|
||
mojoDescriptor.getParameters().stream() | ||
.filter(parameter -> DEPRECATED_CORE_PARAMETERS.containsKey(parameter.getName())) | ||
.forEach(this::logParameter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters