Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-12-10 04:23:23 -0500
committerEike Stepper2011-12-10 04:23:23 -0500
commit030fea1eb3d590c95dc75813e51c31975074fbd0 (patch)
tree0df32567d7396920b00c69c4a393ad0bda2d574e
parenta9b8b8d3831d1729cc067edf91544df3f43fa05d (diff)
downloadcdo-030fea1eb3d590c95dc75813e51c31975074fbd0.tar.gz
cdo-030fea1eb3d590c95dc75813e51c31975074fbd0.tar.xz
cdo-030fea1eb3d590c95dc75813e51c31975074fbd0.zip
[366290] Provide an OMBundle.getClasses() method
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366290
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java154
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTestSuite.java31
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java10
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java10
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java25
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java10
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java117
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java29
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java79
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java10
11 files changed, 319 insertions, 168 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index 467dc59c81..e3bc5fd72a 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -10,7 +10,7 @@
*/
package org.eclipse.emf.cdo.tests;
-import org.eclipse.emf.cdo.tests.bugzilla.*;
+import org.eclipse.emf.cdo.tests.bundle.OM;
import org.eclipse.emf.cdo.tests.config.IScenario;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -100,156 +100,6 @@ public abstract class AllConfigs extends ConfigTestSuite
// TODO testClasses.add(GeneratedEcoreTest.class);
// Bugzilla verifications
-
- testClasses.add(Bugzilla_241464_Test.class);
- testClasses.add(Bugzilla_243310_Test.class);
- testClasses.add(Bugzilla_246442_Test.class);
- testClasses.add(Bugzilla_246622_Test.class);
- testClasses.add(Bugzilla_247141_Test.class);
- testClasses.add(Bugzilla_248052_Test.class);
- testClasses.add(Bugzilla_248124_Test.class);
- testClasses.add(Bugzilla_248915_Test.class);
- testClasses.add(Bugzilla_250036_Test.class);
- testClasses.add(Bugzilla_250757_Test.class);
- testClasses.add(Bugzilla_250910_Test.class);
- testClasses.add(Bugzilla_251087_Test.class);
- testClasses.add(Bugzilla_251263_Test.class);
- testClasses.add(Bugzilla_251544_Test.class);
- testClasses.add(Bugzilla_251752_Test.class);
- testClasses.add(Bugzilla_252214_Test.class);
- testClasses.add(Bugzilla_252909_Test.class);
- testClasses.add(Bugzilla_254489_Test.class);
- testClasses.add(Bugzilla_255662_Test.class);
- testClasses.add(Bugzilla_256141_Test.class);
- testClasses.add(Bugzilla_258278_Test.class);
- testClasses.add(Bugzilla_258850_Test.class);
- testClasses.add(Bugzilla_258933_Test.class);
- testClasses.add(Bugzilla_259695_Test.class);
- testClasses.add(Bugzilla_259949_Test.class);
- testClasses.add(Bugzilla_260756_Test.class);
- testClasses.add(Bugzilla_260764_Test.class);
- testClasses.add(Bugzilla_261218_Test.class);
- testClasses.add(Bugzilla_265114_Test.class);
- testClasses.add(Bugzilla_266857_Test.class);
- testClasses.add(Bugzilla_266982_Test.class);
- testClasses.add(Bugzilla_267050_Test.class);
- testClasses.add(Bugzilla_267352_Test.class);
- testClasses.add(Bugzilla_270429_Test.class);
- testClasses.add(Bugzilla_272861_Test.class);
- testClasses.add(Bugzilla_273233_Test.class);
- testClasses.add(Bugzilla_273565_Test.class);
- testClasses.add(Bugzilla_273758_Test.class);
- testClasses.add(Bugzilla_276696_Test.class);
- testClasses.add(Bugzilla_278900_Test.class);
- testClasses.add(Bugzilla_279565_Test.class);
- testClasses.add(Bugzilla_279982_Test.class);
- testClasses.add(Bugzilla_280102_Test.class);
- testClasses.add(Bugzilla_283131_Test.class);
- testClasses.add(Bugzilla_283985_1_Test.class);
- testClasses.add(Bugzilla_283985_2_Test.class);
- testClasses.add(Bugzilla_283985_3_Test.class);
- testClasses.add(Bugzilla_285008_Test.class);
- testClasses.add(Bugzilla_289932_Test.class);
- testClasses.add(Bugzilla_293283_Test.class);
- testClasses.add(Bugzilla_294859_Test.class);
- testClasses.add(Bugzilla_296561_Test.class);
- testClasses.add(Bugzilla_298561_Test.class);
- testClasses.add(Bugzilla_299190_Test.class);
- testClasses.add(Bugzilla_302233_Test.class);
- testClasses.add(Bugzilla_302414_Test.class);
- testClasses.add(Bugzilla_303466_Test.class);
- testClasses.add(Bugzilla_303807_Test.class);
- testClasses.add(Bugzilla_305527_Test.class);
- testClasses.add(Bugzilla_306710_Test.class);
- testClasses.add(Bugzilla_306998_Test.class);
- testClasses.add(Bugzilla_308895_Test.class);
- testClasses.add(Bugzilla_310574_Test.class);
- testClasses.add(Bugzilla_313326_Test.class);
- testClasses.add(Bugzilla_313913_Test.class);
- testClasses.add(Bugzilla_314186_Test.class);
- testClasses.add(Bugzilla_314264_Test.class);
- testClasses.add(Bugzilla_315043_Test.class);
- testClasses.add(Bugzilla_316145_Test.class);
- testClasses.add(Bugzilla_316273_Test.class);
- testClasses.add(Bugzilla_316434_Test.class);
- testClasses.add(Bugzilla_316444_Test.class);
- testClasses.add(Bugzilla_316887_Test.class);
- testClasses.add(Bugzilla_318518_Test.class);
- testClasses.add(Bugzilla_318844_Test.class);
- testClasses.add(Bugzilla_318876_Test.class);
- testClasses.add(Bugzilla_318919_Test.class);
- testClasses.add(Bugzilla_318998_Test.class);
- testClasses.add(Bugzilla_319836_Test.class);
- testClasses.add(Bugzilla_320690_Test.class);
- testClasses.add(Bugzilla_320837_Test.class);
- testClasses.add(Bugzilla_321699_Test.class);
- testClasses.add(Bugzilla_321986_Test.class);
- testClasses.add(Bugzilla_322754_Test.class);
- testClasses.add(Bugzilla_322804_Test.class);
- testClasses.add(Bugzilla_323930_Test.class);
- testClasses.add(Bugzilla_323958_Test.class);
- testClasses.add(Bugzilla_324084_Test.class);
- testClasses.add(Bugzilla_324585_Test.class);
- testClasses.add(Bugzilla_324635_Test.class);
- testClasses.add(Bugzilla_324756_Test.class);
- testClasses.add(Bugzilla_325603_Test.class);
- testClasses.add(Bugzilla_325866_Test.class);
- testClasses.add(Bugzilla_326518_Test.class);
- testClasses.add(Bugzilla_326743_Test.class);
- testClasses.add(Bugzilla_327604_Test.class);
- testClasses.add(Bugzilla_328790_Test.class);
- testClasses.add(Bugzilla_329254_Test.class);
- testClasses.add(Bugzilla_329752_Test.class);
- testClasses.add(Bugzilla_329753_Test.class);
- testClasses.add(Bugzilla_329869_Test.class);
- testClasses.add(Bugzilla_330052_Test.class);
- testClasses.add(Bugzilla_331619_Test.class);
- testClasses.add(Bugzilla_333157_Test.class);
- testClasses.add(Bugzilla_333299_Test.class);
- testClasses.add(Bugzilla_333950_Test.class);
- testClasses.add(Bugzilla_334608_Test.class);
- testClasses.add(Bugzilla_334995_Test.class);
- testClasses.add(Bugzilla_335004_Test.class);
- testClasses.add(Bugzilla_335675_Test.class);
- testClasses.add(Bugzilla_335772_Test.class);
- testClasses.add(Bugzilla_336314_Test.class);
- testClasses.add(Bugzilla_336382_Test.class);
- testClasses.add(Bugzilla_336590_Test.class);
- testClasses.add(Bugzilla_337054_Test.class);
- testClasses.add(Bugzilla_337523_Test.class);
- testClasses.add(Bugzilla_337587_Test.class);
- testClasses.add(Bugzilla_338779_Test.class);
- testClasses.add(Bugzilla_338884_Test.class);
- testClasses.add(Bugzilla_338921_Test.class);
- testClasses.add(Bugzilla_339313_Test.class);
- testClasses.add(Bugzilla_339461_Test.class);
- testClasses.add(Bugzilla_339908_Test.class);
- testClasses.add(Bugzilla_340961_Test.class);
- testClasses.add(Bugzilla_341875_Test.class);
- testClasses.add(Bugzilla_341995_Test.class);
- testClasses.add(Bugzilla_342130_Test.class);
- testClasses.add(Bugzilla_342135_Test.class);
- testClasses.add(Bugzilla_343332_Test.class);
- testClasses.add(Bugzilla_343471_Test.class);
- testClasses.add(Bugzilla_349793_Test.class);
- testClasses.add(Bugzilla_349804_Test.class);
- testClasses.add(Bugzilla_350027_Test.class);
- testClasses.add(Bugzilla_351067_Test.class);
- testClasses.add(Bugzilla_351096_Test.class);
- testClasses.add(Bugzilla_351393_Test.class);
- testClasses.add(Bugzilla_351921_Test.class);
- testClasses.add(Bugzilla_352204_Test.class);
- testClasses.add(Bugzilla_352303_Test.class);
- testClasses.add(Bugzilla_352832_Test.class);
- testClasses.add(Bugzilla_354395_Test.class);
- testClasses.add(Bugzilla_355915_Test.class);
- testClasses.add(Bugzilla_357441_Test.class);
- testClasses.add(Bugzilla_359669_Test.class);
- testClasses.add(Bugzilla_359966_Test.class);
- testClasses.add(Bugzilla_359992_Test.class);
- testClasses.add(Bugzilla_361819_Test.class);
- testClasses.add(Bugzilla_363287_Test.class);
- testClasses.add(Bugzilla_365204_Test.class);
- testClasses.add(Bugzilla_365832_Test.class);
+ testClasses.addAll(getTestClasses(OM.BUNDLE, "org.eclipse.emf.cdo.tests.bugzilla"));
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTestSuite.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTestSuite.java
index 8bf123425f..5a97ad78c1 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTestSuite.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTestSuite.java
@@ -15,10 +15,15 @@ import org.eclipse.emf.cdo.tests.config.IScenario;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Skips;
+import org.eclipse.net4j.util.om.OMBundle;
+
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -78,6 +83,32 @@ public abstract class ConfigTestSuite implements IConstants
}
}
+ protected List<Class<? extends ConfigTest>> getTestClasses(OMBundle bundle, String packageName)
+ {
+ List<Class<? extends ConfigTest>> result = new ArrayList<Class<? extends ConfigTest>>();
+
+ for (Iterator<Class<?>> it = bundle.getClasses(); it.hasNext();)
+ {
+ Class<?> c = it.next();
+ if (ConfigTest.class.isAssignableFrom(c) && c.getName().startsWith(packageName))
+ {
+ @SuppressWarnings("unchecked")
+ Class<? extends ConfigTest> configTest = (Class<? extends ConfigTest>)c;
+ result.add(configTest);
+ }
+ }
+
+ Collections.sort(result, new Comparator<Class<? extends ConfigTest>>()
+ {
+ public int compare(Class<? extends ConfigTest> c1, Class<? extends ConfigTest> c2)
+ {
+ return c1.getName().compareTo(c2.getName());
+ }
+ });
+
+ return result;
+ }
+
protected abstract void initConfigSuites(TestSuite parent);
protected abstract void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java
index 234a5a7ab2..00622ca287 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java
@@ -69,7 +69,7 @@ public final class Activator extends EMFPlugin
try
{
super.start(context);
- OM.BUNDLE.setBundleContext(context);
+ setBundleContext(context);
doStart();
}
catch (Error error)
@@ -97,7 +97,7 @@ public final class Activator extends EMFPlugin
try
{
doStop();
- OM.BUNDLE.setBundleContext(null);
+ setBundleContext(null);
super.stop(context);
}
catch (Error error)
@@ -127,5 +127,11 @@ public final class Activator extends EMFPlugin
{
LifecycleUtil.deactivate(CDOViewProviderRegistryImpl.INSTANCE, OMLogger.Level.WARN);
}
+
+ @SuppressWarnings("deprecation")
+ private void setBundleContext(BundleContext context)
+ {
+ OM.BUNDLE.setBundleContext(context);
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java
index 65a1b5c1f6..6e7c20805b 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java
@@ -63,7 +63,7 @@ public class UIActivator extends AbstractUIPlugin
try
{
super.start(context);
- omBundle.setBundleContext(context);
+ setBundleContext(context);
((AbstractBundle)omBundle).start();
doStart();
}
@@ -92,7 +92,7 @@ public class UIActivator extends AbstractUIPlugin
{
doStop();
((AbstractBundle)omBundle).stop();
- omBundle.setBundleContext(null);
+ setBundleContext(null);
super.stop(context);
}
catch (Error error)
@@ -121,6 +121,12 @@ public class UIActivator extends AbstractUIPlugin
{
}
+ @SuppressWarnings("deprecation")
+ private void setBundleContext(BundleContext context)
+ {
+ omBundle.setBundleContext(context);
+ }
+
/**
* @author Eike Stepper
* @since 3.1
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
index 1cfa82440e..13111b433c 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
@@ -40,6 +40,8 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport, OMBundle.TranslationSupport
{
+ private static final String CLASS_EXTENSION = ".class";
+
private AbstractPlatform platform;
private String bundleID;
@@ -95,6 +97,7 @@ public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport,
return bundleContext;
}
+ @Deprecated
public void setBundleContext(Object bundleContext)
{
this.bundleContext = bundleContext;
@@ -374,6 +377,28 @@ public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport,
return bundleID + ".properties"; //$NON-NLS-1$
}
+ protected final Class<?> getClassFromBundle(String path)
+ {
+ if (path.endsWith(CLASS_EXTENSION))
+ {
+ int start = path.startsWith("/") ? 1 : 0;
+ int end = path.length() - CLASS_EXTENSION.length();
+ String className = path.substring(start, end).replace('/', '.');
+
+ try
+ {
+ ClassLoader classLoader = getAccessor().getClassLoader();
+ return classLoader.loadClass(className);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ //$FALL-THROUGH$
+ }
+ }
+
+ return null;
+ }
+
private void invokeMethod(String name) throws Exception
{
try
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
index 908ff9398b..30222f89ea 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
@@ -63,7 +63,7 @@ public abstract class OM
public void start(BundleContext context) throws Exception
{
AbstractPlatform.systemContext = context;
- OM.BUNDLE.setBundleContext(context);
+ setBundleContext(context);
((OSGiBundle)OM.BUNDLE).start();
// TODO Make configurable
@@ -92,8 +92,14 @@ public abstract class OM
OSGiActivator.traceStop(context);
((OSGiBundle)OM.BUNDLE).stop();
PluginContainer.dispose();
- OM.BUNDLE.setBundleContext(null);
+ setBundleContext(null);
AbstractPlatform.systemContext = null;
}
+
+ @SuppressWarnings("deprecation")
+ private void setBundleContext(BundleContext context)
+ {
+ OM.BUNDLE.setBundleContext(context);
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java
index cabc83b314..b031cfbd41 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java
@@ -14,6 +14,7 @@ import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
import org.eclipse.net4j.util.ReflectUtil;
import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.IOUtil;
import java.io.File;
@@ -21,9 +22,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
/**
* @author Eike Stepper
@@ -62,6 +69,87 @@ public class LegacyBundle extends AbstractBundle
return baseURL;
}
+ public Iterator<Class<?>> getClasses()
+ {
+ List<Class<?>> result = new ArrayList<Class<?>>();
+
+ if (isArchiveProtocol(baseURL.getProtocol()))
+ {
+ JarFile jarFile = null;
+
+ try
+ {
+ jarFile = new JarFile(baseURL.getFile());
+
+ Enumeration<JarEntry> entries = jarFile.entries();
+ while (entries.hasMoreElements())
+ {
+ JarEntry jarEntry = entries.nextElement();
+ if (!jarEntry.isDirectory())
+ {
+ Class<?> c = getClassFromBundle(jarEntry.getName());
+ if (c != null)
+ {
+ result.add(c);
+ }
+ }
+ }
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ IOUtil.close(jarFile);
+ }
+ }
+ else
+ {
+ try
+ {
+ URL url = getClassesURL(getAccessor());
+ File folder = new File(url.getFile());
+ collectFileClasses(folder, null, result);
+ }
+ catch (MalformedURLException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ return result.iterator();
+ }
+
+ private void collectFileClasses(File folder, String path, List<Class<?>> result)
+ {
+ File file = folder;
+ if (path == null)
+ {
+ path = "";
+ }
+ else
+ {
+ file = new File(folder, path);
+ }
+
+ if (file.isDirectory())
+ {
+ for (String child : file.list())
+ {
+ collectFileClasses(folder, path + "/" + child, result);
+ }
+ }
+ else
+ {
+ Class<?> c = getClassFromBundle(path);
+ if (c != null)
+ {
+ result.add(c);
+ }
+ }
+ }
+
private void loadOptions()
{
InputStream inputStream = null;
@@ -125,11 +213,7 @@ public class LegacyBundle extends AbstractBundle
// file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.
// class
- String className = accessor.getName();
- URL url = accessor.getResource(ReflectUtil.getSimpleName(accessor) + ".class"); //$NON-NLS-1$
-
- int segmentsToTrim = 1 + StringUtil.occurrences(className, '.');
- url = trimSegments(url, segmentsToTrim);
+ URL url = getClassesURL(accessor);
// For an archive URI, check for the plugin.properties in the archive.
if (isArchiveProtocol(url.getProtocol()))
@@ -138,8 +222,18 @@ public class LegacyBundle extends AbstractBundle
{
// If we can open an input stream, then the plugin.properties is there,
// and we have a good base URL.
- InputStream inputStream = new URL(url.toString() + "plugin.properties").openStream(); //$NON-NLS-1$
- inputStream.close();
+ URL u = new URL(url.toString() + "plugin.properties");
+ InputStream inputStream = null;
+
+ try
+ {
+ inputStream = u.openStream();
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+
baseURL = url;
}
catch (IOException exception)
@@ -183,6 +277,15 @@ public class LegacyBundle extends AbstractBundle
}
}
+ private static URL getClassesURL(Class<?> accessor) throws MalformedURLException
+ {
+ String className = accessor.getName();
+ URL url = accessor.getResource(ReflectUtil.getSimpleName(accessor) + ".class"); //$NON-NLS-1$
+
+ int segmentsToTrim = 1 + StringUtil.occurrences(className, '.');
+ return trimSegments(url, segmentsToTrim);
+ }
+
private static String lastSegment(URL url)
{
String path = url.getPath();
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
index 0b86e98890..8090a07251 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
@@ -13,6 +13,7 @@ package org.eclipse.net4j.internal.util.om;
import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.collection.AbstractIterator;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
@@ -22,6 +23,8 @@ import org.osgi.framework.BundleContext;
import java.io.IOException;
import java.net.URL;
+import java.util.Enumeration;
+import java.util.Iterator;
/**
* @author Eike Stepper
@@ -59,6 +62,32 @@ public class OSGiBundle extends AbstractBundle
}
}
+ public Iterator<Class<?>> getClasses()
+ {
+ final Bundle bundle = getBundleContext().getBundle();
+
+ return new AbstractIterator<Class<?>>()
+ {
+ private Enumeration<String> entryPaths = bundle.getEntryPaths("/");
+
+ @Override
+ protected Object computeNextElement()
+ {
+ while (entryPaths.hasMoreElements())
+ {
+ String entryPath = entryPaths.nextElement();
+ Class<?> c = getClassFromBundle(entryPath);
+ if (c != null)
+ {
+ return c;
+ }
+ }
+
+ return END_OF_DATA;
+ }
+ };
+ }
+
public String getStateLocation()
{
Bundle bundle = getBundleContext().getBundle();
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java
new file mode 100644
index 0000000000..897a487bb0
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.collection;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An abstract base class for custom iterators that only requires to implement a single {@link #computeNextElement()}
+ * method.
+ *
+ * @author Eike Stepper
+ * @since 3.2
+ */
+public abstract class AbstractIterator<T> implements Iterator<T>
+{
+ /**
+ * The token to be used in {@link #computeNextElement()} to indicate the end of the iteration.
+ */
+ protected static final Object END_OF_DATA = new Object();
+
+ private boolean computed;
+
+ private T next;
+
+ public AbstractIterator()
+ {
+ }
+
+ public final boolean hasNext()
+ {
+ if (computed)
+ {
+ return true;
+ }
+
+ Object object = computeNextElement();
+ computed = true;
+
+ if (object == END_OF_DATA)
+ {
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ T cast = (T)object;
+ next = cast;
+ return true;
+ }
+
+ public final T next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+
+ computed = false;
+ return next;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the next iteration element, or {@link #END_OF_DATA} if the end of the iteration has been reached.
+ */
+ protected abstract Object computeNextElement();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
index 28b5862871..252912edff 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.Iterator;
import java.util.Properties;
import java.util.ResourceBundle;
@@ -47,7 +48,10 @@ public interface OMBundle
public URL getBaseURL();
- public void setBundleContext(Object bundleContext);
+ /**
+ * @since 3.2
+ */
+ public Iterator<Class<?>> getClasses();
public OMTracer tracer(String name);
@@ -68,6 +72,12 @@ public interface OMBundle
public TranslationSupport getTranslationSupport();
/**
+ * @deprecated For internal use only.
+ */
+ @Deprecated
+ public void setBundleContext(Object bundleContext);
+
+ /**
* A facility for accessing OSGi {@link DebugOptions debug options}, whether OSGi {@link OMPlatform#isOSGiRunning() is
* running} or not.
*
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java
index 50968f839e..2d41ba444b 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java
@@ -61,7 +61,7 @@ public abstract class OSGiActivator implements BundleActivator
try
{
- omBundle.setBundleContext(context);
+ setBundleContext(context);
((AbstractBundle)omBundle).start();
doStart();
}
@@ -89,7 +89,7 @@ public abstract class OSGiActivator implements BundleActivator
{
doStop();
((AbstractBundle)omBundle).stop();
- omBundle.setBundleContext(null);
+ setBundleContext(null);
}
catch (Error error)
{
@@ -147,6 +147,12 @@ public abstract class OSGiActivator implements BundleActivator
{
}
+ @SuppressWarnings("deprecation")
+ private void setBundleContext(BundleContext context)
+ {
+ omBundle.setBundleContext(context);
+ }
+
/**
* @since 2.0
*/

Back to the top