aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-common
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2017-11-01 15:35:50 +0100
committerMartin Stockhammer <martin_s@apache.org>2017-11-01 15:35:50 +0100
commit3dc85427b33f2a045a9e9b460dc906e1f1e5bba5 (patch)
tree7ce46b4535280a1eab637e533ef8bd40b8a362b4 /archiva-modules/archiva-base/archiva-common
parent763991b3d9f3ca8d04a782d08492b9647953597a (diff)
downloadarchiva-3dc85427b33f2a045a9e9b460dc906e1f1e5bba5.tar.gz
archiva-3dc85427b33f2a045a9e9b460dc906e1f1e5bba5.zip
Adding utility method for uri conversion
Diffstat (limited to 'archiva-modules/archiva-base/archiva-common')
-rw-r--r--archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java
index e029e0d28..1adb0a753 100644
--- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java
+++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java
@@ -22,6 +22,7 @@ package org.apache.archiva.common.utils;
import org.apache.commons.lang.StringUtils;
import java.net.MalformedURLException;
+import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -95,4 +96,22 @@ public class PathUtil
return getRelative(basedir, Paths.get(child));
}
+
+ /**
+ * Returns a path object from the given URI. If the URI has no scheme, the path of the URI is used
+ * for creating the filesystem path.
+ *
+ * @param uri the uri to convert
+ * @return a path object with the given path
+ * @throws java.nio.file.FileSystemNotFoundException if the uri scheme is not known.
+ */
+ public static Path getPathFromUri( URI uri) {
+ if (uri==null) {
+ return Paths.get("");
+ } else if (uri.getScheme()==null) {
+ return Paths.get(uri.getPath());
+ } else {
+ return Paths.get(uri);
+ }
+ }
}