Author: jm
Date: 2012-10-29 13:32:13 -0700 (Mon, 29 Oct 2012)
New Revision: 30719

Modified:
   core3/impl/trunk/app-impl/pom.xml
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
Log:
Fixes #1548, #1554: app-impl now defers initialization until framework reaches 
start-level 200.  Removed dependency on internal Karaf JARs because it caused 
conflicts with OSGi APIs.

Modified: core3/impl/trunk/app-impl/pom.xml
===================================================================
--- core3/impl/trunk/app-impl/pom.xml   2012-10-29 19:32:41 UTC (rev 30718)
+++ core3/impl/trunk/app-impl/pom.xml   2012-10-29 20:32:13 UTC (rev 30719)
@@ -119,15 +119,9 @@
                </dependency>
 
                <dependency>
-                       <groupId>org.apache.karaf.features</groupId>
-                       <artifactId>org.apache.karaf.features.core</artifactId>
-                       <version>2.2.7</version>
-               </dependency>
-
-               <dependency>
                        <groupId>org.apache.karaf</groupId>
                        <artifactId>karaf</artifactId>
-                       <version>2.2.7</version>
+                       <version>2.2.9</version>
                        <type>pom</type>
                </dependency>
 

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
 2012-10-29 19:32:41 UTC (rev 30718)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
 2012-10-29 20:32:13 UTC (rev 30719)
@@ -1,6 +1,5 @@
 package org.cytoscape.app.internal;
 
-import org.apache.karaf.features.FeaturesService;
 import org.cytoscape.app.CyAppAdapter;
 import org.cytoscape.app.internal.CyAppAdapterImpl;
 import org.cytoscape.app.internal.action.AppManagerAction;
@@ -70,6 +69,7 @@
 
 
 import org.osgi.framework.BundleContext;
+import org.osgi.service.startlevel.StartLevel;
 
 import org.cytoscape.service.util.AbstractCyActivator;
 import org.cytoscape.task.NetworkViewTaskFactory;
@@ -357,19 +357,18 @@
                WebQuerier webQuerier = new WebQuerier(streamUtilServiceRef);
                registerService(bc, webQuerier, WebQuerier.class, new 
Properties());
                
-               FeaturesService featuresService = getService(bc, 
FeaturesService.class);
-               
                Properties properties = System.getProperties();
 
                for (Entry<Object, Object> entry : properties.entrySet()) {
                        //System.out.println("Entry: " + entry.getKey() + ", 
value: " + entry.getValue());
                }
                
+               StartLevel startLevel = getService(bc, StartLevel.class);
                // Instantiate new manager
                final AppManager appManager = new AppManager(cyAppAdapter, 
-                               cyApplicationConfigurationServiceRef, 
webQuerier, featuresService);
+                               cyApplicationConfigurationServiceRef, 
webQuerier, startLevel);
                registerService(bc, appManager, AppManager.class, new 
Properties());
-               appManager.setFeaturesService(featuresService);
+               bc.addFrameworkListener(appManager);
                
                final DownloadSitesManager downloadSitesManager = new 
DownloadSitesManager(cyPropertyRef);
                

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-10-29 19:32:41 UTC (rev 30718)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-10-29 20:32:13 UTC (rev 30719)
@@ -2,26 +2,19 @@
 
 import java.io.File;
 import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.security.DigestInputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 import java.util.zip.ZipException;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOCase;
 import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
 import org.apache.commons.io.monitor.FileAlterationMonitor;
 import org.apache.commons.io.monitor.FileAlterationObserver;
-import org.apache.karaf.features.FeaturesService;
 import org.cytoscape.app.AbstractCyApp;
 import org.cytoscape.app.internal.event.AppsChangedEvent;
 import org.cytoscape.app.internal.event.AppsChangedListener;
@@ -31,10 +24,12 @@
 import org.cytoscape.app.internal.exception.AppUninstallException;
 import org.cytoscape.app.internal.manager.App.AppStatus;
 import org.cytoscape.app.internal.net.WebQuerier;
-import org.cytoscape.application.CyApplicationConfiguration;
-
 import org.cytoscape.app.internal.util.DebugHelper;
 import org.cytoscape.app.swing.CySwingAppAdapter;
+import org.cytoscape.application.CyApplicationConfiguration;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.service.startlevel.StartLevel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,7 +37,7 @@
  * This class represents an App Manager, which is capable of maintaining a 
list of all currently installed and available apps. The class
  * also provides functionalities for installing and uninstalling apps.
  */
