maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tibordig...@apache.org
Subject [maven-surefire] 01/01: provider classpath should resolve conflicts against test classpath
Date Mon, 24 Sep 2018 18:51:30 GMT
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

commit 12f1498b3b2169a59c6613852924b16aeb22c3b1
Author: Tibor17 <tibordigana@apache.org>
AuthorDate: Mon Sep 24 20:51:14 2018 +0200

    provider classpath should resolve conflicts against test classpath
---
 .../plugin/surefire/AbstractSurefireMojo.java      |  79 +++++-----------
 .../apache/maven/plugin/surefire/ProviderInfo.java |   7 +-
 .../maven/plugin/surefire/TestClassPath.java       | 103 +++++++++++++++++++++
 surefire-its/pom.xml                               |   3 +-
 .../apache/maven/surefire/its/JUnitPlatformIT.java |   9 +-
 5 files changed, 135 insertions(+), 66 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 fa4f257..25f3443 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
@@ -1721,14 +1721,9 @@ public abstract class AbstractSurefireMojo
             Classpath providerClasspath = ClasspathCache.getCachedClassPath( providerName
);
             if ( providerClasspath == null )
             {
-                // todo: 100 milli seconds, try to fetch List<String> within classpath
asynchronously
                 providerClasspath = provider.getProviderClasspath();
                 ClasspathCache.setCachedClasspath( providerName, providerClasspath );
             }
-            Artifact surefireArtifact = getCommonArtifact();
-            Classpath inprocClassPath =
-                    providerClasspath.addClassPathElementUrl( surefireArtifact.getFile().getAbsolutePath()
)
-                            .addClassPathElementUrl( getApiArtifact().getFile().getAbsolutePath()
);
 
             File moduleDescriptor = getModuleDescriptor();
 
@@ -1739,6 +1734,10 @@ public abstract class AbstractSurefireMojo
             }
             else
             {
+                Artifact surefireCommonArtifact = getCommonArtifact();
+                Classpath inprocClassPath =
+                        providerClasspath.addClassPathElementUrl( surefireCommonArtifact.getFile().getAbsolutePath()
)
+                                .addClassPathElementUrl( getApiArtifact().getFile().getAbsolutePath()
);
                 return newStartupConfigForNonModularClasspath( classLoaderConfiguration,
providerClasspath,
                         inprocClassPath, providerName );
             }
@@ -1758,12 +1757,11 @@ public abstract class AbstractSurefireMojo
     }
 
     private StartupConfiguration newStartupConfigForNonModularClasspath(
-            @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Classpath
providerClasspath,
+            @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Set<Artifact>
providerClasspath,
             @Nonnull Classpath inprocClasspath, @Nonnull String providerName )
-            throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException,
-            AbstractArtifactResolutionException
     {
-        Classpath testClasspath = generateTestClasspath();
+        TestClassPath testClasspathWrapper = generateTestClasspath();
+        Classpath testClasspath = testClasspathWrapper.toClasspath();
 
         getConsoleLogger().debug( testClasspath.getLogMessage( "test classpath:" ) );
         getConsoleLogger().debug( providerClasspath.getLogMessage( "provider classpath:"
) );
@@ -1783,10 +1781,9 @@ public abstract class AbstractSurefireMojo
     }
 
     private StartupConfiguration newStartupConfigForModularClasspath(
-            @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Classpath
providerClasspath,
+            @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Set<Artifact>
providerClasspath,
             @Nonnull String providerName, @Nonnull File moduleDescriptor, @Nonnull DefaultScanResult
scanResult )
-            throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException,
-            AbstractArtifactResolutionException, IOException
+            throws AbstractArtifactResolutionException, IOException
     {
         ResolvePathsRequest<String> req = ResolvePathsRequest.withStrings( generateTestClasspath().getClassPath()
)
                 .setMainModuleDescriptor( moduleDescriptor.getAbsolutePath() );
@@ -2425,25 +2422,12 @@ public abstract class AbstractSurefireMojo
     }
 
     /**
-     * Generate the test classpath.
+     * Generates the test classpath.
      *
-     * @return List containing the classpath elements
-     * @throws InvalidVersionSpecificationException
-     *                                     when it happens
-     * @throws MojoFailureException        when it happens
-     * @throws ArtifactNotFoundException   when it happens
-     * @throws ArtifactResolutionException when it happens
+     * @return the classpath elements
      */
