Author: paperwing
Date: 2012-06-18 08:50:37 -0700 (Mon, 18 Jun 2012)
New Revision: 29596
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.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/BundleApp.java
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
Log:
refs #1121 Uninstalled apps are now removed permanently upon the next start-up.
Apps that fail to install are now removed from the installed apps directory.
App Manager dialog title added.
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
2012-06-18 09:25:27 UTC (rev 29595)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
2012-06-18 15:50:37 UTC (rev 29596)
@@ -155,15 +155,6 @@
for (App app : appManager.getApps()) {
if (this.heuristicEquals(app) && this != app) {
- /*
- DebugHelper.print("Install aborted: heuristic
finds app already installed");
- DebugHelper.print("conflict app status: " +
app.getStatus());
- DebugHelper.print("conflict app name: " +
app.getAppName());
- DebugHelper.print("conflict app file: " +
app.getAppFile().getAbsolutePath());
- DebugHelper.print("conflict app: " + app);
- DebugHelper.print("this app file: " +
getAppFile());
- DebugHelper.print("this app: " + this);
- */
// If we already have an App object registered
to the app manager
// that represents this app, re-use that app
object
@@ -403,7 +394,7 @@
// Delete the source file after the
copy operation
String fileName =
this.getAppFile().getName();
this.getAppFile().delete();
- this.setAppFile(new
File(uninstalledAppsPath + File.separator + fileName));
+ this.setAppFile(new
File(uninstalledAppsPath + File.separator + fileName));
}
} catch (IOException e) {
throw new AppUninstallException("Unable to
obtain path: " + e.getMessage());
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-18 09:25:27 UTC (rev 29595)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
2012-06-18 15:50:37 UTC (rev 29596)
@@ -29,12 +29,17 @@
import org.cytoscape.app.internal.net.server.LocalHttpServer;
import org.cytoscape.app.internal.util.DebugHelper;
import org.cytoscape.app.swing.CySwingAppAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* 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 {
+
+ private static final Logger logger =
LoggerFactory.getLogger(AppManager.class);
+
/** Only files with these extensions are checked when looking for apps
in a given subdirectory.
*/
private static final String[] APP_EXTENSIONS = {"jar"};
@@ -113,6 +118,7 @@
appParser = new AppParser();
+ purgeTemporaryDirectories();
initializeAppsDirectories();
this.appListeners = new HashSet<AppsChangedListener>();
@@ -123,7 +129,7 @@
// Load apps from the "uninstalled apps" directory
Set<App> uninstalledApps = obtainAppsFromDirectory(new
File(getUninstalledAppsPath()));
apps.addAll(uninstalledApps);
-
+
setupAlterationMonitor();
DebugHelper.print(this, "config dir: " +
applicationConfiguration.getConfigurationDirectoryLocation());
@@ -143,6 +149,7 @@
FileAlterationObserver uninstallAlterationObserver = new
FileAlterationObserver(
uninstalledAppsPath, new
SingleLevelFileFilter(uninstalledAppsPath), IOCase.SYSTEM);
+ // Listen for events on the "installed apps" folder
installAlterationObserver.addListener(new
FileAlterationListenerAdaptor() {
@Override
public void onFileDelete(File file) {
@@ -156,26 +163,19 @@
if (appFile != null
&&
appFile.getCanonicalPath().equals(canonicalPath)) {
- //
app.setStatus(AppStatus.TO_BE_UNINSTALLED);
-
- // TODO: call
app.setFile(null), prevent re-installation of this app
- // as the file has been
moved
-
- // app.setAppFile(null);
+
app.setAppFile(new
File(getUninstalledAppsPath() + File.separator + appFile.getName()));
try {
uninstallApp(app);
} catch
(AppUninstallException e) {
- // TODO
Auto-generated catch block
+
e.printStackTrace();
}
-
- //
fireAppsChangedEvent();
}
}
} catch (IOException e) {
- // TODO Auto-generated catch block
+
e.printStackTrace();
}
}
@@ -200,14 +200,14 @@
@Override
public void onFileChange(File file) {
- DebugHelper.print("Install directory file
changed");
}
});
+
+ /*
uninstallAlterationObserver.addListener(new
FileAlterationListenerAdaptor() {
@Override
public void onFileDelete(File file) {
- DebugHelper.print("Uninstall directory file
deleted");
try {
String canonicalPath =
file.getCanonicalPath();
@@ -238,8 +238,6 @@
}
for (App appToBeRemoved :
appsToBeRemoved) {
- DebugHelper.print("Removing
app: " + appToBeRemoved.getAppName());
-
removeApp(appToBeRemoved);
}
@@ -281,16 +279,15 @@
@Override
public void onFileChange(File file) {
- DebugHelper.print("Uninstall directory file
changed");
}
});
+ */
-
try {
installAlterationObserver.initialize();
uninstallAlterationObserver.initialize();
-
fileAlterationMonitor.addObserver(installAlterationObserver);
-
fileAlterationMonitor.addObserver(uninstallAlterationObserver);
+ //
fileAlterationMonitor.addObserver(installAlterationObserver);
+ //
fileAlterationMonitor.addObserver(uninstallAlterationObserver);
fileAlterationMonitor.start();
} catch (Exception e) {
// TODO Auto-generated catch block
@@ -348,7 +345,15 @@
*/
public void installApp(App app) throws AppInstallException {
- app.install(this);
+ try {
+ app.install(this);
+ } catch (AppInstallException e) {
+ if (app.getAppFile() != null) {
+ app.getAppFile().delete();
+ }
+
+ throw new AppInstallException(e.getMessage());
+ }
// Let the listeners know that an app has been installed
fireAppsChangedEvent();
@@ -413,7 +418,15 @@
*/
public String getInstalledAppsPath() {
try {
- return getBaseAppPath().getCanonicalPath() +
File.separator + INSTALLED_APPS_DIRECTORY_NAME;
+ // Create the directory if it doesn't exist
+ File path = new File(getBaseAppPath() + File.separator
+ INSTALLED_APPS_DIRECTORY_NAME);
+
+ if (!path.exists()) {
+ path.mkdirs();
+ System.out.println("Remaking installed dir");
+ }
+
+ return path.getCanonicalPath();
} catch (IOException e) {
// TODO: Record error in logger
return null;
@@ -427,7 +440,14 @@
*/
public String getUninstalledAppsPath() {
try {
- return getBaseAppPath().getCanonicalPath() +
File.separator + UNINSTALLED_APPS_DIRECTORY_NAME;
+ // Create the directory if it doesn't exist
+ File path = new File(getBaseAppPath() + File.separator
+ UNINSTALLED_APPS_DIRECTORY_NAME);
+
+ if (!path.exists()) {
+ path.mkdirs();
+ }
+
+ return path.getCanonicalPath();
} catch (IOException e) {
// TODO: Record error in logger
return null;
@@ -442,13 +462,36 @@
*/
public String getDownloadedAppsPath() {
try {
- return getBaseAppPath().getCanonicalPath() +
File.separator + DOWNLOADED_APPS_DIRECTORY_NAME;
+ // Create the directory if it doesn't exist
+ File path = new File(getBaseAppPath() + File.separator
+ DOWNLOADED_APPS_DIRECTORY_NAME);
+
+ if (!path.exists()) {
+ path.mkdirs();
+ }
+
+ return path.getCanonicalPath();
} catch (IOException e) {
// TODO: Record in logger
return null;
}
}
+ /**
+ * Removes the temporary app download directory and the directory used
to store uninstalled apps.
+ */
+ public void purgeTemporaryDirectories() {
+ File downloaded = new File(getDownloadedAppsPath());
+ File uninstalled = new File(getUninstalledAppsPath());
+
+ try {
+ FileUtils.deleteDirectory(downloaded);
+ FileUtils.deleteDirectory(uninstalled);
+
+ } catch (IOException e) {
+ logger.warn("Unable to completely remove temporary
directories for downloaded and uninstalled apps.");
+ }
+ }
+
private void installAppsInDirectory(File directory) {
// Parse App objects from the given directory
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-18 09:25:27 UTC (rev 29595)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
2012-06-18 15:50:37 UTC (rev 29596)
@@ -36,7 +36,7 @@
public void install(AppManager appManager) throws AppInstallException {
// Use the default installation procedure consisting of copying
over
// the file, creating an instance, and registering with the app
manager.
- defaultInstall(appManager);
+ // defaultInstall(appManager);
}
@Override
@@ -44,9 +44,7 @@
// 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
+ // defaultUninstall(appManager);
}
}
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
2012-06-18 09:25:27 UTC (rev 29595)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
2012-06-18 15:50:37 UTC (rev 29596)
@@ -37,7 +37,8 @@
checkForUpdatesPanel1 = new CheckForUpdatesPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
-
+ setTitle("App Manager");
+
mainTabbedPane.addTab("Install from App Store", installNewAppsPanel1);
mainTabbedPane.addTab("Currently Installed",
currentlyInstalledAppsPanel1);
mainTabbedPane.addTab("Check for Updates", checkForUpdatesPanel1);
--
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.