You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/10/02 09:50:51 UTC

svn commit: r1392776 - in /sling/trunk/installer: api/src/main/java/org/apache/sling/installer/api/info/ api/src/main/java/org/apache/sling/installer/api/tasks/ console/src/main/java/org/apache/sling/installer/core/impl/console/ core/src/main/java/org/...

Author: cziegeler
Date: Tue Oct  2 07:50:50 2012
New Revision: 1392776

URL: http://svn.apache.org/viewvc?rev=1392776&view=rev
Log:
SLING-2612 : Add support for excluding artifacts for installation

Modified:
    sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/info/Resource.java
    sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/RegisteredResource.java
    sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/ResourceState.java
    sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java
    sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java

Modified: sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/info/Resource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/info/Resource.java?rev=1392776&r1=1392775&r2=1392776&view=diff
==============================================================================
--- sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/info/Resource.java (original)
+++ sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/info/Resource.java Tue Oct  2 07:50:50 2012
@@ -18,8 +18,10 @@
  */
 package org.apache.sling.installer.api.info;
 
+import org.apache.sling.installer.api.tasks.InstallTask;
 import org.apache.sling.installer.api.tasks.RegisteredResource;
 import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.ResourceTransformer;
 import org.osgi.framework.Version;
 
 
@@ -47,4 +49,14 @@ public interface Resource extends Regist
      * @return -1 if no change , 0 if unknown, > 0 otherwise
      */
     long getLastChange();
+
+    /**
+     * Get the value of an attribute.
+     * Attributes are specific to the resource and are either set
+     * by a {@link ResourceTransformer} or a {@link InstallTask} for
+     * processing.
+     * @param key The name of the attribute
+     * @return The value of the attribute or <code>null</code>
+     */
+    Object getAttribute(String key);
 }

