Skip to content

Commit

Permalink
[SUREFIRE-2211] Fix UNC classpath elements
Browse files Browse the repository at this point in the history
  • Loading branch information
robseidel committed Nov 30, 2023
1 parent 47c5816 commit 189442d
Show file tree
Hide file tree
Showing 2 changed files with 35 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,34 @@ 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);
org.junit.Assume.assumeTrue(someCondition());
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 189442d

Please sign in to comment.