-    private Classpath generateTestClasspath()
-        throws InvalidVersionSpecificationException, MojoFailureException, ArtifactResolutionException,
-        ArtifactNotFoundException, MojoExecutionException
+    private TestClassPath generateTestClasspath()
     {
-        List<String> classpath = new ArrayList<String>( 2 + getProject().getArtifacts().size()
);
-
-        classpath.add( getTestClassesDirectory().getAbsolutePath() );
-
-        classpath.add( getClassesDirectory().getAbsolutePath() );
-
         @SuppressWarnings( "unchecked" ) Set<Artifact> classpathArtifacts = getProject().getArtifacts();
 
         if ( getClasspathDependencyScopeExclude() != null && !getClasspathDependencyScopeExclude().isEmpty()
)
@@ -2459,38 +2443,15 @@ public abstract class AbstractSurefireMojo
             classpathArtifacts = filterArtifacts( classpathArtifacts, dependencyFilter );
         }
 
-        for ( Artifact artifact : classpathArtifacts )
-        {
-            if ( artifact.getArtifactHandler().isAddedToClasspath() )
-            {
-                File file = artifact.getFile();
-                if ( file != null )
-                {
-                    classpath.add( file.getPath() );
-                }
-            }
-        }
-
-        // Add additional configured elements to the classpath
-        if ( getAdditionalClasspathElements() != null )
-        {
-            for ( String classpathElement : getAdditionalClasspathElements() )
-            {
-                if ( classpathElement != null )
-                {
-                    addAll( classpath, split( classpathElement, "," ) );
-                }
-            }
-        }
+        return new TestClassPath( classpathArtifacts, getClassesDirectory(), getTestClassesDirectory(),
getAdditionalClasspathElements() );
 
         // adding TestNG MethodSelector to the classpath
         // Todo: move
-        if ( getTestNgArtifact() != null )
+        // todo: why t use it in general, and surefire-grouper
+        /*if ( getTestNgArtifact() != null )
         {
             addTestNgUtilsArtifacts( classpath );
-        }
-
-        return new Classpath( classpath );
+        }*/
     }
 
     private void addTestNgUtilsArtifacts( List<String> classpath )
@@ -2929,21 +2890,27 @@ public abstract class AbstractSurefireMojo
             this.junitArtifact = junitArtifact;
         }
 
-        @Nonnull public String getProviderName()
+        @Override
+        @Nonnull
+        public String getProviderName()
         {
             return "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider";
         }
 
+        @Override
         public boolean isApplicable()
         {
             return junitArtifact != null;
         }
 
+        @Override
         public void addProviderProperties() throws MojoExecutionException
         {
             convertGroupParameters();
         }
 
