[maven-dependency-plugin] branch master updated (79939b5 -> 9eb1987)

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] branch master updated (79939b5 -> 9eb1987)

rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git.


    from 79939b5  [MDEP-655] - The unpack integration test fails intermittent.
     new 28e4e02  Add integration test that verifies the bug is fixed
     new b0ee420  Ensure integration test uses latest plugin version
     new 3e39ea4  Rewrite go-offline so it resembles resolve-plugins
     new b489c8a  Add unit test for the ExcludeReactorProjectsArtifactFilter
     new 0b34f0a  Move license block the correct place
     new 01decd0  Perform transformation to artifact keys just once
     new 7b6dbfd  Don't replace original author
     new 9eb1987  Replace CapturingLog class with Mockito usage

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |   9 ++
 .../invoker.properties                             |   0
 .../module-1/pom.xml}                              |  22 ++-
 .../module-2/pom.xml}                              |  22 ++-
 .../pom.xml                                        |  29 ++--
 .../dependency/resolvers/AbstractResolveMojo.java  |  41 ++---
 .../ExcludeReactorProjectsArtifactFilter.java      |  94 ++++++++++++
 .../dependency/resolvers/GoOfflineMojo.java        | 100 +++++++++++--
 .../dependency/resolvers/ResolvePluginsMojo.java   |   2 +-
 .../apache/maven/plugins/dependency/TestSkip.java  | 166 ++-------------------
 .../ExcludeReactorProjectsArtifactFilterTest.java  | 101 +++++++++++++
 11 files changed, 367 insertions(+), 219 deletions(-)
 copy src/it/projects/{go-offline => mdep-204-go-offline-resolve-intermodule}/invoker.properties (100%)
 copy src/it/{mrm/repository/ResourceArtifact-1.0.pom => projects/mdep-204-go-offline-resolve-intermodule/module-1/pom.xml} (69%)
 copy src/it/{mrm/repository/ResourceArtifact-1.0.pom => projects/mdep-204-go-offline-resolve-intermodule/module-2/pom.xml} (69%)
 copy src/it/projects/{copy-from-reactor/child-a => mdep-204-go-offline-resolve-intermodule}/pom.xml (71%)
 create mode 100644 src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
 create mode 100644 src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 01/08: Add integration test that verifies the bug is fixed

rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 28e4e02058558324b64616e443572a621da80578
Author: Maarten Mulders <[hidden email]>
AuthorDate: Thu Aug 22 08:38:58 2019 +0200

    Add integration test that verifies the bug is fixed
---
 pom.xml                                            |  3 ++
 .../invoker.properties                             | 18 ++++++++
 .../module-1/pom.xml                               | 42 +++++++++++++++++++
 .../module-2/pom.xml                               | 42 +++++++++++++++++++
 .../pom.xml                                        | 48 ++++++++++++++++++++++
 5 files changed, 153 insertions(+)

diff --git a/pom.xml b/pom.xml
index 40d9a53..c6e5fca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,9 @@ under the License.
     <contributor>
       <name>Markus Karg</name>
     </contributor>
+    <contributor>
+      <name>Maarten Mulders</name>
+    </contributor>
   </contributors>
 
   <properties>
diff --git a/src/it/projects/mdep-204-go-offline-resolve-intermodule/invoker.properties b/src/it/projects/mdep-204-go-offline-resolve-intermodule/invoker.properties
new file mode 100644
index 0000000..bba350b
--- /dev/null
+++ b/src/it/projects/mdep-204-go-offline-resolve-intermodule/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 = dependency:go-offline
diff --git a/src/it/projects/mdep-204-go-offline-resolve-intermodule/module-1/pom.xml b/src/it/projects/mdep-204-go-offline-resolve-intermodule/module-1/pom.xml
new file mode 100644
index 0000000..94f4dea
--- /dev/null
+++ b/src/it/projects/mdep-204-go-offline-resolve-intermodule/module-1/pom.xml
@@ -0,0 +1,42 @@
+<?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>
+
+    <parent>
+        <groupId>org.apache.maven.its.dependency</groupId>
+        <artifactId>test-mdep-204</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>test-sub-1</artifactId>
+    <name>MDEP-204 / Sub-module 1</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-project</artifactId>
+            <version>2.2.1</version>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/src/it/projects/mdep-204-go-offline-resolve-intermodule/module-2/pom.xml b/src/it/projects/mdep-204-go-offline-resolve-intermodule/module-2/pom.xml
new file mode 100644
index 0000000..7fa4c20
--- /dev/null
+++ b/src/it/projects/mdep-204-go-offline-resolve-intermodule/module-2/pom.xml
@@ -0,0 +1,42 @@
+<?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>
+
+    <parent>
+        <groupId>org.apache.maven.its.dependency</groupId>
+        <artifactId>test-mdep-204</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>test-sub-2</artifactId>
+    <name>MDEP-204 / Sub-module 2</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.its.dependency</groupId>
+            <artifactId>test-sub-1</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/src/it/projects/mdep-204-go-offline-resolve-intermodule/pom.xml b/src/it/projects/mdep-204-go-offline-resolve-intermodule/pom.xml
new file mode 100644
index 0000000..fc70f99
--- /dev/null
+++ b/src/it/projects/mdep-204-go-offline-resolve-intermodule/pom.xml
@@ -0,0 +1,48 @@
+<?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.dependency</groupId>
+    <artifactId>test-mdep-204</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>MDEP-204</name>
+    <description>
+        Test dependency:go-offline for multi-module projects
+    </description>
+
+    <modules>
+        <module>module-1</module>
+        <module>module-2</module>
+    </modules>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+    </dependencies>
+
+</project>

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 02/08: Ensure integration test uses latest plugin version

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit b0ee4207a8516dec5eaedac7b1969b0d7ff59d68
Author: Maarten Mulders <[hidden email]>
AuthorDate: Sun Sep 1 22:01:44 2019 +0200

    Ensure integration test uses latest plugin version
