Author: slotia
Date: 2012-07-18 15:24:07 -0700 (Wed, 18 Jul 2012)
New Revision: 29924
Added:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
Removed:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
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/AppParser.java
Log:
Renamed BundleApp to KarafArchiveApp
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-07-18 22:16:52 UTC (rev 29923)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
2012-07-18 22:24:07 UTC (rev 29924)
@@ -368,8 +368,8 @@
}
// For bundle apps, remove temporary files from Karaf deploy
directory on exit
- if (app instanceof BundleApp) {
- File temporaryInstallFile = ((BundleApp)
app).getAppTemporaryInstallFile();
+ if (app instanceof KarafArchiveApp) {
+ File temporaryInstallFile = ((KarafArchiveApp)
app).getAppTemporaryInstallFile();
if (temporaryInstallFile != null) {
// temporaryInstallFile.deleteOnExit();
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-07-18 22:16:52 UTC (rev 29923)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
2012-07-18 22:24:07 UTC (rev 29924)
@@ -112,7 +112,7 @@
// Look for features specified in an xml file
- List<BundleApp.KarafFeature> featuresList =
Collections.emptyList();
+ List<KarafArchiveApp.KarafFeature> featuresList =
Collections.emptyList();
try {
featuresList = getFeaturesXmlFromJar(jarFile);
} catch (AppParsingException e) {
@@ -136,14 +136,14 @@
// If an XML parsing error occurred, continue to attempt to
parse the app as a simple app
if (featuresList.size() > 0 && !xmlParseFailed) {
bundleApp = true;
- parsedApp = new BundleApp();
+ parsedApp = new KarafArchiveApp();
- for (BundleApp.KarafFeature feature: featuresList) {
- ((BundleApp)
parsedApp).getFeaturesList().put(feature.featureName, feature);
+ for (KarafArchiveApp.KarafFeature feature:
featuresList) {
+ ((KarafArchiveApp)
parsedApp).getFeaturesList().put(feature.featureName, feature);
}
} else if (osgiMetadataFound) {
bundleApp = true;
- parsedApp = new BundleApp();
+ parsedApp = new KarafArchiveApp();
}
// Attempt to obtain manifest file from jar
@@ -222,9 +222,9 @@
return parsedApp;
}
- private static List<BundleApp.KarafFeature> getFeaturesXmlFromJar(final
JarFile jarFile) throws AppParsingException
+ private static List<KarafArchiveApp.KarafFeature>
getFeaturesXmlFromJar(final JarFile jarFile) throws AppParsingException
{
- final List<BundleApp.KarafFeature> featuresList = new
LinkedList<BundleApp.KarafFeature>();
+ final List<KarafArchiveApp.KarafFeature> featuresList = new
LinkedList<KarafArchiveApp.KarafFeature>();
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
@@ -253,7 +253,7 @@
&&
qNames.get(0).equalsIgnoreCase("features")
&&
qNames.get(1).equalsIgnoreCase("feature")) {
-
BundleApp.KarafFeature feature = new BundleApp.KarafFeature();
+
KarafArchiveApp.KarafFeature feature = new KarafArchiveApp.KarafFeature();
// Obtain the
feature name and version
feature.featureName = atts.getValue("name");
Deleted:
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-07-18 22:16:52 UTC (rev 29923)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
2012-07-18 22:24:07 UTC (rev 29924)
@@ -1,206 +0,0 @@
-package org.cytoscape.app.internal.manager;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.io.FileExistsException;
-import org.apache.commons.io.FileUtils;
-import org.apache.karaf.features.Feature;
-import org.apache.karaf.features.FeaturesService;
-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.cytoscape.app.swing.CySwingAppAdapter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-
-public class BundleApp extends App {
-
- /**
- * Karaf feature information used to install/uninstall a bundle app,
- * which consists of Karaf features.
- */
- public static class KarafFeature {
- public String featureName;
- public String featureVersion;
- }
-
- private Map<String, KarafFeature> featuresSet;
-
- public BundleApp() {
- super();
-
- this.featuresSet = new HashMap<String, KarafFeature>();
- }
-
- @Override
- public Object createAppInstance(CySwingAppAdapter appAdapter)
- throws AppInstanceException {
-
- BundleContext bundleContext = null;
- Bundle bundle = null;
- try {
- bundle =
bundleContext.installBundle(this.getAppTemporaryInstallFile().toURI().toURL().toString());
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (BundleException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return bundle;
- }
-
- @Override
- public void install(AppManager appManager) throws AppInstallException {
-
- // Check if we already have an app object representing this app
registered to the app manager
- for (App app : appManager.getApps()) {
- if (this.heuristicEquals(app) && this != app) {
-
- app.setAppFile(this.getAppFile());
- app.install(appManager);
-
- return;
- }
- }
-
- File appFile = this.getAppFile();
-
- try {
- if (appFile != null
- &&
!appFile.getParentFile().getCanonicalPath().equals(appManager.getInstalledAppsPath()))
{
-
- FileUtils.copyFileToDirectory(appFile, new
File(appManager.getInstalledAppsPath()));
-
- if
(appFile.getParentFile().getCanonicalPath().equalsIgnoreCase(
-
appManager.getUninstalledAppsPath())) {
- appFile.delete();
- }
-
- this.setAppFile(new
File(appManager.getInstalledAppsPath() + File.separator + appFile.getName()));
- }
- } catch (IOException e) {
- 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 {
-
- // 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");
- }
-
- // Check if the features were installed
- FeaturesService featuresService =
appManager.getFeaturesService();
- List<Feature> installedFeatures =
getCorrespondingFeatures(featuresService);
-
- //System.out.println("features from app: " +
featuresSet.size());
- //System.out.println("available features: " +
featuresService.listFeatures().length);
-
- /*
- if (installedFeatures.size() == featuresSet.size()) {
-
- } else {
- this.getAppTemporaryInstallFile().delete();
- throw new AppInstallException("Not all Karaf features
were successfully installed from the bundle app.");
- }
- */
-
- if (!appManager.getApps().contains(this)) {
- appManager.getApps().add(this);
- }
-
- this.setStatus(AppStatus.INSTALLED);
- }
-
- private List<Feature> getCorrespondingFeatures(FeaturesService
featuresService) {
- List<Feature> correspondingFeatures = new LinkedList<Feature>();
-
- Feature[] availableFeatures = new Feature[]{};
- try {
- availableFeatures = featuresService.listFeatures();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- for (int i = 0; i < availableFeatures.length; i++) {
- Feature availableFeature = availableFeatures[i];
-
- BundleApp.KarafFeature appFeature =
featuresSet.get(availableFeature.getName());
-
- // System.out.println("available feature: " +
availableFeature.getName() + ", " + availableFeature.getVersion());
-
- if (appFeature != null
- &&
appFeature.featureVersion.equalsIgnoreCase(availableFeature.getVersion())) {
- correspondingFeatures.add(availableFeature);
-
- // System.out.println("feature match: " +
availableFeature.getName() + " vs " + appFeature.featureName);
- }
- }
-
- return correspondingFeatures;
- }
-
- @Override
- public void uninstall(AppManager appManager) throws
AppUninstallException {
-
- // Use the default uninstallation procedure consisting of
moving the app file
- // to the uninstalled apps directory
- // defaultUninstall(appManager);
-
- try {
- File uninstallDirectoryTargetFile = new
File(appManager.getUninstalledAppsPath() + File.separator +
getAppFile().getName());
-
- if (uninstallDirectoryTargetFile.exists()) {
- uninstallDirectoryTargetFile.delete();
- }
-
- try {
- FileUtils.moveFile(getAppFile(),
uninstallDirectoryTargetFile);
- } catch (FileExistsException e) {
- }
-
- this.setAppFile(uninstallDirectoryTargetFile);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
-
- throw new AppUninstallException("Unable to move app
file to uninstalled apps directory: " + e.getMessage());
- }
-
- this.getAppTemporaryInstallFile().delete();
-
- this.setStatus(AppStatus.TO_BE_UNINSTALLED);
- }
-
- /**
- * Return the list of karaf features.
- * @return The list of karaf features
- */
- public Map<String, KarafFeature> getFeaturesList() {
- return featuresSet;
- }
-
- public void setFeaturesList(Map<String, KarafFeature> featuresSet) {
- this.featuresSet = featuresSet;
- }
-}
Copied:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
(from rev 29918,
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/KarafArchiveApp.java
(rev 0)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
2012-07-18 22:24:07 UTC (rev 29924)
@@ -0,0 +1,206 @@
+package org.cytoscape.app.internal.manager;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.FileExistsException;
+import org.apache.commons.io.FileUtils;
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
+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.cytoscape.app.swing.CySwingAppAdapter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class KarafArchiveApp extends App {
+
+ /**
+ * Karaf feature information used to install/uninstall a bundle app,
+ * which consists of Karaf features.
+ */
+ public static class KarafFeature {
+ public String featureName;
+ public String featureVersion;
+ }
+
+ private Map<String, KarafFeature> featuresSet;
+
+ public KarafArchiveApp() {
+ super();
+
+ this.featuresSet = new HashMap<String, KarafFeature>();
+ }
+
+ @Override
+ public Object createAppInstance(CySwingAppAdapter appAdapter)
+ throws AppInstanceException {
+
+ BundleContext bundleContext = null;
+ Bundle bundle = null;
+ try {
+ bundle =
bundleContext.installBundle(this.getAppTemporaryInstallFile().toURI().toURL().toString());
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (BundleException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return bundle;
+ }
+
+ @Override
+ public void install(AppManager appManager) throws AppInstallException {
+
+ // Check if we already have an app object representing this app
registered to the app manager
+ for (App app : appManager.getApps()) {
+ if (this.heuristicEquals(app) && this != app) {
+
+ app.setAppFile(this.getAppFile());
+ app.install(appManager);
+
+ return;
+ }
+ }
+
+ File appFile = this.getAppFile();
+
+ try {
+ if (appFile != null
+ &&
!appFile.getParentFile().getCanonicalPath().equals(appManager.getInstalledAppsPath()))
{
+
+ FileUtils.copyFileToDirectory(appFile, new
File(appManager.getInstalledAppsPath()));
+
+ if
(appFile.getParentFile().getCanonicalPath().equalsIgnoreCase(
+
appManager.getUninstalledAppsPath())) {
+ appFile.delete();
+ }
+
+ this.setAppFile(new
File(appManager.getInstalledAppsPath() + File.separator + appFile.getName()));
+ }
+ } catch (IOException e) {
+ 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 {
+
+ // 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");
+ }
+
+ // Check if the features were installed
+ FeaturesService featuresService =
appManager.getFeaturesService();
+ List<Feature> installedFeatures =
getCorrespondingFeatures(featuresService);
+
+ //System.out.println("features from app: " +
featuresSet.size());
+ //System.out.println("available features: " +
featuresService.listFeatures().length);
+
+ /*
+ if (installedFeatures.size() == featuresSet.size()) {
+
+ } else {
+ this.getAppTemporaryInstallFile().delete();
+ throw new AppInstallException("Not all Karaf features
were successfully installed from the bundle app.");
+ }
+ */
+
+ if (!appManager.getApps().contains(this)) {
+ appManager.getApps().add(this);
+ }
+
+ this.setStatus(AppStatus.INSTALLED);
+ }
+
+ private List<Feature> getCorrespondingFeatures(FeaturesService
featuresService) {
+ List<Feature> correspondingFeatures = new LinkedList<Feature>();
+
+ Feature[] availableFeatures = new Feature[]{};
+ try {
+ availableFeatures = featuresService.listFeatures();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ for (int i = 0; i < availableFeatures.length; i++) {
+ Feature availableFeature = availableFeatures[i];
+
+ KarafArchiveApp.KarafFeature appFeature =
featuresSet.get(availableFeature.getName());
+
+ // System.out.println("available feature: " +
availableFeature.getName() + ", " + availableFeature.getVersion());
+
+ if (appFeature != null
+ &&
appFeature.featureVersion.equalsIgnoreCase(availableFeature.getVersion())) {
+ correspondingFeatures.add(availableFeature);
+
+ // System.out.println("feature match: " +
availableFeature.getName() + " vs " + appFeature.featureName);
+ }
+ }
+
+ return correspondingFeatures;
+ }
+
+ @Override
+ public void uninstall(AppManager appManager) throws
AppUninstallException {
+
+ // Use the default uninstallation procedure consisting of
moving the app file
+ // to the uninstalled apps directory
+ // defaultUninstall(appManager);
+
+ try {
+ File uninstallDirectoryTargetFile = new
File(appManager.getUninstalledAppsPath() + File.separator +
getAppFile().getName());
+
+ if (uninstallDirectoryTargetFile.exists()) {
+ uninstallDirectoryTargetFile.delete();
+ }
+
+ try {
+ FileUtils.moveFile(getAppFile(),
uninstallDirectoryTargetFile);
+ } catch (FileExistsException e) {
+ }
+
+ this.setAppFile(uninstallDirectoryTargetFile);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ throw new AppUninstallException("Unable to move app
file to uninstalled apps directory: " + e.getMessage());
+ }
+
+ this.getAppTemporaryInstallFile().delete();
+
+ this.setStatus(AppStatus.TO_BE_UNINSTALLED);
+ }
+
+ /**
+ * Return the list of karaf features.
+ * @return The list of karaf features
+ */
+ public Map<String, KarafFeature> getFeaturesList() {
+ return featuresSet;
+ }
+
+ public void setFeaturesList(Map<String, KarafFeature> featuresSet) {
+ this.featuresSet = featuresSet;
+ }
+}
--
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.