|
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * @test
|
26 |
| - * @bug 8266345 |
| 26 | + * @bug 4313887 7006126 8142968 8178380 8183320 8210112 8266345 8263940 |
27 | 27 | * @modules jdk.jartool
|
28 | 28 | * @library /test/lib
|
29 | 29 | * @build SetDefaultProvider TestProvider m/* jdk.test.lib.process.ProcessTools
|
|
37 | 37 | import java.nio.file.Files;
|
38 | 38 | import java.nio.file.Path;
|
39 | 39 | import java.nio.file.Paths;
|
| 40 | +import java.util.ArrayList; |
| 41 | +import java.util.List; |
40 | 42 | import java.util.spi.ToolProvider;
|
| 43 | +import java.util.stream.Collectors; |
| 44 | +import java.util.stream.Stream; |
41 | 45 |
|
42 | 46 | import jdk.test.lib.process.ProcessTools;
|
43 | 47 |
|
44 |
| -import org.testng.annotations.BeforeTest; |
45 | 48 | import org.testng.annotations.Test;
|
46 | 49 | import static org.testng.Assert.*;
|
47 | 50 |
|
@@ -73,6 +76,45 @@ public void testClassPath() throws Exception {
|
73 | 76 | assertTrue(exitValue == 0);
|
74 | 77 | }
|
75 | 78 |
|
| 79 | + /** |
| 80 | + * Test override of default FileSystemProvider with a |
| 81 | + * FileSystemProvider jar and the main application on the class path. |
| 82 | + */ |
| 83 | + public void testClassPathWithFileSystemProviderJar() throws Exception { |
| 84 | + String testClasses = System.getProperty("test.classes"); |
| 85 | + Path jar = Path.of("testFileSystemProvider.jar"); |
| 86 | + Files.deleteIfExists(jar); |
| 87 | + createFileSystemProviderJar(jar, Path.of(testClasses)); |
| 88 | + String classpath = jar + File.pathSeparator + testClasses |
| 89 | + + File.separator + "modules" + File.separator + "m"; |
| 90 | + int exitValue = exec(SET_DEFAULT_FSP, "-cp", classpath, "p.Main"); |
| 91 | + assertTrue(exitValue == 0); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Creates a JAR containing the FileSystemProvider used to override the |
| 96 | + * default FileSystemProvider |
| 97 | + */ |
| 98 | + private void createFileSystemProviderJar(Path jar, Path dir) throws IOException { |
| 99 | + |
| 100 | + List<String> args = new ArrayList<>(); |
| 101 | + args.add("--create"); |
| 102 | + args.add("--file=" + jar); |
| 103 | + try (Stream<Path> stream = Files.list(dir)) { |
| 104 | + List<String> paths = stream |
| 105 | + .map(path -> path.getFileName().toString()) |
| 106 | + .filter(f -> f.startsWith("TestProvider")) |
| 107 | + .toList(); |
| 108 | + for(var p : paths) { |
| 109 | + args.add("-C"); |
| 110 | + args.add(dir.toString()); |
| 111 | + args.add(p); |
| 112 | + } |
| 113 | + } |
| 114 | + int ret = JAR_TOOL.run(System.out, System.out, args.toArray(new String[0])); |
| 115 | + assertTrue(ret == 0); |
| 116 | + } |
| 117 | + |
76 | 118 | /**
|
77 | 119 | * Test override of default FileSystemProvider with the main application
|
78 | 120 | * on the class path and a SecurityManager enabled.
|
|
0 commit comments