Repository: maven-surefire Updated Branches: refs/heads/SUREFIRE-1400 1e4bdbf03 -> e799e4bc4 (forced update)
[SUREFIRE-1400] Windows surefire boot directory should appear in system default temporary-directory Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/e799e4bc Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/e799e4bc Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/e799e4bc Branch: refs/heads/SUREFIRE-1400 Commit: e799e4bc45127ceacd3bfba5e28ec276de09a342 Parents: 26527d1 Author: Tibor17 <tibordig...@apache.org> Authored: Tue Aug 1 09:37:48 2017 +0200 Committer: Tibor17 <tibordig...@apache.org> Committed: Tue Aug 1 11:37:05 2017 +0200 ---------------------------------------------------------------------- .../plugin/surefire/AbstractSurefireMojo.java | 92 ++++++++++++++- .../surefire/booterclient/ForkStarter.java | 1 + .../surefire/AbstractSurefireMojoTest.java | 111 +++++++++++++++++++ .../apache/maven/surefire/JUnit4SuiteTest.java | 4 +- .../maven/surefire/util/ReflectionUtils.java | 29 ++++- .../surefire/util/ReflectionUtilsTest.java | 6 +- surefire-integration-tests/pom.xml | 2 + .../maven/surefire/its/LongWindowsPathIT.java | 55 +++++++++ .../surefire/its/fixture/HelperAssertions.java | 13 +-- .../test/resources/long-windows-path/pom.xml | 57 ++++++++++ .../test/java/longwindowspath/BasicTest.java | 32 ++++++ .../java/jiras/surefre855/bundle/FooIT.java | 31 +----- .../test/java/jiras/surefire855/jar/FooIT.java | 33 +----- .../test/java/jiras/surefire855/war/FooIT.java | 31 +----- 14 files changed, 395 insertions(+), 102 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- 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 b3df567..a661d40 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 @@ -76,12 +76,14 @@ import org.apache.maven.surefire.testset.TestRequest; import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.DefaultScanResult; import org.apache.maven.surefire.util.RunOrder; +import org.apache.maven.surefire.util.SurefireReflectionException; import org.apache.maven.toolchain.Toolchain; import org.apache.maven.toolchain.ToolchainManager; import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; +import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -98,12 +100,18 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import static java.lang.Thread.currentThread; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; +import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; +import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast; import static org.apache.maven.shared.utils.StringUtils.capitalizeFirstLetter; import static org.apache.maven.shared.utils.StringUtils.isEmpty; import static org.apache.maven.shared.utils.StringUtils.isNotBlank; import static org.apache.maven.shared.utils.StringUtils.split; import static org.apache.maven.surefire.suite.RunResult.failure; import static org.apache.maven.surefire.suite.RunResult.noTestsRun; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeGetter; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeStaticMethod; +import static org.apache.maven.surefire.util.ReflectionUtils.tryLoadClass; /** * Abstract base class for running tests using Surefire. @@ -117,6 +125,8 @@ public abstract class AbstractSurefireMojo { private static final Platform PLATFORM = new Platform(); + private static final File SYSTEM_TMP_DIR = new File( System.getProperty( "java.io.tmpdir" ) ); + private final ProviderDetector providerDetector = new ProviderDetector(); /** @@ -342,7 +352,12 @@ public abstract class AbstractSurefireMojo private String forkMode; /** - * Relative path to <i>project.build.directory</i> containing internal Surefire temporary files. + * Relative path to <i>temporary-surefire-boot</i> directory containing internal Surefire temporary files. + * <br> + * The <i>temporary-surefire-boot</i> directory is <i>project.build.directory</i> on most platforms or + * <i>system default temporary-directory</i> specified by the system property {@code java.io.tmpdir} + * on Windows (see <a href="https://issues.apache.org/jira/browse/SUREFIRE-1400">SUREFIRE-1400</a>). + * <br> * It is deleted after the test set has completed. * * @since 2.20 @@ -1934,6 +1949,7 @@ public abstract class AbstractSurefireMojo protected ForkConfiguration getForkConfiguration() { + // todo: creating tmp dir takes 0.4 second at least, wrap into value-object using Future<File> File tmpDir = getSurefireTempDir(); //noinspection ResultOfMethodCallIgnored tmpDir.mkdirs(); @@ -2061,9 +2077,9 @@ public abstract class AbstractSurefireMojo * * @return A file pointing to the location of surefire's own temp files */ - private File getSurefireTempDir() + File getSurefireTempDir() { - return new File( getProjectBuildDirectory(), getTempDir() ); + return IS_OS_WINDOWS ? createSurefireBootDirectoryInTemp() : createSurefireBootDirectoryInBuild(); } /** @@ -2829,6 +2845,76 @@ public abstract class AbstractSurefireMojo } } + File createSurefireBootDirectoryInBuild() + { + File tmp = new File( getProjectBuildDirectory(), getTempDir() ); + //noinspection ResultOfMethodCallIgnored + tmp.mkdirs(); + return tmp; + } + + // todo use Java7 java.nio.file.Files.createTempDirectory() + File createSurefireBootDirectoryInTemp() + { + if ( isJavaVersionAtLeast( JAVA_1_7 ) ) + { + try + { + return new File( SYSTEM_TMP_DIR, createTmpDirectoryNameWithJava7( getTempDir() ) ); + } + catch ( IOException e ) + { + return createSurefireBootDirectoryInBuild(); + } + } + else + { + try + { + File tmp = File.createTempFile( getTempDir(), null ); + //noinspection ResultOfMethodCallIgnored + return tmp.mkdirs() ? tmp : createSurefireBootDirectoryInBuild(); + } + catch ( IOException e ) + { + return createSurefireBootDirectoryInBuild(); + } + } + } + + /** + * Reflection call of java.nio.file.Files.createTempDirectory( "surefire" ). + * @return Java 7 NIO Path + */ + static Object createTmpDirectoryWithJava7( String directoryPrefix ) + throws IOException + { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + Class<?> filesType = tryLoadClass( classLoader, "java.nio.file.Files" ); + Class<?> fileAttributeType = tryLoadClass( classLoader, "java.nio.file.attribute.FileAttribute" ); + Object attrs = Array.newInstance( fileAttributeType, 0 ); + try + { + return invokeStaticMethod( filesType, "createTempDirectory", + new Class<?>[]{ String.class, attrs.getClass() }, + new Object[]{ directoryPrefix, attrs } ); + } + catch ( SurefireReflectionException e ) + { + Throwable cause = e.getCause(); + throw cause instanceof IOException ? (IOException) cause : new IOException( cause ); + } + } + + static String createTmpDirectoryNameWithJava7( String directoryPrefix ) + throws IOException + { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + Class<?> pathType = tryLoadClass( classLoader, "java.nio.file.Path" ); + Object path = createTmpDirectoryWithJava7( directoryPrefix ); + return invokeGetter( pathType, path, "getFileName" ).toString(); + } + @Override public List<String> getExcludes() { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index 2d82855..7e83060 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -547,6 +547,7 @@ public class ForkStarter try { tempDir = forkConfiguration.getTempDirectory().getCanonicalPath(); + System.out.println( "tempDir = " + tempDir ); BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration ); surefireProperties = booterSerializer.serialize( providerProperties, providerConfiguration, http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java new file mode 100644 index 0000000..cd4ca2b --- /dev/null +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java @@ -0,0 +1,111 @@ +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.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; +import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; +import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast; +import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assume.assumeTrue; +import static org.mockito.Mockito.when; + +/** + * Test for {@link AbstractSurefireMojo}. + */ +@RunWith( MockitoJUnitRunner.class ) +public class AbstractSurefireMojoTest +{ + @Mock + private AbstractSurefireMojo mojo; + + @Test + public void shouldHaveTmpDirectory() throws IOException + { + assumeTrue( isJavaVersionAtLeast( JAVA_1_7 ) ); + + Path path = (Path) AbstractSurefireMojo.createTmpDirectoryWithJava7( "surefire" ); + + assertThat( path ) + .isNotNull(); + + assertThat( path.startsWith( System.getProperty( "java.io.tmpdir" ) ) ) + .isTrue(); + + String dir = path.getName( path.getNameCount() - 1 ).toString(); + + assertThat( dir ) + .startsWith( "surefire" ); + + assertThat( dir ) + .matches( "^surefire[\\d]+$" ); + } + + @Test + public void shouldHaveTmpDirectoryName() throws IOException + { + assumeTrue( isJavaVersionAtLeast( JAVA_1_7 ) ); + + String dir = AbstractSurefireMojo.createTmpDirectoryNameWithJava7( "surefire" ); + + assertThat( dir ) + .isNotNull(); + + assertThat( dir ) + .startsWith( "surefire" ); + + assertThat( dir ) + .matches( "^surefire[\\d]+$" ); + } + + @Test + public void shouldExistTmpDirectory() + { + when( mojo.getTempDir() ).thenReturn( "surefireX" ); + when( mojo.getProjectBuildDirectory() ).thenReturn( new File( System.getProperty( "user.dir" ), "target" ) ); + when( mojo.createSurefireBootDirectoryInTemp() ).thenCallRealMethod(); + when( mojo.createSurefireBootDirectoryInBuild() ).thenCallRealMethod(); + when( mojo.getSurefireTempDir() ).thenCallRealMethod(); + + File tmp = mojo.createSurefireBootDirectoryInTemp(); + assertThat( tmp ).isNotNull(); + assertThat( tmp ).exists(); + assertThat( tmp.getAbsolutePath() ).startsWith( System.getProperty( "java.io.tmpdir" ) ); + + tmp = mojo.createSurefireBootDirectoryInBuild(); + assertThat( tmp ).isNotNull(); + assertThat( tmp ).exists(); + assertThat( tmp.getAbsolutePath() ).startsWith( System.getProperty( "user.dir" ) ); + + tmp = mojo.getSurefireTempDir(); + assertThat( tmp ).isNotNull(); + assertThat( tmp ).exists(); + assertThat( tmp.getAbsolutePath() ) + .startsWith( IS_OS_WINDOWS ? System.getProperty( "java.io.tmpdir" ) : System.getProperty( "user.dir" ) ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java index f7cec19..aec256d 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java @@ -21,6 +21,7 @@ package org.apache.maven.surefire; import junit.framework.JUnit4TestAdapter; import junit.framework.Test; +import org.apache.maven.plugin.surefire.AbstractSurefireMojoTest; import org.apache.maven.plugin.surefire.SurefireHelperTest; import org.apache.maven.plugin.surefire.SurefireReflectorTest; import org.apache.maven.plugin.surefire.SurefirePropertiesTest; @@ -72,7 +73,8 @@ import org.junit.runners.Suite; TestLessInputStreamBuilderTest.class, SPITest.class, SurefireReflectorTest.class, - SurefireHelperTest.class + SurefireHelperTest.class, + AbstractSurefireMojoTest.class } ) @RunWith( Suite.class ) public class JUnit4SuiteTest http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java index 1be4e06..49f8f09 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java @@ -28,6 +28,9 @@ import java.lang.reflect.Method; */ public final class ReflectionUtils { + private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0]; + private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + private ReflectionUtils() { throw new IllegalStateException( "no instantiable constructor" ); @@ -64,7 +67,12 @@ public final class ReflectionUtils public static Object invokeGetter( Object instance, String methodName ) { - final Method method = getMethod( instance, methodName ); + return invokeGetter( instance.getClass(), instance, methodName ); + } + + public static Object invokeGetter( Class<?> instanceType, Object instance, String methodName ) + { + Method method = getMethod( instanceType, methodName ); return invokeMethodWithArray( instance, method ); } @@ -247,14 +255,22 @@ public final class ReflectionUtils * * @param clazz class on which public static no-argument {@code methodName} is invoked * @param methodName public static no-argument method to be called + * @param parameterTypes method parameter types + * @param parameters method parameters * @return value returned by {@code methodName} * @throws RuntimeException if no such method found - * @throws SurefireReflectionException if the method could not be called or threw an exception + * @throws SurefireReflectionException if the method could not be called or threw an exception. + * It has original cause Exception. */ - public static Object invokeStaticMethod( Class<?> clazz, String methodName ) + public static Object invokeStaticMethod( Class<?> clazz, String methodName, + Class<?>[] parameterTypes, Object[] parameters ) { - Method method = getMethod( clazz, methodName ); - return invokeMethodWithArray( null, method ); + if ( parameterTypes.length != parameters.length ) + { + throw new IllegalArgumentException( "arguments length do not match" ); + } + Method method = getMethod( clazz, methodName, parameterTypes ); + return invokeMethodWithArray( null, method, parameters ); } /** @@ -279,7 +295,8 @@ public final class ReflectionUtils { if ( i == 0 ) { - obj = invokeStaticMethod( classesChain[i], noArgMethodNames[i] ); + obj = invokeStaticMethod( classesChain[i], noArgMethodNames[i], + EMPTY_CLASS_ARRAY, EMPTY_OBJECT_ARRAY ); } else { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-api/src/test/java/org/apache/maven/surefire/util/ReflectionUtilsTest.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/util/ReflectionUtilsTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/util/ReflectionUtilsTest.java index 41f9702..5440d6e 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/util/ReflectionUtilsTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/util/ReflectionUtilsTest.java @@ -34,13 +34,15 @@ public class ReflectionUtilsTest @Test(expected = RuntimeException.class) public void shouldNotInvokeStaticMethod() { - ReflectionUtils.invokeStaticMethod( ReflectionUtilsTest.class, "notCallable" ); + ReflectionUtils.invokeStaticMethod( ReflectionUtilsTest.class, "notCallable", + new Class<?>[0], new Object[0] ); } @Test public void shouldInvokeStaticMethod() { - Object o = ReflectionUtils.invokeStaticMethod( ReflectionUtilsTest.class, "callable" ); + Object o = ReflectionUtils.invokeStaticMethod( ReflectionUtilsTest.class, "callable", + new Class<?>[0], new Object[0] ); assertThat( o ) .isEqualTo( 3L ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/pom.xml b/surefire-integration-tests/pom.xml index 267ceda..d9142de 100644 --- a/surefire-integration-tests/pom.xml +++ b/surefire-integration-tests/pom.xml @@ -37,6 +37,8 @@ <it.settings.showPasswords>false</it.settings.showPasswords> <surefire.threadcount>5</surefire.threadcount> <useInterpolatedSettings>false</useInterpolatedSettings> + <maven.compiler.source>1.7</maven.compiler.source> + <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/LongWindowsPathIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/LongWindowsPathIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/LongWindowsPathIT.java new file mode 100644 index 0000000..b980775 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/LongWindowsPathIT.java @@ -0,0 +1,55 @@ +package org.apache.maven.surefire.its; + +/* + * 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.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.Test; + +import java.io.IOException; + +/** + * Testing long path of base.dir where Windows CLI crashes. + * + * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @since 2.20.1 + */ +public class LongWindowsPathIT + extends SurefireJUnit4IntegrationTestCase +{ + private static final String PROJECT_DIR = "long-windows-path"; + private static final String LONG_PATH = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; + private static final String LONG_DIR = LONG_PATH + LONG_PATH + LONG_PATH; + + @Test + public void test() throws IOException + { + unpack().setForkJvm() + .executeTest() + .verifyErrorFreeLog(); + } + + private SurefireLauncher unpack() throws IOException + { + /*File projectDir = unpack( PROJECT_DIR ).getUnpackedAt(); + Files.move( projectDir.toPath(), new File( projectDir, LONG_SUBDIR ).toPath() );*/ + return unpack( PROJECT_DIR/*, "_" + LONG_DIR*/ ).showErrorStackTraces(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java index 98edcfb..17e52a6 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java @@ -18,11 +18,6 @@ package org.apache.maven.surefire.its.fixture; * under the License. */ -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - import org.apache.commons.lang3.JavaVersion; import org.apache.commons.lang3.SystemUtils; import org.apache.maven.plugin.surefire.log.api.ConsoleLogger; @@ -30,12 +25,14 @@ import org.apache.maven.plugin.surefire.log.api.PrintStreamLogger; import org.apache.maven.plugins.surefire.report.ReportTestSuite; import org.apache.maven.plugins.surefire.report.SurefireReportParser; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.apache.commons.lang3.SystemUtils.JAVA_SPECIFICATION_VERSION; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assume.assumeThat; import static org.junit.Assume.assumeTrue; @SuppressWarnings( { "JavaDoc" } ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/resources/long-windows-path/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/long-windows-path/pom.xml b/surefire-integration-tests/src/test/resources/long-windows-path/pom.xml new file mode 100644 index 0000000..c65948c --- /dev/null +++ b/surefire-integration-tests/src/test/resources/long-windows-path/pom.xml @@ -0,0 +1,57 @@ +<?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.surefire</groupId> + <artifactId>it-parent</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>long-windows-path</artifactId> + <version>1.0</version> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>once</forkMode> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/resources/long-windows-path/src/test/java/longwindowspath/BasicTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/long-windows-path/src/test/java/longwindowspath/BasicTest.java b/surefire-integration-tests/src/test/resources/long-windows-path/src/test/java/longwindowspath/BasicTest.java new file mode 100644 index 0000000..e8851ed --- /dev/null +++ b/surefire-integration-tests/src/test/resources/long-windows-path/src/test/java/longwindowspath/BasicTest.java @@ -0,0 +1,32 @@ +package longwindowspath; + +/* + * 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.junit.Test; + +public class BasicTest +{ + @Test + public void test() + { + System.out.println( System.getProperty( "user.dir" ) ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-bundle/src/test/java/jiras/surefre855/bundle/FooIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-bundle/src/test/java/jiras/surefre855/bundle/FooIT.java b/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-bundle/src/test/java/jiras/surefre855/bundle/FooIT.java index aeb666d..d296963 100644 --- a/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-bundle/src/test/java/jiras/surefre855/bundle/FooIT.java +++ b/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-bundle/src/test/java/jiras/surefre855/bundle/FooIT.java @@ -46,7 +46,8 @@ public final class FooIT private static File surefireDir() throws IOException { - return new File( "target/surefire" ).getCanonicalFile(); + String bootPath = System.getProperty( "surefire.real.class.path" ); + return bootPath == null ? null : new File( bootPath ).getParentFile(); } private static File[] surefireProviderProperties() @@ -68,25 +69,6 @@ public final class FooIT } ); } - private static File[] surefireBooterJar() - throws IOException - { - return surefireDir().listFiles( new FileFilter() - { - public boolean accept( File pathname ) - { - try - { - return isSurefireBooter( pathname ); - } - catch ( IOException e ) - { - return false; - } - } - } ); - } - /** * See BooterSerializer#serialize(). */ @@ -110,9 +92,8 @@ public final class FooIT private static String manifestClassPath( Class clazz ) throws IOException { - File[] booters = surefireBooterJar(); - assertThat( booters, is( arrayWithSize( 1 ) ) ); - File booter = booters[0]; + File booter = new File( System.getProperty( "surefire.real.class.path" ) ); + assertThat( booter ).exists(); JarFile jarFile = new JarFile( booter ); try { @@ -158,10 +139,6 @@ public final class FooIT assertThat( classPath, not( containsString( "/target/classes" ) ) ); assertThat( classPath, containsString( "/target/" + ARTIFACT_FILE_NAME ) ); - File surefireDir = new File( "target/surefire" ).getCanonicalFile(); - System.out.println( "SUREFIRE DIR:" ); - System.out.println( surefireDir ); - File[] descriptors = surefireProviderProperties(); assertThat( descriptors ).hasSize( 1 ); assertThat( descriptors ).doesNotContainNull(); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-jar/src/test/java/jiras/surefire855/jar/FooIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-jar/src/test/java/jiras/surefire855/jar/FooIT.java b/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-jar/src/test/java/jiras/surefire855/jar/FooIT.java index 606985a..730c5fa 100644 --- a/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-jar/src/test/java/jiras/surefire855/jar/FooIT.java +++ b/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-jar/src/test/java/jiras/surefire855/jar/FooIT.java @@ -47,7 +47,8 @@ public final class FooIT private static File surefireDir() throws IOException { - return new File( "target/surefire" ).getCanonicalFile(); + String bootPath = System.getProperty( "surefire.real.class.path" ); + return bootPath == null ? null : new File( bootPath ).getParentFile(); } private static File[] surefireProviderProperties() @@ -69,25 +70,6 @@ public final class FooIT } ); } - private static File[] surefireBooterJar() - throws IOException - { - return surefireDir().listFiles( new FileFilter() - { - public boolean accept( File pathname ) - { - try - { - return isSurefireBooter( pathname ); - } - catch ( IOException e ) - { - return false; - } - } - } ); - } - /** * See BooterSerializer#serialize(). */ @@ -111,9 +93,8 @@ public final class FooIT private static String manifestClassPath( Class clazz ) throws IOException { - File[] booters = surefireBooterJar(); - assertThat( booters, is( arrayWithSize( 1 ) ) ); - File booter = booters[0]; + File booter = new File( System.getProperty( "surefire.real.class.path" ) ); + assertThat( booter ).exists(); JarFile jarFile = new JarFile( booter ); try { @@ -161,10 +142,6 @@ public final class FooIT assertThat( classPath, not( containsString( "/target/classes" ) ) ); assertThat( classPath, containsString( "/target/" + ARTIFACT_FILE_NAME ) ); - File surefireDir = new File( "target/surefire" ).getCanonicalFile(); - System.out.println( "SUREFIRE DIR:" ); - System.out.println( surefireDir ); - File[] descriptors = surefireProviderProperties(); assertThat( descriptors ).hasSize( 1 ); assertThat( descriptors ).doesNotContainNull(); @@ -187,7 +164,7 @@ public final class FooIT { assumeThat( System.getProperty( "forkMode" ), is( "never" ) ); - assertThat( surefireDir() ).doesNotExist(); + assertThat( surefireDir() ).isNull(); assertThat( new File( "target/" + ARTIFACT_FILE_NAME ).getCanonicalFile() ).isFile(); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e799e4bc/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-war/src/test/java/jiras/surefire855/war/FooIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-war/src/test/java/jiras/surefire855/war/FooIT.java b/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-war/src/test/java/jiras/surefire855/war/FooIT.java index f15bd15..fa6d640 100644 --- a/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-war/src/test/java/jiras/surefire855/war/FooIT.java +++ b/surefire-integration-tests/src/test/resources/surefire-855-failsafe-use-war/src/test/java/jiras/surefire855/war/FooIT.java @@ -44,7 +44,8 @@ public final class FooIT private static File surefireDir() throws IOException { - return new File( "target/surefire" ).getCanonicalFile(); + String bootPath = System.getProperty( "surefire.real.class.path" ); + return bootPath == null ? null : new File( bootPath ).getParentFile(); } private static File[] surefireProviderProperties() @@ -66,25 +67,6 @@ public final class FooIT } ); } - private static File[] surefireBooterJar() - throws IOException - { - return surefireDir().listFiles( new FileFilter() - { - public boolean accept( File pathname ) - { - try - { - return isSurefireBooter( pathname ); - } - catch ( IOException e ) - { - return false; - } - } - } ); - } - /** * See BooterSerializer#serialize(). */ @@ -108,9 +90,8 @@ public final class FooIT private static String manifestClassPath( Class clazz ) throws IOException { - File[] booters = surefireBooterJar(); - assertThat( booters, is( arrayWithSize( 1 ) ) ); - File booter = booters[0]; + File booter = new File( System.getProperty( "surefire.real.class.path" ) ); + assertThat( booter ).exists(); JarFile jarFile = new JarFile( booter ); try { @@ -155,10 +136,6 @@ public final class FooIT assertThat( classPath, containsString( "/target/classes" ) ); - File surefireDir = new File( "target/surefire" ).getCanonicalFile(); - System.out.println( "SUREFIRE DIR:" ); - System.out.println( surefireDir ); - File[] descriptors = surefireProviderProperties(); assertThat( descriptors ).hasSize( 1 ); assertThat( descriptors ).doesNotContainNull();