Author: cziegeler
Date: Thu Oct 20 09:35:14 2011
New Revision: 1186689

URL: http://svn.apache.org/viewvc?rev=1186689&view=rev
Log:
SLING-2252 : If a config is removed and a different config is to be installed 
perform an update 

Added:
    
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
   (with props)
Modified:
    
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java

Added: 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java?rev=1186689&view=auto
==============================================================================
--- 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
 (added)
+++ 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
 Thu Oct 20 09:35:14 2011
@@ -0,0 +1,51 @@
+/*
+ * 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.installer.factories.configuration.impl;
+
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.TaskResourceGroup;
+
+/**
+ * Simple general task, setting the state of a registered resource.
+ */
+public class ChangeStateTask extends AbstractConfigTask {
+
+    private static final String ORDER = "00-";
+
+    private final ResourceState state;
+
+    public ChangeStateTask(final TaskResourceGroup r,
+                           final ResourceState s) {
+        super(r, null);
+        this.state = s;
+    }
+
+    /**
+     * @see 
org.apache.sling.installer.api.tasks.InstallTask#execute(org.apache.sling.installer.api.tasks.InstallationContext)
+     */
+    public void execute(final InstallationContext ctx) {
+        this.setFinishedState(this.state);
+    }
+
+    @Override
+    public String getSortKey() {
+        return ORDER + getResource().getEntityId();
+    }
+}

Propchange: 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ChangeStateTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java?rev=1186689&r1=1186688&r2=1186689&view=diff
==============================================================================
--- 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
 (original)
+++ 
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
 Thu Oct 20 09:35:14 2011
@@ -69,7 +69,15 @@ public class ConfigTaskCreator
 
         final InstallTask result;
                if (toActivate.getState() == ResourceState.UNINSTALL) {
-                   result = new ConfigRemoveTask(group, this.configAdmin);
+            // if this is an uninstall, check if we have to install an older 
version
+            // in this case we should do an update instead of 
uninstall/install (!)
+            final TaskResource second = group.getNextActiveResource();
+            if ( second != null &&
+                ( second.getState() == ResourceState.IGNORED || 
second.getState() == ResourceState.INSTALLED || second.getState() == 
ResourceState.INSTALL ) ) {
+                result = new ChangeStateTask(group, ResourceState.UNINSTALLED);
+            } else {
+                result = new ConfigRemoveTask(group, this.configAdmin);
+            }
                } else {
                result = new ConfigInstallTask(group, this.configAdmin);
                }


Reply via email to