diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-16 00:52:30 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-16 00:52:30 +0000 |
commit | f520619c5ef71428448b6487c05ab364e21b5b7a (patch) | |
tree | 080d1bad0cd40e08e6156c7a2eb5f6bd1112a62d /java/sca/modules | |
parent | a05d78179ffb379b5cbf987081947039769f10e2 (diff) |
Bring up the equinox-based junit plugin for maven
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734877 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
2 files changed, 96 insertions, 24 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java index 74dedca4a8..d9e42711ff 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java @@ -30,7 +30,10 @@ import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.thir import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.thisBundleLocation; import java.io.File; +import java.io.FileNotFoundException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -55,12 +58,14 @@ public class EquinoxHost { private BundleContext bundleContext; private Bundle launcherBundle; private boolean startedEclipse; + private Set<URL> dependencies; private List<String> bundleFiles = new ArrayList<String>(); private List<String> bundleNames = new ArrayList<String>(); private List<String> jarFiles = new ArrayList<String>(); private Map<String, Bundle> allBundles = new HashMap<String, Bundle>(); private List<Bundle> installedBundles = new ArrayList<Bundle>(); + /* private final static String systemPackages = "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0, " @@ -113,6 +118,15 @@ public class EquinoxHost { + "org.omg.PortableInterceptor, " + "org.omg.stub.java.rmi, " + "javax.rmi.CORBA"; + */ + public EquinoxHost() { + super(); + } + + public EquinoxHost(Set<URL> dependencies) { + super(); + this.dependencies = dependencies; + } /** * Start the Equinox host. @@ -167,17 +181,7 @@ public class EquinoxHost { // Determine the runtime classpath entries Set<URL> urls; - if (!startedEclipse) { - - // Use classpath entries from a distribution if there is one and the modules - // directories available in a dev environment for example - urls = runtimeClasspathEntries(true, false, true); - } else { - - // Use classpath entries from a distribution if there is one and the classpath - // entries on the current application's classloader - urls = runtimeClasspathEntries(true, true, false); - } + urls = findDependencies(); // Sort out which are bundles (and not already installed) and which are just // regular JARs @@ -325,6 +329,23 @@ public class EquinoxHost { } } + private Set<URL> findDependencies() throws FileNotFoundException, URISyntaxException, MalformedURLException { + if (dependencies == null) { + if (!startedEclipse) { + + // Use classpath entries from a distribution if there is one and the modules + // directories available in a dev environment for example + dependencies = runtimeClasspathEntries(true, false, true); + } else { + + // Use classpath entries from a distribution if there is one and the classpath + // entries on the current application's classloader + dependencies = runtimeClasspathEntries(true, true, false); + } + } + return dependencies; + } + /** * Stop the Equinox host. */ diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java index db53eb7852..d52d3ccf86 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java @@ -261,22 +261,67 @@ final class NodeLauncherUtil { */ private static void addPackages(String jarFile, Set<String> packages) throws IOException { String version = ";version=" + jarVersion(jarFile); - ZipInputStream is = new ZipInputStream(new FileInputStream(file(new URL(jarFile)))); - ZipEntry entry; - while ((entry = is.getNextEntry()) != null) { - String entryName = entry.getName(); - if (!entry.isDirectory() && entryName != null - && entryName.length() > 0 - && !entryName.startsWith(".") - && entryName.endsWith(".class") // Exclude resources from Export-Package - && entryName.lastIndexOf("/") > 0) { - String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.') + version; + File file = file(new URL(jarFile)); + if (file.isDirectory()) { + List<String> classFiles = listClassFiles(file); + for (String cls : classFiles) { + int index = cls.lastIndexOf('/'); + String pkg = cls.substring(0, index); + pkg = pkg.replace('/', '.') + version; packages.add(pkg); } + } else if (file.isFile()) { + ZipInputStream is = new ZipInputStream(new FileInputStream(file)); + ZipEntry entry; + while ((entry = is.getNextEntry()) != null) { + String entryName = entry.getName(); + if (!entry.isDirectory() && entryName != null + && entryName.length() > 0 + && !entryName.startsWith(".") + && entryName.endsWith(".class") // Exclude resources from Export-Package + && entryName.lastIndexOf("/") > 0) { + String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.') + version; + packages.add(pkg); + } + } + is.close(); + } + } + + private static List<String> listClassFiles(File directory) { + List<String> artifacts = new ArrayList<String>(); + traverse(artifacts, directory, directory); + return artifacts; + } + + /** + * Recursively traverse a root directory + * + * @param fileList + * @param file + * @param root + * @throws IOException + */ + private static void traverse(List<String> fileList, File file, File root) { + if (file.isFile() && file.getName().endsWith(".class")) { + fileList.add(root.toURI().relativize(file.toURI()).toString()); + } else if (file.isDirectory()) { + String uri = root.toURI().relativize(file.toURI()).toString(); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + fileList.add(uri); + + File[] files = file.listFiles(); + for (File f: files) { + if (!f.getName().startsWith(".")) { + traverse(fileList, f, root); + } + } } - is.close(); } + /** * Generate a manifest from a list of third-party JAR files. * @@ -362,7 +407,11 @@ final class NodeLauncherUtil { if (url == null) { throw new FileNotFoundException(resource); } - URI uri = url.toURI(); + String str = url.toString(); + if (str.contains(" ")) { + str = str.replace(" ", "%20"); + } + URI uri = URI.create(str); String scheme = uri.getScheme(); if (scheme.equals("jar")) { @@ -506,7 +555,9 @@ final class NodeLauncherUtil { } else { JarFile jar = new JarFile(file, false); Manifest manifest = jar.getManifest(); - bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + if (manifest != null) { + bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + } jar.close(); } if (bundleName == null) { |