You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:16:41 UTC

[sling-org-apache-sling-settings] 05/09: SLING-2674: SlingSettingsServiceImpl should detect and handle upgrades

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.settings-1.2.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-settings.git

commit 1ae0f68160210726624a2255b19248b33d9eee4c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Nov 23 06:47:31 2012 +0000

    SLING-2674: SlingSettingsServiceImpl should detect and handle upgrades
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@1412761 13f79535-47bb-0310-9956-ffa450edef68
---
 .../settings/impl/SlingSettingsServiceImpl.java    | 47 ++++++++++------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
index b998690..e1de632 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -74,14 +74,14 @@ public class SlingSettingsServiceImpl
     public SlingSettingsServiceImpl(final BundleContext context) {
         this.setupSlingHome(context);
         final boolean isInstall = this.setupSlingId(context);
-        
+
         // Detect if upgrading from a previous version (where OPTIONS_FILE did not exist),
         // as in terms of run modes this needs to be handled like an install
         final File options = context.getDataFile(OPTIONS_FILE);
         final boolean isUpgrade = !isInstall && !options.exists();
-                
+
         logger.info("isInstall={}, isUpgrade={}", isInstall, isUpgrade);
-        this.setupRunModes(context, isInstall, isUpgrade);
+        this.setupRunModes(context, isInstall || isUpgrade);
 
     }
 
@@ -128,8 +128,8 @@ public class SlingSettingsServiceImpl
     }
 
     private List<Options> handleOptions(final Set<String> modesSet, final String propOptions) {
+        final List<Options> optionsList = new ArrayList<Options>();
         if ( propOptions != null && propOptions.trim().length() > 0 ) {
-            final List<Options> optionsList = new ArrayList<Options>();
 
             final String[] options = propOptions.trim().split("\\|");
             for(final String opt : options) {
@@ -154,9 +154,8 @@ public class SlingSettingsServiceImpl
                 o.modes = modes;
                 optionsList.add(o);
             }
-            return optionsList;
         }
-        return null;
+        return optionsList;
     }
 
     /**
@@ -164,7 +163,7 @@ public class SlingSettingsServiceImpl
      */
     @SuppressWarnings("unchecked")
     private void setupRunModes(final BundleContext context,
-            final boolean isInstall, final boolean isUpgrade) {
+            final boolean inspectInstallOptions) {
         final Set<String> modesSet = new HashSet<String>();
 
         // check configuration property first
@@ -179,25 +178,23 @@ public class SlingSettingsServiceImpl
         // now options
         this.handleOptions(modesSet, context.getProperty(RUN_MODE_OPTIONS));
         // now install options
-        if ( isInstall || isUpgrade) {
+        if ( inspectInstallOptions ) {
             final List<Options> optionsList = this.handleOptions(modesSet, context.getProperty(RUN_MODE_INSTALL_OPTIONS));
-            if ( optionsList != null ) {
-                final File file = context.getDataFile(OPTIONS_FILE);
-                FileOutputStream fos = null;
-                ObjectOutputStream oos = null;
-                try {
-                    fos = new FileOutputStream(file);
-                    oos = new ObjectOutputStream(fos);
-                    oos.writeObject(optionsList);
-                } catch ( final IOException ioe ) {
-                    throw new RuntimeException("Unable to write to options data file.", ioe);
-                } finally {
-                    if ( oos != null ) {
-                        try { oos.close(); } catch ( final IOException ignore) {}
-                    }
-                    if ( fos != null ) {
-                        try { fos.close(); } catch ( final IOException ignore) {}
-                    }
+            final File file = context.getDataFile(OPTIONS_FILE);
+            FileOutputStream fos = null;
+            ObjectOutputStream oos = null;
+            try {
+                fos = new FileOutputStream(file);
+                oos = new ObjectOutputStream(fos);
+                oos.writeObject(optionsList);
+            } catch ( final IOException ioe ) {
+                throw new RuntimeException("Unable to write to options data file.", ioe);
+            } finally {
+                if ( oos != null ) {
+                    try { oos.close(); } catch ( final IOException ignore) {}
+                }
+                if ( fos != null ) {
+                    try { fos.close(); } catch ( final IOException ignore) {}
                 }
             }
         } else {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.