This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch 1564 in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/1564 by this push: new 7380d3e implemented avoidArtifactDuplicates() 7380d3e is described below commit 7380d3e15dbfadaf2ced599099561051e3275324 Author: Tibor17 <tibordig...@apache.org> AuthorDate: Wed Sep 26 00:35:52 2018 +0200 implemented avoidArtifactDuplicates() --- .../plugin/surefire/AbstractSurefireMojo.java | 2 +- .../maven/plugin/surefire/TestClassPath.java | 32 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index c407ffe..905cdab 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -2452,7 +2452,7 @@ public abstract class AbstractSurefireMojo } return new TestClassPath( classpathArtifacts, getClassesDirectory(), - getTestClassesDirectory(), getAdditionalClasspathElements() ); + getTestClassesDirectory(), getAdditionalClasspathElements(), logger ); // adding TestNG MethodSelector to the classpath // Todo: move diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java index 8727106..6249ccd 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java @@ -21,9 +21,11 @@ package org.apache.maven.plugin.surefire; import org.apache.maven.artifact.Artifact; import org.apache.maven.surefire.booter.Classpath; +import org.codehaus.plexus.logging.Logger; import java.io.File; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -36,21 +38,45 @@ final class TestClassPath private final File classesDirectory; private final File testClassesDirectory; private final String[] additionalClasspathElements; + private final Logger logger; TestClassPath( Iterable<Artifact> artifacts, File classesDirectory, File testClassesDirectory, - String[] additionalClasspathElements ) + String[] additionalClasspathElements, + Logger logger ) { this.artifacts = artifacts; this.classesDirectory = classesDirectory; this.testClassesDirectory = testClassesDirectory; this.additionalClasspathElements = additionalClasspathElements; + this.logger = logger; } - void avoidArtifactDuplicates( Set<Artifact> providerClasspath ) + void avoidArtifactDuplicates( Set<Artifact> providerArtifacts ) { - + for ( Artifact artifact : artifacts ) + { + Iterator<Artifact> it = providerArtifacts.iterator(); + while ( it.hasNext() ) + { + Artifact providerArtifact = it.next(); + String classifier1 = providerArtifact.getClassifier(); + String classifier2 = artifact.getClassifier(); + if ( providerArtifact.getGroupId().equals( artifact.getGroupId() ) + && providerArtifact.getArtifactId().equals( artifact.getArtifactId() ) + && providerArtifact.getType().equals( artifact.getType() ) + && ( classifier1 == null ? classifier2 == null : classifier1.equals( classifier2 ) ) ) + { + it.remove(); + if ( logger.isDebugEnabled() ) + { + logger.debug( "Removed artifact " + providerArtifact + " from provider. " + + "Already appears in test classpath." ); + } + } + } + } } Iterable<Artifact> getArtifacts()