X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FCmsStateImpl.java;h=fd2c5f9cdb47d4632ae7b9cf8464e92f3bdb94d9;hb=f3ea14abccc33b1c3326417a87c91145be776c72;hp=dff4d85df8e953f30c2812b7b891fec99a979fb3;hpb=3840f7ca1017b358a3859d24c47fd7968178a7ec;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java b/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java index dff4d85df..fd2c5f9cd 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java @@ -1,12 +1,8 @@ package org.argeo.cms.internal.runtime; -import java.io.File; -import java.io.FileFilter; import java.io.IOException; import java.io.Reader; -import java.net.InetAddress; import java.net.URL; -import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -25,13 +21,13 @@ import java.util.UUID; import javax.security.auth.login.Configuration; -import org.apache.commons.io.FileUtils; import org.argeo.api.cms.CmsConstants; import org.argeo.api.cms.CmsLog; import org.argeo.api.cms.CmsState; import org.argeo.api.uuid.UuidFactory; import org.argeo.cms.CmsDeployProperty; import org.argeo.cms.auth.ident.IdentClient; +import org.argeo.util.FsUtils; /** * Implementation of a {@link CmsState}, initialising the required services. @@ -44,7 +40,7 @@ public class CmsStateImpl implements CmsState { private UUID uuid; // private final boolean cleanState; - private String hostname; +// private String hostname; private UuidFactory uuidFactory; @@ -59,12 +55,16 @@ public class CmsStateImpl implements CmsState { deployPropertyDefaults.put(CmsDeployProperty.SSL_KEYSTORETYPE, PkiUtils.PKCS12); deployPropertyDefaults.put(CmsDeployProperty.SSL_PASSWORD, PkiUtils.DEFAULT_KEYSTORE_PASSWORD); Path keyStorePath = getDataPath(PkiUtils.DEFAULT_KEYSTORE_PATH); - deployPropertyDefaults.put(CmsDeployProperty.SSL_KEYSTORE, keyStorePath.toAbsolutePath().toString()); + if (keyStorePath != null) { + deployPropertyDefaults.put(CmsDeployProperty.SSL_KEYSTORE, keyStorePath.toAbsolutePath().toString()); + } Path trustStorePath = getDataPath(PkiUtils.DEFAULT_TRUSTSTORE_PATH); + if (trustStorePath != null) { + deployPropertyDefaults.put(CmsDeployProperty.SSL_TRUSTSTORE, trustStorePath.toAbsolutePath().toString()); + } deployPropertyDefaults.put(CmsDeployProperty.SSL_TRUSTSTORETYPE, PkiUtils.PKCS12); deployPropertyDefaults.put(CmsDeployProperty.SSL_TRUSTSTOREPASSWORD, PkiUtils.DEFAULT_KEYSTORE_PASSWORD); - deployPropertyDefaults.put(CmsDeployProperty.SSL_TRUSTSTORE, trustStorePath.toAbsolutePath().toString()); this.deployPropertyDefaults = Collections.unmodifiableMap(deployPropertyDefaults); } @@ -83,11 +83,11 @@ public class CmsStateImpl implements CmsState { // this.uuid = UUID.fromString(stateUuidStr); this.uuid = uuidFactory.timeUUID(); // this.cleanState = stateUuid.equals(frameworkUuid); - try { - this.hostname = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - log.error("Cannot set hostname: " + e); - } +// try { +// this.hostname = InetAddress.getLocalHost().getHostName(); +// } catch (UnknownHostException e) { +// log.error("Cannot set hostname: " + e); +// } availableSince = System.currentTimeMillis(); if (log.isDebugEnabled()) { @@ -112,14 +112,13 @@ public class CmsStateImpl implements CmsState { log.debug("## CMS starting... (" + uuid + ")\n" + sb + "\n"); } -// initI18n(); -// initServices(); - if (!Files.exists(getDataPath(CmsConstants.NODE))) {// first init + Path nodeBase = getDataPath(CmsConstants.NODE); + if (nodeBase != null && !Files.exists(nodeBase)) {// first init firstInit(); } } catch (RuntimeException | IOException e) { - log.error("## FATAL: CMS activator failed", e); + log.error("## FATAL: CMS state failed", e); } } @@ -337,10 +336,6 @@ public class CmsStateImpl implements CmsState { /* * ACCESSORS */ - public String getHostname() { - return hostname; - } - @Override public UUID getUuid() { return uuid; @@ -357,7 +352,7 @@ public class CmsStateImpl implements CmsState { public static void prepareFirstInitInstanceArea(List nodeInits) { for (String nodeInit : nodeInits) { - if(nodeInit==null) + if (nodeInit == null) continue; if (nodeInit.startsWith("http")) { @@ -366,29 +361,17 @@ public class CmsStateImpl implements CmsState { } else { // TODO use java.nio.file - File initDir; + Path initDir; if (nodeInit.startsWith(".")) initDir = KernelUtils.getExecutionDir(nodeInit); else - initDir = new File(nodeInit); + initDir = Paths.get(nodeInit); // TODO also uncompress archives - if (initDir.exists()) - try { - // TODO use NIO utilities - FileUtils.copyDirectory(initDir, KernelUtils.getOsgiInstancePath("").toFile(), - new FileFilter() { - - @Override - public boolean accept(File pathname) { - if (pathname.getName().equals(".svn") || pathname.getName().equals(".git")) - return false; - return true; - } - }); - log.info("CMS initialized from " + initDir.getCanonicalPath()); - } catch (IOException e) { - throw new RuntimeException("Cannot initialize from " + initDir, e); - } + if (Files.exists(initDir)) { + Path dataPath = KernelUtils.getOsgiInstancePath(""); + FsUtils.copyDirectory(initDir, dataPath); + log.info("CMS initialized from " + initDir); + } } } }