You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/11/29 23:42:20 UTC
[maven-plugin-tools] branch master updated: [MPLUGIN-382] exclude dependency in provided scope from plugin descriptor
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git
The following commit(s) were added to refs/heads/master by this push:
new 5389e5c [MPLUGIN-382] exclude dependency in provided scope from plugin descriptor
5389e5c is described below
commit 5389e5c6a1dfd3e82f1b1e8db4474f7f8a6ee420
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sun Nov 28 16:03:31 2021 +0100
[MPLUGIN-382] exclude dependency in provided scope from plugin descriptor
plugin.xml descriptor - shouldn't contain dependencies in provided scope
---
maven-plugin-plugin/pom.xml | 1 +
.../invoker.properties | 18 +++++
.../pom.xml | 94 ++++++++++++++++++++++
.../org/apache/maven/plugin/coreit/FirstMojo.java | 53 ++++++++++++
.../verify.groovy | 36 +++++++++
.../tools/plugin/generator/GeneratorUtils.java | 19 +++--
.../tools/plugin/generator/GeneratorUtilsTest.java | 36 ++++++++-
7 files changed, 247 insertions(+), 10 deletions(-)
diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml
index e035c9a..c623797 100644
--- a/maven-plugin-plugin/pom.xml
+++ b/maven-plugin-plugin/pom.xml
@@ -348,6 +348,7 @@
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
+ <streamLogsOnFailures>true</streamLogsOnFailures>
<filterProperties>
<sitePluginVersion>3.3</sitePluginVersion>
<antVersion>${antVersion}</antVersion>
diff --git a/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/invoker.properties b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/invoker.properties
new file mode 100644
index 0000000..c959b53
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = process-classes
diff --git a/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/pom.xml b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/pom.xml
new file mode 100644
index 0000000..7ac218e
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.mplugin-382</groupId>
+ <artifactId>mplugin-382-exclude-provided-dependency</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Maven Integration Test :: mplugin-382-empty-dependency</name>
+ <description>
+ Test plugin-plugin, plugin.xml descriptor - shouldn't contain dependencies in provided scope
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>@mavenVersion@</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>@project.version@</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- dependency in compile scope -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math3</artifactId>
+ <version>3.6.1</version>
+ </dependency>
+
+ <!-- dependency in runtime scope -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-rng-client-api</artifactId>
+ <version>1.4</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+
+ </build>
+</project>
diff --git a/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
new file mode 100644
index 0000000..b8f7f62
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -0,0 +1,53 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.annotations.Execute;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Touches a test file.
+ *
+ * @since 1.2
+ */
+@Mojo( name = "first", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.INTEGRATION_TEST )
+public class FirstMojo
+ extends AbstractMojo
+{
+
+ /**
+ * @since 0.1
+ * @deprecated As of 0.2
+ */
+ @Parameter( alias = "alias" )
+ private String aliasedParam;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ // nothing
+ }
+}
diff --git a/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/verify.groovy b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/verify.groovy
new file mode 100644
index 0000000..408b8f0
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/verify.groovy
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" );
+assert descriptorFile.isFile()
+
+def pluginDescriptor = new XmlParser().parse( descriptorFile );
+
+// one mojo with one parameter
+assert pluginDescriptor.mojos.mojo.size() == 1
+assert pluginDescriptor.mojos.mojo.parameters.parameter.size() == 1
+
+// dependencies without provided
+assert pluginDescriptor.dependencies.dependency.size() == 2
+
+// expected dependencies on list
+assert pluginDescriptor.dependencies.dependency.find{ it.artifactId.text() == "commons-math3" } != null
+assert pluginDescriptor.dependencies.dependency.find{ it.artifactId.text() == "commons-rng-client-api" } != null
+
+return true;
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
index af9dc84..e9ec47f 100644
--- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
@@ -19,7 +19,10 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
-import static java.nio.charset.StandardCharsets.UTF_8;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.parser.ParserDelegator;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -40,11 +43,6 @@ import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.swing.text.MutableAttributeSet;
-import javax.swing.text.html.HTML;
-import javax.swing.text.html.HTMLEditorKit;
-import javax.swing.text.html.parser.ParserDelegator;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -56,6 +54,8 @@ import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.XMLWriter;
import org.w3c.tidy.Tidy;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
/**
* Convenience methods to play with Maven plugins.
*
@@ -122,7 +122,7 @@ public final class GeneratorUtils
/**
* @param artifacts not null collection of <code>Artifact</code>
- * @return list of component dependencies
+ * @return list of component dependencies, without in provided scope
*/
public static List<ComponentDependency> toComponentDependencies( Collection<Artifact> artifacts )
{
@@ -130,6 +130,11 @@ public final class GeneratorUtils
for ( Artifact artifact : artifacts )
{
+ if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
+ {
+ continue;
+ }
+
ComponentDependency cd = new ComponentDependency();
cd.setArtifactId( artifact.getArtifactId() );
diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
index 6662aa4..bb5a30d 100644
--- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
+++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
@@ -19,6 +19,13 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.codehaus.plexus.component.repository.ComponentDependency;
@@ -26,9 +33,6 @@ import org.codehaus.plexus.util.xml.CompactXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import org.junit.Test;
-import java.io.StringWriter;
-import java.util.Collections;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -210,4 +214,30 @@ public class GeneratorUtilsTest
assertFalse( GeneratorUtils.isMavenReport( impl, stub ) );
}
+ @Test
+ public void testExcludeProvidedScopeFormComponentDependencies()
+ {
+
+ Artifact a1 = new DefaultArtifact( "g", "a1", "1.0", Artifact.SCOPE_COMPILE, "jar", "", null );
+ Artifact a2 = new DefaultArtifact( "g", "a2", "2.0", Artifact.SCOPE_PROVIDED, "jar", "", null );
+ Artifact a3 = new DefaultArtifact( "g", "a3", "3.0", Artifact.SCOPE_RUNTIME, "jar", "", null );
+ List<Artifact> depList = Arrays.asList( a1, a2, a3 );
+
+ List<ComponentDependency> componentDependencies = GeneratorUtils.toComponentDependencies( depList );
+
+ assertEquals( 2, componentDependencies.size() );
+
+ ComponentDependency componentDependency1 = componentDependencies.get( 0 );
+ assertEquals( a1.getGroupId(), componentDependency1.getGroupId() );
+ assertEquals( a1.getArtifactId(), componentDependency1.getArtifactId() );
+ assertEquals( a1.getVersion(), componentDependency1.getVersion() );
+ assertEquals( a1.getType(), componentDependency1.getType() );
+
+ ComponentDependency componentDependency2 = componentDependencies.get( 1 );
+ assertEquals( a3.getGroupId(), componentDependency2.getGroupId() );
+ assertEquals( a3.getArtifactId(), componentDependency2.getArtifactId() );
+ assertEquals( a3.getVersion(), componentDependency2.getVersion() );
+ assertEquals( a3.getType(), componentDependency2.getType() );
+ }
+
}