Author: cziegeler
Date: Fri Aug 13 09:22:23 2010
New Revision: 985140
URL: http://svn.apache.org/viewvc?rev=985140&view=rev
Log:
SLING-1460 : Move SlingSettingsService to new Settings bundle
Added:
sling/trunk/bundles/extensions/settings/
sling/trunk/bundles/extensions/settings/pom.xml (with props)
sling/trunk/bundles/extensions/settings/src/
sling/trunk/bundles/extensions/settings/src/main/
sling/trunk/bundles/extensions/settings/src/main/java/
sling/trunk/bundles/extensions/settings/src/main/java/org/
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
(contents, props changed)
- copied, changed from r985114,
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/services/SlingSettingsService.java
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
(with props)
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
(with props)
Removed:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/services/SlingSettingsService.java
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java
sling/trunk/bundles/engine/pom.xml
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingSettingsService.java
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingSettingsServiceImpl.java
sling/trunk/bundles/extensions/event/pom.xml
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
sling/trunk/launchpad/builder/src/main/bundles/list.xml
sling/trunk/pom.xml
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
---
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java
(original)
+++
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java
Fri Aug 13 09:22:23 2010
@@ -357,36 +357,6 @@ public class SlingConstants {
public static final String PROPERTY_ADAPTER_CLASSES = "adapters";
/**
- * 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
- * @since 2.1
- */
- public static final 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
- * @since 2.1
- */
- public static final String SLING_HOME_URL = "sling.home.url";
-
- /**
* The name of the request attribute providing the name of the currently
* executing servlet (value is "sling.core.current.servletName"). This
* attribute is set immediately before calling the
Modified: sling/trunk/bundles/engine/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/pom.xml?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
--- sling/trunk/bundles/engine/pom.xml (original)
+++ sling/trunk/bundles/engine/pom.xml Fri Aug 13 09:22:23 2010
@@ -103,6 +103,12 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.settings</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.auth</artifactId>
<version>0.9.0-SNAPSHOT</version>
<scope>provided</scope>
Modified:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingSettingsService.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingSettingsService.java?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
---
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingSettingsService.java
(original)
+++
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingSettingsService.java
Fri Aug 13 09:22:23 2010
@@ -20,7 +20,7 @@ package org.apache.sling.engine;
/**
* The <code>SlingSettingsService</code> provides basic Sling settings.
- * @deprecated Use the {...@link
org.apache.sling.api.services.SlingSettingsService}
+ * @deprecated Use the {...@link
org.apache.sling.settings.SlingSettingsService}
*/
@Deprecated
public interface SlingSettingsService {
Modified:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
---
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
(original)
+++
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
Fri Aug 13 09:22:23 2010
@@ -18,40 +18,21 @@
*/
package org.apache.sling.engine.impl;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.apache.sling.engine.SlingSettingsService;
import org.apache.sling.engine.impl.request.RequestHistoryConsolePlugin;
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 for the Sling engine.
- * It registers the SlingSettingsService.
+ * It registers the web console plugin
*
*/
public class EngineBundleActivator 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[] {
-
org.apache.sling.api.services.SlingSettingsService.class.getName(),
-
SlingSettingsService.class.getName()},
- service, props);
try {
RequestHistoryConsolePlugin.initPlugin(context);
} catch (Throwable ignore) {
@@ -63,10 +44,6 @@ public class EngineBundleActivator imple
* @see
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- if ( serviceRegistration != null ) {
- serviceRegistration.unregister();
- serviceRegistration = null;
- }
try {
RequestHistoryConsolePlugin.destroyPlugin();
} catch (Throwable ignore) {
Modified:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingSettingsServiceImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingSettingsServiceImpl.java?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
---
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingSettingsServiceImpl.java
(original)
+++
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingSettingsServiceImpl.java
Fri Aug 13 09:22:23 2010
@@ -18,119 +18,24 @@
*/
package org.apache.sling.engine.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.api.SlingConstants;
import org.apache.sling.engine.SlingSettingsService;
-import org.osgi.framework.BundleContext;
-import org.slf4j.LoggerFactory;
/**
- * This is the basic implementation of the sling settings service.
+ * The implementation of the settings service has moved to the
+ * settings module. This is just a wrapper for compatibility.
+ * @scr.component metatype=false
+ * @scr.service
*/
public class SlingSettingsServiceImpl
- implements SlingSettingsService,
org.apache.sling.api.services.SlingSettingsService {
-
- /** The logger */
- private org.slf4j.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;
+ implements SlingSettingsService {
- public SlingSettingsServiceImpl(final BundleContext context) {
- this.slingHome = context.getProperty(SlingConstants.SLING_HOME);
- final String url = context.getProperty(SlingConstants.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
- File idFile = context.getDataFile("sling.id.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.");
- }
- if (idFile.exists() && idFile.length() >= 36) {
- FileInputStream fin = null;
- try {
- fin = new FileInputStream(idFile);
- byte[] rawBytes = new byte[36];
- if (fin.read(rawBytes) == 36) {
- String rawString = new String(rawBytes, "ISO-8859-1");
-
- // roundtrip to ensure correct format of UUID value
- slingId = UUID.fromString(rawString).toString();
- }
- } 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) {
- }
- }
- }
- }
-
- // no sling id yet or failure to read file: create an id and store
- if (slingId == null) {
- slingId = UUID.randomUUID().toString();
-
- 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) {
- }
- }
- }
- }
- }
+ /** @scr.reference */
+ private org.apache.sling.settings.SlingSettingsService settingsService;
/**
- * @see org.apache.sling.api.services.SlingSettingsService#getSlingId()
+ * @see org.apache.sling.engine.SlingSettingsService#getSlingId()
*/
public String getSlingId() {
- return this.slingId;
- }
-
- /**
- * @see org.apache.sling.api.services.SlingSettingsService#getSlingHome()
- */
- public URL getSlingHome() {
- return this.slingHomeUrl;
- }
-
- /**
- * @see
org.apache.sling.api.services.SlingSettingsService#getSlingHomePath()
- */
- public String getSlingHomePath() {
- return this.slingHome;
+ return this.settingsService.getSlingId();
}
}
Modified: sling/trunk/bundles/extensions/event/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Fri Aug 13 09:22:23 2010
@@ -123,8 +123,8 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.api</artifactId>
- <version>2.0.9-SNAPSHOT</version>
+ <artifactId>org.apache.sling.settings</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified:
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
(original)
+++
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
Fri Aug 13 09:22:23 2010
@@ -33,12 +33,12 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.api.services.SlingSettingsService;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.event.JobStatusProvider;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceUtil;
+import org.apache.sling.settings.SlingSettingsService;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
Modified:
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
(original)
+++
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
Fri Aug 13 09:22:23 2010
@@ -29,11 +29,11 @@ import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.apache.sling.api.services.SlingSettingsService;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.threads.ModifiableThreadPoolConfig;
import org.apache.sling.commons.threads.ThreadPoolConfig;
import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.settings.SlingSettingsService;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Added: sling/trunk/bundles/extensions/settings/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/pom.xml?rev=985140&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/settings/pom.xml (added)
+++ sling/trunk/bundles/extensions/settings/pom.xml Fri Aug 13 09:22:23 2010
@@ -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>
Propchange: sling/trunk/bundles/extensions/settings/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/settings/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: sling/trunk/bundles/extensions/settings/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
(from r985114,
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/services/SlingSettingsService.java)
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java?p2=sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java&p1=sling/trunk/bundles/api/src/main/java/org/apache/sling/api/services/SlingSettingsService.java&r1=985114&r2=985140&rev=985140&view=diff
==============================================================================
---
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/services/SlingSettingsService.java
(original)
+++
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
Fri Aug 13 09:22:23 2010
@@ -16,30 +16,57 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.api.services;
+package org.apache.sling.settings;
import java.net.URL;
/**
* The <code>SlingSettingsService</code> provides basic Sling settings.
*
- * @since 2.1
*/
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
org.apache.sling.api.SlingConstants#SLING_HOME}
+ * Returns the value of the {...@link #SLING_HOME}
* property.
*/
String getSlingHomePath();
/**
- * Returns the value of the {...@link
org.apache.sling.api.SlingConstants#SLING_HOME_URL}
+ * Returns the value of the {...@link #SLING_HOME_URL}
* property.
*/
URL getSlingHome();
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java?rev=985140&view=auto
==============================================================================
---
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
(added)
+++
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
Fri Aug 13 09:22:23 2010
@@ -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;
+ }
+ }
+}
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java?rev=985140&view=auto
==============================================================================
---
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
(added)
+++
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
Fri Aug 13 09:22:23 2010
@@ -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;
+ }
+}
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Fri Aug 13 09:22:23
2010
@@ -45,6 +45,11 @@
</bundle>
<bundle>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.settings</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </bundle>
+ <bundle>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.auth</artifactId>
<version>0.9.0-SNAPSHOT</version>
</bundle>
Modified: sling/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/pom.xml?rev=985140&r1=985139&r2=985140&view=diff
==============================================================================
--- sling/trunk/pom.xml (original)
+++ sling/trunk/pom.xml Fri Aug 13 09:22:23 2010
@@ -126,6 +126,7 @@
<module>bundles/extensions/formauth</module>
<module>bundles/extensions/httpauth</module>
<module>bundles/extensions/openidauth</module>
+ <module>bundles/extensions/settings</module>
<module>bundles/extensions/threaddump</module>
<module>bundles/extensions/webconsolebranding</module>
<module>bundles/extensions/groovy</module>