-public class AppManager {
+public class AppManager implements FrameworkListener {
        
        private static final Logger logger = 
LoggerFactory.getLogger(AppManager.class);
        
@@ -71,6 +66,8 @@
        /** This subdirectory in the local Cytoscape storage directory is used 
to store app data, as 
         * well as installed and uninstalled apps. */
        private static final String APPS_DIRECTORY_NAME = "3" + File.separator 
+ "apps";
+
+       private static final int APP_START_LEVEL = 200;
        
        /** The set of all apps, represented by {@link App} objects, registered 
to this App Manager. */
        private Set<App> apps;
@@ -90,7 +87,7 @@
        /**
         * The {@link FeaturesService} used to communicate with Apache Karaf to 
manage OSGi bundle based apps
         */
-       private FeaturesService featuresService;
+//     private FeaturesService featuresService;
        
        
        // private KarService karService;
@@ -106,6 +103,10 @@
        private CySwingAppAdapter swingAppAdapter;
        
        private FileAlterationMonitor fileAlterationMonitor;
+
+       private StartLevel startLevel;
+
+       private boolean isInitialized;
        
        /**
         * A {@link FileFilter} that accepts only files in the first depth 
level of a given directory
@@ -131,11 +132,11 @@
        }
        
        public AppManager(CySwingAppAdapter swingAppAdapter, 
CyApplicationConfiguration applicationConfiguration, 
-                       final WebQuerier webQuerier, FeaturesService 
featuresService) {
+                       final WebQuerier webQuerier, StartLevel startLevel) {
                this.applicationConfiguration = applicationConfiguration;
                this.swingAppAdapter = swingAppAdapter;
                this.webQuerier = webQuerier;
-               this.featuresService = featuresService;
+               this.startLevel = startLevel;
                
                apps = new HashSet<App>();
                appParser = new AppParser();
@@ -145,6 +146,27 @@
                purgeTemporaryDirectories();
                initializeAppsDirectories();
                
+               attemptInitialization();
+       }
+       
+       @Override
+       public void frameworkEvent(FrameworkEvent event) {
+               // Defer initialization until we reach the right start level.
+               if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
+                       attemptInitialization();
+               }
+       }
+       
+       void attemptInitialization() {
+               synchronized (this) {
+                       if (!isInitialized && startLevel.getStartLevel() >= 
APP_START_LEVEL) {
+                               initializeApps();
+                               isInitialized = true;
+                       }
+               }
+       }
+       
+       void initializeApps() {
                // Move apps from install-on-restart directory to install 
directory
                Set<App> installOnRestartApps = obtainAppsFromDirectory(new 
File(getInstallOnRestartAppsPath()), false);
                for (App app: installOnRestartApps) {
@@ -235,14 +257,6 @@
                DebugHelper.print(this, "config dir: " + 
applicationConfiguration.getConfigurationDirectoryLocation());
        }
        
-       public FeaturesService getFeaturesService() {
-               return this.featuresService;
-       }
-       
-       public void setFeaturesService(FeaturesService featuresService) {
-               this.featuresService = featuresService;
-       }
-       
        private void setupAlterationMonitor() {
                // Set up the FileAlterationMonitor to install/uninstall apps 
when apps are moved in/out of the 
                // installed/uninstalled app directories

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
     2012-10-29 19:32:41 UTC (rev 30718)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
     2012-10-29 20:32:13 UTC (rev 30719)
@@ -4,15 +4,10 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.FileExistsException;
 import org.apache.commons.io.FileUtils;
-import org.apache.karaf.features.Feature;
-import org.apache.karaf.features.FeaturesService;
-import org.cytoscape.app.CyAppAdapter;
 import org.cytoscape.app.internal.exception.AppDisableException;
 import org.cytoscape.app.internal.exception.AppInstallException;
 import org.cytoscape.app.internal.exception.AppInstanceException;
@@ -130,35 +125,36 @@
                
                */
        }
+
+// Ticket 1554: FeaturesService is not API so we shouldn't use it.  Disabled 
for now.
+//     private List<Feature> getCorrespondingFeatures(FeaturesService 
featuresService) {
+//             List<Feature> correspondingFeatures = new LinkedList<Feature>();
+//             
+//             Feature[] availableFeatures = new Feature[]{};
+//             try {
+//                     availableFeatures = featuresService.listFeatures();
+//             } catch (Exception e) {
+//                     e.printStackTrace();
+//             }
+//             
+//             for (int i = 0; i < availableFeatures.length; i++) {
+//                     Feature availableFeature = availableFeatures[i];
+//                     
+//                     KarafArchiveApp.KarafFeature appFeature = 
featuresSet.get(availableFeature.getName());
+//                     
+//                     // System.out.println("available feature: " + 
availableFeature.getName() + ", " + availableFeature.getVersion());
+//                     
+//                     if (appFeature != null
+//                                     && 
appFeature.featureVersion.equalsIgnoreCase(availableFeature.getVersion())) {
+//                             correspondingFeatures.add(availableFeature);
+//                             
+//                             // System.out.println("feature match: " + 
availableFeature.getName() + " vs " + appFeature.featureName);
+//                     }
+//             }
+//             
+//             return correspondingFeatures;
+//     }
        
-       private List<Feature> getCorrespondingFeatures(FeaturesService 
featuresService) {
-               List<Feature> correspondingFeatures = new LinkedList<Feature>();
-               
-               Feature[] availableFeatures = new Feature[]{};
-               try {
-                       availableFeatures = featuresService.listFeatures();
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-               
-               for (int i = 0; i < availableFeatures.length; i++) {
-                       Feature availableFeature = availableFeatures[i];
-                       
-                       KarafArchiveApp.KarafFeature appFeature = 
featuresSet.get(availableFeature.getName());
-                       
-                       // System.out.println("available feature: " + 
availableFeature.getName() + ", " + availableFeature.getVersion());
-                       
-                       if (appFeature != null
-                                       && 
appFeature.featureVersion.equalsIgnoreCase(availableFeature.getVersion())) {
-                               correspondingFeatures.add(availableFeature);
-                               
-                               // System.out.println("feature match: " + 
availableFeature.getName() + " vs " + appFeature.featureName);
-                       }
-               }
-               
-               return correspondingFeatures;
-       }
-       
        @Override
        public void uninstall(AppManager appManager) throws 
AppUninstallException {
                

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to