You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2018/08/10 18:14:53 UTC

[geode] branch develop updated: GEODE-5212: use Paths.get to retrieve resourcePath (#2295)

This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1785f73  GEODE-5212: use Paths.get to retrieve resourcePath (#2295)
1785f73 is described below

commit 1785f7369f73128412f705824f73f244fabdb68a
Author: Sai Boorlagadda <sa...@gmail.com>
AuthorDate: Fri Aug 10 11:14:47 2018 -0700

    GEODE-5212: use Paths.get to retrieve resourcePath (#2295)
---
 .../java/org/apache/geode/util/test/TestUtil.java  | 30 ++++++++++++----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/geode-junit/src/main/java/org/apache/geode/util/test/TestUtil.java b/geode-junit/src/main/java/org/apache/geode/util/test/TestUtil.java
index 025a1ee..4192867 100644
--- a/geode-junit/src/main/java/org/apache/geode/util/test/TestUtil.java
+++ b/geode-junit/src/main/java/org/apache/geode/util/test/TestUtil.java
@@ -18,9 +18,10 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.file.FileSystemNotFoundException;
+import java.nio.file.Paths;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.SystemUtils;
 
 public class TestUtil {
 
@@ -57,21 +58,24 @@ public class TestUtil {
       throw new RuntimeException("Could not find resource " + name);
     }
     try {
-      String path = resource.toURI().getPath();
-      if (path == null) {
-        String filename = name.replaceFirst(".*/", "");
-        File tmpFile = File.createTempFile(filename, null);
-        tmpFile.deleteOnExit();
-        FileUtils.copyURLToFile(resource, tmpFile);
-        return tmpFile.getAbsolutePath();
-      }
-      return compatibleWithWindows(path);
-    } catch (URISyntaxException | IOException e) {
+      return Paths.get(resource.toURI()).toAbsolutePath().toString();
+    } catch (FileSystemNotFoundException e) {
+      // create a temporary copy when Paths.get() fails (eg: jar:file:/...)
+      return createTemporaryCopy(name, resource);
+    } catch (URISyntaxException e) {
       throw new RuntimeException("Failed getting path to resource " + name, e);
     }
   }
 
-  private static String compatibleWithWindows(String path) {
-    return SystemUtils.IS_OS_WINDOWS ? path.substring(1) : path;
+  private static String createTemporaryCopy(String name, URL resource) {
+    try {
+      String filename = name.replaceFirst(".*/", "");
+      File tmpFile = File.createTempFile(filename, null);
+      tmpFile.deleteOnExit();
+      FileUtils.copyURLToFile(resource, tmpFile);
+      return tmpFile.getAbsolutePath();
+    } catch (IOException e1) {
+      throw new RuntimeException("Failed getting path to resource " + name, e1);
+    }
   }
 }