---
 .../projects/mdep-204-go-offline-resolve-intermodule/invoker.properties | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/it/projects/mdep-204-go-offline-resolve-intermodule/invoker.properties b/src/it/projects/mdep-204-go-offline-resolve-intermodule/invoker.properties
index bba350b..e596121 100644
--- a/src/it/projects/mdep-204-go-offline-resolve-intermodule/invoker.properties
+++ b/src/it/projects/mdep-204-go-offline-resolve-intermodule/invoker.properties
@@ -15,4 +15,4 @@
 # specific language governing permissions and limitations
 # under the License.
 
-invoker.goals = dependency:go-offline
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:go-offline

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 03/08: Rewrite go-offline so it resembles resolve-plugins

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 3e39ea46f8caf8b94006dda703bce87d84de03bf
Author: Maarten Mulders <[hidden email]>
AuthorDate: Sun Sep 1 22:07:27 2019 +0200

    Rewrite go-offline so it resembles resolve-plugins
---
 .../dependency/resolvers/AbstractResolveMojo.java  | 41 +++------
 .../ExcludeReactorProjectsArtifactFilter.java      | 95 +++++++++++++++++++++
 .../dependency/resolvers/GoOfflineMojo.java        | 99 +++++++++++++++++++---
 .../dependency/resolvers/ResolvePluginsMojo.java   |  2 +-
 4 files changed, 195 insertions(+), 42 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
index 6947b59..e63db81 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
@@ -27,12 +27,12 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo;
 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
-import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
 import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
 import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
 import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
+import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
 import org.apache.maven.shared.artifact.filter.collection.TypeFilter;
 import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
 import org.apache.maven.shared.transfer.dependencies.DependableCoordinate;
@@ -72,7 +72,7 @@ public abstract class AbstractResolveMojo
     protected boolean appendOutput;
 
     /**
-     * Don't resolve plugins that are in the current reactor. Only works for plugins at the moment.
+     * Don't resolve plugins that are in the current reactor.
      *
      * @since 2.7
      */
@@ -94,40 +94,19 @@ public abstract class AbstractResolveMojo
     /**
      * @return {@link FilterArtifacts}
      */
-    protected FilterArtifacts getPluginArtifactsFilter()
+    protected FilterArtifacts getArtifactsFilter()
     {
+        final FilterArtifacts filter = new FilterArtifacts();
+
         if ( excludeReactor )
         {
-            final StringBuilder exAids = new StringBuilder();
-            if ( this.excludeArtifactIds != null )
-            {
-                exAids.append( this.excludeArtifactIds );
-            }
-
-            for ( final MavenProject rp : reactorProjects )
-            {
-                if ( !"maven-plugin".equals( rp.getPackaging() ) )
-                {
-                    continue;
-                }
-
-                if ( exAids.length() > 0 )
-                {
-                    exAids.append( "," );
-                }
-
-                exAids.append( rp.getArtifactId() );
-            }
-
-            this.excludeArtifactIds = exAids.toString();
-        }
 
-        final FilterArtifacts filter = new FilterArtifacts();
+            filter.addFilter( new ExcludeReactorProjectsArtifactFilter( reactorProjects, getLog() ) );
+
+        }
 
