incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r996445 - in /sling/trunk/installer/osgi/installer/src: main/java/org/apache/sling/osgi/installer/impl/ main/java/org/apache/sling/osgi/installer/impl/config/ test/java/org/apache/sling/osgi/installer/impl/ test/java/org/apache/sling/osgi/i...
Date Mon, 13 Sep 2010 08:06:24 GMT
Author: cziegeler
Date: Mon Sep 13 08:06:24 2010
New Revision: 996445

URL: http://svn.apache.org/viewvc?rev=996445&view=rev
Log:
SLING-1737 : Add state management for resources

Removed:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigurationPid.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
Mon Sep 13 08:06:24 2010
@@ -41,9 +41,6 @@ public interface RegisteredResource exte
         IGNORED
     }
 
-    /** Attribute key: configuration pid */
-    String CONFIG_PID_ATTRIBUTE = "config.pid";
-
     String getScheme();
 
     /**

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
Mon Sep 13 08:06:24 2010
@@ -44,10 +44,11 @@ import java.util.jar.Manifest;
 
 import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.sling.osgi.installer.InstallableResource;
-import org.apache.sling.osgi.installer.impl.config.ConfigurationPid;
+import org.apache.sling.osgi.installer.impl.config.ConfigTaskCreator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 /**
  * Implementation of the registered resource
@@ -160,16 +161,39 @@ public class RegisteredResourceImpl
             }
 		} else if ( resourceType.equals(InstallableResource.TYPE_CONFIG)) {
             this.dataFile = null;
-            final ConfigurationPid pid = new ConfigurationPid(id);
-            entity = ENTITY_CONFIG_PREFIX + pid.getCompositePid();
-            attributes.put(CONFIG_PID_ATTRIBUTE, pid);
             this.digest = (digest != null && digest.length() > 0 ? digest : id
+ ":" + computeDigest(dict));
+            // remove path
+            String pid = id;
+            final int slashPos = pid.lastIndexOf('/');
+            if ( slashPos != -1 ) {
+                pid = pid.substring(slashPos + 1);
+            }
+            // remove extension
+            if ( RegisteredResourceImpl.isConfigExtension(RegisteredResourceImpl.getExtension(pid)))
{
+                final int lastDot = pid.lastIndexOf('.');
+                pid = pid.substring(0, lastDot);
+            }
+            // split pid and factory pid alias
+            final String factoryPid;
+            final String configPid;
+            int n = pid.indexOf('-');
+            if (n > 0) {
+                configPid = pid.substring(n + 1);
+                factoryPid = pid.substring(0, n);
+            } else {
+                factoryPid = null;
+                configPid = pid;
+            }
+            entity = ENTITY_CONFIG_PREFIX + (factoryPid == null ? "" : factoryPid + ".")
+ configPid;
+
+            attributes.put(Constants.SERVICE_PID, configPid);
             // Add pseudo-properties
-            this.dictionary.put(ConfigurationPid.CONFIG_PATH_KEY, this.getURL());
+            this.dictionary.put(ConfigTaskCreator.CONFIG_PATH_KEY, this.getURL());
 
             // Factory?
-            if (pid.getFactoryPid() != null) {
-                this.dictionary.put(ConfigurationPid.ALIAS_KEY, pid.getFactoryPid());
+            if (factoryPid != null) {
+                attributes.put(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
+                this.dictionary.put(ConfigTaskCreator.ALIAS_KEY, configPid);
             }
 
 		} else {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java
Mon Sep 13 08:06:24 2010
@@ -39,10 +39,11 @@ abstract class AbstractConfigTask extend
     protected static final Set<String> ignoredProperties = new HashSet<String>();
     static {
         ignoredProperties.add("service.pid");
-        ignoredProperties.add(ConfigurationPid.CONFIG_PATH_KEY);
+        ignoredProperties.add(ConfigTaskCreator.CONFIG_PATH_KEY);
     }
 
-    protected final ConfigurationPid pid;
+    protected final String configPid;
+    protected final String factoryPid;
 
     /** Tracker for the configuration admin. */
     private final ServiceTracker configAdminServiceTracker;
