Author: paperwing
Date: 2012-06-22 16:03:25 -0700 (Fri, 22 Jun 2012)
New Revision: 29672
Modified:
core3/impl/trunk/app-impl/pom.xml
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/BundleApp.java
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
Log:
App Manager now checks if an app consists of bundles. This is done by looking
for values in the xml file that specifies the karaf features to be installed.
Modified: core3/impl/trunk/app-impl/pom.xml
===================================================================
--- core3/impl/trunk/app-impl/pom.xml 2012-06-22 22:50:49 UTC (rev 29671)
+++ core3/impl/trunk/app-impl/pom.xml 2012-06-22 23:03:25 UTC (rev 29672)
@@ -116,14 +116,6 @@
<version>chargebee-1.0</version>
</dependency>
- <!--
- <dependency>
- <groupId>cytoscape-temp</groupId>
- <artifactId>simple-json-parser</artifactId>
- <version>1.0-b20120413</version>
- </dependency>
- -->
-
<!-- dependency for Http server, uses the Apache HttpComponents
library -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@@ -131,6 +123,27 @@
<version>4.2</version>
</dependency>
+ <!-- dependency for ssh client to connect to karaf console for
bundle apps -->
+ <dependency>
+ <groupId>org.apache.sshd</groupId>
+ <artifactId>sshd</artifactId>
+ <version>0.6.0</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlbeans</groupId>
+
<artifactId>com.springsource.org.apache.xmlbeans</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.xml</groupId>
+ <artifactId>namespace</artifactId>
+ <version>1.0.1</version>
+ <type>pom</type>
+ </dependency>
+
<!-- dependencies needed for plugin manager -->
<dependency>
<groupId>org.cytoscape</groupId>
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-06-22 22:50:49 UTC (rev 29671)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
2012-06-22 23:03:25 UTC (rev 29672)
@@ -2,11 +2,33 @@
import java.io.File;
import java.io.IOException;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Stack;
+import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
import org.cytoscape.app.internal.exception.AppParsingException;
import org.cytoscape.app.internal.util.DebugHelper;
+import org.json.XML;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
/**
* This class represents an app parser that is capable of parsing given {@link
File}
@@ -84,6 +106,111 @@
throw new AppParsingException("Error parsing given file
as a jar file: " + e.getMessage());
}
+ boolean bundleApp = false;
+ boolean xmlParseFailed = false;
+
+ final List<BundleApp.KarafFeature> featuresList = new
LinkedList<BundleApp.KarafFeature>();
+
+ // Look for features specified in an xml file
+ Enumeration<JarEntry> entries = jarFile.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry jarEntry = entries.nextElement();
+
+ if (jarEntry.getName().endsWith("xml")) {
+
+ try {
+ SAXParserFactory spf =
SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ XMLReader xmlReader =
spf.newSAXParser().getXMLReader();
+
+ xmlReader.setContentHandler(new
ContentHandler() {
+
+ private Stack<String> qNames = new
Stack<String>();
+
+ @Override
+ public void
startPrefixMapping(String arg0, String arg1)
+ throws
SAXException {
+ }
+
+ @Override
+ public void startElement(String
uri, String localName, String qName,
+ Attributes
atts) throws SAXException {
+
+ qNames.push(qName);
+
+ if (qNames.size() == 2
+ &&
qNames.get(0).equalsIgnoreCase("features")
+ &&
qNames.get(1).equalsIgnoreCase("feature")) {
+
+
BundleApp.KarafFeature feature = new BundleApp.KarafFeature();
+
+ // Obtain the
feature name and version
+
feature.featureName = atts.getValue("name");
+
feature.featureVersion = atts.getValue("version");
+
+
featuresList.add(feature);
+ }
+ }
+
+ @Override
+ public void startDocument()
throws SAXException {
+ }
+
+ @Override
+ public void
skippedEntity(String arg0) throws SAXException {
+ }
+
+ @Override
+ public void
setDocumentLocator(Locator arg0) {
+ }
+
+ @Override
+ public void
processingInstruction(String arg0, String arg1)
+ throws
SAXException {
+ }
+
+ @Override
+ public void
ignorableWhitespace(char[] arg0, int arg1, int arg2)
+ throws
SAXException {
+ }
+
+ @Override
+ public void
endPrefixMapping(String arg0) throws SAXException {
+ }
+
+ @Override
+ public void endElement(String
arg0, String arg1, String arg2)
+ throws
SAXException {
+ qNames.pop();
+ }
+
+ @Override
+ public void endDocument()
throws SAXException {
+ }
+
+ @Override
+ public void characters(char[]
arg0, int arg1, int arg2) throws SAXException {
+ }
+ });
+
+ xmlReader.parse(new
InputSource(jarFile.getInputStream(jarEntry)));
+
+ } catch (SAXException e) {
+ xmlParseFailed = true;
+ } catch (IOException e) {
+ xmlParseFailed = true;
+ } catch (ParserConfigurationException e) {
+ xmlParseFailed = true;
+ }
+ }
+ }
+
+ // 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();
+ }
+
// Attempt to obtain manifest file from jar
Manifest manifest = null;
try {
@@ -97,10 +224,14 @@
throw new AppParsingException("No manifest was found in
the jar file.");
}
- // Obtain the fully-qualified name of the class to instantiate
upon app installation
- String entryClassName =
manifest.getMainAttributes().getValue(APP_CLASS_TAG);
- if (entryClassName == null || entryClassName.trim().length() ==
0) {
- throw new AppParsingException("Jar is missing value for
entry " + APP_CLASS_TAG + " in its manifest file.");
+ String entryClassName = null;
+ // Bundle apps are instantiated by OSGi using their activator
classes
+ if (!bundleApp) {
+ // Obtain the fully-qualified name of the class to
instantiate upon app installation
+ entryClassName =
manifest.getMainAttributes().getValue(APP_CLASS_TAG);
+ if (entryClassName == null ||
entryClassName.trim().length() == 0) {
+ throw new AppParsingException("Jar is missing
value for entry " + APP_CLASS_TAG + " in its manifest file.");
+ }
}
// Obtain the human-readable name of the app
@@ -144,5 +275,7 @@
parsedApp.setAppValidated(true);
return parsedApp;
+
+
}
}
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-22 22:50:49 UTC (rev 29671)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
2012-06-22 23:03:25 UTC (rev 29672)
@@ -1,6 +1,7 @@
package org.cytoscape.app.internal.manager;
import java.net.MalformedURLException;
+import java.util.List;
import org.cytoscape.app.CyAppAdapter;
import org.cytoscape.app.internal.exception.AppInstallException;
@@ -13,6 +14,17 @@
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 List<KarafFeature> featuresList = null;
+
@Override
public Object createAppInstance(CySwingAppAdapter appAdapter)
throws AppInstanceException {
@@ -47,4 +59,18 @@
// defaultUninstall(appManager);
}
+ /**
+ * Return the list of karaf features.
+ * @return The list of karaf features
+ */
+ public List<KarafFeature> getFeaturesList() {
+ return featuresList;
+ }
+
+ public void setFeaturesList(List<KarafFeature> featuresList) {
+ this.featuresList = featuresList;
+ }
+
+
+
}
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
2012-06-22 22:50:49 UTC (rev 29671)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
2012-06-22 23:03:25 UTC (rev 29672)
@@ -117,7 +117,7 @@
try {
App app =
appManager.getAppParser().parseApp(appFile);
-
+
appManager.installApp(app);
} catch (AppParsingException e)
{
installStatus =
"install-failed";
--
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.