Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 9a5acdffd -> 4ed2a221b


KARAF-4475 Do not wipe karaf cache and data dir while karaf is running.

ConfigurationProperties was used as "Parser" for karaf config, by status and 
stop scripts.
This change moves all "state modifications" to a separate method which is only 
called by Main


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/4ed2a221
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/4ed2a221
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/4ed2a221

Branch: refs/heads/karaf-4.0.x
Commit: 4ed2a221b1ee5c3350e483c85bb8b1351104d008
Parents: 9a5acdf
Author: Fabian Lange <[email protected]>
Authored: Wed Apr 6 18:35:14 2016 +0200
Committer: Fabian Lange <[email protected]>
Committed: Wed Apr 6 18:35:14 2016 +0200

----------------------------------------------------------------------
 .../org/apache/karaf/main/ConfigProperties.java | 85 ++++++++++----------
 .../main/java/org/apache/karaf/main/Main.java   |  1 +
 2 files changed, 44 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/4ed2a221/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java 
b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
index 7283398..0383191 100644
--- a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
+++ b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
@@ -135,8 +135,6 @@ public class ConfigProperties {
     
     private static final String KARAF_DELAY_CONSOLE = "karaf.delay.console";
 
-    private static final String DEFAULT_SHUTDOWN_COMMAND = "SHUTDOWN";
-
     private static final String PROPERTY_LOCK_CLASS_DEFAULT = 
SimpleFileLock.class.getName();
 
     private static final String SECURITY_PROVIDERS = 
"org.apache.karaf.security.providers";
@@ -187,8 +185,9 @@ public class ConfigProperties {
         this.karafInstances = Utils.getKarafDirectory(PROP_KARAF_INSTANCES, 
ENV_KARAF_INSTANCES, new File(karafHome, "instances"), false, false);
 
         Package p = Package.getPackage("org.apache.karaf.main");
-        if (p != null && p.getImplementationVersion() != null)
+        if (p != null && p.getImplementationVersion() != null) {
             System.setProperty(PROP_KARAF_VERSION, 
p.getImplementationVersion());
+        }
         System.setProperty(PROP_KARAF_HOME, karafHome.getPath());
         System.setProperty(PROP_KARAF_BASE, karafBase.getPath());
         System.setProperty(PROP_KARAF_DATA, karafData.getPath());
@@ -199,39 +198,18 @@ public class ConfigProperties {
         }
         PropertiesLoader.loadSystemProperties(new File(karafEtc, 
SYSTEM_PROPERTIES_FILE_NAME));
 
-        File cleanAllIndicatorFile = new File(karafData, "clean_all");
-        File cleanCacheIndicatorFile = new File(karafData, "clean_cache");
-        if (Boolean.getBoolean("karaf.clean.all") || 
cleanAllIndicatorFile.exists()) {
-            if (cleanAllIndicatorFile.exists()) {
-                cleanAllIndicatorFile.delete();
-            }
-            Utils.deleteDirectory(this.karafData);
-            this.karafData = Utils.getKarafDirectory(PROP_KARAF_DATA, 
ENV_KARAF_DATA, new File(karafBase, "data"), true, true);
-        } else {
-            if (Boolean.getBoolean("karaf.clean.cache") || 
cleanCacheIndicatorFile.exists()) {
-                if (cleanCacheIndicatorFile.exists()) {
-                    cleanCacheIndicatorFile.delete();
-                }
-                File karafCache = Utils.validateDirectoryExists(new 
File(karafData, "cache").getPath(), "Invalid cache directory", true, true);
-                Utils.deleteDirectory(karafCache);
-            }
-        }
-
-        File file = new File(karafEtc, CONFIG_PROPERTIES_FILE_NAME);
-        this.props = PropertiesLoader.loadConfigProperties(file);
+        this.props = PropertiesLoader.loadConfigProperties(new File(karafEtc, 
CONFIG_PROPERTIES_FILE_NAME));
 
-        String prop = props.getProperty(SECURITY_PROVIDERS);
-        this.securityProviders = (prop != null) ? prop.split(",") : new 
String[] {};
+        this.securityProviders = getSecurityProviders();
         this.defaultStartLevel = 
Integer.parseInt(props.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
         System.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, 
Integer.toString(this.defaultStartLevel));
-        this.lockStartLevel = 
Integer.parseInt(props.getProperty(PROPERTY_LOCK_LEVEL, 
Integer.toString(lockStartLevel)));                
+        this.lockStartLevel = 
Integer.parseInt(props.getProperty(PROPERTY_LOCK_LEVEL, 
Integer.toString(lockStartLevel)));
         this.lockDelay = 
Integer.parseInt(props.getProperty(PROPERTY_LOCK_DELAY, DEFAULT_LOCK_DELAY));
         this.lockSlaveBlock = 
Boolean.parseBoolean(props.getProperty(PROPERTY_LOCK_SLAVE_BLOCK, "false"));
         this.props.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, 
Integer.toString(lockDefaultBootLevel));
         this.shutdownTimeout = 
Integer.parseInt(props.getProperty(KARAF_SHUTDOWN_TIMEOUT, 
Integer.toString(shutdownTimeout)));
         this.useLock = 
Boolean.parseBoolean(props.getProperty(PROPERTY_USE_LOCK, "true"));
         this.lockClass = props.getProperty(PROPERTY_LOCK_CLASS, 
PROPERTY_LOCK_CLASS_DEFAULT);
-        initFrameworkStorage(karafData);
         this.frameworkFactoryClass = 
props.getProperty(KARAF_FRAMEWORK_FACTORY);
         this.frameworkBundle = getFramework();
         this.defaultRepo = System.getProperty(DEFAULT_REPO, "system");
@@ -245,11 +223,42 @@ public class ConfigProperties {
         this.startupMessage = props.getProperty(KARAF_STARTUP_MESSAGE, "Apache 
Karaf starting up. Press Enter to open the shell now...");
         this.delayConsoleStart = 
Boolean.parseBoolean(props.getProperty(KARAF_DELAY_CONSOLE, "false"));
         System.setProperty(KARAF_DELAY_CONSOLE, new 
Boolean(this.delayConsoleStart).toString());
+    }
+
+    public void performInit() throws Exception {
+        File cleanAllIndicatorFile = new File(karafData, "clean_all");
+        File cleanCacheIndicatorFile = new File(karafData, "clean_cache");
+        if (Boolean.getBoolean("karaf.clean.all") || 
cleanAllIndicatorFile.exists()) {
+            if (cleanAllIndicatorFile.exists()) {
+                cleanAllIndicatorFile.delete();
+            }
+            Utils.deleteDirectory(this.karafData);
+            this.karafData = Utils.getKarafDirectory(PROP_KARAF_DATA, 
ENV_KARAF_DATA, new File(karafBase, "data"), true, true);
+        } else {
+            if (Boolean.getBoolean("karaf.clean.cache") || 
cleanCacheIndicatorFile.exists()) {
+                if (cleanCacheIndicatorFile.exists()) {
+                    cleanCacheIndicatorFile.delete();
+                }
+                File karafCache = Utils.validateDirectoryExists(new 
File(karafData, "cache").getPath(), "Invalid cache directory", true, true);
+                Utils.deleteDirectory(karafCache);
+            }
+        }
+
+        String frameworkStoragePath = 
props.getProperty(Constants.FRAMEWORK_STORAGE);
+        if (frameworkStoragePath == null) {
+            File storage = new File(karafData.getPath(), "cache");
+            try {
+                storage.mkdirs();
+            } catch (SecurityException se) {
+                throw new Exception(se.getMessage()); 
+            }
+            props.setProperty(Constants.FRAMEWORK_STORAGE, 
storage.getAbsolutePath());
+        }
 
         if (shutdownCommand == null || shutdownCommand.isEmpty()) {
             try {
                 shutdownCommand = UUID.randomUUID().toString();
-                Properties temp = new Properties(file);
+                Properties temp = new Properties(new File(karafEtc, 
CONFIG_PROPERTIES_FILE_NAME));
                 temp.put(KARAF_SHUTDOWN_COMMAND, Arrays.asList("", "#", "# 
Generated command shutdown", "#"), shutdownCommand);
                 temp.save();
             } catch (IOException ioException) {
@@ -265,26 +274,18 @@ public class ConfigProperties {
         }
         return value;
     }
-    
+
+    private String[] getSecurityProviders() {
+        String prop = props.getProperty(SECURITY_PROVIDERS);
+        return (prop != null) ? prop.split(",") : new String[] {};
+    }
+
     private URI getFramework() throws URISyntaxException {
         String framework = getPropertyOrFail(KARAF_FRAMEWORK);
         String frameworkBundleUri = getPropertyOrFail(KARAF_FRAMEWORK + "." + 
framework);
         return new URI(frameworkBundleUri);
     }
 
-    private void initFrameworkStorage(File karafData) throws Exception {
-        String frameworkStoragePath = 
props.getProperty(Constants.FRAMEWORK_STORAGE);
-        if (frameworkStoragePath == null) {
-            File storage = new File(karafData.getPath(), "cache");
-            try {
-                storage.mkdirs();
-            } catch (SecurityException se) {
-                throw new Exception(se.getMessage()); 
-            }
-            props.setProperty(Constants.FRAMEWORK_STORAGE, 
storage.getAbsolutePath());
-        }
-    }
-    
     private int getDefaultBundleStartLevel(int ibsl) {
         try {
             String str = props.getProperty("karaf.startlevel.bundle");

http://git-wip-us.apache.org/repos/asf/karaf/blob/4ed2a221/main/src/main/java/org/apache/karaf/main/Main.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/Main.java 
b/main/src/main/java/org/apache/karaf/main/Main.java
index ea68aab..7f9bfff 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -228,6 +228,7 @@ public class Main {
 
     public void launch() throws Exception {
         config = new ConfigProperties();
+        config.performInit();
         if (config.delayConsoleStart) {
             System.out.println(config.startupMessage);
         }

Reply via email to