Skip to content

Commit

Permalink
[SUREFIRE-2211] additionalClasspathElement with UNC path not working …
Browse files Browse the repository at this point in the history
…with Maven Failsafe Plugin

This closes apache#689
  • Loading branch information
robseidel committed Dec 4, 2023
1 parent aa864f4 commit e8af683
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ static String relativize(@Nonnull Path parent, @Nonnull Path child) throws Illeg
}

static String toAbsoluteUri(@Nonnull Path absolutePath) {
// UNC paths need to be written as file:////
// see https://bugs.openjdk.org/browse/JDK-8320760
if (absolutePath.toString().startsWith("\\\\")) {
return absolutePath.toFile().toURI().toASCIIString();
}
return absolutePath.toUri().toASCIIString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
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.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Files.delete;
import static org.assertj.core.util.Files.newTemporaryFolder;
import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -163,6 +165,33 @@ public URI answer(InvocationOnMock invocation) throws URISyntaxException {
.isEqualTo("file:///X:/Users/me/.m2/repository/grp/art/1.0/art-1.0.jar");
}

@Test
public void uncWindows() throws Exception {
assumeTrue(IS_OS_WINDOWS);
mockStatic(JarManifestForkConfiguration.class);
mockStatic(InPluginProcessDumpSingleton.class);
when(InPluginProcessDumpSingleton.getSingleton()).thenReturn(mock(InPluginProcessDumpSingleton.class));
Path parent = mock(Path.class);
when(parent.toString()).thenReturn("C:\\Windows\\Temp\\surefire");
Path classPathElement = mock(Path.class);
when(classPathElement.toString()).thenReturn("\\\\server\\grp\\art\\1.0\\art-1.0.jar");
when(classPathElement.toFile()).thenAnswer(new Answer<File>() {
@Override
public File answer(InvocationOnMock invocation) {
String path = invocation.getMock().toString();
return new File(path);
}
});
when(relativize(same(parent), same(classPathElement)))
.thenThrow(new IllegalArgumentException("'other' has different root"));
when(toClasspathElementUri(same(parent), same(classPathElement), same(dumpDirectory), anyBoolean()))
.thenCallRealMethod();
when(escapeUri(anyString(), any(Charset.class))).thenCallRealMethod();
when(toAbsoluteUri(same(classPathElement))).thenCallRealMethod();
assertThat(toClasspathElementUri(parent, classPathElement, dumpDirectory, true).uri)
.isEqualTo("file:////server/grp/art/1.0/art-1.0.jar");
}

@Test
@SuppressWarnings("checkstyle:magicnumber")
public void shouldEscapeUri() throws Exception {
Expand Down

0 comments on commit e8af683

Please sign in to comment.