Modified: sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/RegisteredResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/RegisteredResource.java?rev=1392776&r1=1392775&r2=1392776&view=diff
==============================================================================
--- sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/RegisteredResource.java (original)
+++ sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/RegisteredResource.java Tue Oct  2 07:50:50 2012
@@ -30,12 +30,12 @@ import java.util.Dictionary;
 public interface RegisteredResource {
 
     /**
-     * Return the scheme from where the artifact is orginated.
+     * Return the scheme from where the artifact is originated.
      */
     String getScheme();
 
     /**
-     * Return this data's url. The url is the {@link #getScheme}
+     * Return this data's URL. The URL is the {@link #getScheme}
      * followed by a colon, followed by a unique identifier of
      * the resource within the providers space..
      */
@@ -75,12 +75,12 @@ public interface RegisteredResource {
     /**
      * Return the priority of this resource. Priorities are used to decide which
      * resource to install when several are registered for the same OSGi entity
-     * (bundle, config, etc.)
+     * (bundle, configuration, etc.)
      */
     int getPriority();
 
-	/**
-	 * Return the identifier of the OSGi "entity" that this resource
+    /**
+     * Return the identifier of the OSGi "entity" that this resource
      * represents, for example "bundle:SID" where SID is the bundle's
      * symbolic ID, or "config:PID" where PID is config's PID.
      */

Modified: sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/ResourceState.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/ResourceState.java?rev=1392776&r1=1392775&r2=1392776&view=diff
==============================================================================
--- sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/ResourceState.java (original)
+++ sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/ResourceState.java Tue Oct  2 07:50:50 2012
@@ -20,12 +20,25 @@ package org.apache.sling.installer.api.t
 
 /**
  * The state of a resource.
+ * 
+ * The state represents the OSGi installer's view. It might not
+ * reflect the current state of the system. For example if a
+ * bundle is installed through the OSGi installer, it gets the
+ * state "INSTALLED". However if the admin now deinstalls the
+ * bundle through any other way like e.g. the web console,
+ * the artifact still has the state "INSTALLED".
+ * 
+ * The state "INSTALLED" might either mean installed or
+ * if the attribute {@link TaskResource#ATTR_INSTALL_EXCLUDED}
+ * is set on the resource, the resource is excluded from
+ * installation. It gets also marked as "INSTALLED" in order
+ * to mark it as "processed" for the OSGi installer.
  */
 public enum ResourceState {
 
-        INSTALL,        // the resource should be installed
-        UNINSTALL,      // the resource should be uninstalled
-        INSTALLED,      // the resource is installed
-        UNINSTALLED,    // the resource is uninstalled
-        IGNORED         // the resource has been ignored
+    INSTALL,        // the resource should be installed
+    UNINSTALL,      // the resource should be uninstalled
+    INSTALLED,      // the resource is installed
+    UNINSTALLED,    // the resource is uninstalled
+    IGNORED         // the resource has been ignored
 }

Modified: sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java?rev=1392776&r1=1392775&r2=1392776&view=diff
==============================================================================
--- sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java (original)
+++ sling/trunk/installer/api/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java Tue Oct  2 07:50:50 2012
@@ -28,9 +28,24 @@ import org.osgi.framework.Version;
  */
 public interface TaskResource extends RegisteredResource {
 
+    /** Additional installation information in human readable format. */
+    String ATTR_INSTALL_INFO = "org.apache.sling.installer.api.resource.install.info";
+
+    /** If this attribute is set and the resource has the state installed,
+     * it actually means that this resource has been processed but not installed.
+     * For example this can be used to exclude environment specific bundles on non
+     * supported environments etc.
+     * The value of this attribute should contain some human readable reason why this
+     * resource has been excluded.
+     */
+    String ATTR_INSTALL_EXCLUDED = "org.apache.sling.installer.api.resource.install.excluded";
+
     /**
      * Get the value of an attribute.
-     * Attributes include the bundle symbolic name, bundle version, etc.
+     * Attributes are specific to the resource and are either set
+     * by a {@link ResourceTransformer} or a {@link InstallTask} for
+     * processing.
+     * Typical attributes are the bundle symbolic name or bundle version.
      * @param key The name of the attribute
      * @return The value of the attribute or <code>null</code>
      */

Modified: sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java?rev=1392776&r1=1392775&r2=1392776&view=diff
==============================================================================
--- sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java (original)
+++ sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java Tue Oct  2 07:50:50 2012
@@ -42,6 +42,7 @@ import org.apache.sling.installer.api.in
 import org.apache.sling.installer.api.info.ResourceGroup;
 import org.apache.sling.installer.api.tasks.RegisteredResource;
 import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.TaskResource;
 import org.osgi.framework.Constants;
 
 
@@ -89,6 +90,13 @@ public class OsgiInstallerWebConsolePlug
         return rsrc.getURL();
     }
 
+    private String getState(final Resource rsrc) {
+        if ( rsrc.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null ) {
+            return "EXCLUDED";
+        }
+        return rsrc.getState().toString();
+    }
+
     private String getInfo(final RegisteredResource rsrc) {
         return rsrc.getDigest() + '/' + String.valueOf(rsrc.getPriority());
     }
@@ -109,7 +117,7 @@ public class OsgiInstallerWebConsolePlug
 
     @Override
     public void service(final ServletRequest req, final ServletResponse res)
-    throws IOException {
+            throws IOException {
         final PrintWriter pw = res.getWriter();
 
         final InstallationState state = this.installer.getInstallationState();
@@ -167,7 +175,7 @@ public class OsgiInstallerWebConsolePlug
                 pw.print("</td><td>");
                 pw.print(getURL(first));
                 pw.print("</td><td>");
-                pw.print(first.getState());
+                pw.print(getState(first));
                 if ( first.getState() == ResourceState.INSTALLED ) {
                     final long lastChange = first.getLastChange();
                     if ( lastChange > 0 ) {
@@ -176,13 +184,21 @@ public class OsgiInstallerWebConsolePlug
                     }
                 }
                 pw.print("</td></tr>");
+                if ( first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null ) {
+                    pw.printf("<tr><td></td><td colspan='2'>%s</td><td></td></tr>",
+                            first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED));
+                }
+                if ( first.getAttribute(TaskResource.ATTR_INSTALL_INFO) != null ) {
+                    pw.printf("<tr><td></td><td colspan='2'>%s</td><td></td></tr>",
+                            first.getAttribute(TaskResource.ATTR_INSTALL_INFO));
 
+                }
                 while ( iter.hasNext() ) {
                     final Resource resource = iter.next();
                     pw.printf("<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>",
-                        getInfo(resource),
-                        getURL(resource),
-                        resource.getState());
+                            getInfo(resource),
+                            getURL(resource),
+                            resource.getState());
                 }
             }
         }
@@ -205,8 +221,8 @@ public class OsgiInstallerWebConsolePlug
                 rt = registeredResource.getType();
             }
             pw.printf("<tr><td>%s</td><td>%s</td></tr>",
-                getInfo(registeredResource),
-                registeredResource.getURL());
+                    getInfo(registeredResource),
+                    registeredResource.getURL());
         }
         if ( rt != null ) {
             pw.println("</tbody></table>");
@@ -256,13 +272,22 @@ public class OsgiInstallerWebConsolePlug
                         getEntityId(first, group.getAlias()),
                         getInfo(first),
                         getURL(first),
-                        first.getState());
+                        getState(first));
+                if ( first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null ) {
+                    pw.printf("  : %s",
+                            first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED));
+                }
+                if ( first.getAttribute(TaskResource.ATTR_INSTALL_INFO) != null ) {
+                    pw.printf("  : %s",
+                            first.getAttribute(TaskResource.ATTR_INSTALL_INFO));
+
+                }
                 while ( iter.hasNext() ) {
                     final Resource resource = iter.next();
                     pw.printf("  - %s, %s, %s%n",
-                        getInfo(resource),
-                        getURL(resource),
-                        resource.getState());
+                            getInfo(resource),
+                            getURL(resource),
+                            resource.getState());
                 }
             }
         }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1392776&r1=1392775&r2=1392776&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java Tue Oct  2 07:50:50 2012
