From dbe90660f213c06d7cbaa3f2357d8c302ef81278 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 18 Nov 2023 17:04:10 +0100 Subject: [PATCH] [MNG-7939] Allow to exclude plugins from validation (cherry picked from commit 56bd8fc23b7a426f357f5129a1d6d05feee5f53c) --- ...Tmng7939PluginsValidationExcludesTest.java | 101 ++++++++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 1 + .../pom.xml | 43 ++++++++ .../maven/plugin/coreit/LocalRepoMojo.java | 40 +++++++ 4 files changed, 185 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7939PluginsValidationExcludesTest.java create mode 100644 core-it-suite/src/test/resources/mng-7939-plugins-validation-excludes/pom.xml create mode 100644 core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/LocalRepoMojo.java diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7939PluginsValidationExcludesTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7939PluginsValidationExcludesTest.java new file mode 100644 index 000000000..69cccbd57 --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7939PluginsValidationExcludesTest.java @@ -0,0 +1,101 @@ +/* + * 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.it; + +import java.io.File; +import java.util.List; + +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +/** + * This is a test set for + * MNG-7939. + * Allow to exclude plugins from validation + */ +class MavenITmng7939PluginsValidationExcludesTest extends AbstractMavenIntegrationTestCase { + + protected MavenITmng7939PluginsValidationExcludesTest() { + super("[3.9.6,)"); + } + + @Test + void warningForPluginValidationIsPresentInProject() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7939-plugins-validation-excludes"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.setLogFileName("with-warning-log.txt"); + verifier.deleteDirectory("target"); + verifier.addCliArgument("-Dmaven.plugin.validation=verbose"); + verifier.addCliArgument("validate"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + List logs = verifier.loadLines(verifier.getLogFileName(), null); + + verifyTextInLog(logs, "[INFO] [MAVEN-CORE-IT-LOG] localRepository"); + verifyTextInLog(logs, "[WARNING] * org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT"); + verifyTextInLog( + logs, "[WARNING] Plugin [INTERNAL, EXTERNAL] validation issues were detected in following plugin(s)"); + verifyTextInLog( + logs, "[WARNING] * Mojo itconfiguration:localRepo (org.apache.maven.plugin.coreit.LocalRepoMojo)"); + verifyTextInLog( + logs, + "[WARNING] - Parameter 'localRepository' uses deprecated parameter expression '${localRepository}'"); + } + + @Test + void excludePluginFromValidation() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7939-plugins-validation-excludes"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.setLogFileName("without-warning-log.txt"); + verifier.deleteDirectory("target"); + verifier.addCliArgument("-Dmaven.plugin.validation=verbose"); + verifier.addCliArgument( + "-Dmaven.plugin.validation.excludes=org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT"); + verifier.addCliArgument("validate"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + List logs = verifier.loadLines(verifier.getLogFileName(), null); + + verifyTextInLog(logs, "[INFO] [MAVEN-CORE-IT-LOG] localRepository"); + verifyTextNotInLog( + logs, "[WARNING] * org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT"); + verifyTextNotInLog( + logs, "[WARNING] Plugin [INTERNAL, EXTERNAL] validation issues were detected in following plugin(s)"); + verifyTextNotInLog( + logs, "[WARNING] * Mojo itconfiguration:localRepo (org.apache.maven.plugin.coreit.LocalRepoMojo)"); + verifyTextNotInLog( + logs, + "[WARNING] - Parameter 'localRepository' uses deprecated parameter expression '${localRepository}'"); + } + + private void verifyTextInLog(List logs, String text) { + assertTrue("Log file not contains: " + text, logs.stream().anyMatch(l -> l.contains(text))); + } + + private void verifyTextNotInLog(List logs, String text) { + assertFalse("Log file contains: " + text, logs.stream().anyMatch(l -> l.contains(text))); + } +} diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 05800b47d..159406bdd 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,7 @@ public TestSuiteOrdering() { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITmng7939PluginsValidationExcludesTest.class); suite.addTestSuite(MavenITmng7804PluginExecutionOrderTest.class); suite.addTestSuite(MavenITmng7836AlternativePomSyntaxTest.class); suite.addTestSuite(MavenITmng7891ConfigurationForExtensionsTest.class); diff --git a/core-it-suite/src/test/resources/mng-7939-plugins-validation-excludes/pom.xml b/core-it-suite/src/test/resources/mng-7939-plugins-validation-excludes/pom.xml new file mode 100644 index 000000000..544b058a9 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7939-plugins-validation-excludes/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.maven.its.mng7939 + test + 1.0.0-SNAPSHOT + + + + + org.apache.maven.its.plugins + maven-it-plugin-configuration + 2.1-SNAPSHOT + + + + localRepo + + + + + + + diff --git a/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/LocalRepoMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/LocalRepoMojo.java new file mode 100644 index 000000000..becb49cd0 --- /dev/null +++ b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/LocalRepoMojo.java @@ -0,0 +1,40 @@ +/* + * 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.coreit; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * simple Mojo using detracted localRepository, in order to test plugin verification + */ +@Mojo(name = "localRepo", defaultPhase = LifecyclePhase.VALIDATE) +public class LocalRepoMojo extends AbstractMojo { + + @Parameter(defaultValue = "${localRepository}", readonly = true) + private ArtifactRepository localRepository; + + public void execute() throws MojoExecutionException { + getLog().info("[MAVEN-CORE-IT-LOG] localRepository " + localRepository); + } +}