< prev index next >

test/java/nio/file/spi/SetDefaultProvider.java

Print this page

        

@@ -30,10 +30,11 @@
  * @summary Runs tests with -Djava.nio.file.spi.DefaultFileSystemProvider set on
  *          the command line to override the default file system provider
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.spi.ToolProvider;
 

@@ -52,10 +53,16 @@
     private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
         .orElseThrow(() ->
             new RuntimeException("jar tool not found")
         );
 
+    private static Path createTempDirectory(String dir) throws IOException {
+        Path testDir = Paths.get(System.getProperty("test.dir", "."), dir);
+        return Files.exists(testDir) ?
+            testDir : Files.createDirectory(testDir);
+    }
+
     /**
      * Test override of default FileSystemProvider with the main application
      * on the class path.
      */
     public void testClassPath() throws Exception {

@@ -89,11 +96,11 @@
     /**
      * Test override of default FileSystemProvider where the main application
      * is a module that is patched by an exploded patch.
      */
     public void testExplodedModuleWithExplodedPatch() throws Exception {
-        Path patchdir = Files.createTempDirectory("patch");
+        Path patchdir = createTempDirectory("patch");
         String modulePath = System.getProperty("jdk.module.path");
         int exitValue = exec(SET_DEFAULT_FSP,
                              "--patch-module", "m=" + patchdir,
                              "-p", modulePath,
                              "-m", "m/p.Main");

@@ -103,11 +110,11 @@
     /**
      * Test override of default FileSystemProvider where the main application
      * is a module that is patched by an exploded patch.
      */
     public void testExplodedModuleWithJarPatch() throws Exception {
-        Path patchdir = Files.createTempDirectory("patch");
+        Path patchdir = createTempDirectory("patch");
         Files.createDirectory(patchdir.resolve("m.properties"));
         Path patch = createJarFile(patchdir);
         String modulePath = System.getProperty("jdk.module.path");
         int exitValue = exec(SET_DEFAULT_FSP,
                              "--patch-module", "m=" + patch,

@@ -140,11 +147,11 @@
 
     /**
      * Creates a JAR file containing the entries in the given file tree.
      */
     private Path createJarFile(Path dir) throws Exception {
-        Path jar = Files.createTempDirectory("tmp").resolve("m.jar");
+        Path jar = createTempDirectory("tmp").resolve("m.jar");
         String[] args = { "--create", "--file=" + jar, "-C", dir.toString(), "." };
         int ret = JAR_TOOL.run(System.out, System.out, args);
         assertTrue(ret == 0);
         return jar;
     }
< prev index next >