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:15:51 UTC

[sling-org-apache-sling-settings] annotated tag org.apache.sling.settings-1.0.0 created (now d746872)

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

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


      at d746872  (tag)
 tagging 17c02690eb4f4bd35c635335dca93e142c441b14 (commit)
      by Felix Meschberger
      on Fri Aug 27 06:30:59 2010 +0000

- Log -----------------------------------------------------------------
org.apache.sling.settings-1.0.0
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new e29b17b  SLING-1460 : Move SlingSettingsService to new Settings bundle
     new 2f625ec  SLING-1651 - Integrate RunMode module into new Settings Module SLING-983 - Add sling.properties file to configuration status page
     new fdbf548  SLING-1651 - Integrate RunMode module into new Settings Module SLING-983 - Add sling.properties file to configuration status page
     new 02d570e  Ignore Eclipse files
     new c7ffd13  Don't delete sling id file in engine for compatibility and add a temporary np check
     new fee338d  Delayed activation if engine bundle is available but not started yet.
     new 9381905  Some pom formatting, set export version and make dependencies provided
     new d766e1e  Add site generation properties and Bundle-DocURL manifest header
     new 55a7b4b  [maven-release-plugin] prepare release org.apache.sling.settings-1.0.0
     new 022e42f  [maven-scm] copy for tag org.apache.sling.settings-1.0.0
     new 17c0269  Add README.txt

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


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

[sling-org-apache-sling-settings] 07/11: Some pom formatting, set export version and make dependencies provided

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9381905d9626039fa4ffce3ccab8bd5038093e9d
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Aug 24 06:51:09 2010 +0000

    Some pom formatting, set export version and make dependencies provided
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@988405 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 38202e9..38d96cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,7 @@
                 <configuration>
                     <instructions>
                         <Export-Package>
-                            org.apache.sling.settings
+                            org.apache.sling.settings;version=1.0.0
                         </Export-Package>
                         <Private-Package>
                             org.apache.sling.settings.impl

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

