X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FKernelUtils.java;h=9b43044d446a0e638a8d17292387cfcf525642d8;hb=0dfcfef53a629cf38bade4f8605c5b7e507c7436;hp=b2fb03d8eaf7b0cfbc8d426f933e2241c45487c9;hpb=9dba7b01008499bdaf15c754190906d3200713fe;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelUtils.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelUtils.java index b2fb03d8e..9b43044d4 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelUtils.java @@ -7,6 +7,7 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; +import java.util.TreeSet; import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; @@ -16,6 +17,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; +import org.osgi.framework.BundleContext; /** Package utilities */ class KernelUtils implements KernelConstants { @@ -41,12 +43,36 @@ class KernelUtils implements KernelConstants { return asDictionary(props); } + static File getExecutionDir(String relativePath) { + File executionDir = new File(getFrameworkProp("user.dir")); + if (relativePath == null) + return executionDir; + try { + return new File(executionDir, relativePath).getCanonicalFile(); + } catch (IOException e) { + throw new CmsException("Cannot get canonical file", e); + } + } + static File getOsgiInstanceDir() { return new File(Activator.getBundleContext() .getProperty(OSGI_INSTANCE_AREA).substring("file:".length())) .getAbsoluteFile(); } + static String getOsgiInstancePath(String relativePath) { + try { + if (relativePath == null) + return getOsgiInstanceDir().getCanonicalPath(); + else + return new File(getOsgiInstanceDir(), relativePath) + .getCanonicalPath(); + } catch (IOException e) { + throw new CmsException("Cannot get instance path for " + + relativePath, e); + } + } + static File getOsgiConfigurationFile(String relativePath) { try { return new File(new URI(Activator.getBundleContext().getProperty( @@ -74,7 +100,8 @@ class KernelUtils implements KernelConstants { Subject subject = new Subject(); LoginContext lc; try { - lc = new LoginContext(AuthConstants.LOGIN_CONTEXT_ANONYMOUS, subject); + lc = new LoginContext(AuthConstants.LOGIN_CONTEXT_ANONYMOUS, + subject); lc.login(); return subject; } catch (LoginException e) { @@ -112,6 +139,24 @@ class KernelUtils implements KernelConstants { Object headerValue = request.getHeader(headerName); log.debug(headerName + ": " + headerValue); } + log.debug(""); + } + + static void logFrameworkProperties(Log log) { + BundleContext bc = Activator.getBundleContext(); + for (Object sysProp : new TreeSet(System.getProperties() + .keySet())) { + log.debug(sysProp + "=" + bc.getProperty(sysProp.toString())); + } + // String[] keys = { Constants.FRAMEWORK_STORAGE, + // Constants.FRAMEWORK_OS_NAME, Constants.FRAMEWORK_OS_VERSION, + // Constants.FRAMEWORK_PROCESSOR, Constants.FRAMEWORK_SECURITY, + // Constants.FRAMEWORK_TRUST_REPOSITORIES, + // Constants.FRAMEWORK_WINDOWSYSTEM, Constants.FRAMEWORK_VENDOR, + // Constants.FRAMEWORK_VERSION, Constants.FRAMEWORK_STORAGE_CLEAN, + // Constants.FRAMEWORK_LANGUAGE, Constants.FRAMEWORK_UUID }; + // for (String key : keys) + // log.debug(key + "=" + bc.getProperty(key)); } private KernelUtils() {