[GitHub] jglick commented on a change in pull request #199: Surefire 1593
jglick commented on a change in pull request #199: Surefire 1593 URL: https://github.com/apache/maven-surefire/pull/199#discussion_r233595772 ## File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java ## @@ -0,0 +1,216 @@ +package org.apache.maven.plugin.surefire.booterclient; + +/* + * 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 java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; + +import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton; + +import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.relativize; +import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.toAbsoluteUri; +import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.toClasspathElementUri; +import static org.fest.assertions.Assertions.assertThat; + +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import static org.mockito.ArgumentMatchers.same; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; + +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Unit tests for {@link JarManifestForkConfiguration}. + */ +@RunWith( PowerMockRunner.class ) +@PrepareForTest( { JarManifestForkConfiguration.class, InPluginProcessDumpSingleton.class } ) +public class JarManifestForkConfigurationTest +{ +@ClassRule +public static final TemporaryFolder TMP = new TemporaryFolder(); + +private static File dumpDirectory; + +@BeforeClass +public static void createSystemTemporaryDir() +throws IOException +{ +TMP.create(); Review comment: Unnecessary; implied by it being registered as a `@ClassRule` (called by `TemporaryFolder.before`). This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] jglick commented on a change in pull request #199: Surefire 1593
jglick commented on a change in pull request #199: Surefire 1593 URL: https://github.com/apache/maven-surefire/pull/199#discussion_r233594305 ## File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java ## @@ -0,0 +1,190 @@ +package org.apache.maven.plugin.surefire.booterclient; + +/* + * 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 java.io.File; +import java.net.URI; + +import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton; +import static org.fest.assertions.Assertions.assertThat; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Unit tests for {@link JarManifestForkConfiguration}. + */ +@RunWith( PowerMockRunner.class ) +@PrepareForTest( { JarManifestForkConfiguration.class, InPluginProcessDumpSingleton.class } ) +public class JarManifestForkConfigurationTest +{ +private static final String BASE_DIR = System.getProperty( "user.dir" ); + +@Test +public void relativeClasspathUnixSimple() +throws Exception +{ +mockStatic( JarManifestForkConfiguration.class ); +String parent = "/home/me/prj/target/surefire"; +String classPathElement = "/home/me/.m2/repository/grp/art/1.0/art-1.0.jar"; +when( JarManifestForkConfiguration.relativize( parent, classPathElement ) ) +.thenReturn( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" ); +when( JarManifestForkConfiguration.toClasspathElementUri( anyString(), anyString(), any( File.class ) ) ) +.thenCallRealMethod(); +File dump = new File( BASE_DIR, "target/test-dump" ); +//noinspection ResultOfMethodCallIgnored +dump.mkdir(); +assertThat( JarManifestForkConfiguration.toClasspathElementUri( parent, classPathElement, dump ) ) +.isEqualTo( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" ); +} + +@Test +public void relativeClasspathUnixTricky() +throws Exception +{ +mockStatic( JarManifestForkConfiguration.class ); +String parent = "/home/me/prj/target/surefire"; +String classPathElement = "/the Maven repo/grp/art/1.0/art-1.0.jar"; +when( JarManifestForkConfiguration.relativize( parent, classPathElement ) ) +.thenReturn( "../../../../../the Maven repo/grp/art/1.0/art-1.0.jar" ); +when( JarManifestForkConfiguration.toClasspathElementUri( anyString(), anyString(), any( File.class ) ) ) +.thenCallRealMethod(); +File dump = new File( BASE_DIR, "target/test-dump" ); +assertThat( JarManifestForkConfiguration.toClasspathElementUri( parent, classPathElement, dump ) ) +.isEqualTo( "../../../../../the%20Maven%20repo/grp/art/1.0/art-1.0.jar" ); +} + +@Test +public void relativeClasspathWindowsSimple() +throws Exception +{ +mockStatic( JarManifestForkConfiguration.class ); +String parent = "C:\\Windows\\Temp\\surefire"; +String classPathElement = "C:\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar"; +when( JarManifestForkConfiguration.relativize( parent, classPathElement ) ) +.thenReturn( "..\\..\\..\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" ); +when( JarManifestForkConfiguration.toClasspathElementUri( anyString(), anyString(), any( File.class ) ) ) +.thenCallRealMethod(); +File dump = new File( BASE_DIR, "target/test-dump" ); +assertThat( JarManifestForkConfiguration.toClasspathElementUri( parent, classPathElement, dump ) ) +.isEqualTo( "../../../Users/me/.m2/repository/grp/art/1.0/art-1.0.jar" ); +} + +@Test +
[GitHub] jglick commented on a change in pull request #199: Surefire 1593
jglick commented on a change in pull request #199: Surefire 1593 URL: https://github.com/apache/maven-surefire/pull/199#discussion_r233073868 ## File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java ## @@ -116,10 +116,10 @@ private File createJar( @Nonnull List classPath, @Nonnull String startCl StringBuilder cp = new StringBuilder(); for ( Iterator it = classPath.iterator(); it.hasNext(); ) { -File classPathElement = new File( it.next() ); +String classPathElement = it.next(); String uri = toClasspathElementUri( parent, classPathElement, dumpLogDirectory ); cp.append( uri ); -if ( classPathElement.isDirectory() && !uri.endsWith( "/" ) ) +if ( new File( classPathElement ).isDirectory() && !uri.endsWith( "/" ) ) Review comment: > `Files.isDirectory` will be more consistent with the new use of `Path`s. I chose to make a more minimal change to solve the immediate regression, rather than rewriting the whole class to use NIO methods. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] jglick commented on a change in pull request #199: Surefire 1593
jglick commented on a change in pull request #199: Surefire 1593 URL: https://github.com/apache/maven-surefire/pull/199#discussion_r233070329 ## File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java ## @@ -116,10 +116,10 @@ private File createJar( @Nonnull List classPath, @Nonnull String startCl StringBuilder cp = new StringBuilder(); for ( Iterator it = classPath.iterator(); it.hasNext(); ) { -File classPathElement = new File( it.next() ); +String classPathElement = it.next(); String uri = toClasspathElementUri( parent, classPathElement, dumpLogDirectory ); cp.append( uri ); -if ( classPathElement.isDirectory() && !uri.endsWith( "/" ) ) +if ( new File( classPathElement ).isDirectory() && !uri.endsWith( "/" ) ) Review comment: > we should change the method signature No, I deliberately used `String` parameters so as to make it possible to write unit tests. `Path`s can (as far as I know) only be constructed using platform-specific methods, making the tests behave differently according to the machine running them. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] jglick commented on a change in pull request #199: Surefire 1593
jglick commented on a change in pull request #199: Surefire 1593 URL: https://github.com/apache/maven-surefire/pull/199#discussion_r233067360 ## File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java ## @@ -0,0 +1,190 @@ +package org.apache.maven.plugin.surefire.booterclient; + +/* + * 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 java.io.File; +import java.net.URI; + +import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton; +import static org.fest.assertions.Assertions.assertThat; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Unit tests for {@link JarManifestForkConfiguration}. + */ +@RunWith( PowerMockRunner.class ) +@PrepareForTest( { JarManifestForkConfiguration.class, InPluginProcessDumpSingleton.class } ) +public class JarManifestForkConfigurationTest +{ +private static final String BASE_DIR = System.getProperty( "user.dir" ); + +@Test +public void relativeClasspathUnixSimple() +throws Exception +{ +mockStatic( JarManifestForkConfiguration.class ); +String parent = "/home/me/prj/target/surefire"; +String classPathElement = "/home/me/.m2/repository/grp/art/1.0/art-1.0.jar"; +when( JarManifestForkConfiguration.relativize( parent, classPathElement ) ) +.thenReturn( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" ); +when( JarManifestForkConfiguration.toClasspathElementUri( anyString(), anyString(), any( File.class ) ) ) +.thenCallRealMethod(); +File dump = new File( BASE_DIR, "target/test-dump" ); +//noinspection ResultOfMethodCallIgnored +dump.mkdir(); +assertThat( JarManifestForkConfiguration.toClasspathElementUri( parent, classPathElement, dump ) ) +.isEqualTo( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" ); +} + +@Test +public void relativeClasspathUnixTricky() +throws Exception +{ +mockStatic( JarManifestForkConfiguration.class ); +String parent = "/home/me/prj/target/surefire"; +String classPathElement = "/the Maven repo/grp/art/1.0/art-1.0.jar"; +when( JarManifestForkConfiguration.relativize( parent, classPathElement ) ) +.thenReturn( "../../../../../the Maven repo/grp/art/1.0/art-1.0.jar" ); +when( JarManifestForkConfiguration.toClasspathElementUri( anyString(), anyString(), any( File.class ) ) ) +.thenCallRealMethod(); +File dump = new File( BASE_DIR, "target/test-dump" ); +assertThat( JarManifestForkConfiguration.toClasspathElementUri( parent, classPathElement, dump ) ) +.isEqualTo( "../../../../../the%20Maven%20repo/grp/art/1.0/art-1.0.jar" ); +} + +@Test +public void relativeClasspathWindowsSimple() +throws Exception +{ +mockStatic( JarManifestForkConfiguration.class ); +String parent = "C:\\Windows\\Temp\\surefire"; +String classPathElement = "C:\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar"; +when( JarManifestForkConfiguration.relativize( parent, classPathElement ) ) +.thenReturn( "..\\..\\..\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" ); +when( JarManifestForkConfiguration.toClasspathElementUri( anyString(), anyString(), any( File.class ) ) ) +.thenCallRealMethod(); +File dump = new File( BASE_DIR, "target/test-dump" ); +assertThat( JarManifestForkConfiguration.toClasspathElementUri( parent, classPathElement, dump ) ) +.isEqualTo( "../../../Users/me/.m2/repository/grp/art/1.0/art-1.0.jar" ); +} + +@Test +
[GitHub] jglick commented on a change in pull request #199: Surefire 1593
jglick commented on a change in pull request #199: Surefire 1593 URL: https://github.com/apache/maven-surefire/pull/199#discussion_r233068986 ## File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java ## @@ -0,0 +1,190 @@ +package org.apache.maven.plugin.surefire.booterclient; + +/* + * 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 java.io.File; +import java.net.URI; + +import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton; +import static org.fest.assertions.Assertions.assertThat; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Unit tests for {@link JarManifestForkConfiguration}. + */ +@RunWith( PowerMockRunner.class ) +@PrepareForTest( { JarManifestForkConfiguration.class, InPluginProcessDumpSingleton.class } ) +public class JarManifestForkConfigurationTest +{ +private static final String BASE_DIR = System.getProperty( "user.dir" ); Review comment: This will pollute the CWD when `mvn` is run using `-f` rather than defaulting the basedir. If you want a temporary directory, I would suggest using the `TemporaryFolder` rule. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services