diff options
author | Hannes Wellmann | 2021-12-03 07:06:06 +0000 |
---|---|---|
committer | Hannes Wellmann | 2022-02-10 19:07:37 +0000 |
commit | 3889f7ce2d2906ca7d46f341de95ebe865212808 (patch) | |
tree | 9d3aef604b18b84341f740afeaf5cbd154fb31a7 | |
parent | 845db7c302684fada9e9065333c8439efe0e0708 (diff) | |
download | rt.equinox.framework-3889f7ce2d2906ca7d46f341de95ebe865212808.tar.gz rt.equinox.framework-3889f7ce2d2906ca7d46f341de95ebe865212808.tar.xz rt.equinox.framework-3889f7ce2d2906ca7d46f341de95ebe865212808.zip |
Bug 577574 - Enable adaption of EquinoxBundle to its location fileY20220211-0800I20220210-1800
Change-Id: I55887d3233af7638100b8066f4964cc3ba0cca88
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/188490
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
Reviewed-by: Thomas Watson <tjwatson@us.ibm.com>
3 files changed, 81 insertions, 0 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java index 9fd972ea9..dfebc7ac4 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java @@ -26,6 +26,7 @@ import org.junit.runners.Suite; PersistedBundleTests.class, // CascadeConfigTests.class, // DiscardBundleTests.class, // + EquinoxBundleAdaptTests.class, // LoggingTests.class, // BundleResourceTests.class, // BundleInstallUpdateTests.class, // diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java new file mode 100644 index 000000000..7cc19ef03 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2022, 2022 Hannes Wellmann and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Hannes Wellmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.osgi.tests.bundles; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.net.URL; +import java.security.Permission; +import java.security.ProtectionDomain; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.osgi.container.Module; +import org.eclipse.osgi.internal.framework.EquinoxBundle; +import org.eclipse.osgi.signedcontent.SignedContent; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +public class EquinoxBundleAdaptTests extends AbstractBundleTests { + + @Test + public void testAdapt_Module() throws Exception { + Bundle bundle = installer.installBundle("test"); + Module module = bundle.adapt(org.eclipse.osgi.container.Module.class); + assertEquals(((EquinoxBundle) bundle).getModule(), module); + } + + @Test + public void testAdapt_ProtectionDomain() throws Exception { + Bundle bundle = installer.installBundle("test"); + SecurityManager previousSM = System.getSecurityManager(); + try { + System.setSecurityManager(new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + // Just permit everything + } + }); + ProtectionDomain domain = bundle.adapt(java.security.ProtectionDomain.class); + assertNotNull(domain); + } finally { + System.setSecurityManager(previousSM); + } + } + + @Test + public void testAdapt_SignedContent() throws Exception { + Bundle bundle = installer.installBundle("test"); + SignedContent content = bundle.adapt(org.eclipse.osgi.signedcontent.SignedContent.class); + assertNotNull(content); + } + + @Test + public void testAdapt_File() throws Exception { + URL testBundleURL = FrameworkUtil.getBundle(EquinoxBundleAdaptTests.class).getEntry("."); + File testBundleRoot = new File(FileLocator.toFileURL(testBundleURL).toURI()).getCanonicalFile(); + + Bundle bundle = installer.installBundle("test"); + + File file = bundle.adapt(java.io.File.class).getCanonicalFile(); + assertEquals(new File(testBundleRoot, "bundle_tests"), file.getParentFile()); + assertEquals("test", file.getName().replace(".jar", "")); + } +} diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java index 6f8e306e9..189cfe8d0 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java @@ -954,6 +954,10 @@ public class EquinoxBundle implements Bundle, BundleReference { if (SignedContent.class.equals(adapterType)) { return (A) getSignedContent(); } + if (File.class.equals(adapterType)) { + Generation current = (Generation) module.getCurrentRevision().getRevisionInfo(); + return (A) current.getContent(); + } return null; } |