Author: paperwing
Date: 2012-05-25 12:20:33 -0700 (Fri, 25 May 2012)
New Revision: 29358

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/AppManager.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
Log:
App manager now synchronizes with local app storage directory: apps moved to 
the installed apps directory are during runtime are installed, apps removed 
from this directory are uninstalled, moving apps between the installed apps 
directory and the uninstalled apps directory causes the corresponding 
install/uninstall actions.

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-05-25 18:58:22 UTC (rev 29357)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
 2012-05-25 19:20:33 UTC (rev 29358)
@@ -63,8 +63,7 @@
        public enum AppStatus{
                INSTALLED("Installed"),
                TO_BE_UNINSTALLED("Uninstall-on-restart"),
-               UNINSTALLED("Uninstalled"),
-               UNDEFINED("Undefined");
+               UNINSTALLED("Uninstalled");
                
                String readableStatus;
                
@@ -151,6 +150,28 @@
                        throw new AppInstallException("This app has already 
been installed.");
                }
                
+               
+               for (App app : appManager.getApps()) {
+                       if (this.heuristicEquals(app) && this != app) {
+                               /*
+                               System.out.println("Install aborted: heuristic 
finds app already installed");
+                               System.out.println("conflict app status: " + 
app.getStatus());
+                               System.out.println("conflict app name: " + 
app.getAppName());
+                               System.out.println("conflict app file: " + 
app.getAppFile().getAbsolutePath());
+                               System.out.println("conflict app: " + app);
+                               System.out.println("this app file: " + 
getAppFile());
+                               System.out.println("this app: " + this);
+                               */
+                               
+                               // If we already have an App object registered 
to the app manager
+                               // that represents this app, re-use that app 
object
+                               app.setAppFile(this.appFile);
+                               appManager.installApp(app);
+                               
+                               return;
+                       }
+               }
+               
                // Obtain the paths to the local storage directories for 
holding installed and uninstalled apps.
                String installedAppsPath = appManager.getInstalledAppsPath();
                String uninstalledAppsPath = 
appManager.getUninstalledAppsPath();
@@ -159,6 +180,11 @@
                try {
                        File appFile = this.getAppFile();
                        
+                       if (!appFile.exists()) {
+                               System.out.println("Install aborted: file " + 
appFile.getCanonicalPath() + " does not exist");
+                               return;
+                       }
+                       
                        // Make sure no app with the same filename and app name 
is already installed
                        File installedDirectoryTargetFile = new 
File(installedAppsPath + File.separator + appFile.getName());
                        File uninstalledDirectoryTargetFile = new 
File(uninstalledAppsPath + File.separator + appFile.getName());
@@ -194,9 +220,30 @@
                                                // Forgive the collision if we 
are copying from the uninstalled apps directory
                                                if 
(appFile.getParentFile().getCanonicalPath().equals(uninstalledAppsPath)) {
                                                        
+                                               // Forgive collision if other 
app is not installed
+                                               } else if 
(conflictingApp.getStatus() == AppStatus.UNINSTALLED) {
+                                               
+                                               // Ignore collisions with self
+                                               // } else if 
(conflictingApp.getAppFile().equals(appFile)) {
+                                                       
                                                } else {
+                                                       /*
+                                                       for (App app : 
appManager.getApps()) {
+                                                               if 
(this.heuristicEquals(app) && this != app) {
+                                                                       
System.out.println("Install aborted: heuristic finds app already installed");
+                                                                       
System.out.println("conflict app status: " + app.getStatus());
+                                                                       
System.out.println("conflict app name: " + app.getAppName());
+                                                                       
+                                                                       
appManager.installApp(app);
+                                                                       
+                                                                       return;
+                                                               }
+                                                       }
+                                                       */
+                                                       
                                                        // Skip installation, 
suspected that a copy of the app is already installed
-                                                       return;
+                                                       
+                                                       // return;
                                                }
                                                
                                        } else {
@@ -326,6 +373,13 @@
                // perform file moving. Instead, attempt to try to complete the 
uninstallation without 
                // regard to app's file.
                if (this.getAppFile() != null) {
+                       
+                       if (!this.getAppFile().exists()) {
+                               
+                               // Skip file moving if the file has been moved
+                               return;
+                       }
+                       
                        // 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();
@@ -371,6 +425,25 @@
                }
        }
        
+       /**
+        * Uses heuristics to check if another App represents the same 
Cytoscape app as this App, 
+        * ignoring filename differences.
+        * 
+        * @param other The app to compare against.
+        * @return <code>true</code> if the apps are suspected to be the same 
Cytoscape app,
+        * <code>false</code> otherwise.
+        */
+       public boolean heuristicEquals(App other) {
+               
+               // Return false if different app names
+               if (appName.equalsIgnoreCase(other.appName)
+                               && version.equalsIgnoreCase(other.version)) {
+                       return true;
+               }
+               
+               return false;
+       }
+       
        public String getAppName() {
                return appName;
        }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-05-25 18:58:22 UTC (rev 29357)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-05-25 19:20:33 UTC (rev 29358)
@@ -151,7 +151,8 @@
                                                        // TODO: call 
app.setFile(null), prevent re-installation of this app
                                                        // as the file has been 
moved
                                                        
-                                                       app.setAppFile(null);
+                                                       // app.setAppFile(null);
+                                                       app.setAppFile(new 
File(getUninstalledAppsPath() + File.separator + appFile.getName()));
                                                        
                                                        try {
                                                                
uninstallApp(app);
@@ -209,9 +210,15 @@
                                                // If the app was uninstalled 
and was moved from the uninstalled apps
                                                // directory, remove it from 
the app manager
                                                if (appFile != null 
-                                                               && 
appFile.getCanonicalPath().equals(canonicalPath)
-                                                               && 
app.getStatus() == AppStatus.UNINSTALLED) {
-                                                       
appsToBeRemoved.add(app);
+                                                               && 
appFile.getCanonicalPath().equals(canonicalPath)) {
+                                                       
+                                                       //app.setAppFile(null);
+                                                       app.setAppFile(new 
File(getInstalledAppsPath() + File.separator + appFile.getName()));
+                                                       
+                                                       if (app.getStatus() == 
AppStatus.UNINSTALLED) {
+                                                               
appsToBeRemoved.add(app);
+                                                       }
+                                                               
                                                }
                                                
                                                // TODO: Currently keeps the 
app registered to the app manager
@@ -221,6 +228,8 @@
                                        }
                                        
                                        for (App appToBeRemoved : 
appsToBeRemoved) {
+                                               System.out.println("Removing 
app: " + appToBeRemoved.getAppName());
+                                               
                                                removeApp(appToBeRemoved);
                                        }
                                        
@@ -235,6 +244,28 @@
                        
                        @Override
                        public void onFileCreate(File file) {
+                               try {
+                                       App parsedApp = 
appParser.parseApp(file);
+                                       
+                                       // If no installed app has the same 
name, register it and make it available
+                                       boolean nameConflict = false;
+                                       
+                                       for (App registeredApp : apps) {
+                                               if 
(registeredApp.getAppName().equalsIgnoreCase(parsedApp.getAppName())) {
+                                                       nameConflict = true;
+                                                       break;
+                                               }
+                                       }
+                                       
+                                       if (!nameConflict) {
+                                               addApp(parsedApp);
+                                               fireAppsChangedEvent();
+                                       }
+                                       
+                               } catch (AppParsingException e) {
+                               
+                               }
+                               
                                // Do nothing if a file is added to the 
uninstalled apps directory
                        }
                        

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-05-25 18:58:22 UTC (rev 29357)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-05-25 19:20:33 UTC (rev 29358)
@@ -61,6 +61,10 @@
                
                System.out.println("Parsing: " + file.getPath());
                
+               if (!file.exists()) {
+                       throw new AppParsingException("No file with path: " + 
file.getAbsolutePath());
+               }
+               
                if (!file.isFile()) {
                        throw new AppParsingException("The given file, " + file 
+ ", is not a file.");
                }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-05-25 18:58:22 UTC (rev 29357)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-05-25 19:20:33 UTC (rev 29358)
@@ -256,7 +256,7 @@
        for (App app : appManager.getApps()) {  
                tableModel.addRow(new Object[]{
                                        app,
-                                       app.getAppName(),
+                                       app.getAppFile() != null ? 
app.getAppName() : app.getAppName() + " (File moved)",
                                        app.getAuthors(),
                                        app.getVersion(),
                                        app.getStatus()

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