@@ -50,7 +51,8 @@ abstract class AbstractConfigTask extend
     AbstractConfigTask(final RegisteredResource r, final ServiceTracker configAdminServiceTracker)
{
         super(r);
         this.configAdminServiceTracker = configAdminServiceTracker;
-        this.pid = (ConfigurationPid)r.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE);
+        this.configPid = (String)r.getAttributes().get(Constants.SERVICE_PID);
+        this.factoryPid = (String)r.getAttributes().get(ConfigurationAdmin.SERVICE_FACTORYPID);
     }
 
     /**
@@ -60,18 +62,20 @@ abstract class AbstractConfigTask extend
         return (ConfigurationAdmin)this.configAdminServiceTracker.getService();
     }
 
+    protected String getCompositePid() {
+        return (factoryPid == null ? "" : factoryPid + ".") + configPid;
+    }
 
     protected Configuration getConfiguration(final ConfigurationAdmin ca,
-                                             final ConfigurationPid cp,
                                              final boolean createIfNeeded)
     throws IOException, InvalidSyntaxException {
         Configuration result = null;
 
-        if (cp.getFactoryPid() == null) {
+        if (this.factoryPid == null) {
             if ( createIfNeeded ) {
-                result = ca.getConfiguration(cp.getConfigPid(), null);
+                result = ca.getConfiguration(this.configPid, null);
             } else {
-                String filter = "(" + Constants.SERVICE_PID + "=" + cp.getConfigPid() + ")";
+                String filter = "(" + Constants.SERVICE_PID + "=" + this.configPid + ")";
                 Configuration[] configs = ca.listConfigurations( filter );
                 if ( configs != null && configs.length > 0 ) {
                     result = configs[0];
@@ -79,13 +83,13 @@ abstract class AbstractConfigTask extend
             }
         } else {
             Configuration configs[] = ca.listConfigurations(
-                "(|(" + ConfigurationPid.ALIAS_KEY
-                + "=" + cp.getFactoryPid() + ")(.alias_factory_pid=" + cp.getFactoryPid()
+                "(|(" + ConfigurationAdmin.SERVICE_FACTORYPID
+                + "=" + this.factoryPid + ")(" + ConfigTaskCreator.ALIAS_KEY + "=" + configPid
                 + "))");
 
             if (configs == null || configs.length == 0) {
                 if (createIfNeeded) {
-                    result = ca.createFactoryConfiguration(cp.getConfigPid(), null);
+                    result = ca.createFactoryConfiguration(this.factoryPid, null);
                 }
             } else {
                 result = configs[0];

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
Mon Sep 13 08:06:24 2010
@@ -37,7 +37,7 @@ public class ConfigInstallTask extends A
 
     @Override
     public String getSortKey() {
-        return CONFIG_INSTALL_ORDER + pid.getCompositePid();
+        return CONFIG_INSTALL_ORDER + getCompositePid();
     }
 
     @SuppressWarnings("unchecked")
@@ -53,10 +53,10 @@ public class ConfigInstallTask extends A
         // update if the new one has the same values.
         boolean created = false;
         try {
-            Configuration config = getConfiguration(ca, pid, false);
+            Configuration config = getConfiguration(ca, false);
             if (config == null) {
                 created = true;
-                config = getConfiguration(ca, pid, true);
+                config = getConfiguration(ca, true);
             } else {
     			if (isSameData(config.getProperties(), getResource().getDictionary())) {
     			    this.getLogger().debug("Configuration {} already installed with same data, update
request ignored: {}",

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
Mon Sep 13 08:06:24 2010
@@ -36,7 +36,7 @@ public class ConfigRemoveTask extends Ab
 
     @Override
     public String getSortKey() {
-        return CONFIG_REMOVE_ORDER + pid.getCompositePid();
+        return CONFIG_REMOVE_ORDER + getCompositePid();
     }
 
     /**
@@ -51,21 +51,21 @@ public class ConfigRemoveTask extends Ab
         }
 
         try {
-            final Configuration cfg = getConfiguration(ca, pid, false);
+            final Configuration cfg = getConfiguration(ca, false);
             if (cfg == null) {
-                this.getLogger().debug("Cannot delete config , pid={} not found, ignored
({})", pid, getResource());
+                this.getLogger().debug("Cannot delete config , pid={} not found, ignored
({})", getCompositePid(), getResource());
                 this.getResource().setState(RegisteredResource.State.IGNORED);
             } else {
-                if ( cfg.getProperties().get(ConfigurationPid.CONFIG_PATH_KEY) == null )
{
+                if ( cfg.getProperties().get(ConfigTaskCreator.CONFIG_PATH_KEY) == null )
{
                     this.getLogger().debug("Configuration has not been installed by this
resource. Not removing!");
                     this.getResource().setState(RegisteredResource.State.IGNORED);
                 } else if ( !isSameData(cfg.getProperties(), this.getResource().getDictionary())
) {
                     this.getLogger().debug("Configuration has changed after is has been installed.
Not removing!");
                     this.getResource().setState(RegisteredResource.State.IGNORED);
                 } else {
-                    this.getLogger().debug("Deleting config {} ({})", pid, getResource());
+                    this.getLogger().debug("Deleting config {} ({})", getCompositePid(),
getResource());
                     cfg.delete();
-                    ctx.log("Deleted configuration {} from resource {}", pid, getResource());
+                    ctx.log("Deleted configuration {} from resource {}", getCompositePid(),
getResource());
                     this.getResource().setState(RegisteredResource.State.UNINSTALLED);
                 }
             }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java
Mon Sep 13 08:06:24 2010
@@ -29,6 +29,10 @@ import org.osgi.util.tracker.ServiceTrac
  */
 public class ConfigTaskCreator {
 
+    public static final String ALIAS_KEY = "org.apache.sling.installer.osgi.factoryaliaspid";
+    public static final String CONFIG_PATH_KEY = "org.apache.sling.installer.osgi.path";
+
+
     /** Interface of the config admin */
     private static String CONFIG_ADMIN_SERVICE_NAME = ConfigurationAdmin.class.getName();
 

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java?rev=996445&r1=996444&r2=996445&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
Mon Sep 13 08:06:24 2010
@@ -72,7 +72,7 @@ public class RegisteredResourceTest {
             final Dictionary<String, Object> d = r.getDictionary();
             assertNotNull("CONFIG resource provides a Dictionary", d);
             assertEquals("CONFIG resource dictionary has three properties", 3, d.size());
-            assertNotNull("CONFIG resource has a pid attribute", r.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE));
+            assertNotNull("CONFIG resource has a pid attribute", r.getAttributes().get(Constants.SERVICE_PID));
         }
     }
 



Mime
View raw message