[sling-org-apache-sling-settings] 11/11: Add README.txt

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 17c02690eb4f4bd35c635335dca93e142c441b14
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Fri Aug 27 06:30:59 2010 +0000

    Add README.txt
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.settings-1.0.0@990041 13f79535-47bb-0310-9956-ffa450edef68
---
 README.txt | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..96aeead
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,26 @@
+Apache Sling Settings
+
+Settings support including run modes.
+
+Getting Started
+===============
+
+This component uses a Maven 2 (http://maven.apache.org/) build
+environment. It requires a Java 5 JDK (or higher) and Maven (http://maven.apache.org/)
+2.0.7 or later. We recommend to use the latest Maven version.
+
+If you have Maven 2 installed, you can compile and
+package the jar using the following command:
+
+    mvn package
+
+See the Maven 2 documentation for other build features.
+
+The latest source code for this component is available in the
+Subversion (http://subversion.tigris.org/) source repository of
+the Apache Software Foundation. If you have Subversion installed,
+you can checkout the latest source using the following command:
+
+    svn checkout http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings
+
+See the Subversion documentation for other source control features.

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

[sling-org-apache-sling-settings] 04/11: Ignore Eclipse files

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 02d570e3b4489a0a6adc4e86b7b93761464b78b1
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Fri Aug 13 14:58:39 2010 +0000

    Ignore Eclipse files
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@985225 13f79535-47bb-0310-9956-ffa450edef68

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

[sling-org-apache-sling-settings] 09/11: [maven-release-plugin] prepare release org.apache.sling.settings-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 55a7b4bedef14b56e29b1236e6a5962fdc4ee8e6
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Fri Aug 27 06:26:43 2010 +0000

    [maven-release-plugin] prepare release org.apache.sling.settings-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@990034 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3c1fafd..443a2a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 
     <artifactId>org.apache.sling.settings</artifactId>
     <packaging>bundle</packaging>
-    <version>0.1.0-SNAPSHOT</version>
+    <version>1.0.0</version>
 
     <name>Apache Sling Settings</name>
     <description>
@@ -38,13 +38,13 @@
 
     <scm>
         <connection>
-            scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings
+            scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.settings-1.0.0
         </connection>
         <developerConnection>
-            scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings
+            scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.settings-1.0.0
         </developerConnection>
         <url>
-            http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings
+            http://svn.apache.org/viewvc/sling/tags/org.apache.sling.settings-1.0.0
         </url>
     </scm>
 

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

[sling-org-apache-sling-settings] 05/11: Don't delete sling id file in engine for compatibility and add a temporary np check

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c7ffd1381921b1c6ead5ad4deb6fa45892c68819
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Aug 15 10:26:13 2010 +0000

    Don't delete sling id file in engine for compatibility and add a temporary np check
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@985650 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/settings/impl/SlingSettingsServiceImpl.java     | 5 ++---
 1 file changed, 2 insertions(+), 3 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 2bcb200..92a7bf1 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -101,12 +101,11 @@ public class SlingSettingsServiceImpl
         // if we don't have an id yet, we look for the engine bundle for compatibility reasons
         if ( this.slingId == null ) {
             final Bundle engineBundle = this.searchEngineBundle(context);
-            if ( engineBundle != null ) {
+            // TODO - we need the bundle context, maybe we should wait for the engine bundle to become active?
+            if ( engineBundle != null && engineBundle.getBundleContext() != null ) {
                 final File engineIdFile = engineBundle.getBundleContext().getDataFile(DATA_FILE);
                 this.slingId = this.readSlingId(engineIdFile);
                 if ( this.slingId != null ) {
-                    // delete the old file
-                    engineIdFile.delete();
                     this.writeSlingId(idFile, this.slingId);
                 }
             }

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

[sling-org-apache-sling-settings] 03/11: SLING-1651 - Integrate RunMode module into new Settings Module SLING-983 - Add sling.properties file to configuration status page

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fdbf5482f951c0603502b94662d57c1b919f773e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Aug 13 11:54:41 2010 +0000

    SLING-1651 - Integrate RunMode module into new Settings Module
    SLING-983 - Add sling.properties file to configuration status page
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@985165 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   5 +
 .../sling/settings/impl/RunModeImplTest.java       | 198 +++++++++++++++++++++
 2 files changed, 203 insertions(+)

diff --git a/pom.xml b/pom.xml
index 6be3d20..38202e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,9 +105,14 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+      <!-- Testing -->
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java b/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
new file mode 100644
index 0000000..3235e0b
--- /dev/null
+++ b/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.Set;
+
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class RunModeImplTest {
+
+    private void assertParse(String str, String [] expected) {
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock(str));
+        final Set<String> modes = rm.getRunModes();
+        final String[] actual = modes.toArray(new String[modes.size()]);
+        assertArrayEquals("Parsed runModes match for '" + str + "'", expected, actual);
+    }
+
+    @org.junit.Test public void testParseRunModes() {
+        assertParse(null, new String[0]);
+        assertParse("", new String[0]);
+        assertParse(" foo \t", new String[] { "foo" });
+        assertParse(" foo \t,  bar\n", new String[] { "foo", "bar" });
+    }
+
+    @org.junit.Test public void testMatchesNotEmpty() {
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar"));
+
+        assertTrue("single foo should be active", rm.getRunModes().contains("foo"));
+
+        assertFalse("wiz should be not active", rm.getRunModes().contains("wiz"));
+        assertFalse("bah should be not active", rm.getRunModes().contains("bah"));
+        assertFalse("empty should be not active", rm.getRunModes().contains(""));
+    }
+
+    private static final class BundleContextMock implements BundleContext {
+
+        private final String str;
+
+        public BundleContextMock(String str) {
+            this.str = str;
+        }
+
+        public void addBundleListener(BundleListener listener) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public void addFrameworkListener(FrameworkListener listener) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public void addServiceListener(ServiceListener listener, String filter)
+                throws InvalidSyntaxException {
+            // TODO Auto-generated method stub
+
+        }
+
+        public void addServiceListener(ServiceListener listener) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public Filter createFilter(String filter) throws InvalidSyntaxException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public ServiceReference[] getAllServiceReferences(String clazz,
+                String filter) throws InvalidSyntaxException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Bundle getBundle() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Bundle getBundle(long id) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Bundle[] getBundles() {
+            return new Bundle[0];
+        }
+
+        public File getDataFile(String filename) {
+            try {
+                final File f = File.createTempFile("sling", "id");
+                f.deleteOnExit();
+                return f;
+            } catch (IOException ioe) {
+                throw new RuntimeException(ioe);
+            }
+        }
+
+        public String getProperty(String key) {
+            return str;
+        }
+
+        public Object getService(ServiceReference reference) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public ServiceReference getServiceReference(String clazz) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public ServiceReference[] getServiceReferences(String clazz,
+                String filter) throws InvalidSyntaxException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Bundle installBundle(String location, InputStream input)
+                throws BundleException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Bundle installBundle(String location) throws BundleException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @SuppressWarnings("unchecked")
+        public ServiceRegistration registerService(String clazz,
+                Object service, Dictionary properties) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @SuppressWarnings("unchecked")
+        public ServiceRegistration registerService(String[] clazzes,
+                Object service, Dictionary properties) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public void removeBundleListener(BundleListener listener) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public void removeFrameworkListener(FrameworkListener listener) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public void removeServiceListener(ServiceListener listener) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public boolean ungetService(ServiceReference reference) {
+            // TODO Auto-generated method stub
+            return false;
+        }
+    }
+}
\ No newline at end of file

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

[sling-org-apache-sling-settings] 08/11: Add site generation properties and Bundle-DocURL manifest header

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d766e1e733ad12abdd25d4f2834c830663a4e9a2
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Fri Aug 27 05:57:27 2010 +0000

    Add site generation properties and Bundle-DocURL manifest header
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@990028 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pom.xml b/pom.xml
index 38d96cf..3c1fafd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,11 @@
         </url>
     </scm>
 
+    <properties>
+        <site.jira.version.id>12315254</site.jira.version.id>
+        <site.javadoc.exclude>**.impl.**</site.javadoc.exclude>
+    </properties>
+
     <build>
         <plugins>
             <plugin>
@@ -56,6 +61,9 @@
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
+                        <Bundle-DocURL>
+                            http://sling.apache.org/site/sling-settings-orgapacheslingsettings.html
+                        </Bundle-DocURL>
                         <Export-Package>
                             org.apache.sling.settings;version=1.0.0
                         </Export-Package>

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

[sling-org-apache-sling-settings] 02/11: SLING-1651 - Integrate RunMode module into new Settings Module SLING-983 - Add sling.properties file to configuration status page

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2f625ec81ff7a4cbf24a4d2813517f70e42063a8
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Aug 13 11:30:39 2010 +0000

    SLING-1651 - Integrate RunMode module into new Settings Module
    SLING-983 - Add sling.properties file to configuration status page
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@985159 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   4 +-
 .../sling/settings/SlingSettingsService.java       |  22 ++++
 .../org/apache/sling/settings/impl/Activator.java  |  32 ++++-
 .../apache/sling/settings/impl/RunModeCommand.java | 101 +++++++++++++++
 .../settings/impl/SlingPropertiesPrinter.java      | 144 +++++++++++++++++++++
 .../sling/settings/impl/SlingSettingsPrinter.java  |  96 ++++++++++++++
 .../settings/impl/SlingSettingsServiceImpl.java    |  61 ++++++++-
 7 files changed, 454 insertions(+), 6 deletions(-)

diff --git a/pom.xml b/pom.xml
index 91b28c7..6be3d20 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,11 +89,13 @@
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.shell</artifactId>
             <version>1.0.0</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.webconsole</artifactId>
-            <version>1.2.0</version>
+            <version>3.0.0</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
diff --git a/src/main/java/org/apache/sling/settings/SlingSettingsService.java b/src/main/java/org/apache/sling/settings/SlingSettingsService.java
index 97c8fcc..f8b6904 100644
--- a/src/main/java/org/apache/sling/settings/SlingSettingsService.java
+++ b/src/main/java/org/apache/sling/settings/SlingSettingsService.java
@@ -19,10 +19,16 @@
 package org.apache.sling.settings;
 
 import java.net.URL;
+import java.util.Set;
 
 /**
  * The <code>SlingSettingsService</code> provides basic Sling settings.
+ * - Sling home : If the Sling launchpad is used
+ * - Sling Id : A unique id of the installation
  *
+ * Run Mode Support
+ * A run mode is simply a string like "author", "test", "development",...
+ * The server can have a set of active run modes.
  */
 public interface SlingSettingsService {
 
@@ -55,6 +61,14 @@ public interface SlingSettingsService {
     String SLING_HOME_URL = "sling.home.url";
 
     /**
+     * The name of the framework property defining the set of used
+     * run modes.
+     * The value is a comma separated list of run modes.
+     */
+    String RUN_MODES_PROPERTY = "sling.run.modes";
+
+
+    /**
      * The identifier of the running Sling instance.
      */
     String getSlingId();
@@ -70,4 +84,12 @@ public interface SlingSettingsService {
      * property.
      */
     URL getSlingHome();
+
+    /**
+     * Return the set of activate run modes.
+     * This set might be empty.
+     * @return A non modifiable set of run modes.
+     */
+    Set<String> getRunModes();
+
 }
diff --git a/src/main/java/org/apache/sling/settings/impl/Activator.java b/src/main/java/org/apache/sling/settings/impl/Activator.java
index cb3b522..8047867 100644
--- a/src/main/java/org/apache/sling/settings/impl/Activator.java
+++ b/src/main/java/org/apache/sling/settings/impl/Activator.java
@@ -41,7 +41,7 @@ public class Activator implements BundleActivator {
      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
     public void start(BundleContext context) throws Exception {
-        final Object service = new SlingSettingsServiceImpl(context);
+        final SlingSettingsService service = new SlingSettingsServiceImpl(context);
         final Dictionary<String, String> props = new Hashtable<String, String>();
         props.put(Constants.SERVICE_PID, service.getClass().getName());
         props.put(Constants.SERVICE_DESCRIPTION,
@@ -50,12 +50,42 @@ public class Activator implements BundleActivator {
         serviceRegistration = context.registerService(new String[] {
                                                SlingSettingsService.class.getName()},
                                            service, props);
+        try {
+            SlingPropertiesPrinter.initPlugin(context);
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            SlingSettingsPrinter.initPlugin(context, service);
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            RunModeCommand.initPlugin(context, service.getRunModes());
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
     }
 
     /**
      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
      */
     public void stop(BundleContext context) throws Exception {
+        try {
+            RunModeCommand.destroyPlugin();
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            SlingSettingsPrinter.destroyPlugin();
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            SlingPropertiesPrinter.destroyPlugin();
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
         if ( serviceRegistration != null ) {
             serviceRegistration.unregister();
             serviceRegistration = null;
diff --git a/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java b/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
new file mode 100644
index 0000000..1aa93cf
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Set;
+
+import org.apache.felix.shell.Command;
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Run mode command for the shell.
+ */
+public class RunModeCommand implements Command {
+
+    private static ServiceRegistration pluginReg;
+
+    public static void initPlugin(final BundleContext bundleContext,
+            final Set<String> modes) {
+        final RunModeCommand command = new RunModeCommand(modes);
+
+        final Dictionary<String, String> props = new Hashtable<String, String>();
+        props.put(Constants.SERVICE_DESCRIPTION,
+            "Apache Sling Sling Run Mode Shell Command");
+        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+        pluginReg = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                command,
+                props);
+    }
+
+    public static void destroyPlugin() {
+        if ( pluginReg != null) {
+            pluginReg.unregister();
+            pluginReg = null;
+        }
+    }
+
+    private static final String CMD_NAME = "runmodes";
+
+    /** @scr.reference */
+    private Set<String> modes;
+
+    public RunModeCommand(final Set<String> modes) {
+        this.modes = modes;
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#getName()
+     */
+    public String getName() {
+        return CMD_NAME;
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#getShortDescription()
+     */
+    public String getShortDescription() {
+        return "lists current run modes";
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#getUsage()
+     */
+    public String getUsage() {
+        return CMD_NAME;
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#execute(java.lang.String, java.io.PrintStream, java.io.PrintStream)
+     */
+    public void execute(String command, PrintStream out, PrintStream err) {
+        out.print("Current Run Modes: ");
+        if (modes == null || modes.size() == 0) {
+            out.println("-");
+        } else {
+            out.println(modes);
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java b/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
new file mode 100644
index 0000000..fd3fbdc
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.webconsole.ModeAwareConfigurationPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is a configuration printer for the web console which
+ * prints out the Sling properties from Launchpad if available.
+ *
+ */
+public class SlingPropertiesPrinter implements ModeAwareConfigurationPrinter {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SlingPropertiesPrinter.class);
+
+    private static ServiceRegistration propertiesPlugin;
+
+    public static void initPlugin(final BundleContext bundleContext) {
+        // if the properties are available, we register the sling properties plugin
+        final String propUrl = bundleContext.getProperty("sling.properties.url");
+        if ( propUrl != null ) {
+            // try to read properties
+            Properties props = null;
+            try {
+                final URL url = new URL(propUrl);
+                final InputStream is = url.openStream();
+                final Properties tmp = new Properties();
+                tmp.load(is);
+                props = tmp;
+            } catch (IOException ioe) {
+                LOGGER.warn("Unable to read sling properties from " + propUrl, ioe);
+            }
+            if ( props != null ) {
+                final SlingPropertiesPrinter propertiesPrinter = new SlingPropertiesPrinter(props);
+                final Dictionary<String, String> serviceProps2 = new Hashtable<String, String>();
+                serviceProps2.put(Constants.SERVICE_DESCRIPTION,
+                    "Apache Sling Sling Properties Configuration Printer");
+                serviceProps2.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+                propertiesPlugin = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                        propertiesPrinter,
+                        serviceProps2);
+            }
+        }
+    }
+
+    public static void destroyPlugin() {
+        if ( propertiesPlugin != null) {
+            propertiesPlugin.unregister();
+            propertiesPlugin = null;
+        }
+    }
+
+    private static String HEADLINE = "Apache Sling Launchpad Properties";
+
+    private final Properties props;
+
+    public SlingPropertiesPrinter(final Properties props) {
+        this.props = props;
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+     */
+    public String getTitle() {
+        return "Sling Properties";
+    }
+
+    /**
+     * Print out the servlet filter chains.
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    public void printConfiguration(PrintWriter pw) {
+        pw.println(HEADLINE);
+        pw.println();
+        SortedSet<Object> keys = new TreeSet<Object>( props.keySet() );
+        for ( Iterator<Object> ki = keys.iterator(); ki.hasNext(); ) {
+            final Object key = ki.next();
+            pw.print( key );
+            pw.print(" = ");
+            final Object value = props.get(key);
+            if ( value != null ) {
+                pw.print(value.toString());
+            }
+            pw.println();
+        }
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ModeAwareConfigurationPrinter#printConfiguration(java.io.PrintWriter, java.lang.String)
+     */
+    public void printConfiguration(PrintWriter printWriter, String mode) {
+        if ( mode != ConfigurationPrinter.MODE_ZIP ) {
+            this.printConfiguration(printWriter);
+        } else {
+            // write into byte array first
+            String contents = null;
+            try {
+                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                this.props.store(baos , HEADLINE);
+                contents = baos.toString("8859_1");
+            } catch (IOException ioe) {
+                // if something goes wrong here we default to text output
+                this.printConfiguration(printWriter);
+                return;
+            }
+            printWriter.write(contents);
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java b/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
new file mode 100644
index 0000000..d45b9a4
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * This is a configuration printer for the web console which
+ * prints out the sling settings.
+ *
+ */
+public class SlingSettingsPrinter implements ConfigurationPrinter {
+
+    private static ServiceRegistration pluginReg;
+
+    public static void initPlugin(final BundleContext bundleContext,
+            final SlingSettingsService service) {
+        final SlingSettingsPrinter printer = new SlingSettingsPrinter(service);
+
+        final Dictionary<String, String> props = new Hashtable<String, String>();
+        props.put(Constants.SERVICE_DESCRIPTION,
+            "Apache Sling Sling Settings Configuration Printer");
+        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+        pluginReg = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                printer,
+                props);
+    }
+
+    public static void destroyPlugin() {
+        if ( pluginReg != null) {
+            pluginReg.unregister();
+            pluginReg = null;
+        }
+    }
+
+    private static String HEADLINE = "Apache Sling Settings";
+
+    private final SlingSettingsService settings;
+
+    public SlingSettingsPrinter(final SlingSettingsService settings) {
+        this.settings = settings;
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+     */
+    public String getTitle() {
+        return "Sling Settings";
+    }
+
+    /**
+     * Print out the servlet filter chains.
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    public void printConfiguration(PrintWriter pw) {
+        pw.println(HEADLINE);
+        pw.println();
+        pw.print("Sling ID = ");
+        pw.print(this.settings.getSlingId());
+        pw.println();
+        pw.print("Sling Home = ");
+        pw.print(this.settings.getSlingHomePath());
+        pw.println();
+        pw.print("Sling Home URL = ");
+        pw.print(this.settings.getSlingHome());
+        pw.println();
+        pw.print("Run Modes = ");
+        pw.print(this.settings.getRunModes());
+        pw.println();
+    }
+}
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 b8fdf7f..2bcb200 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -24,6 +24,9 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.UUID;
 
 import org.apache.sling.settings.SlingSettingsService;
@@ -45,20 +48,33 @@ public class SlingSettingsServiceImpl
     private String slingId;
 
     /** The sling home */
-    private final String slingHome;
+    private String slingHome;
 
     /** The sling home url */
     private URL slingHomeUrl;
 
+    private Set<String> runModes;
+
+    /** The name of the data file holding the sling id. */
     private static final String DATA_FILE = "sling.id.file";
 
     /**
      * Create the service and search the Sling home urls and
      * get/create a sling id.
+     * Setup run modes
      * @param context The bundle context
      */
     public SlingSettingsServiceImpl(final BundleContext context) {
-        // get sling home and sling home url
+        this.setupSlingHome(context);
+        this.setupSlingId(context);
+        this.setupRunModes(context);
+
+    }
+
+    /**
+     * Get sling home and sling home url
+     */
+    private void setupSlingHome(final BundleContext context) {
         this.slingHome = context.getProperty(SLING_HOME);
         final String url = context.getProperty(SLING_HOME_URL);
         if ( url != null ) {
@@ -68,7 +84,12 @@ public class SlingSettingsServiceImpl
                 logger.error("Sling home url is not a url: {}", url);
             }
         }
+    }
 
+    /**
+     * Get / create sling id
+     */
+    private void setupSlingId(final BundleContext context) {
         // try to read the id from the id file first
         final File idFile = context.getDataFile(DATA_FILE);
         if ( idFile == null ) {
@@ -98,7 +119,30 @@ public class SlingSettingsServiceImpl
         }
     }
 
-    /** Read the id from a file. */
+    /**
+     * Set up run modes.
+     */
+    private void setupRunModes(final BundleContext context) {
+        final String prop = context.getProperty(RUN_MODES_PROPERTY);
+        if (prop == null || prop.trim().length() == 0) {
+            this.runModes = Collections.emptySet();
+        } else {
+            final Set<String> modesSet = new HashSet<String>();
+            final String[] modes = prop.split(",");
+            for(int i=0; i < modes.length; i++) {
+                modesSet.add(modes[i].trim());
+            }
+            // make the set unmodifiable and synced
+            // we propably don't need a synced set as it is read only
+            this.runModes = Collections.synchronizedSet(Collections.unmodifiableSet(modesSet));
+            logger.info("Active run modes {}", this.runModes);
+        }
+    }
+
+
+    /**
+     * Read the id from a file.
+     */
     private String readSlingId(final File idFile) {
         if (idFile.exists() && idFile.length() >= 36) {
             FileInputStream fin = null;
@@ -129,7 +173,9 @@ public class SlingSettingsServiceImpl
         return null;
     }
 
-    /** Write the sling id file. */
+    /**
+     * Write the sling id file.
+     */
     private void writeSlingId(final File idFile, final String id) {
         idFile.delete();
         idFile.getParentFile().mkdirs();
@@ -181,4 +227,11 @@ public class SlingSettingsServiceImpl
     public String getSlingHomePath() {
         return this.slingHome;
     }
+
+    /**
+     * @see org.apache.sling.settings.SlingSettingsService#getRunModes()
+     */
+    public Set<String> getRunModes() {
+        return this.runModes;
+    }
 }

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

[sling-org-apache-sling-settings] 06/11: Delayed activation if engine bundle is available but not started yet.

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fee338dcc1d6d9dde4a4496354b7d1076f7ca18a
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Aug 15 15:14:31 2010 +0000

    Delayed activation if engine bundle is available but not started yet.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@985687 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/settings/impl/Activator.java  | 53 ++++++++++++++++++----
 .../settings/impl/SlingSettingsServiceImpl.java    | 27 +++++++++--
 2 files changed, 68 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/sling/settings/impl/Activator.java b/src/main/java/org/apache/sling/settings/impl/Activator.java
index 8047867..61a0bae 100644
--- a/src/main/java/org/apache/sling/settings/impl/Activator.java
+++ b/src/main/java/org/apache/sling/settings/impl/Activator.java
@@ -24,6 +24,8 @@ import java.util.Hashtable;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 
@@ -32,45 +34,79 @@ import org.osgi.framework.ServiceRegistration;
  * It registers the SlingSettingsService.
  *
  */
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator, BundleListener {
 
     /** The service registration */
     private ServiceRegistration serviceRegistration;
 
+    /** The bundle context. */
+    private BundleContext bundleContext;
+
+    /** The settings service. */
+    private SlingSettingsServiceImpl settingsService;
+
     /**
      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
     public void start(BundleContext context) throws Exception {
-        final SlingSettingsService service = new SlingSettingsServiceImpl(context);
+        this.bundleContext = context;
+        this.settingsService = new SlingSettingsServiceImpl(context);
+        // for compatibility, we might have to wait for the engine bundle
+        // to be started to get the Sling ID
+
+        if ( this.settingsService.isDelayedStart() ) {
+            this.bundleContext.addBundleListener(this);
+        } else {
+            this.startService();
+        }
+    }
+
+    /**
+     * @param event
+     */
+    public void bundleChanged(BundleEvent event) {
+        if ( SlingSettingsServiceImpl.ENGINE_SYMBOLIC_NAME.equals(event.getBundle().getSymbolicName())) {
+            this.settingsService.initDelayed(this.bundleContext);
+            if ( !this.settingsService.isDelayedStart() ) {
+                this.bundleContext.removeBundleListener(this);
+                this.startService();
+            }
+        }
+
+    }
+
+    private void startService() {
         final Dictionary<String, String> props = new Hashtable<String, String>();
-        props.put(Constants.SERVICE_PID, service.getClass().getName());
+        props.put(Constants.SERVICE_PID, this.settingsService.getClass().getName());
         props.put(Constants.SERVICE_DESCRIPTION,
             "Apache Sling Settings Service");
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-        serviceRegistration = context.registerService(new String[] {
+        serviceRegistration = this.bundleContext.registerService(new String[] {
                                                SlingSettingsService.class.getName()},
-                                           service, props);
+                                               this.settingsService, props);
         try {
-            SlingPropertiesPrinter.initPlugin(context);
+            SlingPropertiesPrinter.initPlugin(this.bundleContext);
         } catch (Throwable ignore) {
             // we just ignore this
         }
         try {
-            SlingSettingsPrinter.initPlugin(context, service);
+            SlingSettingsPrinter.initPlugin(this.bundleContext, this.settingsService);
         } catch (Throwable ignore) {
             // we just ignore this
         }
         try {
-            RunModeCommand.initPlugin(context, service.getRunModes());
+            RunModeCommand.initPlugin(this.bundleContext, this.settingsService.getRunModes());
         } catch (Throwable ignore) {
             // we just ignore this
         }
+
     }
 
     /**
      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
      */
     public void stop(BundleContext context) throws Exception {
+        this.bundleContext.removeBundleListener(this);
         try {
             RunModeCommand.destroyPlugin();
         } catch (Throwable ignore) {
@@ -90,5 +126,6 @@ public class Activator implements BundleActivator {
             serviceRegistration.unregister();
             serviceRegistration = null;
         }
+        this.settingsService = null;
     }
 }
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 92a7bf1..da47c2b 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -41,6 +41,8 @@ import org.slf4j.LoggerFactory;
 public class SlingSettingsServiceImpl
     implements SlingSettingsService {
 
+    public static final String ENGINE_SYMBOLIC_NAME = "org.apache.sling.engine";
+
     /** The logger */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -58,6 +60,9 @@ public class SlingSettingsServiceImpl
     /** The name of the data file holding the sling id. */
     private static final String DATA_FILE = "sling.id.file";
 
+    /** Flag indicating a delayed start of this service. */
+    private boolean delayedStart = false;
+
     /**
      * Create the service and search the Sling home urls and
      * get/create a sling id.
@@ -101,9 +106,14 @@ public class SlingSettingsServiceImpl
         // if we don't have an id yet, we look for the engine bundle for compatibility reasons
         if ( this.slingId == null ) {
             final Bundle engineBundle = this.searchEngineBundle(context);
-            // TODO - we need the bundle context, maybe we should wait for the engine bundle to become active?
-            if ( engineBundle != null && engineBundle.getBundleContext() != null ) {
-                final File engineIdFile = engineBundle.getBundleContext().getDataFile(DATA_FILE);
+            if ( engineBundle != null && engineBundle.getState() != Bundle.UNINSTALLED ) {
+                final BundleContext engineCtx = engineBundle.getBundleContext();
+                if ( engineCtx == null ) {
+                    // we need a delayed start
+                    this.delayedStart = true;
+                    return;
+                }
+                final File engineIdFile = engineCtx.getDataFile(DATA_FILE);
                 this.slingId = this.readSlingId(engineIdFile);
                 if ( this.slingId != null ) {
                     this.writeSlingId(idFile, this.slingId);
@@ -199,7 +209,7 @@ public class SlingSettingsServiceImpl
     private Bundle searchEngineBundle(final BundleContext bc) {
         final Bundle[] bundles = bc.getBundles();
         for(final Bundle b : bundles) {
-            if ( "org.apache.sling.engine".equals(b.getSymbolicName()) ) {
+            if ( ENGINE_SYMBOLIC_NAME.equals(b.getSymbolicName()) ) {
                 return b;
             }
         }
@@ -233,4 +243,13 @@ public class SlingSettingsServiceImpl
     public Set<String> getRunModes() {
         return this.runModes;
     }
+
+    public boolean isDelayedStart() {
+        return this.delayedStart;
+    }
+
+    public void initDelayed(final BundleContext context) {
+        this.delayedStart = false;
+        this.setupSlingId(context);
+    }
 }

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

[sling-org-apache-sling-settings] 01/11: SLING-1460 : Move SlingSettingsService to new Settings bundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e29b17b90e574ff06995f669a30f2e0cb18c12e7
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Aug 13 09:22:23 2010 +0000

    SLING-1460 : Move SlingSettingsService to new Settings bundle
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@985140 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 111 +++++++++++++
 .../sling/settings/SlingSettingsService.java       |  73 ++++++++
 .../org/apache/sling/settings/impl/Activator.java  |  64 +++++++
 .../settings/impl/SlingSettingsServiceImpl.java    | 184 +++++++++++++++++++++
 4 files changed, 432 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..91b28c7
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>9</version>
+        <relativePath>../../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.settings</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.1.0-SNAPSHOT</version>
+
+    <name>Apache Sling Settings</name>
+    <description>
+        Settings support including run modes
+    </description>
+
+    <scm>
+        <connection>
+            scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings
+        </connection>
+        <developerConnection>
+            scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings
+        </developerConnection>
+        <url>
+            http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings
+        </url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>
+                            org.apache.sling.settings
+                        </Export-Package>
+                        <Private-Package>
+                            org.apache.sling.settings.impl
+                        </Private-Package>
+                        <Bundle-Activator>
+                            org.apache.sling.settings.impl.Activator
+                        </Bundle-Activator>
+                        <Import-Package>
+                            javax.servlet.*;
+                            org.apache.felix.shell;
+                            org.apache.felix.webconsole;
+                            resolution:=optional, *
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.shell</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+            <version>1.2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/settings/SlingSettingsService.java b/src/main/java/org/apache/sling/settings/SlingSettingsService.java
new file mode 100644
index 0000000..97c8fcc
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/SlingSettingsService.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings;
+
+import java.net.URL;
+
+/**
+ * The <code>SlingSettingsService</code> provides basic Sling settings.
+ *
+ */
+public interface SlingSettingsService {
+
+    /**
+     * The name of the framework property defining the Sling home directory
+     * (value is "sling.home"). This is a Platform file system directory below
+     * which all runtime data, such as the Felix bundle archives, logfiles, the
+     * repository, etc., is located.
+     * <p>
+     * This property is available calling the
+     * <code>BundleContext.getProperty(String)</code> method.
+     *
+     * @see #SLING_HOME_URL
+     */
+    String SLING_HOME = "sling.home";
+
+    /**
+     * The name of the framework property defining the Sling home directory as
+     * an URL (value is "sling.home.url").
+     * <p>
+     * The value of this property is assigned the value of
+     * <code>new File(${sling.home}).toURI().toString()</code> before
+     * resolving the property variables.
+     * <p>
+     * This property is available calling the
+     * <code>BundleContext.getProperty(String)</code> method.
+     *
+     * @see #SLING_HOME
+     */
+    String SLING_HOME_URL = "sling.home.url";
+
+    /**
+     * The identifier of the running Sling instance.
+     */
+    String getSlingId();
+
+    /**
+     * Returns the value of the {@link #SLING_HOME}
+     * property.
+     */
+    String getSlingHomePath();
+
+    /**
+     * Returns the value of the {@link #SLING_HOME_URL}
+     * property.
+     */
+    URL getSlingHome();
+}
diff --git a/src/main/java/org/apache/sling/settings/impl/Activator.java b/src/main/java/org/apache/sling/settings/impl/Activator.java
new file mode 100644
index 0000000..cb3b522
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/Activator.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * This is the bundle activator.
+ * It registers the SlingSettingsService.
+ *
+ */
+public class Activator implements BundleActivator {
+
+    /** The service registration */
+    private ServiceRegistration serviceRegistration;
+
+    /**
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+     */
+    public void start(BundleContext context) throws Exception {
+        final Object service = new SlingSettingsServiceImpl(context);
+        final Dictionary<String, String> props = new Hashtable<String, String>();
+        props.put(Constants.SERVICE_PID, service.getClass().getName());
+        props.put(Constants.SERVICE_DESCRIPTION,
+            "Apache Sling Settings Service");
+        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        serviceRegistration = context.registerService(new String[] {
+                                               SlingSettingsService.class.getName()},
+                                           service, props);
+    }
+
+    /**
+     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+     */
+    public void stop(BundleContext context) throws Exception {
+        if ( serviceRegistration != null ) {
+            serviceRegistration.unregister();
+            serviceRegistration = null;
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
new file mode 100644
index 0000000..b8fdf7f
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.settings.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.UUID;
+
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is the basic implementation of the sling settings service.
+ */
+public class SlingSettingsServiceImpl
+    implements SlingSettingsService {
+
+    /** The logger */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** The sling instance id. */
+    private String slingId;
+
+    /** The sling home */
+    private final String slingHome;
+
+    /** The sling home url */
+    private URL slingHomeUrl;
+
+    private static final String DATA_FILE = "sling.id.file";
+
+    /**
+     * Create the service and search the Sling home urls and
+     * get/create a sling id.
+     * @param context The bundle context
+     */
+    public SlingSettingsServiceImpl(final BundleContext context) {
+        // get sling home and sling home url
+        this.slingHome = context.getProperty(SLING_HOME);
+        final String url = context.getProperty(SLING_HOME_URL);
+        if ( url != null ) {
+            try {
+                this.slingHomeUrl = new URL(url);
+            } catch (MalformedURLException e) {
+                logger.error("Sling home url is not a url: {}", url);
+            }
+        }
+
+        // try to read the id from the id file first
+        final File idFile = context.getDataFile(DATA_FILE);
+        if ( idFile == null ) {
+            // the osgi framework does not support storing something in the file system
+            throw new RuntimeException("Unable to read from bundle data file.");
+        }
+        this.slingId = this.readSlingId(idFile);
+
+        // if we don't have an id yet, we look for the engine bundle for compatibility reasons
+        if ( this.slingId == null ) {
+            final Bundle engineBundle = this.searchEngineBundle(context);
+            if ( engineBundle != null ) {
+                final File engineIdFile = engineBundle.getBundleContext().getDataFile(DATA_FILE);
+                this.slingId = this.readSlingId(engineIdFile);
+                if ( this.slingId != null ) {
+                    // delete the old file
+                    engineIdFile.delete();
+                    this.writeSlingId(idFile, this.slingId);
+                }
+            }
+        }
+
+        // no sling id yet or failure to read file: create an id and store
+        if (slingId == null) {
+            slingId = UUID.randomUUID().toString();
+            this.writeSlingId(idFile, this.slingId);
+        }
+    }
+
+    /** Read the id from a file. */
+    private String readSlingId(final File idFile) {
+        if (idFile.exists() && idFile.length() >= 36) {
+            FileInputStream fin = null;
+            try {
+                fin = new FileInputStream(idFile);
+                final byte[] rawBytes = new byte[36];
+                if (fin.read(rawBytes) == 36) {
+                    final String rawString = new String(rawBytes, "ISO-8859-1");
+
+                    // roundtrip to ensure correct format of UUID value
+                    final String id = UUID.fromString(rawString).toString();
+                    logger.debug("Got Sling ID {} from file {}", id, idFile);
+
+                    return id;
+                }
+            } catch (Throwable t) {
+                logger.error("Failed reading UUID from id file " + idFile
+                        + ", creating new id", t);
+            } finally {
+                if (fin != null) {
+                    try {
+                        fin.close();
+                    } catch (IOException ignore) {
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    /** Write the sling id file. */
+    private void writeSlingId(final File idFile, final String id) {
+        idFile.delete();
+        idFile.getParentFile().mkdirs();
+        FileOutputStream fout = null;
+        try {
+            fout = new FileOutputStream(idFile);
+            fout.write(slingId.getBytes("ISO-8859-1"));
+            fout.flush();
+        } catch (Throwable t) {
+            logger.error("Failed writing UUID to id file " + idFile, t);
+        } finally {
+            if (fout != null) {
+                try {
+                    fout.close();
+                } catch (IOException ignore) {
+                }
+            }
+        }
+    }
+
+    /** Search the engine bundle. */
+    private Bundle searchEngineBundle(final BundleContext bc) {
+        final Bundle[] bundles = bc.getBundles();
+        for(final Bundle b : bundles) {
+            if ( "org.apache.sling.engine".equals(b.getSymbolicName()) ) {
+                return b;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.sling.settings.SlingSettingsService#getSlingId()
+     */
+    public String getSlingId() {
+        return this.slingId;
+    }
+
+    /**
+     * @see org.apache.sling.settings.SlingSettingsService#getSlingHome()
+     */
+    public URL getSlingHome() {
+        return this.slingHomeUrl;
+    }
+
+    /**
+     * @see org.apache.sling.settings.SlingSettingsService#getSlingHomePath()
+     */
+    public String getSlingHomePath() {
+        return this.slingHome;
+    }
+}

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

[sling-org-apache-sling-settings] 10/11: [maven-scm] copy for tag org.apache.sling.settings-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 022e42f954efe225bea0785f25e99efc52ec6618
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Fri Aug 27 06:27:06 2010 +0000

    [maven-scm] copy for tag org.apache.sling.settings-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.settings-1.0.0@990035 13f79535-47bb-0310-9956-ffa450edef68

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