diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
index cce830667a86..e80ff315367f 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
@@ -28,7 +28,10 @@
/**
* Abstraction of an artifact repository. Artifact repositories can be remote, local, or even build reactor or
* IDE workspace.
+ *
+ * @deprecated Avoid use of this type, if you need access to local repository use repository system classes instead.
*/
+@Deprecated
public interface ArtifactRepository {
String pathOf(Artifact artifact);
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
index a38f65e87afb..93d1bb9a8a14 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
@@ -25,7 +25,9 @@
* Describes a set of policies for a repository to use under certain conditions.
*
* @author Brett Porter
+ * @deprecated Avoid use of this type, if you need access to local repository use repository system session instead.
*/
+@Deprecated
public class ArtifactRepositoryPolicy {
public static final String UPDATE_POLICY_NEVER = "never";
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
index a71c04429f7e..d44675cdb8eb 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
@@ -22,7 +22,13 @@
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
-/** @author jdcasey */
+/**
+ * Repository layout.
+ *
+ * @author jdcasey
+ * @deprecated Avoid use of this type, if you need access to local repository use repository system session instead.
+ */
+@Deprecated
public interface ArtifactRepositoryLayout {
String ROLE = ArtifactRepositoryLayout.class.getName();
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
index 6341acac2313..d58bf92aaf73 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
@@ -38,7 +38,7 @@
*
session | | the actual {@link MavenSession} |
* session.* | (since Maven 3) | |
* localRepository | |
- * {@link MavenSession#getLocalRepository()} |
+ * {@link MavenSession#getLocalRepository()} DEPRECATED: Avoid use of {@link org.apache.maven.artifact.repository.ArtifactRepository} type. If you need access to local repository, switch to '${repositorySystemSession}' expression and get LRM from it instead. See MNG-7706 |
* reactorProjects | | {@link MavenSession#getProjects()} |
* repositorySystemSession | (since Maven 3) |
* {@link MavenSession#getRepositorySession()} |
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginDescriptorSourcedParametersValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginDescriptorSourcedParametersValidator.java
new file mode 100644
index 000000000000..94ca55781263
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginDescriptorSourcedParametersValidator.java
@@ -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 IGNORED_PROPERTY_VALUES = Arrays.asList(
+ "basedir",
+ "executedProject",
+ "localRepository",
+ "mojo",
+ "mojoExecution",
+ "plugin",
+ "project",
+ "reactorProjects",
+ "session",
+ "settings");
+
+ private static final List 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);
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginParametersValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginParametersValidator.java
index 7a0f46c4e8a1..809a75dfc2e0 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginParametersValidator.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/AbstractMavenPluginParametersValidator.java
@@ -18,9 +18,7 @@
*/
package org.apache.maven.plugin.internal;
-import java.util.Arrays;
-import java.util.List;
-
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.apache.maven.shared.utils.logging.MessageUtils;
@@ -28,6 +26,7 @@
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Common implementations for plugin parameters configuration validation.
@@ -36,28 +35,9 @@
*/
abstract class AbstractMavenPluginParametersValidator implements MavenPluginConfigurationValidator {
- // 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 IGNORED_PROPERTY_VALUES = Arrays.asList(
- "basedir",
- "executedProject",
- "localRepository",
- "mojo",
- "mojoExecution",
- "plugin",
- "project",
- "reactorProjects",
- "session",
- "settings");
-
- private static final List IGNORED_PROPERTY_PREFIX =
- Arrays.asList("mojo.", "plugin.", "project.", "session.", "settings.");
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
- protected abstract Logger getLogger();
-
- protected static boolean isValueSet(PlexusConfiguration config, ExpressionEvaluator expressionEvaluator) {
+ protected boolean isValueSet(PlexusConfiguration config, ExpressionEvaluator expressionEvaluator) {
if (config == null) {
return false;
}
@@ -91,18 +71,25 @@ protected static boolean isValueSet(PlexusConfiguration config, ExpressionEvalua
return false;
}
- private static boolean isIgnoredProperty(String strValue) {
- if (!strValue.startsWith("${")) {
- return false;
+ @Override
+ public final void validate(
+ MojoDescriptor mojoDescriptor,
+ PlexusConfiguration pomConfiguration,
+ ExpressionEvaluator expressionEvaluator) {
+ if (!logger.isWarnEnabled()) {
+ return;
}
- String propertyName = strValue.replace("${", "").replace("}", "");
+ doValidate(mojoDescriptor, pomConfiguration, expressionEvaluator);
+ }
- if (IGNORED_PROPERTY_VALUES.contains(propertyName)) {
- return true;
- }
+ protected abstract void doValidate(
+ MojoDescriptor mojoDescriptor,
+ PlexusConfiguration pomConfiguration,
+ ExpressionEvaluator expressionEvaluator);
- return IGNORED_PROPERTY_PREFIX.stream().anyMatch(propertyName::startsWith);
+ protected boolean isIgnoredProperty(String strValue) {
+ return false;
}
protected abstract String getParameterLogReason(Parameter parameter);
@@ -120,6 +107,6 @@ protected void logParameter(Parameter parameter) {
messageBuilder.warning(" ").warning(getParameterLogReason(parameter));
- getLogger().warn(messageBuilder.toString());
+ logger.warn(messageBuilder.toString());
}
}
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
new file mode 100644
index 000000000000..0437b6252c1f
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedCoreExpressionValidator.java
@@ -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 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 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);
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java
index 4c421c979312..96f94df87b92 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java
@@ -26,38 +26,25 @@
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Print warnings if deprecated mojo or parameters of plugin are used in configuration.
*
* @author Slawomir Jaranowski
*/
-@Named
@Singleton
-class DeprecatedPluginValidator extends AbstractMavenPluginParametersValidator {
- private static final Logger LOGGER = LoggerFactory.getLogger(DeprecatedPluginValidator.class);
-
- @Override
- protected Logger getLogger() {
- return LOGGER;
- }
-
+@Named
+class DeprecatedPluginValidator extends AbstractMavenPluginDescriptorSourcedParametersValidator {
@Override
protected String getParameterLogReason(Parameter parameter) {
return "is deprecated: " + parameter.getDeprecated();
}
@Override
- public void validate(
+ protected void doValidate(
MojoDescriptor mojoDescriptor,
PlexusConfiguration pomConfiguration,
ExpressionEvaluator expressionEvaluator) {
- if (!LOGGER.isWarnEnabled()) {
- return;
- }
-
if (mojoDescriptor.getDeprecated() != null) {
logDeprecatedMojo(mojoDescriptor);
}
@@ -85,6 +72,6 @@ private void logDeprecatedMojo(MojoDescriptor mojoDescriptor) {
.warning(mojoDescriptor.getDeprecated())
.toString();
- LOGGER.warn(message);
+ logger.warn(message);
}
}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/ReadOnlyPluginParametersValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/ReadOnlyPluginParametersValidator.java
index c90ac8bc1556..6c1555079709 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/internal/ReadOnlyPluginParametersValidator.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/ReadOnlyPluginParametersValidator.java
@@ -25,8 +25,6 @@
import org.apache.maven.plugin.descriptor.Parameter;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Print warnings if read-only parameters of a plugin are used in configuration.
@@ -35,25 +33,18 @@
*/
@Named
@Singleton
-public class ReadOnlyPluginParametersValidator extends AbstractMavenPluginParametersValidator {
- private static final Logger LOGGER = LoggerFactory.getLogger(ReadOnlyPluginParametersValidator.class);
-
- @Override
- protected Logger getLogger() {
- return LOGGER;
- }
-
+class ReadOnlyPluginParametersValidator extends AbstractMavenPluginDescriptorSourcedParametersValidator {
@Override
protected String getParameterLogReason(Parameter parameter) {
return "is read-only, must not be used in configuration";
}
@Override
- public void validate(
+ protected void doValidate(
MojoDescriptor mojoDescriptor,
PlexusConfiguration pomConfiguration,
ExpressionEvaluator expressionEvaluator) {
- if (!LOGGER.isWarnEnabled()) {
+ if (mojoDescriptor.getParameters() == null) {
return;
}
@@ -62,7 +53,7 @@ public void validate(
.forEach(parameter -> checkParameter(parameter, pomConfiguration, expressionEvaluator));
}
- protected void checkParameter(
+ private void checkParameter(
Parameter parameter, PlexusConfiguration pomConfiguration, ExpressionEvaluator expressionEvaluator) {
PlexusConfiguration config = pomConfiguration.getChild(parameter.getName(), false);