Author: paperwing
Date: 2012-08-16 15:28:05 -0700 (Thu, 16 Aug 2012)
New Revision: 30209
Added:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppUpdateException.java
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/AppParser.java
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
Log:
refs #1362, #1342 Can now check for, and install updates for simple and bundle
apps by clicking on the Check for Updates tab. For simple apps, the new version
is installed on restart.
Added:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppUpdateException.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppUpdateException.java
(rev 0)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppUpdateException.java
2012-08-16 22:28:05 UTC (rev 30209)
@@ -0,0 +1,18 @@
+package org.cytoscape.app.internal.exception;
+
+/**
+ * An exception thrown to signal errors found while attempting to perform
+ * an update on an app
+ */
+public class AppUpdateException extends Exception {
+
+ private static final long serialVersionUID = 4741554087496424850L;
+
+ public AppUpdateException(String message) {
+ super(message);
+ }
+
+ public AppUpdateException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
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-08-16 21:34:03 UTC (rev 30208)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
2012-08-16 22:28:05 UTC (rev 30209)
@@ -86,7 +86,7 @@
INSTALLED("Installed"),
DISABLED("Disabled"),
UNINSTALLED("Uninstalled"),
- TO_BE_INSTALLED("Install-on-restart"),
+ TO_BE_INSTALLED("Install on Restart"),
FILE_MOVED("File Moved (Uninstalled)");
String readableStatus;
@@ -681,6 +681,9 @@
* Moves an app file to the given directory, copying the app if it is
outside one of the local app storage directories
* and moving if it is not. Also assigns filename that does not
colliide with any from the local app storage directories.
*
+ * Will also add postfix to filename if desired filename already exists
in target directory when
+ * moving app to a directory other than the 3 local app storage
directories.
+ *
* @param appManager A reference to the app manager
* @param targetDirectory The local storage directory to move to, such
as the local sotrage directory
* containing installed apps obtained via the app manager
@@ -696,21 +699,27 @@
LinkedList<String> uniqueNameDirectories = new
LinkedList<String>();
if (!parentPath.equals(installDirectoryPath))
-
uniqueNameDirectories.add(installDirectoryPath.getAbsolutePath());
+
uniqueNameDirectories.add(installDirectoryPath.getCanonicalPath());
if (!parentPath.equals(disabledDirectoryPath))
-
uniqueNameDirectories.add(disabledDirectoryPath.getAbsolutePath());
+
uniqueNameDirectories.add(disabledDirectoryPath.getCanonicalPath());
if (!parentPath.equals(uninstallDirectoryPath))
-
uniqueNameDirectories.add(uninstallDirectoryPath.getAbsolutePath());
+
uniqueNameDirectories.add(uninstallDirectoryPath.getCanonicalPath());
+ if (!parentPath.equals(targetDirectory)
+ && !installDirectoryPath.equals(targetDirectory)
+ &&
!disabledDirectoryPath.equals(targetDirectory)
+ &&
!uninstallDirectoryPath.equals(targetDirectory))
+
uniqueNameDirectories.add(targetDirectory.getCanonicalPath());
+
// If the app file is in one of these directories, do a move
instead of a copy
LinkedList<File> moveDirectories = new LinkedList<File>();
moveDirectories.add(installDirectoryPath);
moveDirectories.add(disabledDirectoryPath);
moveDirectories.add(uninstallDirectoryPath);
-
- File targetFile = new File(targetDirectory.getAbsolutePath() +
File.separator
+
+ File targetFile = new File(targetDirectory.getCanonicalPath() +
File.separator
+ suggestFileName(uniqueNameDirectories,
this.getAppFile().getName()));
if (!targetDirectory.equals(parentPath)) {
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-08-16 21:34:03 UTC (rev 30208)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
2012-08-16 22:28:05 UTC (rev 30209)
@@ -65,6 +65,9 @@
/** Apps that are loaded are stored in this temporary directory. */
private static final String TEMPORARY_LOADED_APPS_DIRECTORY_NAME =
".temp-installed";
+ /** Apps that are to be installed on restart are stored in this
directory. */
+ private static final String INSTALL_RESTART_DIRECTORY_NAME =
"install-on-restart";
+
/** 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.0" +
File.separator + "apps";
@@ -142,8 +145,23 @@
purgeTemporaryDirectories();
initializeAppsDirectories();
+ // Move apps from install-on-restart directory to install
directory
+ Set<App> installOnRestartApps = obtainAppsFromDirectory(new
File(getInstallOnRestartAppsPath()), false);
+ for (App app: installOnRestartApps) {
+ try {
+ app.moveAppFile(this, new
File(getInstalledAppsPath()));
+ } catch (IOException e) {
+ }
+ }
+
+ // Remove the install-on-restart directory after apps were moved
+ try {
+ FileUtils.deleteDirectory(new
File(getInstallOnRestartAppsPath()));
+ } catch (IOException e) {
+ }
+
setupAlterationMonitor();
-
+
// Obtain previously disabled, installed apps
Set<App> disabledFolderApps = obtainAppsFromDirectory(new
File(getDisabledAppsPath()), false);
@@ -247,6 +265,7 @@
try {
parsedApp = appParser.parseApp(file);
} catch (AppParsingException e) {
+ logger.warn(e.getMessage());
return;
}
@@ -445,6 +464,12 @@
}
}
+ private void checkForFileChanges() {
+ for (FileAlterationObserver observer :
fileAlterationMonitor.getObservers()) {
+ observer.checkAndNotify();
+ }
+ }
+
public CySwingAppAdapter getSwingAppAdapter() {
return swingAppAdapter;
}
@@ -508,6 +533,8 @@
} catch (IOException e) {
throw new AppInstallException("Unable to move app file,
" + e.getMessage());
}
+
+ checkForFileChanges();
}
/**
@@ -528,6 +555,8 @@
} catch (IOException e) {
throw new AppUninstallException("Unable to move app
file, " + e.getMessage());
}
+
+ checkForFileChanges();
}
public void disableApp(App app) throws AppDisableException {
@@ -537,9 +566,11 @@
} catch (IOException e) {
throw new AppDisableException("Unable to move app file,
" + e.getMessage());
}
+
+ checkForFileChanges();
}
- private void fireAppsChangedEvent() {
+ public void fireAppsChangedEvent() {
AppsChangedEvent appEvent = new AppsChangedEvent(this);
for (AppsChangedListener appListener : appListeners) {
appListener.appsChanged(appEvent);
@@ -678,32 +709,27 @@
}
}
- /*
- public String getKarafDeployDirectory() {
- File directory = new File(System.getProperty("user.home") +
File.separator + ".cytoscape" + File.separator + "3.0"
- + File.separator + "apps" + File.separator +
"deploy");
+ /**
+ * Return the canonical path of the subdirectory in the local storage
directory used to contain apps that
+ * are installed on restart.
+ * @return The canonical path of the subdirectory in the local storage
directory containing
+ * apps to install on restart.
+ */
+ public String getInstallOnRestartAppsPath() {
+ File path = new File(getBaseAppPath() + File.separator +
INSTALL_RESTART_DIRECTORY_NAME);
- directory.mkdirs();
-
- return directory.getAbsolutePath();
- }
- */
-
- /*
- public void cleanKarafDeployDirectory() {
- String[] bundleAppExtensions = new String[]{"kar"};
- File karafDeployDirectory = new File(getKarafDeployDirectory());
- Collection<File> files =
FileUtils.listFiles(karafDeployDirectory, bundleAppExtensions, false);
-
- for (File potentialApp : files) {
+ try {
+ // Create the directory if it doesn't exist
+ if (!path.exists()) {
+ path.mkdirs();
+ }
- if (checkIfCytoscapeApp(potentialApp)) {
- DebugHelper.print("Cleaning: " +
potentialApp.getName());
- potentialApp.delete();
- }
+ return path.getCanonicalPath();
+ } catch (IOException e) {
+ logger.warn("Failed to obtain path to directory
containing apps to install on restart");
+ return path.getAbsolutePath();
}
}
- */
private boolean checkIfCytoscapeApp(File file) {
JarFile jarFile = null;
@@ -853,6 +879,12 @@
created = created && downloadedDirectory.mkdirs();
}
+ File installRestartDirectory = new
File(getInstallOnRestartAppsPath());
+ if (!installRestartDirectory.exists()) {
+ created = created && installRestartDirectory.mkdirs();
+ logger.info("Creating " + installRestartDirectory + ".
Success? " + created);
+ }
+
if (!created) {
logger.error("Failed to create local app storage
directories.");
}
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
2012-08-16 21:34:03 UTC (rev 30208)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
2012-08-16 22:28:05 UTC (rev 30209)
@@ -220,7 +220,13 @@
+ "\". Assuming default value 3.0.");
compatibleVersions = "3.0";
} else {
- throw new AppParsingException("Jar is missing value for entry
" + APP_COMPATIBLE_TAG + " in its manifest file.");
+
+ // For now, accept the deprecated field
Cytoscape-App-Works-With if the official field was not found
+ compatibleVersions =
manifest.getMainAttributes().getValue("Cytoscape-App-Works-With");
+
+ if (compatibleVersions == null ||
compatibleVersions.trim().length() == 0) {
+ throw new AppParsingException("Jar is missing value for
entry " + APP_COMPATIBLE_TAG + " in its manifest file.");
+ }
}
} else if
(!compatibleVersions.matches(APP_COMPATIBLE_TAG_REGEX)) {
throw new AppParsingException("The known compatible
versions of Cytoscape specified in the manifest under the"
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
2012-08-16 21:34:03 UTC (rev 30208)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
2012-08-16 22:28:05 UTC (rev 30209)
@@ -1,6 +1,7 @@
package org.cytoscape.app.internal.net;
import java.io.File;
+import java.io.IOException;
import java.sql.Time;
import java.util.Calendar;
import java.util.HashSet;
@@ -14,10 +15,14 @@
import org.cytoscape.app.internal.exception.AppInstallException;
import org.cytoscape.app.internal.exception.AppParsingException;
import org.cytoscape.app.internal.exception.AppUninstallException;
+import org.cytoscape.app.internal.exception.AppUpdateException;
import org.cytoscape.app.internal.manager.App;
+import org.cytoscape.app.internal.manager.SimpleApp;
import org.cytoscape.app.internal.manager.AppManager;
+import org.cytoscape.app.internal.manager.App.AppStatus;
import org.cytoscape.app.internal.util.DebugHelper;
import org.cytoscape.application.events.SetSelectedNetworksEvent;
+import org.omg.CORBA.FREE_MEM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,7 +72,7 @@
* @param update The update to install
* @param appManager The {@link AppManager} keeping track of current
apps
*/
- public void installUpdate(Update update, AppManager appManager) {
+ public void installUpdate(Update update, AppManager appManager) throws
AppUpdateException {
WebQuerier webQuerier = appManager.getWebQuerier();
@@ -92,8 +97,33 @@
// Uninstall old app
appManager.uninstallApp(update.getApp());
- // Install app
- appManager.installApp(parsedApp);
+ if (update.getApp() instanceof SimpleApp) {
+ try {
+
parsedApp.moveAppFile(appManager, new
File(appManager.getInstallOnRestartAppsPath()));
+ } catch (IOException e) {
+ // TODO Auto-generated catch
block
+ throw new
AppUpdateException("Unable to move update for simple app " +
update.getApp().getAppName() + " to " +
appManager.getInstallOnRestartAppsPath() + ", " + e.getMessage());
+ }
+
+ boolean appAlreadyRegistered = false;
+
+ for (App app : appManager.getApps()) {
+ if
(app.heuristicEquals(parsedApp)) {
+ appAlreadyRegistered =
true;
+ }
+ }
+
+ if (!appAlreadyRegistered) {
+ appManager.addApp(parsedApp);
+
+
parsedApp.setStatus(AppStatus.TO_BE_INSTALLED);
+
appManager.fireAppsChangedEvent();
+ }
+
+ } else {
+ // Install app
+ appManager.installApp(parsedApp);
+ }
if (this.updates.contains(update)) {
this.updates.remove(update);
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
2012-08-16 21:34:03 UTC (rev 30208)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
2012-08-16 22:28:05 UTC (rev 30209)
@@ -200,9 +200,12 @@
+ (updateCount == 1 ? "update" :
"updates") + " available.");
Calendar lastUpdateCheckTime =
updateManager.getLastUpdateCheckTime();
+
+ int minute = lastUpdateCheckTime.get(Calendar.MINUTE);
+
updateCheckTimeLabel.setText("Today, at "
+ lastUpdateCheckTime.get(Calendar.HOUR) + ":"
- + lastUpdateCheckTime.get(Calendar.MINUTE) + " "
+ + (minute < 10 ? "0" : "") + minute + " "
+ (lastUpdateCheckTime.get(Calendar.AM_PM) ==
Calendar.AM ? "am" : "pm"));
// populateUpdatesTable();
@@ -365,10 +368,7 @@
installSelectedButton.setEnabled(false);
} else if (selectedUpdates.size() == 1) {
Update update = selectedUpdates.iterator().next();
- descriptionTextArea.setText("Update for "
- + update.getApp().getAppName()
- + ": " + update.getApp().getVersion() + " -> "
- + update.getRelease().getReleaseVersion());
+ descriptionTextArea.setText("");
if (!installSelectedButton.isEnabled()) {
installSelectedButton.setEnabled(true);
--
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.