Author: Yue Dong
Date: 2012-04-22 19:17:43 -0700 (Sun, 22 Apr 2012)
New Revision: 28944

Removed:
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppMoveException.java
Modified:
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/Update.java
Log:
Removed unused AppMoveException class, moved SimpleApp's app file moving 
functionalities to App to allow access by BundleApp. Started basic 
implementation for installing bundle apps.

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
     2012-04-21 00:31:23 UTC (rev 28943)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
     2012-04-23 02:17:43 UTC (rev 28944)
@@ -28,6 +28,9 @@
         */
        private FileUtil fileUtil;
        
+       /**
+        * Creates and sets up the AbstractCyAction, placing an item into the 
menu.
+        */
        public AppManagerAction(AppManager appManager, CySwingApplication 
swingApplication, FileUtil fileUtil) {
                super("App Manager 2");
                

Deleted: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppMoveException.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppMoveException.java
  2012-04-21 00:31:23 UTC (rev 28943)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppMoveException.java
  2012-04-23 02:17:43 UTC (rev 28944)
@@ -1,20 +0,0 @@
-package org.cytoscape.app.internal.exception;
-
-import org.cytoscape.app.internal.manager.AppManager;
-
-/**
- * An exception thrown by the {@link AppManager} when it encounters errors 
while attempting to move an app file.
- */
-public class AppMoveException extends Exception {
-
-       /** Long serial version identifier required by the Serializable class */
-       private static final long serialVersionUID = 9013239765398696280L;
-       
-       public AppMoveException(String message) {
-               super(message);
-       }
-       
-       public AppMoveException(String message, Throwable cause) {
-               super(message, cause);
-       }
-}

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
 2012-04-21 00:31:23 UTC (rev 28943)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
 2012-04-23 02:17:43 UTC (rev 28944)
@@ -1,8 +1,10 @@
 package org.cytoscape.app.internal.manager;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 
+import org.apache.commons.io.FileUtils;
 import org.cytoscape.app.AbstractCyApp;
 import org.cytoscape.app.CyAppAdapter;
 import org.cytoscape.app.internal.exception.AppInstallException;
@@ -110,6 +112,125 @@
         */
        public abstract void uninstall(AppManager appManager) throws 
AppUninstallException;
        
+       /**
+        * Default app installation method that can be used by classes 
extending this class.
+        * 
+        * Attempts to install an app by copying it to the installed apps 
directory,
+        * creating an instance of the app's class that extends the {@link 
AbstractCyApp} class,
+        * and registering it with the given {@link AppManager} object. The app 
is instanced by
+        * calling its createAppInstance() method.
+        * 
+        * @param appManager The AppManager used to register this app with.
+        * @throws AppInstallException If there was an error while attempting 
to install the app such
+        * as improper app packaging, failure to copy the file to the installed 
apps directory, 
+        * or failure to create an instance of the app.
+        */
+       protected void defaultInstall(AppManager appManager) throws 
AppInstallException {
+               // Check if the app has been verified to contain proper 
packaging.
+               if (!this.isAppValidated()) {
+                       
+                       // If the app is not packaged properly or is missing 
fields in its manifest file, do not install the app
+                       // as the install operation will fail.
+                       throw new AppInstallException("Cannot install app; app 
file has not been checked to comply with app specifications");
+               }
+               
+               // Check if the app has already been installed.
+               if (this.getStatus() == AppStatus.INSTALLED) {
+                       
+                       // Do nothing if it is already installed
+                       throw new AppInstallException("This app has already 
been installed.");
+               }
+               
+               // Obtain the paths to the local storage directories for 
holding installed and uninstalled apps.
+               String installedAppsPath = appManager.getInstalledAppsPath();
+               String uninstalledAppsPath = 
appManager.getUninstalledAppsPath();
+               
+               // Attempt to copy the app to the directory for installed apps.
+               try {
+                       File appFile = this.getAppFile();
+                       
+                       // Only perform the copy if the app was not already in 
the target directory
+                       if 
(!appFile.getParentFile().getCanonicalPath().equals(installedAppsPath)) {
+                               
+                               // Uses Apache Commons library; overwrites 
files with the same name.
+                               FileUtils.copyFileToDirectory(appFile, new 
File(installedAppsPath));
+                               
+                               // If we copied it from the uninstalled apps 
directory, remove it from that directory
+                               if 
(appFile.getParentFile().getCanonicalPath().equals(uninstalledAppsPath)) {
+                                       appFile.delete();
+                               }
+                               
+                               // Update the app's path
+                               String fileName = this.getAppFile().getName();
+                               this.setAppFile(new File(installedAppsPath + 
File.separator + fileName));
+                       }
+               } catch (IOException e) {
+                       throw new AppInstallException("Unable to copy app file 
to installed apps directory: " + e.getMessage());
+               }
+       
+               // Create an app instance only if one was not already created
+               if (this.getAppInstance() == null) {
+                       Object appInstance;
+                       try {
+                               appInstance = 
createAppInstance(appManager.getAppAdapter());
+                       } catch (AppInstanceException e) {
+                               throw new AppInstallException("Unable to create 
app instance: " + e.getMessage());
+                       }
+                       
+                       // Keep a reference to the newly created instance
+                       this.setAppInstance((AbstractCyApp) appInstance);
+               }
+               
+               this.setStatus(AppStatus.INSTALLED);
+               appManager.addApp(this);
+       }
+       
+       /**
+        * Default app uninstallation method that can be used by classes 
extending this class.
+        * 
+        * The default app uninstallation procedure consists of simply moving 
the app to the uninstalled apps
+        * directory.
+        * 
+        * @param appManager The app manager responsible for managing apps, 
which is used to obtain
+        * the path of the storage directories containing the installed and 
uninstalled apps
+        * @throws AppUninstallException If there was an error while 
uninstalling the app, such as
+        * attempting to uninstall an app that is not installed, or failure to 
move the app to
+        * the uninstalled apps directory
+        */
+       protected void defaultUninstall(AppManager appManager) throws 
AppUninstallException {
+               // Check if the app is installed before attempting to uninstall.
+               if (this.getStatus() != AppStatus.INSTALLED) {
+                       // If it is not installed, do not attempt to uninstall 
it.
+                       throw new AppUninstallException("App is not installed; 
cannot uninstall.");
+               }
+               
+               // Check if the app is inside the directory containing 
currently installed apps.
+               // If so, prepare to move it to the uninstalled directory.
+               File appParentDirectory = this.getAppFile().getParentFile();
+               try {
+                       // Obtain the path of the "uninstalled apps" 
subdirectory.
+                       String uninstalledAppsPath = 
appManager.getUninstalledAppsPath();
+                       
+                       if (appParentDirectory.getCanonicalPath().equals(
+                                       appManager.getInstalledAppsPath())) {
+                               
+                               // Use the Apache commons library to copy over 
the file, overwriting existing files.
+                               try {
+                                       
FileUtils.copyFileToDirectory(this.getAppFile(), new File(uninstalledAppsPath));
+                               } catch (IOException e) {
+                                       throw new AppUninstallException("Unable 
to move file: " + e.getMessage());
+                               }
+                               
+                               // Delete the source file after the copy 
operation
+                               String fileName = this.getAppFile().getName();
+                               this.getAppFile().delete();
+                               this.setAppFile(new File(uninstalledAppsPath + 
File.separator + fileName));                             
+                       }
+               } catch (IOException e) {
+                       throw new AppUninstallException("Unable to obtain path: 
" + e.getMessage());
+               }
+       }
+       
        public String getAppName() {
                return appName;
        }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   2012-04-21 00:31:23 UTC (rev 28943)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   2012-04-23 02:17:43 UTC (rev 28944)
@@ -1,29 +1,49 @@
 package org.cytoscape.app.internal.manager;
 
+import java.net.MalformedURLException;
+
 import org.cytoscape.app.CyAppAdapter;
 import org.cytoscape.app.internal.exception.AppInstallException;
 import org.cytoscape.app.internal.exception.AppInstanceException;
 import org.cytoscape.app.internal.exception.AppUninstallException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 
 public class BundleApp extends App {
 
        @Override
        public Object createAppInstance(CyAppAdapter appAdapter)
                        throws AppInstanceException {
-               // TODO Auto-generated method stub
-               return null;
+               
+               BundleContext bundleContext = null;
+               Bundle bundle;
+               try {
+                       bundle = 
bundleContext.installBundle(this.getAppFile().toURL().toString());
+               } catch (MalformedURLException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (BundleException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
        }
 
        @Override
        public void install(AppManager appManager) throws AppInstallException {
-               // TODO Auto-generated method stub
-               
+               // Use the default installation procedure consisting of copying 
over
+               // the file, creating an instance, and registering with the app 
manager.
+               defaultInstall(appManager);
        }
 
        @Override
        public void uninstall(AppManager appManager) throws 
AppUninstallException {
-               // TODO Auto-generated method stub
                
+               // Use the default uninstallation procedure consisting of 
moving the app file
+               // to the uninstalled apps directory
+               defaultUninstall(appManager);
+               
+               // Now, we need to unregister the bundle
        }
 
 }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
   2012-04-21 00:31:23 UTC (rev 28943)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
   2012-04-23 02:17:43 UTC (rev 28944)
@@ -75,103 +75,20 @@
 
        @Override
        public void install(AppManager appManager) throws AppInstallException {
-               // Check if the app has been verified to contain proper 
packaging.
-               if (!this.isAppValidated()) {
-                       
-                       // If the app is not packaged properly or is missing 
fields in its manifest file, do not install the app
-                       // as the install operation will fail.
-                       throw new AppInstallException("Cannot install app; app 
file has not been checked to comply with app specifications");
-               }
-               
-               // Check if the app has already been installed.
-               if (this.getStatus() == AppStatus.INSTALLED) {
-                       
-                       // Do nothing if it is already installed
-                       throw new AppInstallException("This app has already 
been installed.");
-               }
-               
-               // Obtain the paths to the local storage directories for 
holding installed and uninstalled apps.
-               String installedAppsPath = appManager.getInstalledAppsPath();
-               String uninstalledAppsPath = 
appManager.getUninstalledAppsPath();
-               
-               // Attempt to copy the app to the directory for installed apps.
-               try {
-                       File appFile = this.getAppFile();
-                       
-                       // Only perform the copy if the app was not already in 
the target directory
-                       if 
(!appFile.getParentFile().getCanonicalPath().equals(installedAppsPath)) {
-                               
-                               // Uses Apache Commons library; overwrites 
files with the same name.
-                               FileUtils.copyFileToDirectory(appFile, new 
File(installedAppsPath));
-                               
-                               // If we copied it from the uninstalled apps 
directory, remove it from that directory
-                               if 
(appFile.getParentFile().getCanonicalPath().equals(uninstalledAppsPath)) {
-                                       appFile.delete();
-                               }
-                               
-                               // Update the app's path
-                               String fileName = this.getAppFile().getName();
-                               this.setAppFile(new File(installedAppsPath + 
File.separator + fileName));
-                       }
-               } catch (IOException e) {
-                       throw new AppInstallException("Unable to copy app file 
to installed apps directory: " + e.getMessage());
-               }
-       
-               // Create an app instance only if one was not already created
-               if (this.getAppInstance() == null) {
-                       Object appInstance;
-                       try {
-                               appInstance = 
createAppInstance(appManager.getAppAdapter());
-                       } catch (AppInstanceException e) {
-                               throw new AppInstallException("Unable to create 
app instance: " + e.getMessage());
-                       }
-                       
-                       // Keep a reference to the newly created instance
-                       this.setAppInstance((AbstractCyApp) appInstance);
-               }
-               
-               this.setStatus(AppStatus.INSTALLED);
-               appManager.addApp(this);
+               // Use the default installation method of copying over the file,
+               // creating an instance, and registering with the app manager.
+               defaultInstall(appManager);
        }
 
        @Override
        public void uninstall(AppManager appManager) throws 
AppUninstallException {
                
-               // Check if the app is installed before attempting to uninstall.
-               if (this.getStatus() != AppStatus.INSTALLED) {
-                       // If it is not installed, do not attempt to uninstall 
it.
-                       throw new AppUninstallException("App is not installed; 
cannot uninstall.");
-               }
-               
-               // Check if the app is inside the directory containing 
currently installed apps.
-               // If so, prepare to move it to the uninstalled directory.
-               File appParentDirectory = this.getAppFile().getParentFile();
-               try {
-                       // Obtain the path of the "uninstalled apps" 
subdirectory.
-                       String uninstalledAppsPath = 
appManager.getUninstalledAppsPath();
-                       
-                       if (appParentDirectory.getCanonicalPath().equals(
-                                       appManager.getInstalledAppsPath())) {
+               // Use the default uninstallation procedure which is to mvoe 
the app to\
+               // the uninstalled apps directory
+               defaultUninstall(appManager);
                                
-                               // Use the Apache commons library to copy over 
the file, overwriting existing files.
-                               try {
-                                       
FileUtils.copyFileToDirectory(this.getAppFile(), new File(uninstalledAppsPath));
-                               } catch (IOException e) {
-                                       throw new AppUninstallException("Unable 
to move file: " + e.getMessage());
-                               }
-                               
-                               // Delete the source file after the copy 
operation
-                               String fileName = this.getAppFile().getName();
-                               this.getAppFile().delete();
-                               this.setAppFile(new File(uninstalledAppsPath + 
File.separator + fileName));
-                               
-                               // Simple apps require a Cytoscape restart to 
be uninstalled
-                               this.setStatus(AppStatus.TO_BE_UNINSTALLED);
-                               
-                       }
-               } catch (IOException e) {
-                       throw new AppUninstallException("Unable to obtain path: 
" + e.getMessage());
-               }
+               // Simple apps require a Cytoscape restart to be uninstalled
+               setStatus(AppStatus.TO_BE_UNINSTALLED);
        }
 
 }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/Update.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/Update.java
  2012-04-21 00:31:23 UTC (rev 28943)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/net/Update.java
  2012-04-23 02:17:43 UTC (rev 28944)
@@ -16,14 +16,17 @@
        /** The version of the new updated app */
        private String updateVersion;
 
+       /** Obtain the {@link App}pp object that the update is associated with. 
*/
        public App getApp() {
                return app;
        }
        
+       /** Obtain information about the update. */
        public String getUpdateInformation() {
                return updateInformation;
        }
        
+       /** Obtain the new version of the app once the update is applied. */
        public String getUpdateVersion() {
                return updateVersion;
        }

-- 
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