Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-09-18 16:40:47 -0400
committerThomas Watson2019-09-23 10:24:24 -0400
commit4b1088352687b1301b62ea8ff2f22abba5bf8f49 (patch)
treeba749e5e8ea2f3050389c7a48fb2ea0e44783560
parent2e4ede64355d197f1b4a25a0dc58ec0959d71588 (diff)
downloadrt.equinox.framework-4b1088352687b1301b62ea8ff2f22abba5bf8f49.tar.gz
rt.equinox.framework-4b1088352687b1301b62ea8ff2f22abba5bf8f49.tar.xz
rt.equinox.framework-4b1088352687b1301b62ea8ff2f22abba5bf8f49.zip
Bug 551376 - Add getWrappedType to BundleFileWrapperChain
Remove some duplicate code that walks the wrapper chain looking for a specific type of bundle file wrapped in the chain Change-Id: I308ad1b6966c857a81154226952590e255e2e9f2 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java17
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java16
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapperChain.java19
3 files changed, 31 insertions, 21 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java
index 18a05b257..3f1507a1c 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java
@@ -54,23 +54,10 @@ public class CDSHookImpls extends ClassLoaderHook implements BundleFileWrapperFa
// WrapperChain -> Wrapper<N> -> WrapperChain -> CDSBundleFile -> WrapperChain -> BundleFile
//
private static CDSBundleFile getCDSBundleFile(BundleFile bundleFile) {
- CDSBundleFile cdsBundleFile = null;
-
if (bundleFile instanceof BundleFileWrapperChain) {
- // Equinox > 3.4
- BundleFile wrapped = null;
- do {
- wrapped = ((BundleFileWrapperChain) bundleFile).getWrapped();
- if (wrapped instanceof CDSBundleFile) {
- cdsBundleFile = (CDSBundleFile) wrapped;
- break;
- }
-
- //Go to next wrapper chain.
- bundleFile = ((BundleFileWrapperChain) bundleFile).getNext();
- } while (wrapped != null);
+ return ((BundleFileWrapperChain) bundleFile).getWrappedType(CDSBundleFile.class);
}
- return cdsBundleFile;
+ return null;
}
@Override
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
index cfe4b48fb..601d03297 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
@@ -18,9 +18,16 @@ import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.security.*;
+import java.security.AllPermission;
+import java.security.CodeSource;
+import java.security.PermissionCollection;
+import java.security.ProtectionDomain;
import java.security.cert.Certificate;
-import java.util.*;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.osgi.container.ModuleRevision;
import org.eclipse.osgi.internal.debug.Debug;
import org.eclipse.osgi.internal.framework.EquinoxConfiguration;
@@ -353,10 +360,7 @@ public abstract class ModuleClassLoader extends ClassLoader implements BundleRef
Certificate[] certs = null;
SignedContent signedContent = null;
if (bundlefile instanceof BundleFileWrapperChain) {
- BundleFileWrapperChain wrapper = (BundleFileWrapperChain) bundlefile;
- while (wrapper != null && (!(wrapper.getWrapped() instanceof SignedContent)))
- wrapper = wrapper.getNext();
- signedContent = wrapper == null ? null : (SignedContent) wrapper.getWrapped();
+ signedContent = ((BundleFileWrapperChain) bundlefile).getWrappedType(SignedContent.class);
}
if (getConfiguration().CLASS_CERTIFICATE && signedContent != null && signedContent.isSigned()) {
SignerInfo[] signers = signedContent.getSignerInfos();
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapperChain.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapperChain.java
index 348e8fd49..3421da4f2 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapperChain.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapperChain.java
@@ -51,4 +51,23 @@ public class BundleFileWrapperChain extends BundleFileWrapper {
public BundleFileWrapperChain getNext() {
return next;
}
+
+ /**
+ * Returns the first bundle file wrapped in this chain which
+ * also is an instance of the specified type.
+ * @param <T> The type being searched for
+ * @param type the class of the type being searched for
+ * @return the found bundle file that is an instance of the specified type
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getWrappedType(Class<T> type) {
+ BundleFileWrapperChain current = this;
+ do {
+ if (type.isInstance(current.getWrapped())) {
+ return (T) current.getWrapped();
+ }
+ current = current.getNext();
+ } while (current != null);
+ return null;
+ }
}

Back to the top