Author: paperwing
Date: 2012-06-28 16:02:46 -0700 (Thu, 28 Jun 2012)
New Revision: 29721

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/BundleApp.java
Log:
Cytoscape no longer removes app files from framework/deploy directory upon exit 
(was added in last commit), added FileAlterationObserver to track apps that 
were copied manually to the framework/deploy directory

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-06-28 22:15:54 UTC (rev 29720)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-06-28 23:02:46 UTC (rev 29721)
@@ -6,6 +6,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.Executors;
 import java.util.jar.JarFile;
@@ -19,6 +20,7 @@
 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.Feature;
 import org.apache.karaf.features.FeaturesService;
 import org.cytoscape.app.AbstractCyApp;
 import org.cytoscape.app.CyAppAdapter;
@@ -134,7 +136,7 @@
 
                appParser = new AppParser();
                
-               cleanKarafDeployDirectory();
+               // cleanKarafDeployDirectory();
                purgeTemporaryDirectories();
                initializeAppsDirectories();
                
@@ -248,12 +250,40 @@
                karafDeployObserver.addListener(new 
FileAlterationListenerAdaptor() {
                        @Override
                        public void onFileDelete(File file) {
-                               //System.out.println("File deleted from 
deploy:"  + file.getName());
+                               for (App app : getApps()) {
+                                       if 
(app.getAppTemporaryInstallFile().equals(file)) {
+                                               try {
+                                                       uninstallApp(app);
+                                               } catch (AppUninstallException 
e) {
+                                                       logger.warn("Failed to 
uninstall app that was removed from Karaf deploy directory: " + 
app.getAppName());
+                                               }
+                                       }
+                               }
                        }
                        
                        @Override
                        public void onFileCreate(File file) {
-                               //System.out.println("File added to deploy: " + 
file.getName());
+                               if (checkIfCytoscapeApp(file)) {
+                                       
+                                       App parsedApp = null;
+                                       try {
+                                               parsedApp = 
appParser.parseApp(file);
+                                               
+                                               if (parsedApp instanceof 
SimpleApp) {
+                                                       logger.warn("A simple 
app " + file.getName() + " was moved to the " 
+                                                                       + 
"framework/deploy directory. It should be installed via the "
+                                                                       + "app 
manager! Installing anyway..");
+                                               }
+
+                                               installApp(parsedApp);
+                                       } catch (AppParsingException e) {
+                                               logger.error("Failed to parse 
app that was moved to Karaf deploy directory: " + file.getName()
+                                                               + ". The error 
was: " + e.getMessage());
+                                       } catch (AppInstallException e) {
+                                               logger.error("Failed to 
register app with app manager: " + file.getName()
+                                                               + ". The error 
was:" + e.getMessage());
+                                       }
+                               }
                        }                       
                });
                
@@ -264,7 +294,7 @@
                        e.printStackTrace();
                }
                
-               fileAlterationMonitor.addObserver(karafDeployObserver);
+               // fileAlterationMonitor.addObserver(karafDeployObserver);
        }
        
        public CySwingAppAdapter getSwingAppAdapter() {
@@ -327,6 +357,15 @@
                        throw new AppInstallException(e.getMessage());
                }
                
+               // For bundle apps, remove temporary files from Karaf deploy 
directory on exit
+               if (app instanceof BundleApp) {
+                       File temporaryInstallFile = ((BundleApp) 
app).getAppTemporaryInstallFile();
+                       
+                       if (temporaryInstallFile != null) {
+                               // temporaryInstallFile.deleteOnExit();
+                       }
+               }
+               
                // Let the listeners know that an app has been installed
                fireAppsChangedEvent();
        }

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   2012-06-28 22:15:54 UTC (rev 29720)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   2012-06-28 23:02:46 UTC (rev 29721)
@@ -64,8 +64,7 @@
                // the file, creating an instance, and registering with the app 
manager.
                // defaultInstall(appManager);
                
-               // Copy to Karaf deploy directory
-               String karafDeployDirectory = 
appManager.getKarafDeployDirectory();
+               
                File appFile = this.getAppFile();
                
                try {
@@ -85,10 +84,19 @@
                        throw new AppInstallException("Failed to copy bundle 
app to local storage directory for installed apps");
                }
                
+               // Prepare to copy to Karaf deploy directory
+               String karafDeployDirectory = 
appManager.getKarafDeployDirectory();
+               
                try {
-                       FileUtils.copyFileToDirectory(this.getAppFile(), new 
File(karafDeployDirectory));
-                       this.setAppTemporaryInstallFile(new 
File(karafDeployDirectory + File.separator + this.getAppFile().getName()));
-                       this.getAppTemporaryInstallFile().deleteOnExit();
+                       
+                       // Copy if not already in Karaf deploy directory 
+                       File karafTargetFile = new File(karafDeployDirectory + 
File.separator + this.getAppFile().getName());
+                       if (!karafTargetFile.exists()) {
+                               FileUtils.copyFile(this.getAppFile(), 
karafTargetFile);
+                       }
+                       
+                       this.setAppTemporaryInstallFile(karafTargetFile);
+                       
                } catch (IOException e) {
                        throw new AppInstallException("Failed to copy bundle 
app to Karaf deploy directory");
                }

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