-        //CHECKSTYLE_OFF: LineLength
-        filter.addFilter( new org.apache.maven.shared.artifact.filter.collection.ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
-                                                                                              DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );
-        //CHECKSTYLE_ON: LineLength
+        filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
+                                           DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );
 
         filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ),
                                           DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) );
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
new file mode 100644
index 0000000..fbeda30
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
@@ -0,0 +1,95 @@
+package org.apache.maven.plugins.dependency.resolvers;
+
+/*
+ * 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.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactsFilter;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * {@link ArtifactFilter} implementation that excludes artifacts found in the Reactor.
+ *
+ * @author Maarten Mulders
+ */
+public class ExcludeReactorProjectsArtifactFilter extends AbstractArtifactsFilter
+{
+    private final Log log;
+    private final Set<Artifact> reactorArtifacts;
+
+    public ExcludeReactorProjectsArtifactFilter( final List<MavenProject> reactorProjects, final Log log )
+    {
+        this.log = log;
+        this.reactorArtifacts = new HashSet<>( reactorProjects.size() );
+        for ( final MavenProject project : reactorProjects )
+        {
+            this.reactorArtifacts.add( project.getArtifact() );
+        }
+    }
+
+    @Override
+    public Set<Artifact> filter( final Set<Artifact> artifacts ) throws ArtifactFilterException
+    {
+        final Set<Artifact> results = new LinkedHashSet<>( artifacts.size() );
+
+        for ( final Artifact artifact : artifacts )
+        {
+            if ( !isArtifactInReactor( artifact ) )
+            {
+                results.add( artifact );
+            }
+            else
+            {
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "Skipped artifact "
+                            + ArtifactUtils.key( artifact )
+                            + " because it is present in the reactor" );
+                }
+            }
+        }
+
+        return results;
+    }
+
+    private boolean isArtifactInReactor( final Artifact artifact )
+    {
+        for ( final Artifact reactorArtifact : reactorArtifacts )
+        {
+            final String reactorArtifactKey = ArtifactUtils.key( reactorArtifact );
+            final String artifactKey = ArtifactUtils.key( artifact );
+
+            // This check only includes GAV. Should we take a look at the types, too?
+            if ( reactorArtifactKey.equals( artifactKey ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
index df74357..408f9ab 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
@@ -22,27 +22,31 @@ package org.apache.maven.plugins.dependency.resolvers;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
-import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
+import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
+import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
 
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 /**
  * Goal that resolves all project dependencies, including plugins and reports and their dependencies.
  *
- * @author <a href="mailto:[hidden email]">Brian Fox</a>
+ * @author Maarten Mulders
  * @since 2.0
  */
-@Mojo( name = "go-offline", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
-@Execute( goal = "resolve-plugins" )
+@Mojo( name = "go-offline", threadSafe = true )
 public class GoOfflineMojo
     extends AbstractResolveMojo
 {
 
     /**
-     * Main entry into mojo. Gets the list of dependencies and iterates through displaying the resolved version.
+     * Main entry into mojo. Gets the list of dependencies, resolves all that are not in the Reactor, and iterates
+     * through displaying the resolved versions.
      *
      * @throws MojoExecutionException with a message if an error occurs.
      */
@@ -50,15 +54,90 @@ public class GoOfflineMojo
     protected void doExecute()
         throws MojoExecutionException
     {
-        Set<Artifact> artifacts = getProject().getArtifacts();
 
-        if ( !isSilent() )
+        try
         {
-            for ( Artifact artifact : artifacts )
+            final Set<Artifact> plugins = resolvePluginArtifacts();
+
+            final Set<Artifact> dependencies = resolveDependencyArtifacts();
+
+            if ( !isSilent() )
             {
-                this.getLog().info( "Resolved: " + DependencyUtil.getFormattedFileName( artifact, false ) );
+                for ( Artifact artifact : plugins )
+                {
+                    this.getLog().info( "Resolved plugin: "
+                            + DependencyUtil.getFormattedFileName( artifact, false ) );
+                }
+
+                for ( Artifact artifact : dependencies )
+                {
+                    this.getLog().info( "Resolved dependency: "
+                            + DependencyUtil.getFormattedFileName( artifact, false ) );
+                }
             }
+
+        }
+        catch ( ArtifactFilterException | ArtifactResolverException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+
+    }
+
+    /**
+     * This method resolves the dependency artifacts from the project.
+     *
+     * @return set of resolved dependency artifacts.
+     * @throws ArtifactFilterException in case of an error while filtering the artifacts.
+     * @throws ArtifactResolverException in case of an error while resolving the artifacts.
+     */
+    protected Set<Artifact> resolveDependencyArtifacts()
+            throws ArtifactFilterException, ArtifactResolverException
+    {
+        final Set<Artifact> artifacts = getProject().getDependencyArtifacts();
+
+        return resolveFilteredArtifacts( artifacts );
+    }
+
+    /**
+     * This method resolves the plugin artifacts from the project.
+     *
+     * @return set of resolved plugin artifacts.
+     * @throws ArtifactFilterException in case of an error while filtering the artifacts.
+     * @throws ArtifactResolverException in case of an error while resolving the artifacts.
+     */
+    protected Set<Artifact> resolvePluginArtifacts()
+            throws ArtifactFilterException, ArtifactResolverException
+    {
+        final Set<Artifact> plugins = getProject().getPluginArtifacts();
+        final Set<Artifact> reports = getProject().getReportArtifacts();
+
+        final Set<Artifact> artifacts = new LinkedHashSet<>();
+        artifacts.addAll( reports );
+        artifacts.addAll( plugins );
+
+        return resolveFilteredArtifacts( artifacts );
+    }
+
+    protected Set<Artifact> resolveFilteredArtifacts( final Set<Artifact> artifacts )
+            throws ArtifactFilterException, ArtifactResolverException
+    {
+        final FilterArtifacts filter = getArtifactsFilter();
+        final Set<Artifact> filteredArtifacts = filter.filter( artifacts );
+
+        final Set<Artifact> resolvedArtifacts = new LinkedHashSet<>( artifacts.size() );
+        for ( final Artifact artifact : filteredArtifacts )
+        {
+            final ProjectBuildingRequest buildingRequest =
+                    new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+
+            // resolve the new artifact
+            final Artifact resolvedArtifact = getArtifactResolver()
+                    .resolveArtifact( buildingRequest, artifact ).getArtifact();
+            resolvedArtifacts.add( resolvedArtifact );
         }
+
+        return resolvedArtifacts;
     }
 
     @Override
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
index 0825cbc..643b004 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
@@ -181,7 +181,7 @@ public class ResolvePluginsMojo
         artifacts.addAll( reports );
         artifacts.addAll( plugins );
 
-        final FilterArtifacts filter = getPluginArtifactsFilter();
+        final FilterArtifacts filter = getArtifactsFilter();
         artifacts = filter.filter( artifacts );
 
         Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>( artifacts.size() );

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 04/08: Add unit test for the ExcludeReactorProjectsArtifactFilter

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit b489c8a4ba121ecc72a78eec9afcbfea6c0ba882
Author: Maarten Mulders <[hidden email]>
AuthorDate: Mon Sep 2 21:26:38 2019 +0200

    Add unit test for the ExcludeReactorProjectsArtifactFilter
---
 .../maven/plugins/dependency/CapturingLog.java     | 179 +++++++++++++++++++++
 .../apache/maven/plugins/dependency/TestSkip.java  | 156 ------------------
 .../ExcludeReactorProjectsArtifactFilterTest.java  |  88 ++++++++++
 3 files changed, 267 insertions(+), 156 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
new file mode 100644
index 0000000..089fa69
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
@@ -0,0 +1,179 @@
+package org.apache.maven.plugins.dependency;
+
+import org.apache.maven.plugin.logging.Log;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/*
+ * 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.
+ */
+
+/** Helper to do assertions on what is being logged. */
+public class CapturingLog
+    implements Log
+{
+    StringBuilder sb = new StringBuilder();
+
+    /** {@inheritDoc} */
+    public void debug( CharSequence content )
+    {
+        print( "debug", content );
+    }
+
+    /** {@inheritDoc} */
+    public void debug( CharSequence content, Throwable error )
+    {
+        print( "debug", content, error );
+    }
+
+    /** {@inheritDoc} */
+    public void debug( Throwable error )
+    {
+        print( "debug", error );
+    }
+
+    /** {@inheritDoc} */
+    public void info( CharSequence content )
+    {
+        print( "info", content );
+    }
+
+    /** {@inheritDoc} */
+    public void info( CharSequence content, Throwable error )
+    {
+        print( "info", content, error );
+    }
+
+    /** {@inheritDoc} */
+    public void info( Throwable error )
+    {
+        print( "info", error );
+    }
+
+    /** {@inheritDoc} */
+    public void warn( CharSequence content )
+    {
+        print( "warn", content );
+    }
+
+    /** {@inheritDoc} */
+    public void warn( CharSequence content, Throwable error )
+    {
+        print( "warn", content, error );
+    }
+
+    /** {@inheritDoc} */
+    public void warn( Throwable error )
+    {
+        print( "warn", error );
+    }
+
+    /** {@inheritDoc} */
+    public void error( CharSequence content )
+    {
+        System.err.println( "[error] " + content.toString() );
+    }
+
+    /** {@inheritDoc} */
+    public void error( CharSequence content, Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        System.err.println( "[error] " + content.toString() + System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
+    }
+
+    /**
+     * @see Log#error(Throwable)
+     */
+    public void error( Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        System.err.println( "[error] " + sWriter.toString() );
+    }
+
+    /**
+     * @see Log#isDebugEnabled()
+     */
+    public boolean isDebugEnabled()
+    {
+        // TODO: Not sure how best to set these for this implementation...
+        return true;
+    }
+
+    /**
+     * @see Log#isInfoEnabled()
+     */
+    public boolean isInfoEnabled()
+    {
+        return true;
+    }
+
+    /**
+     * @see Log#isWarnEnabled()
+     */
+    public boolean isWarnEnabled()
+    {
+        return true;
+    }
+
+    /**
+     * @see Log#isErrorEnabled()
+     */
+    public boolean isErrorEnabled()
+    {
+        return true;
+    }
+
+    private void print( String prefix, CharSequence content )
+    {
+        sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( System.lineSeparator() );
+    }
+
+    private void print( String prefix, Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        sb.append( "[" ).append( prefix ).append( "] " ).append( sWriter.toString() ).append( System.lineSeparator() );
+    }
+
+    private void print( String prefix, CharSequence content, Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( System.lineSeparator() ).append( System.lineSeparator() ).append( sWriter.toString() ).append( System.lineSeparator() );
+    }
+
+    public String getContent()
+    {
+        return sb.toString();
+    }
+}
diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
index 932c9da..54e3d3d 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
@@ -1,11 +1,8 @@
 package org.apache.maven.plugins.dependency;
 
 import org.apache.maven.plugin.Mojo;
-import org.apache.maven.plugin.logging.Log;
 
 import java.io.File;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -168,157 +165,4 @@ public class TestSkip
         assertTrue( log.getContent().contains( "Skipping plugin execution" ) );
     }
 
-    class CapturingLog
-        implements Log
-    {
-        StringBuilder sb = new StringBuilder();
-
-        /** {@inheritDoc} */
-        public void debug( CharSequence content )
-        {
-            print( "debug", content );
-        }
-
-        /** {@inheritDoc} */
-        public void debug( CharSequence content, Throwable error )
-        {
-            print( "debug", content, error );
-        }
-
-        /** {@inheritDoc} */
-        public void debug( Throwable error )
-        {
-            print( "debug", error );
-        }
-
-        /** {@inheritDoc} */
-        public void info( CharSequence content )
-        {
-            print( "info", content );
-        }
-
-        /** {@inheritDoc} */
-        public void info( CharSequence content, Throwable error )
-        {
-            print( "info", content, error );
-        }
-
-        /** {@inheritDoc} */
-        public void info( Throwable error )
-        {
-            print( "info", error );
-        }
-
-        /** {@inheritDoc} */
-        public void warn( CharSequence content )
-        {
-            print( "warn", content );
-        }
-
-        /** {@inheritDoc} */
-        public void warn( CharSequence content, Throwable error )
-        {
-            print( "warn", content, error );
-        }
-
-        /** {@inheritDoc} */
-        public void warn( Throwable error )
-        {
-            print( "warn", error );
-        }
-
-        /** {@inheritDoc} */
-        public void error( CharSequence content )
-        {
-            System.err.println( "[error] " + content.toString() );
-        }
-
-        /** {@inheritDoc} */
-        public void error( CharSequence content, Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            System.err.println( "[error] " + content.toString() + System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
-         */
-        public void error( Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            System.err.println( "[error] " + sWriter.toString() );
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
-         */
-        public boolean isDebugEnabled()
-        {
-            // TODO: Not sure how best to set these for this implementation...
-            return false;
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
-         */
-        public boolean isInfoEnabled()
-        {
-            return true;
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
-         */
-        public boolean isWarnEnabled()
-        {
-            return true;
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
-         */
-        public boolean isErrorEnabled()
-        {
-            return true;
-        }
-
-        private void print( String prefix, CharSequence content )
-        {
-            sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( System.lineSeparator() );
-        }
-
-        private void print( String prefix, Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            sb.append( "[" ).append( prefix ).append( "] " ).append( sWriter.toString() ).append( System.lineSeparator() );
-        }
-
-        private void print( String prefix, CharSequence content, Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( System.lineSeparator() ).append( System.lineSeparator() ).append( sWriter.toString() ).append( System.lineSeparator() );
-        }
-
-        protected String getContent()
-        {
-            return sb.toString();
-        }
-    }
-
 }
diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
new file mode 100644
index 0000000..65b35f6
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
@@ -0,0 +1,88 @@
+package org.apache.maven.plugins.dependency.resolvers;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugins.dependency.CapturingLog;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Collections.singleton;
+import static java.util.Collections.singletonList;
+
+/*
+ * 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.
+ */
+
+public class ExcludeReactorProjectsArtifactFilterTest
+        extends AbstractDependencyMojoTestCase
+{
+
+    public void testFilter()
+            throws ArtifactFilterException
+    {
+        Artifact artifact1 = new ArtifactStub();
+        artifact1.setGroupId("org.apache.maven.plugins");
+        artifact1.setArtifactId("maven-dependency-plugin-dummy");
+        artifact1.setVersion("1.0");
+
+        Artifact artifact2 = new ArtifactStub();
+        artifact2.setGroupId("org.apache.maven.plugins");
+        artifact2.setArtifactId("maven-dependency-plugin-other-dummy");
+        artifact2.setVersion("1.0");
+
+        Set<Artifact> artifacts = new HashSet<>();
+        artifacts.add( artifact1 );
+        artifacts.add( artifact2 );
+
+        CapturingLog log = new CapturingLog();
+        MavenProject project = new MavenProjectStub();
+        project.setArtifact(artifact1);
+
+        ExcludeReactorProjectsArtifactFilter filter = new ExcludeReactorProjectsArtifactFilter(
+                singletonList( project ), log );
+
+        Set<Artifact> result = filter.filter( artifacts );
+
+        assertEquals( 1, result.size() );
+    }
+
+    public void testFilterWithLogging()
+            throws ArtifactFilterException
+    {
+        Artifact artifact = new ArtifactStub();
+        artifact.setGroupId("org.apache.maven.plugins");
+        artifact.setArtifactId("maven-dependency-plugin-dummy");
+        artifact.setVersion("1.0");
+
+        CapturingLog log = new CapturingLog();
+        MavenProject project = new MavenProjectStub();
+        project.setArtifact(artifact);
+
+        ExcludeReactorProjectsArtifactFilter filter = new ExcludeReactorProjectsArtifactFilter(
+                singletonList( project ), log );
+
+        filter.filter( singleton( artifact ) );
+
+        assertTrue( log.getContent().contains( "Skipped artifact" ) );
+    }
+}

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 05/08: Move license block the correct place

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 0b34f0ac3ec7243146d3ca1889fd2d1531157431
Author: Maarten Mulders <[hidden email]>
AuthorDate: Fri Sep 6 15:31:34 2019 +0200

    Move license block the correct place
---
 .../maven/plugins/dependency/CapturingLog.java     | 10 ++++----
 .../ExcludeReactorProjectsArtifactFilterTest.java  | 28 +++++++++++-----------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
index 089fa69..4506823 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
@@ -1,10 +1,5 @@
 package org.apache.maven.plugins.dependency;
 
-import org.apache.maven.plugin.logging.Log;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -24,6 +19,11 @@ import java.io.StringWriter;
  * under the License.
  */
 
+import org.apache.maven.plugin.logging.Log;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
 /** Helper to do assertions on what is being logged. */
 public class CapturingLog
     implements Log
diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
index 65b35f6..8d83f55 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
@@ -1,19 +1,5 @@
 package org.apache.maven.plugins.dependency.resolvers;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugins.dependency.CapturingLog;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import static java.util.Collections.singleton;
-import static java.util.Collections.singletonList;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -33,6 +19,20 @@ import static java.util.Collections.singletonList;
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugins.dependency.CapturingLog;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Collections.singleton;
+import static java.util.Collections.singletonList;
+
 public class ExcludeReactorProjectsArtifactFilterTest
         extends AbstractDependencyMojoTestCase
 {

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 06/08: Perform transformation to artifact keys just once

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 01decd08e7f067592e25570f8f480dd2af1dc782
Author: Maarten Mulders <[hidden email]>
AuthorDate: Fri Sep 6 15:32:11 2019 +0200

    Perform transformation to artifact keys just once
---
 .../resolvers/ExcludeReactorProjectsArtifactFilter.java          | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
index fbeda30..4c57ca5 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
@@ -40,15 +40,15 @@ import java.util.Set;
 public class ExcludeReactorProjectsArtifactFilter extends AbstractArtifactsFilter
 {
     private final Log log;
-    private final Set<Artifact> reactorArtifacts;
+    private final Set<String> reactorArtifactKeys;
 
     public ExcludeReactorProjectsArtifactFilter( final List<MavenProject> reactorProjects, final Log log )
     {
         this.log = log;
-        this.reactorArtifacts = new HashSet<>( reactorProjects.size() );
+        this.reactorArtifactKeys = new HashSet<>( reactorProjects.size() );
         for ( final MavenProject project : reactorProjects )
         {
-            this.reactorArtifacts.add( project.getArtifact() );
+            this.reactorArtifactKeys.add( ArtifactUtils.key( project.getArtifact() ) );
         }
     }
 
@@ -79,9 +79,8 @@ public class ExcludeReactorProjectsArtifactFilter extends AbstractArtifactsFilte
 
     private boolean isArtifactInReactor( final Artifact artifact )
     {
-        for ( final Artifact reactorArtifact : reactorArtifacts )
+        for ( final String reactorArtifactKey : this.reactorArtifactKeys )
         {
-            final String reactorArtifactKey = ArtifactUtils.key( reactorArtifact );
             final String artifactKey = ArtifactUtils.key( artifact );
 
             // This check only includes GAV. Should we take a look at the types, too?

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 07/08: Don't replace original author

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 7b6dbfd646945ef46412391c357bc3b4eb6f3978
Author: Maarten Mulders <[hidden email]>
AuthorDate: Fri Sep 6 15:32:26 2019 +0200

    Don't replace original author
---
 .../org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java     | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
index 408f9ab..9309801 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
@@ -36,6 +36,7 @@ import java.util.Set;
 /**
  * Goal that resolves all project dependencies, including plugins and reports and their dependencies.
  *
+ * <a href="mailto:[hidden email]">Brian Fox</a>
  * @author Maarten Mulders
  * @since 2.0
  */

Reply | Threaded
Open this post in threaded view
|

[maven-dependency-plugin] 08/08: Replace CapturingLog class with Mockito usage

rfscholte
In reply to this post by rfscholte
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 9eb19876491c3f9c069b8acacabdad4a49a0f940
Author: Maarten Mulders <[hidden email]>
AuthorDate: Mon Sep 9 07:29:57 2019 +0200

    Replace CapturingLog class with Mockito usage
---
 pom.xml                                            |   6 +
 .../maven/plugins/dependency/CapturingLog.java     | 179 ---------------------
 .../apache/maven/plugins/dependency/TestSkip.java  |  12 +-
 .../ExcludeReactorProjectsArtifactFilterTest.java  |  21 ++-
 4 files changed, 33 insertions(+), 185 deletions(-)

diff --git a/pom.xml b/pom.xml
index c6e5fca..35c1ac5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -282,6 +282,12 @@ under the License.
       <version>${pluginTestingVersion}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>2.28.2</version>
+      <scope>test</scope>
+    </dependency>
 
    <dependency>
       <groupId>org.codehaus.plexus</groupId>
diff --git a/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
deleted file mode 100644
index 4506823..0000000
--- a/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package org.apache.maven.plugins.dependency;
-
-/*
- * 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.logging.Log;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-/** Helper to do assertions on what is being logged. */
-public class CapturingLog
-    implements Log
-{
-    StringBuilder sb = new StringBuilder();
-
-    /** {@inheritDoc} */
-    public void debug( CharSequence content )
-    {
-        print( "debug", content );
-    }
-
-    /** {@inheritDoc} */
-    public void debug( CharSequence content, Throwable error )
-    {
-        print( "debug", content, error );
-    }
-
-    /** {@inheritDoc} */
-    public void debug( Throwable error )
-    {
-        print( "debug", error );
-    }
-
-    /** {@inheritDoc} */
-    public void info( CharSequence content )
-    {
-        print( "info", content );
-    }
-
-    /** {@inheritDoc} */
-    public void info( CharSequence content, Throwable error )
-    {
-        print( "info", content, error );
-    }
-
-    /** {@inheritDoc} */
-    public void info( Throwable error )
-    {
-        print( "info", error );
-    }
-
-    /** {@inheritDoc} */
-    public void warn( CharSequence content )
-    {
-        print( "warn", content );
-    }
-
-    /** {@inheritDoc} */
-    public void warn( CharSequence content, Throwable error )
-    {
-        print( "warn", content, error );
-    }
-
-    /** {@inheritDoc} */
-    public void warn( Throwable error )
-    {
-        print( "warn", error );
-    }
-
-    /** {@inheritDoc} */
-    public void error( CharSequence content )
-    {
-        System.err.println( "[error] " + content.toString() );
-    }
-
-    /** {@inheritDoc} */
-    public void error( CharSequence content, Throwable error )
-    {
-        StringWriter sWriter = new StringWriter();
-        PrintWriter pWriter = new PrintWriter( sWriter );
-
-        error.printStackTrace( pWriter );
-
-        System.err.println( "[error] " + content.toString() + System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
-    }
-
-    /**
-     * @see Log#error(Throwable)
-     */
-    public void error( Throwable error )
-    {
-        StringWriter sWriter = new StringWriter();
-        PrintWriter pWriter = new PrintWriter( sWriter );
-
-        error.printStackTrace( pWriter );
-
-        System.err.println( "[error] " + sWriter.toString() );
-    }
-
-    /**
-     * @see Log#isDebugEnabled()
-     */
-    public boolean isDebugEnabled()
-    {
-        // TODO: Not sure how best to set these for this implementation...
-        return true;
-    }
-
-    /**
-     * @see Log#isInfoEnabled()
-     */
-    public boolean isInfoEnabled()
-    {
-        return true;
-    }
-
-    /**
-     * @see Log#isWarnEnabled()
-     */
-    public boolean isWarnEnabled()
-    {
-        return true;
-    }
-
-    /**
-     * @see Log#isErrorEnabled()
-     */
-    public boolean isErrorEnabled()
-    {
-        return true;
-    }
-
-    private void print( String prefix, CharSequence content )
-    {
-        sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( System.lineSeparator() );
-    }
-
-    private void print( String prefix, Throwable error )
-    {
-        StringWriter sWriter = new StringWriter();
-        PrintWriter pWriter = new PrintWriter( sWriter );
-
-        error.printStackTrace( pWriter );
-
-        sb.append( "[" ).append( prefix ).append( "] " ).append( sWriter.toString() ).append( System.lineSeparator() );
-    }
-
-    private void print( String prefix, CharSequence content, Throwable error )
-    {
-        StringWriter sWriter = new StringWriter();
-        PrintWriter pWriter = new PrintWriter( sWriter );
-
-        error.printStackTrace( pWriter );
-
-        sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( System.lineSeparator() ).append( System.lineSeparator() ).append( sWriter.toString() ).append( System.lineSeparator() );
-    }
-
-    public String getContent()
-    {
-        return sb.toString();
-    }
-}
diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
index 54e3d3d..b681f0c 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
@@ -1,9 +1,15 @@
 package org.apache.maven.plugins.dependency;
 
 import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.logging.Log;
+import org.mockito.ArgumentCaptor;
 
 import java.io.File;
 
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -158,11 +164,13 @@ public class TestSkip
         File testPom = new File( getBasedir(), "target/test-classes/unit/skip-test/" + configFile );
         Mojo mojo = lookupMojo( mojoName, testPom );
         assertNotNull( mojo );
-        CapturingLog log = new CapturingLog();
+        Log log = mock( Log.class );
         mojo.setLog( log );
         mojo.execute();
 
-        assertTrue( log.getContent().contains( "Skipping plugin execution" ) );
+        ArgumentCaptor<String> captor = ArgumentCaptor.forClass( String.class );
+        verify( log, atLeastOnce() ).info( captor.capture() );
+        assertTrue( captor.getValue().contains( "Skipping plugin execution" ) );
     }
 
 }
diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
index 8d83f55..c6de09b 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
@@ -20,18 +20,24 @@ package org.apache.maven.plugins.dependency.resolvers;
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugins.dependency.CapturingLog;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
+import org.mockito.ArgumentCaptor;
 
 import java.util.HashSet;
 import java.util.Set;
 
 import static java.util.Collections.singleton;
 import static java.util.Collections.singletonList;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class ExcludeReactorProjectsArtifactFilterTest
         extends AbstractDependencyMojoTestCase
@@ -54,16 +60,19 @@ public class ExcludeReactorProjectsArtifactFilterTest
         artifacts.add( artifact1 );
         artifacts.add( artifact2 );
 
-        CapturingLog log = new CapturingLog();
         MavenProject project = new MavenProjectStub();
         project.setArtifact(artifact1);
 
+        Log log = mock( Log.class );
+        when( log.isDebugEnabled() ).thenReturn( false );
+
         ExcludeReactorProjectsArtifactFilter filter = new ExcludeReactorProjectsArtifactFilter(
                 singletonList( project ), log );
 
         Set<Artifact> result = filter.filter( artifacts );
 
         assertEquals( 1, result.size() );
+        verify( log, never() ).debug( any( String.class ) );
     }
 
     public void testFilterWithLogging()
@@ -74,15 +83,19 @@ public class ExcludeReactorProjectsArtifactFilterTest
         artifact.setArtifactId("maven-dependency-plugin-dummy");
         artifact.setVersion("1.0");
 
-        CapturingLog log = new CapturingLog();
         MavenProject project = new MavenProjectStub();
         project.setArtifact(artifact);
 
+        Log log = mock( Log.class );
+        when( log.isDebugEnabled() ).thenReturn( true );
+
         ExcludeReactorProjectsArtifactFilter filter = new ExcludeReactorProjectsArtifactFilter(
                 singletonList( project ), log );
 
         filter.filter( singleton( artifact ) );
 
-        assertTrue( log.getContent().contains( "Skipped artifact" ) );
+        ArgumentCaptor<String> captor = ArgumentCaptor.forClass( String.class );
+        verify( log ).debug( captor.capture() );
+        assertTrue( captor.getValue().contains( "Skipped artifact" ) );
     }
 }