+        @Override
+        @Nonnull
         public Classpath getProviderClasspath()
             throws ArtifactResolutionException, ArtifactNotFoundException
         {
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java
index a3fb88e..5f00cab 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java
@@ -19,12 +19,15 @@ package org.apache.maven.plugin.surefire;
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.surefire.booter.Classpath;
 
 import javax.annotation.Nonnull;
+import java.util.Set;
 
 /**
  * @author Kristian Rosenvold
@@ -37,8 +40,8 @@ public interface ProviderInfo
     boolean isApplicable();
 
     @Nonnull
-    Classpath getProviderClasspath()
-        throws ArtifactResolutionException, ArtifactNotFoundException;
+    Set<Artifact> getProviderClasspath()
+        throws AbstractArtifactResolutionException;
 
     void addProviderProperties() throws MojoExecutionException;
 }
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
new file mode 100644
index 0000000..b4f65ef
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java
@@ -0,0 +1,103 @@
+package org.apache.maven.plugin.surefire;
+
+/*
+ * 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.surefire.booter.Classpath;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.Collections.addAll;
+import static org.apache.maven.shared.utils.StringUtils.split;
+
+final class TestClassPath
+{
+    private final Iterable<Artifact> artifacts;
+    private final File classesDirectory;
+    private final File testClassesDirectory;
+    private final String[] additionalClasspathElements;
+
+    TestClassPath( Iterable<Artifact> artifacts,
+                   File classesDirectory,
+                   File testClassesDirectory,
+                   String[] additionalClasspathElements )
+    {
+        this.artifacts = artifacts;
+        this.classesDirectory = classesDirectory;
+        this.testClassesDirectory = testClassesDirectory;
+        this.additionalClasspathElements = additionalClasspathElements;
+    }
+
+    Iterable<Artifact> getArtifacts()
+    {
+        return artifacts;
+    }
+
+    File getClassesDirectory()
+    {
+        return classesDirectory;
+    }
+
+    File getTestClassesDirectory()
+    {
+        return testClassesDirectory;
+    }
+
+    String[] getAdditionalClasspathElements()
+    {
+        return additionalClasspathElements;
+    }
+
+    Classpath toClasspath()
+    {
+        List<String> classpath = new ArrayList<String>();
+        classpath.add( classesDirectory.getAbsolutePath() );
+        classpath.add( testClassesDirectory.getAbsolutePath() );
+        for ( Artifact artifact : artifacts )
+        {
+            if ( artifact.getArtifactHandler().isAddedToClasspath() )
+            {
+                File file = artifact.getFile();
+                if ( file != null )
+                {
+                    classpath.add( file.getPath() );
+                }
+            }
+        }
+        if ( additionalClasspathElements != null )
+        {
+            for ( String additionalClasspathElement : additionalClasspathElements )
+            {
+                if ( additionalClasspathElement != null )
+                {
+                    addAll( classpath, split( additionalClasspathElement, "," ) );
+                }
+            }
+        }
+        // todo: why t use it in general, and surefire-grouper
+        /*if ( getTestNgArtifact() != null )
+        {
+            addTestNgUtilsArtifacts( classpath );
+        }*/
+        return new Classpath( classpath );
+    }
+}
diff --git a/surefire-its/pom.xml b/surefire-its/pom.xml
index 5ee30c9..892bccd 100644
--- a/surefire-its/pom.xml
+++ b/surefire-its/pom.xml
@@ -97,6 +97,7 @@
         <artifactId>maven-failsafe-plugin</artifactId>
         <version>2.12.4</version> <!-- ${shadedVersion}, but resolved due
to https://issues.apache.org/jira/browse/MRELEASE-799 -->
         <configuration>
+          <skipTests>false</skipTests>
           <jvm>${jdk.home}/bin/java</jvm>
           <runOrder>alphabetical</runOrder>
           <threadCount>1</threadCount>
@@ -104,7 +105,7 @@
           <forkMode>once</forkMode>
           <argLine>-server -Xmx64m -XX:+UseG1GC -XX:+TieredCompilation -XX:TieredStopAtLevel=1
-Djava.awt.headless=true</argLine>
           <includes>
-            <include>org/apache/**/*IT*.java</include>
+            <include>org/apache/**/JUnitPlatformIT.java</include>
           </includes>
           <!-- Pass current surefire version to the main suite so that it -->
           <!-- can forward to all integration test projects. SUREFIRE-513 -->
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java
b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java
index 5884cea..87f338a 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java
@@ -24,10 +24,7 @@ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
 import org.junit.Before;
 import org.junit.Test;
 
-import static java.lang.System.getProperty;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assume.assumeThat;
+import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion;
 
 public class JUnitPlatformIT
     extends SurefireJUnit4IntegrationTestCase
@@ -35,8 +32,7 @@ public class JUnitPlatformIT
     @Before
     public void setUp()
     {
-        assumeThat( "java.specification.version: ",
-                    getProperty( "java.specification.version" ), is( greaterThanOrEqualTo(
"1.8" ) ) );
+        assumeJavaVersion( 1.8d );
     }
 
     @Test
@@ -67,7 +63,6 @@ public class JUnitPlatformIT
     public void testJUnitPlatform_1_0_0()
     {
         OutputValidator validator = unpack( "/junit-platform-1.0.0" )
-                .setLauncherJavaHome(System.getenv("JAVA_HOME"))
                 .addGoal("-X")
                 .executeTest()
                 .verifyErrorFree( 1 );


Mime
View raw message