incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1127807 - in /sling/trunk/installer/core: ./ src/main/java/org/apache/sling/installer/core/impl/tasks/
Date Thu, 26 May 2011 07:17:38 GMT
Author: cziegeler
Date: Thu May 26 07:17:38 2011
New Revision: 1127807

URL: http://svn.apache.org/viewvc?rev=1127807&view=rev
Log:
SLING-2060 : Refresh bundles with optional dependencies if such dependency is installed

Added:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
  (with props)
Modified:
    sling/trunk/installer/core/pom.xml
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1127807&r1=1127806&r2=1127807&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Thu May 26 07:17:38 2011
@@ -66,7 +66,8 @@
 						</Private-Package>
                         <Embed-Dependency>
                             org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.*",
-                            org.osgi.compendium;inline="org/osgi/util/tracker/*"
+                            org.osgi.compendium;inline="org/osgi/util/tracker/*",
+                            org.apache.sling.commons.osgi;inline="org/apache/sling/commons/osgi/ManifestHeader*.*"
                         </Embed-Dependency>
 					</instructions>
 				</configuration>
@@ -135,6 +136,12 @@
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.0.6</version>
+            <scope>provided</scope>
+        </dependency>
       <!-- We use a class from the config admin implementation to read config files -->
         <dependency>
             <groupId>org.apache.felix</groupId>

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java?rev=1127807&r1=1127806&r2=1127807&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java
Thu May 26 07:17:38 2011
@@ -84,6 +84,7 @@ public class BundleInstallTask extends A
             // mark this resource as installed and to be started
             this.getResource().setAttribute(BundleTaskCreator.ATTR_START, "true");
             ctx.addTaskToCurrentCycle(new BundleStartTask(getResourceGroup(), b.getBundleId(),
this.creator));
+            ctx.addTaskToNextCycle(new RefreshOptionalPackagesTask(this.creator));
         } catch (Exception ex) {
             // if something goes wrong we simply try it again
             this.getLogger().debug("Exception during install of bundle " + this.getResource()
+ " : " + ex.getMessage() + ". Retrying later.", ex);

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java?rev=1127807&r1=1127806&r2=1127807&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
Thu May 26 07:17:38 2011
@@ -89,7 +89,8 @@ public class BundleUpdateTask extends Ab
             } else {
                 this.setFinishedState(ResourceState.INSTALLED);
             }
-            ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.creator));
+            ctx.addTaskToNextCycle(new SynchronousRefreshPackagesTask(this.creator));
+            ctx.addTaskToCurrentCycle(new RefreshOptionalPackagesTask(this.creator));
             this.getLogger().debug("Bundle updated: {}/{}", b.getBundleId(), b.getSymbolicName());
     	} catch (Exception e) {
             if ( !canRetry ) {

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java?rev=1127807&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
(added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
Thu May 26 07:17:38 2011
@@ -0,0 +1,132 @@
+/*
+ * 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.core.impl.tasks;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.apache.sling.installer.core.impl.AbstractInstallTask;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * Checks for bundles with optional imports that are not wired.
+ */
+public class RefreshOptionalPackagesTask extends AbstractInstallTask {
+
+    private static final String REFRESH_PACKAGES_ORDER = "80-";
+
+    private static final String DIRECTIVE = "resolution";
+    private static final String DIRECTIVE_OPTIONAL = "optional";
+    private static final String MARKER = DIRECTIVE + ":=" + DIRECTIVE_OPTIONAL;
+
+    /** Tracker for the package admin. */
+    private final BundleTaskCreator bundleTaskCreator;
+
+	public RefreshOptionalPackagesTask(final BundleTaskCreator bundleTaskCreator) {
+	    super(null);
+	    this.bundleTaskCreator = bundleTaskCreator;
+	}
+
+	@Override
+	public String getSortKey() {
+		return REFRESH_PACKAGES_ORDER;
+	}
+
+	@Override
+	public String toString() {
+		return getClass().getSimpleName();
+	}
+
+    private PackageAdmin getPackageAdmin() {
+        return this.bundleTaskCreator.getPackageAdmin();
+    }
+
+    /**
+     * @see org.apache.sling.installer.api.tasks.InstallTask#execute(org.apache.sling.installer.api.tasks.InstallationContext)
+     */
+    public void execute(final InstallationContext ctx) {
+        if ( true ) {
+            return;
+        }
+        getLogger().info("** Invoking refresh optional packages!");
+        final PackageAdmin packageAdmin = this.getPackageAdmin();
+
+        ExportedPackage[] exports = null;
+        final List<Bundle> refreshBundles = new ArrayList<Bundle>();
+        final Bundle[] bundles = this.bundleTaskCreator.getBundleContext().getBundles();
+        for(final Bundle bundle : bundles) {
+            if ( bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.ACTIVE
) {
+                final String importHeader = (String)bundle.getHeaders().get(Constants.IMPORT_PACKAGE);
+                if ( importHeader != null && importHeader.contains(MARKER) ) {
+                    boolean needsRefresh = false;
+                    final ManifestHeader mf = ManifestHeader.parse(importHeader);
+                    for(final ManifestHeader.Entry entry : mf.getEntries()) {
+                        if ( DIRECTIVE_OPTIONAL.equals(entry.getDirectiveValue(DIRECTIVE))
) {
+                            final String pkgName = entry.getValue();
+                            getLogger().info("Found optional dependency {} in bundle {}",
pkgName, bundle.getSymbolicName());
+                            if ( exports == null ) {
+                                exports = packageAdmin.getExportedPackages( ( Bundle ) null
);
+                                // just a sanity check
+                                if ( exports == null ) {
+                                    exports = new ExportedPackage[0];
+                                }
+                            }
+                            boolean wiringFound = false;
+                            boolean packageFound = false;
+                            for(final ExportedPackage ep : exports) {
+                                if ( ep.getName().equals(pkgName) ) {
+                                    packageFound = true;
+                                    final Bundle[] importingBundles = ep.getImportingBundles();
+                                    for(final Bundle ib : importingBundles) {
+                                        if ( ib.getBundleId() == bundle.getBundleId() ) {
+                                            wiringFound = true;
+                                            break;
+                                        }
+                                    }
+                                }
+                                if ( wiringFound ) {
+                                    break;
+                                }
+                            }
+                            if ( !wiringFound && packageFound ) {
+                                getLogger().info("Found unresolved optional dependency {}
in bundle {} which might now be resolvable", pkgName, bundle.getSymbolicName());
+                                needsRefresh = true;
+                                break;
+                            }
+                        }
+                    }
+
+                    if ( needsRefresh ) {
+                        refreshBundles.add(bundle);
+                    }
+                }
+            }
+        }
+        if ( refreshBundles.size() > 0 ) {
+            getLogger().info("** Refreshing bundles {}", refreshBundles);
+            packageAdmin.refreshPackages(refreshBundles.toArray(new Bundle[refreshBundles.size()]));
+        }
+        getLogger().info("** Finished refresh optional packages!");
+	}
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java?rev=1127807&r1=1127806&r2=1127807&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java
Thu May 26 07:17:38 2011
@@ -116,6 +116,5 @@ public class SynchronousRefreshPackagesT
         } finally {
         	this.bundleTaskCreator.getBundleContext().removeFrameworkListener(this);
         }
-        return;
 	}
 }



Mime
View raw message