@@ -74,7 +74,7 @@ import org.slf4j.LoggerFactory;
  *  the main list at the end of the cycle.
  */
 public class OsgiInstallerImpl
-    implements OsgiInstaller, ResourceChangeListener, RetryHandler, InfoProvider, Runnable {
+implements OsgiInstaller, ResourceChangeListener, RetryHandler, InfoProvider, Runnable {
 
     /** The logger */
     private final Logger logger =  LoggerFactory.getLogger(this.getClass());
@@ -318,7 +318,7 @@ public class OsgiInstallerImpl
      * The new versions has a set resource type.
      */
     private List<InternalResource> createResources(final String scheme,
-                                                   final InstallableResource[] resources) {
+            final InstallableResource[] resources) {
         checkScheme(scheme);
         List<InternalResource> createdResources = null;
         if ( resources != null && resources.length > 0 ) {
@@ -360,8 +360,8 @@ public class OsgiInstallerImpl
      * @see org.apache.sling.installer.api.OsgiInstaller#updateResources(java.lang.String, org.apache.sling.installer.api.InstallableResource[], java.lang.String[])
      */
     public void updateResources(final String scheme,
-                                final InstallableResource[] resources,
-                                final String[] ids) {
+            final InstallableResource[] resources,
+            final String[] ids) {
         this.listener.start();
         try {
             final List<InternalResource> updatedResources = this.createResources(scheme, resources);
@@ -497,7 +497,7 @@ public class OsgiInstallerImpl
                             if ( !found) {
                                 logger.debug("Resource {} seems to be removed.", r);
                                 if ( first && (r.getState() == ResourceState.INSTALLED
-                                           ||  r.getState() == ResourceState.INSTALL) ) {
+                                        ||  r.getState() == ResourceState.INSTALL) ) {
                                     ((RegisteredResourceImpl)r).setState(ResourceState.UNINSTALL);
                                 } else {
                                     toRemove.add(r);
@@ -776,7 +776,7 @@ public class OsgiInstallerImpl
                     // check if this transformer has already been invoked for the resource
                     final String transformers = (String)((RegisteredResourceImpl)resource).getAttribute(ResourceTransformer.class.getName());
                     if ( id == null ||
-                         (transformers != null && transformers.contains(":" + id + ':'))) {
+                            (transformers != null && transformers.contains(":" + id + ':'))) {
                         continue;
                     }
                     final ResourceTransformer transformer = (ResourceTransformer) this.transformerTracker.getService(reference);
@@ -855,7 +855,7 @@ public class OsgiInstallerImpl
                         final InputStream localIS = data.getInputStream();
                         try {
                             final UpdateResult result = (localIS == null ? handler.handleUpdate(resourceType, entityId, tr.getURL(), data.getDictionary(), attributes)
-                                                                         : handler.handleUpdate(resourceType, entityId, tr.getURL(), localIS, attributes));
+                                    : handler.handleUpdate(resourceType, entityId, tr.getURL(), localIS, attributes));
                             if ( result != null ) {
                                 if ( !result.getURL().equals(tr.getURL()) && !result.getResourceIsMoved() ) {
                                     // resource has been added!
@@ -919,7 +919,7 @@ public class OsgiInstallerImpl
                         final InputStream localIS = data.getInputStream();
                         try {
                             final UpdateResult result = (localIS == null ? handler.handleUpdate(resourceType, entityId, null, data.getDictionary(), attributes)
-                                                                         : handler.handleUpdate(resourceType, entityId, null, localIS, attributes));
+                                    : handler.handleUpdate(resourceType, entityId, null, localIS, attributes));
                             if ( result != null ) {
                                 final InternalResource internalResource = new InternalResource(result.getScheme(),
                                         result.getResourceId(),
@@ -1124,6 +1124,10 @@ public class OsgiInstallerImpl
                             public long getLastChange() {
                                 return ((RegisteredResourceImpl)tr).getLastChange();
                             }
+
+                            public Object getAttribute(final String key) {
+                                return tr.getAttribute(key);
+                            }
                         });
                     }
                     final ResourceGroup rg = new ResourceGroup() {