From commits-return-76285-archive-asf-public=cust-asf.ponee.io@maven.apache.org Mon Sep 24 20:51:32 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 45E9E18077F for ; Mon, 24 Sep 2018 20:51:31 +0200 (CEST) Received: (qmail 88407 invoked by uid 500); 24 Sep 2018 18:51:30 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 88223 invoked by uid 99); 24 Sep 2018 18:51:30 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Sep 2018 18:51:30 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id A0F6C829DB; Mon, 24 Sep 2018 18:51:29 +0000 (UTC) Date: Mon, 24 Sep 2018 18:51:30 +0000 To: "commits@maven.apache.org" Subject: [maven-surefire] 01/01: provider classpath should resolve conflicts against test classpath MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: tibordigana@apache.org In-Reply-To: <153781508954.17980.12842734921139336073@gitbox.apache.org> References: <153781508954.17980.12842734921139336073@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: maven-surefire X-Git-Refname: refs/heads/1564 X-Git-Reftype: branch X-Git-Rev: 12f1498b3b2169a59c6613852924b16aeb22c3b1 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180924185129.A0F6C829DB@gitbox.apache.org> 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 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 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 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 providerClasspath, @Nonnull String providerName, @Nonnull File moduleDescriptor, @Nonnull DefaultScanResult scanResult ) - throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException, - AbstractArtifactResolutionException, IOException + throws AbstractArtifactResolutionException, IOException { ResolvePathsRequest 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 classpath = new ArrayList( 2 + getProject().getArtifacts().size() ); - - classpath.add( getTestClassesDirectory().getAbsolutePath() ); - - classpath.add( getClassesDirectory().getAbsolutePath() ); - @SuppressWarnings( "unchecked" ) Set 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 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 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 artifacts; + private final File classesDirectory; + private final File testClassesDirectory; + private final String[] additionalClasspathElements; + + TestClassPath( Iterable artifacts, + File classesDirectory, + File testClassesDirectory, + String[] additionalClasspathElements ) + { + this.artifacts = artifacts; + this.classesDirectory = classesDirectory; + this.testClassesDirectory = testClassesDirectory; + this.additionalClasspathElements = additionalClasspathElements; + } + + Iterable getArtifacts() + { + return artifacts; + } + + File getClassesDirectory() + { + return classesDirectory; + } + + File getTestClassesDirectory() + { + return testClassesDirectory; + } + + String[] getAdditionalClasspathElements() + { + return additionalClasspathElements; + } + + Classpath toClasspath() + { + List classpath = new ArrayList(); + 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 @@ maven-failsafe-plugin 2.12.4 + false ${jdk.home}/bin/java alphabetical 1 @@ -104,7 +105,7 @@ once -server -Xmx64m -XX:+UseG1GC -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Djava.awt.headless=true - org/apache/**/*IT*.java + org/apache/**/JUnitPlatformIT.java 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 );