X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FKernelUtils.java;h=295578f535a3711fdf90bcab95fab58433c6042f;hb=f3ea14abccc33b1c3326417a87c91145be776c72;hp=60c796af73280639bc8f03868ec5ec67ed03cbb9;hpb=b843d903237a2a4192c40d8c933e71137284050b;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/runtime/KernelUtils.java b/org.argeo.cms/src/org/argeo/cms/internal/runtime/KernelUtils.java index 60c796af7..295578f53 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/runtime/KernelUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/runtime/KernelUtils.java @@ -1,6 +1,5 @@ package org.argeo.cms.internal.runtime; -import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.net.URI; @@ -19,7 +18,7 @@ import org.argeo.api.cms.CmsLog; import org.argeo.cms.internal.osgi.CmsActivator; /** Package utilities */ -public class KernelUtils implements KernelConstants { +class KernelUtils implements KernelConstants { final static String OSGI_INSTANCE_AREA = "osgi.instance.area"; final static String OSGI_CONFIGURATION_AREA = "osgi.configuration.area"; @@ -52,12 +51,12 @@ public class KernelUtils implements KernelConstants { return asDictionary(props); } - static File getExecutionDir(String relativePath) { - File executionDir = new File(getFrameworkProp("user.dir")); + static Path getExecutionDir(String relativePath) { + Path executionDir = Paths.get(getFrameworkProp("user.dir")); if (relativePath == null) return executionDir; try { - return new File(executionDir, relativePath).getCanonicalFile(); + return executionDir.resolve(relativePath).toRealPath(); } catch (IOException e) { throw new IllegalArgumentException("Cannot get canonical file", e); } @@ -69,26 +68,34 @@ public class KernelUtils implements KernelConstants { // } public static Path getOsgiInstancePath(String relativePath) { - return Paths.get(getOsgiInstanceUri(relativePath)); + URI uri = getOsgiInstanceUri(relativePath); + if (uri == null) // no data area available + return null; + return Paths.get(uri); } public static URI getOsgiInstanceUri(String relativePath) { String osgiInstanceBaseUri = getFrameworkProp(OSGI_INSTANCE_AREA); - if (osgiInstanceBaseUri != null) - return safeUri(osgiInstanceBaseUri + (relativePath != null ? relativePath : "")); - else - return Paths.get(System.getProperty("user.dir"), (relativePath != null ? relativePath : "")).toUri(); + if (osgiInstanceBaseUri == null) // no data area available + return null; + + if (!osgiInstanceBaseUri.endsWith("/")) + osgiInstanceBaseUri = osgiInstanceBaseUri + "/"; +// if (osgiInstanceBaseUri != null) + return safeUri(osgiInstanceBaseUri + (relativePath != null ? relativePath : "")); +// else +// return Paths.get(System.getProperty("user.dir"), (relativePath != null ? relativePath : "")).toUri(); } - static File getOsgiConfigurationFile(String relativePath) { - try { - return new File( - new URI(CmsActivator.getBundleContext().getProperty(OSGI_CONFIGURATION_AREA) + relativePath)) - .getCanonicalFile(); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot get configuration file for " + relativePath, e); - } - } +// static File getOsgiConfigurationFile(String relativePath) { +// try { +// return new File( +// new URI(CmsActivator.getBundleContext().getProperty(OSGI_CONFIGURATION_AREA) + relativePath)) +// .getCanonicalFile(); +// } catch (Exception e) { +// throw new IllegalArgumentException("Cannot get configuration file for " + relativePath, e); +// } +// } static String getFrameworkProp(String key, String def) { String value; @@ -101,7 +108,7 @@ public class KernelUtils implements KernelConstants { return value; } - public static String getFrameworkProp(String key) { + static String getFrameworkProp(String key) { return getFrameworkProp(key, null); }