Adding utility method for uri conversion
Project: http://git-wip-us.apache.org/repos/asf/archiva/repo Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/3dc85427 Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/3dc85427 Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/3dc85427 Branch: refs/heads/master Commit: 3dc85427b33f2a045a9e9b460dc906e1f1e5bba5 Parents: 763991b Author: Martin Stockhammer <[email protected]> Authored: Wed Nov 1 15:35:50 2017 +0100 Committer: Martin Stockhammer <[email protected]> Committed: Wed Nov 1 15:35:50 2017 +0100 ---------------------------------------------------------------------- .../apache/archiva/common/utils/PathUtil.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/archiva/blob/3dc85427/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java ---------------------------------------------------------------------- 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 e029e0d..1adb0a7 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); + } + } }
