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 7c9f72c46bac36be6c8271c8cb7ec4a6257cae75 Author: Carsten Ziegeler <[email protected]> AuthorDate: Fri Nov 23 14:46:43 2012 +0000 Support portals bridge git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@1412905 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 6 + .../settings/impl/SlingSettingsServiceImpl.java | 136 ++++++++++++--------- 2 files changed, 87 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index 8f3f2af..b147e79 100644 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.launchpad.api</artifactId> + <version>1.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> 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 e1de632..4ab883c 100644 --- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java +++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Set; import java.util.UUID; +import org.apache.sling.launchpad.api.StartupMode; import org.apache.sling.settings.SlingSettingsService; import org.osgi.framework.BundleContext; import org.slf4j.Logger; @@ -78,15 +79,24 @@ public class SlingSettingsServiceImpl // 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(); + final boolean isUpdate = !isInstall && !options.exists(); - logger.info("isInstall={}, isUpgrade={}", isInstall, isUpgrade); - this.setupRunModes(context, isInstall || isUpgrade); + final String startupModeObj = context.getProperty(StartupMode.class.getName()); + final StartupMode mode; + if ( startupModeObj != null ) { + mode = StartupMode.valueOf(startupModeObj); + logger.debug("Settings: Using startup mode : {}", mode); + } else { + logger.debug("Settings: Startup mode detection: isInstall={}, isUpdate={}", isInstall, isUpdate); + mode = isInstall ? StartupMode.INSTALL : (isUpdate ? StartupMode.UPDATE : StartupMode.RESTART); + } + + this.setupRunModes(context, mode); } /** - * Get sling home and sling home url + * Get sling home and sling home URL */ private void setupSlingHome(final BundleContext context) { this.slingHome = context.getProperty(SLING_HOME); @@ -163,7 +173,7 @@ public class SlingSettingsServiceImpl */ @SuppressWarnings("unchecked") private void setupRunModes(final BundleContext context, - final boolean inspectInstallOptions) { + final StartupMode startupMode) { final Set<String> modesSet = new HashSet<String>(); // check configuration property first @@ -175,62 +185,31 @@ public class SlingSettingsServiceImpl } } - // now options + // handle configured options this.handleOptions(modesSet, context.getProperty(RUN_MODE_OPTIONS)); - // now install options - if ( inspectInstallOptions ) { - final List<Options> optionsList = this.handleOptions(modesSet, context.getProperty(RUN_MODE_INSTALL_OPTIONS)); - 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 { - final File file = context.getDataFile(OPTIONS_FILE); - if ( file.exists() ) { - List<Options> optionsList = null; - FileInputStream fis = null; - ObjectInputStream ois = null; - try { - fis = new FileInputStream(file); - ois = new ObjectInputStream(fis); - - optionsList = (List<Options>) ois.readObject(); - } catch ( final IOException ioe ) { - throw new RuntimeException("Unable to read from options data file.", ioe); - } catch (ClassNotFoundException cnfe) { - throw new RuntimeException("Unable to read from options data file.", cnfe); - } finally { - if ( ois != null ) { - try { ois.close(); } catch ( final IOException ignore) {} - } - if ( fis != null ) { - try { fis.close(); } catch ( final IOException ignore) {} - } - } - if ( optionsList != null ) { - for(final Options o : optionsList) { - for(final String m : o.modes) { - modesSet.remove(m); - } - modesSet.add(o.selected); + + // handle configured install options + if ( startupMode != StartupMode.INSTALL ) { + // read persisted options if restart or update + final List<Options> storedOptions = readOptions(context); + if ( storedOptions != null ) { + for(final Options o : storedOptions) { + for(final String m : o.modes) { + modesSet.remove(m); } + modesSet.add(o.selected); } } } + // now install options + if ( startupMode != StartupMode.RESTART ) { + // process new install options if install or update + final List<Options> optionsList = this.handleOptions(modesSet, context.getProperty(RUN_MODE_INSTALL_OPTIONS)); + // and always save new install options + writeOptions(context, optionsList); + } + // make the set unmodifiable and synced // we probably don't need a synced set as it is read only this.runModes = Collections.synchronizedSet(Collections.unmodifiableSet(modesSet)); @@ -242,6 +221,53 @@ public class SlingSettingsServiceImpl } + private List<Options> readOptions(final BundleContext context) { + List<Options> optionsList = null; + final File file = context.getDataFile(OPTIONS_FILE); + if ( file.exists() ) { + FileInputStream fis = null; + ObjectInputStream ois = null; + try { + fis = new FileInputStream(file); + ois = new ObjectInputStream(fis); + + optionsList = (List<Options>) ois.readObject(); + } catch ( final IOException ioe ) { + throw new RuntimeException("Unable to read from options data file.", ioe); + } catch (ClassNotFoundException cnfe) { + throw new RuntimeException("Unable to read from options data file.", cnfe); + } finally { + if ( ois != null ) { + try { ois.close(); } catch ( final IOException ignore) {} + } + if ( fis != null ) { + try { fis.close(); } catch ( final IOException ignore) {} + } + } + } + return optionsList; + } + + private void writeOptions(final BundleContext context, final List<Options> optionsList) { + 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) {} + } + } + } + /** * Read the id from a file. */ -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
