summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-09-14 10:11:15 (EDT)
committerpelder2006-09-14 10:11:15 (EDT)
commit6cda106c6bd1348ecbc053d47d56c3fb2d0965b9 (patch)
tree5ea3ed3251a0299ff1113f80ab99af9d7df52714
parent7b9290b4ad8f977cb34a5dac0214cc425506abb1 (diff)
downloadorg.eclipse.jet-6cda106c6bd1348ecbc053d47d56c3fb2d0965b9.zip
org.eclipse.jet-6cda106c6bd1348ecbc053d47d56c3fb2d0965b9.tar.gz
org.eclipse.jet-6cda106c6bd1348ecbc053d47d56c3fb2d0965b9.tar.bz2
[157311] Add JET transformation JARs found 'Additional Locations for JET Transformations' directories to the transformation search path.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/ModelLoaderExtManager.java9
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/AdditionalBundleLocationProvider.java228
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/BundleJarInfo.java87
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java24
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DirectoryBundleProvider.java188
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java42
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java3
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleJarUtil.java47
8 files changed, 607 insertions, 21 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/ModelLoaderExtManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/ModelLoaderExtManager.java
index 347e473..52a0236 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/ModelLoaderExtManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/ModelLoaderExtManager.java
@@ -59,6 +59,8 @@ import org.eclipse.jet.runtime.model.ILoaderManager;
*/
public final class ModelLoaderExtManager implements IRegistryChangeListener
{
+ private static boolean DEBUG = InternalJET2Platform.getDefault().isDebugging()
+ && Boolean.valueOf(Platform.getDebugOption("org.eclipse.jet/debug/modelLoaderExtensions")).booleanValue(); //$NON-NLS-1$
private static final String PLUGIN_ID = "org.eclipse.jet"; //$NON-NLS-1$
@@ -115,10 +117,17 @@ public final class ModelLoaderExtManager implements IRegistryChangeListener
IExtension ext = deltas[i].getExtension();
if (deltas[i].getKind() == IExtensionDelta.ADDED)
{
+ if(DEBUG)
+ {
+ System.out.println("ModelLoaderExtManager.registryChanged(add " + ext.getContributor().getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
addConfigElements(ext.getConfigurationElements());
}
else
{
+ if(DEBUG) {
+ System.out.println("ModelLoaderExtManager.registryChanged(remove " + ext.getContributor().getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
removeConfigElements(ext.getConfigurationElements());
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/AdditionalBundleLocationProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/AdditionalBundleLocationProvider.java
new file mode 100644
index 0000000..c9954f2
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/AdditionalBundleLocationProvider.java
@@ -0,0 +1,228 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.JETPreferences;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * BundleProvider for directories referenced in the JET preferences
+ */
+public class AdditionalBundleLocationProvider implements IJETBundleProvider, IPreferenceChangeListener
+{
+ private static boolean DEBUG = InternalJET2Platform.getDefault().isDebugging()
+ && Boolean.valueOf(Platform.getDebugOption("org.eclipse.jet/debug/additionalBundleLoading")).booleanValue(); //$NON-NLS-1$
+
+ private IEclipsePreferences defaultsNode;
+ private IEclipsePreferences configurationNode;
+ private IEclipsePreferences instanceNode;
+ private IEclipsePreferences[] searchList;
+ private final IPreferencesService service = Platform.getPreferencesService();
+ private final List directoryProviders = new ArrayList();
+
+ private String[] parseAdditionalPathString(String stringList) {
+ if(stringList == null) return new String[0];
+ StringTokenizer st = new StringTokenizer(stringList, File.pathSeparator
+ + "\n\r");//$NON-NLS-1$
+ List v = new ArrayList();
+ while (st.hasMoreElements()) {
+ v.add(st.nextElement());
+ }
+ return (String[]) v.toArray(new String[v.size()]);
+}
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#getAllJETBundleDescriptors()
+ */
+ public Collection getAllJETBundleDescriptors()
+ {
+ Set allIds = getAllJETBundleIds();
+
+ List descriptors = new ArrayList(allIds.size());
+ for (Iterator i = allIds.iterator(); i.hasNext();)
+ {
+ String id = (String)i.next();
+ descriptors.add(getDescriptor(id));
+ }
+
+ return descriptors;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#getAllJETBundleIds()
+ */
+ public Set getAllJETBundleIds()
+ {
+ if(DEBUG) System.out.println("AdditionalBundleLocationProvider.getAllJETBundleIds()");; //$NON-NLS-1$
+ Set result = new HashSet();
+ for (Iterator i = directoryProviders.iterator(); i.hasNext();)
+ {
+ DirectoryBundleProvider provider = (DirectoryBundleProvider)i.next();
+ result.addAll(provider.getAllJETBundleIds());
+ }
+ if(DEBUG) System.out.println(" " + result); //$NON-NLS-1$
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#getDescriptor(java.lang.String)
+ */
+ public IJETBundleDescriptor getDescriptor(String id)
+ {
+ if(DEBUG) System.out.println("AdditionalBundleLocationProvider.getDescriptor(" + id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ IJETBundleDescriptor descriptor = null;
+ for (Iterator i = directoryProviders.iterator(); i.hasNext() && descriptor == null;)
+ {
+ DirectoryBundleProvider provider = (DirectoryBundleProvider)i.next();
+ descriptor = provider.getDescriptor(id);
+ }
+ return descriptor;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#load(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public Bundle load(String id, IProgressMonitor monitor) throws BundleException
+ {
+ Bundle bundle = null;
+ final DynamicJETBundleDescriptor descriptor = (DynamicJETBundleDescriptor)getDescriptor(id);
+ if(descriptor != null)
+ {
+ bundle = InternalJET2Platform.getDefault().getJETBundleInstaller().installBundle(descriptor.getBundleURL());
+ if(DEBUG) System.out.println("[deployedBundle] Loaded " + bundle.getSymbolicName()); //$NON-NLS-1$
+ }
+ return bundle;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#shutdown()
+ */
+ public void shutdown()
+ {
+ instanceNode.removePreferenceChangeListener(this);
+ directoryProviders.clear();
+
+ configurationNode = null;
+ instanceNode = null;
+ searchList = null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#startup()
+ */
+ public void startup()
+ {
+ if(DEBUG) {
+ System.out.println("DirectoryJETBundleProvider.startup()"); //$NON-NLS-1$
+ }
+ defaultsNode = new DefaultScope().getNode(JET2Platform.PLUGIN_ID);
+ configurationNode = new ConfigurationScope().getNode(JET2Platform.PLUGIN_ID);
+ instanceNode = new InstanceScope().getNode(JET2Platform.PLUGIN_ID);
+ searchList = new IEclipsePreferences[] {
+ instanceNode,
+ configurationNode,
+ defaultsNode,
+ };
+
+ final String additonalLocations = service.get(JETPreferences.ADDITIONAL_TEMPLATE_JAR_LOCATIONS, null, searchList);
+ addTransforms(additonalLocations);
+
+ instanceNode.addPreferenceChangeListener(this);
+ }
+
+
+ /**
+ * @param additonalLocations
+ */
+ private void addTransforms(final String additonalLocations)
+ {
+ System.out.println("DirectoryJETBundleProvider.addTransforms(" + additonalLocations + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] dirNames = parseAdditionalPathString(additonalLocations);
+
+
+ directoryProviders.clear();
+
+ File[] dirs = new File[dirNames.length];
+ for (int i = 0; i < dirNames.length; i++)
+ {
+ dirs[i] = new File(dirNames[i]);
+ if(dirs[i].exists() && dirs[i].isDirectory())
+ {
+ directoryProviders.add(new DirectoryBundleProvider(dirs[i]));
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#unload(java.lang.String)
+ */
+ public void unload(String id) throws BundleException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#unload(org.osgi.framework.Bundle)
+ */
+ public void unload(Bundle bundle) throws BundleException
+ {
+ if(bundle != null)
+ {
+ if(DEBUG) System.out.println("[deployedBundle] Unloading " + bundle.getSymbolicName()); //$NON-NLS-1$
+ bundle.uninstall();
+ }
+ }
+
+
+ public void preferenceChange(PreferenceChangeEvent event)
+ {
+ if(DEBUG) {
+ System.out.println("DirectoryJETBundleProvider.preferenceChange()"); //$NON-NLS-1$
+ System.out.println(" key: " + event.getKey()); //$NON-NLS-1$
+ System.out.println(" old: " + event.getOldValue()); //$NON-NLS-1$
+ System.out.println(" new: " + event.getNewValue()); //$NON-NLS-1$
+ }
+ if(JETPreferences.ADDITIONAL_TEMPLATE_JAR_LOCATIONS.equals(event.getKey())) {
+ final String additonalLocations = service.get(JETPreferences.ADDITIONAL_TEMPLATE_JAR_LOCATIONS, null, searchList);
+ addTransforms(additonalLocations);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/BundleJarInfo.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/BundleJarInfo.java
new file mode 100644
index 0000000..84429fe
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/BundleJarInfo.java
@@ -0,0 +1,87 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Information class on OSGi Bundle Jars.
+ */
+public class BundleJarInfo
+{
+ /**
+ * Factory for create a BundleJarInfo instance
+ * @param jarName the jar file name
+ * @return the BundleJarInfo instance, or <code>null</code> if <code>jarName</code> is not a bundle jar.
+ */
+ public static BundleJarInfo createBundleJarInfo(String jarName)
+ {
+ final Matcher m = jarPattern.matcher(jarName);
+
+
+ return m.matches() ? new BundleJarInfo(jarName, m.group(1), m.group(2)) : null;
+ }
+
+ private final String jarName;
+
+ private static final String VERSION = "\\d+\\.\\d+\\.\\d+"; //$NON-NLS-1$
+ /**
+ * Pattern for pulling symbolic name and version from an exported JAR which is of the form
+ * <p><code>symbolicName_version.jar</code></p>
+ * <p>
+ * Note that plug-in is can contain numbers, and that the 4th component may contain underscores, so
+ * you can have a plug-in such as:
+ * </p>
+ * <p><code>symbolic name: a.b.c_1.2.3.x_yz</code></p>
+ * <p><code>version: 4.5.6.a_b_c</code></p>
+ * <p><code>jar file name: a.b.c_1.2.3.x_yz_4.5.6.a_b_c.jar</code></p>
+ */
+ private final static Pattern jarPattern = Pattern.compile(
+ "((?:\\w|\\.|\\_)+)" // group 1: capture symbolic name //$NON-NLS-1$
+ + "_(" + VERSION + "(?:\\..*)?)" // group 2: capture version //$NON-NLS-1$ //$NON-NLS-2$
+ + "(?!" + VERSION + ").jar" // negative look-ahead for VERSION unsures we get the right parts //$NON-NLS-1$ //$NON-NLS-2$
+ );
+
+ private final String symbolicName;
+
+ private final String version;
+
+ private BundleJarInfo(String jarName, String symbolicName, String version)
+ {
+ this.jarName = jarName;
+ this.symbolicName = symbolicName;
+ this.version = version;
+ }
+
+ public String getBundleSymbolicName()
+ {
+ return symbolicName;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public final String getJarName()
+ {
+ return jarName;
+ }
+
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java
index 18bd661..00f4e98 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java
@@ -16,8 +16,6 @@
*/
package org.eclipse.jet.internal.runtime;
-import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Collection;
@@ -38,8 +36,6 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.extensionpoints.TransformData;
-import org.eclipse.jet.internal.extensionpoints.TransformDataFactory;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.transform.IJETBundleDescriptor;
import org.osgi.framework.Bundle;
@@ -157,28 +153,16 @@ public class DeployedJETBundleProvider implements IJETBundleProvider, IRegistryC
if (jet2Bundle != null)
{
Bundle declaringBundle = Platform.getBundle(configElements[i].getDeclaringExtension().getNamespace());
- try
+ URL bundleURL = declaringBundle.getEntry(jet2Bundle);
+ IJETBundleDescriptor descriptor = JETBundleManager.getJETBundleDescriptorForJAR(bundleURL);
+ if(descriptor != null)
{
- URL bundleURL = declaringBundle.getEntry(jet2Bundle);
- URL jarURL = new URL("jar", "", bundleURL.toExternalForm() + "!/"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- JETBundleManifest manifest = JETBundleManager.loadManifest(jarURL);
- TransformData transformData = TransformDataFactory.INSTANCE.createTransformData(manifest.getTransformId(), jarURL);
-
- final DynamicJETBundleDescriptor descriptor = new DynamicJETBundleDescriptor(manifest, transformData, jarURL, bundleURL);
descriptorsById.put(descriptor.getId(), descriptor);
if (DEBUG)
{
- InternalJET2Platform.debugMessage(this, "addTransforms(" + descriptor.getId() + ", " + jarURL + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ InternalJET2Platform.debugMessage(this, "addTransforms(" + descriptor.getId() + ", " + bundleURL + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
}
- catch (MalformedURLException e)
- {
- InternalJET2Platform.logError("Unexpected failure getting deployed transform information.", e); //$NON-NLS-1$
- }
- catch (IOException e)
- {
- InternalJET2Platform.logError("Unexpected failure reading deployed transform manifest.", e); //$NON-NLS-1$
- }
}
else
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DirectoryBundleProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DirectoryBundleProvider.java
new file mode 100644
index 0000000..305dfad
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DirectoryBundleProvider.java
@@ -0,0 +1,188 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * Bundle Provider for bundles stored in a directory.
+ */
+public class DirectoryBundleProvider implements IJETBundleProvider
+{
+ private static boolean DEBUG = InternalJET2Platform.getDefault().isDebugging()
+ && Boolean.valueOf(Platform.getDebugOption("org.eclipse.jet/debug/additionalBundleLoading")).booleanValue(); //$NON-NLS-1$
+
+ private final File directory;
+
+ /**
+ *
+ * @param directoryLocation
+ */
+ public DirectoryBundleProvider(String directoryLocation)
+ {
+ this(new File(directoryLocation));
+ }
+
+ public DirectoryBundleProvider(File directory)
+ {
+ if(!directory.exists() || !directory.isDirectory())
+ {
+ throw new IllegalArgumentException();
+ }
+ this.directory = directory;
+ System.out.println("DirectoryBundleProvider.DirectoryBundleProvider(" + directory.getAbsolutePath() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public Collection getAllJETBundleDescriptors()
+ {
+ final Map descriptorsById = getDescriptorsById();
+ return descriptorsById.values();
+ }
+
+ /**
+ * @return
+ */
+ private Map getDescriptorsById()
+ {
+ final Map descriptorsById = new HashMap();
+ directory.listFiles(new FileFilter() {
+
+ public boolean accept(File pathname)
+ {
+ final BundleJarInfo jarInfo = BundleJarInfo.createBundleJarInfo(pathname.getName());
+
+ if(jarInfo != null)
+ {
+ try
+ {
+ final URL bundleURL = pathname.toURL();
+ final IJETBundleDescriptor descriptor = JETBundleManager.getJETBundleDescriptorForJAR(bundleURL);
+ if(descriptor != null)
+ {
+ descriptorsById.put(jarInfo.getBundleSymbolicName(), descriptor);
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ // should not have happened.
+ }
+ }
+
+ return false;
+ }});
+ return descriptorsById;
+ }
+
+ public Set getAllJETBundleIds()
+ {
+ if(DEBUG) System.out.println("DirectoryBundleProvider.getAllJETBundleIds()"); //$NON-NLS-1$
+
+ final Map descriptorsById = getDescriptorsById();
+ if(DEBUG) System.out.println(" ids: " + descriptorsById.keySet()); //$NON-NLS-1$
+ return descriptorsById.keySet();
+ }
+
+ private URL getBundleURL(final String id)
+ {
+
+ File[] jars = directory.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name)
+ {
+ final BundleJarInfo jarInfo = BundleJarInfo.createBundleJarInfo(name);
+ return jarInfo != null && jarInfo.getBundleSymbolicName().equals(id);
+ }});
+
+ URL url = null;
+ if(jars.length > 0)
+ {
+ try
+ {
+ url = jars[0].toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // do nothing...
+ }
+ }
+
+ return url;
+ }
+
+ public IJETBundleDescriptor getDescriptor(String id)
+ {
+ if(DEBUG) System.out.println("DirectoryBundleProvider.getDescriptor("+ id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ URL bundleURL = getBundleURL(id);
+ IJETBundleDescriptor descriptor = null;
+
+ if(bundleURL != null)
+ {
+ descriptor = JETBundleManager.getJETBundleDescriptorForJAR(bundleURL);
+ }
+
+ if(DEBUG) System.out.println(" " + (descriptor == null ? "not found" : "found")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return descriptor;
+ }
+
+ public Bundle load(String id, IProgressMonitor monitor) throws BundleException
+ {
+ URL bundleURL = getBundleURL(id);
+ Bundle bundle = null;
+ if(bundleURL != null)
+ {
+ bundle = InternalJET2Platform.getDefault().getJETBundleInstaller().installBundle(bundleURL);
+ }
+ return bundle;
+ }
+
+ public void shutdown()
+ {
+ }
+
+ public void startup()
+ {
+ }
+
+ public void unload(String id) throws BundleException
+ {
+ }
+
+ public void unload(Bundle bundle) throws BundleException
+ {
+ if(bundle != null)
+ {
+ bundle.uninstall();
+ }
+ }
+
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
index 93723c7..abc812c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
@@ -18,6 +18,7 @@ package org.eclipse.jet.internal.runtime;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
@@ -39,6 +40,8 @@ import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.extensionpoints.TransformData;
+import org.eclipse.jet.internal.extensionpoints.TransformDataFactory;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.transform.IJETBundleDescriptor;
import org.eclipse.jet.transform.IJETBundleManager;
@@ -127,6 +130,36 @@ public class JETBundleManager implements IJETBundleManager
}
}
+ /**
+ * Return a JET bundle descriptor the JAR refered to by <code>bundleURL</code>.
+ * @param bundleURL a URL to a bundle JAR
+ * @return the bundle descriptor, or <code>null</code> if this is not a JET bundle.
+ */
+ public static IJETBundleDescriptor getJETBundleDescriptorForJAR(URL bundleURL)
+ {
+ IJETBundleDescriptor descriptor = null;
+ try
+ {
+ URL jarURL = new URL("jar", "", bundleURL.toExternalForm() + "!/"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ JETBundleManifest manifest = JETBundleManager.loadManifest(jarURL);
+ TransformData transformData = TransformDataFactory.INSTANCE.createTransformData(manifest.getTransformId(), jarURL);
+
+ descriptor = new DynamicJETBundleDescriptor(manifest, transformData, jarURL, bundleURL);
+ if(descriptor.getTemplateLoaderClass() == null) {
+ descriptor = null;
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ InternalJET2Platform.logError("Failed to correctly format a jar URL. bundleURL = " + bundleURL.toExternalForm(), e); //$NON-NLS-1$
+ }
+ catch (IOException e)
+ {
+ // can't read. Assume it's not a JET bundle.
+ }
+ return descriptor;
+ }
+
private static Properties manifestToProperties(Attributes d) {
Iterator iter = d.keySet().iterator();
Properties result = new Properties();
@@ -143,6 +176,8 @@ public class JETBundleManager implements IJETBundleManager
private DeployedJETBundleProvider deployedBundleProvider;
+ private AdditionalBundleLocationProvider additionalBundleLocationProvider;
+
private IJETBundleProvider[] providerSearchOrder;
private Map bundlesById = new HashMap();
@@ -241,6 +276,9 @@ public class JETBundleManager implements IJETBundleManager
deployedBundleProvider.shutdown();
deployedBundleProvider = null;
+ additionalBundleLocationProvider.shutdown();
+ additionalBundleLocationProvider = null;
+
providerSearchOrder = null;
}
@@ -257,11 +295,15 @@ public class JETBundleManager implements IJETBundleManager
deployedBundleProvider = new DeployedJETBundleProvider();
deployedBundleProvider.startup();
+ additionalBundleLocationProvider = new AdditionalBundleLocationProvider();
+ additionalBundleLocationProvider.startup();
+
// Note: The order here is significant. Changing it will have impacts on
// which transform is found.
providerSearchOrder = new IJETBundleProvider[] {
installedBundleProvider,
projectBundleProvider,
+ additionalBundleLocationProvider,
deployedBundleProvider,
};
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java
index d2e7fe9..1b5c8a9 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java
@@ -9,8 +9,9 @@ public class AllTests {
TestSuite suite = new TestSuite(
"Test for org.eclipse.jet.tests.runtime");
//$JUnit-BEGIN$
- suite.addTestSuite(TestBundleDescriptions.class);
suite.addTestSuite(TestBundleLoading.class);
+ suite.addTestSuite(TestBundleJarUtil.class);
+ suite.addTestSuite(TestBundleDescriptions.class);
//$JUnit-END$
return suite;
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleJarUtil.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleJarUtil.java
new file mode 100644
index 0000000..0eaf172
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleJarUtil.java
@@ -0,0 +1,47 @@
+package org.eclipse.jet.tests.runtime;
+
+import org.eclipse.jet.internal.runtime.BundleJarInfo;
+
+import junit.framework.TestCase;
+
+public class TestBundleJarUtil extends TestCase {
+
+ private BundleJarInfo complexBJU;
+ private BundleJarInfo simpleBJU;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ complexBJU = BundleJarInfo.createBundleJarInfo("a.b.c_1.2.3.x_yz_4.5.6.a_b_c.jar");
+ simpleBJU = BundleJarInfo.createBundleJarInfo("a.b.c_1.2.3.jar");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testGetBundleSymbolicName_complex() {
+ assertEquals("a.b.c_1.2.3.x_yz", complexBJU.getBundleSymbolicName());
+ }
+
+ public void testGetVersion_complex() {
+ assertEquals("4.5.6.a_b_c", complexBJU.getVersion());
+ }
+
+ public void testGetJarName_complex() {
+ assertEquals("a.b.c_1.2.3.x_yz_4.5.6.a_b_c.jar", complexBJU.getJarName());
+ }
+
+ public void testGetBundleSymbolicName_simple() {
+ assertEquals("a.b.c", simpleBJU.getBundleSymbolicName());
+ }
+
+ public void testGetVersion_simple() {
+ assertEquals("1.2.3", simpleBJU.getVersion());
+ }
+
+ public void testGetJarName_simple() {
+ assertEquals("a.b.c_1.2.3.jar", simpleBJU.getJarName());
+ }
+
+}