From d8ba008b28dc2778e2db9fffcdefbc272f4905aa Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 10 Apr 2014 16:18:27 -0500 Subject: Bug 432485 - EE changes not detected and so resolve state does not change --- .../osgi/tests/bundles/SystemBundleTests.java | 91 ++++++++++++++++++++++ .../src/org/eclipse/osgi/storage/Storage.java | 6 +- 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index ec62923e9..e37a06f32 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -22,6 +22,7 @@ import junit.framework.TestSuite; import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.junit.Assert; import org.osgi.framework.*; import org.osgi.framework.hooks.resolver.ResolverHook; import org.osgi.framework.hooks.resolver.ResolverHookFactory; @@ -928,6 +929,82 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType()); //$NON-NLS-1$ } + public void testChangeEE() throws IOException, BundleException { + URL javaSE7Profile = OSGiTestsActivator.getContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getEntry("JavaSE-1.7.profile"); + URL javaSE8Profile = OSGiTestsActivator.getContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getEntry("JavaSE-1.8.profile"); + + // configure equinox for javaSE 8 + File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$ + Map configuration = new HashMap(); + configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()); + configuration.put("osgi.java.profile", javaSE8Profile.toExternalForm()); //$NON-NLS-1$ + + Equinox equinox = new Equinox(configuration); + equinox.start(); + + // install a bundle that requires java 8 + BundleContext systemContext = equinox.getBundleContext(); + assertNotNull("System context is null", systemContext); //$NON-NLS-1$ + Map testHeaders = new HashMap(); + testHeaders.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + testHeaders.put(Constants.BUNDLE_SYMBOLICNAME, getName()); + testHeaders.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-1.8"); + File testBundle = createBundle(config, getName(), testHeaders); + Bundle b = systemContext.installBundle("reference:file:///" + testBundle.getAbsolutePath()); //$NON-NLS-1$ + long bid = b.getBundleId(); + + // should resolve fine + Assert.assertTrue("Could not resolve bundle.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b))); + + // put the framework back to the RESOLVED state + equinox.stop(); + try { + equinox.waitForStop(10000); + } catch (InterruptedException e) { + fail("Unexpected interrupted exception", e); //$NON-NLS-1$ + } + + // configure equinox for java 7 + configuration.put("osgi.java.profile", javaSE7Profile.toExternalForm()); + equinox = new Equinox(configuration); + try { + equinox.start(); + } catch (BundleException e) { + fail("Failed to start the framework", e); //$NON-NLS-1$ + } + // bundle should fail to resolve + b = equinox.getBundleContext().getBundle(bid); + Assert.assertFalse("Could resolve bundle.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b))); + + // put the framework back to the RESOLVED state + equinox.stop(); + try { + equinox.waitForStop(10000); + } catch (InterruptedException e) { + fail("Unexpected interrupted exception", e); //$NON-NLS-1$ + } + + // move back to java 8 + configuration.put("osgi.java.profile", javaSE8Profile.toExternalForm()); + equinox = new Equinox(configuration); + try { + equinox.start(); + } catch (BundleException e) { + fail("Failed to start the framework", e); //$NON-NLS-1$ + } + // bundle should succeed to resolve again + b = equinox.getBundleContext().getBundle(bid); + Assert.assertTrue("Could not resolve bundle.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b))); + + // put the framework back to the RESOLVED state + equinox.stop(); + try { + equinox.waitForStop(10000); + } catch (InterruptedException e) { + fail("Unexpected interrupted exception", e); //$NON-NLS-1$ + } + } + public void testMRUBundleFileList() { doMRUBundleFileList(10); } @@ -2119,4 +2196,18 @@ public class SystemBundleTests extends AbstractBundleTests { } return manifest; } + + private static File createBundle(File outputDir, String bundleName, Map headers) throws IOException { + Manifest m = new Manifest(); + Attributes attributes = m.getMainAttributes(); + attributes.putValue("Manifest-Version", "1.0"); + for (Map.Entry entry : headers.entrySet()) { + attributes.putValue(entry.getKey(), entry.getValue()); + } + File file = new File(outputDir, "bundle" + bundleName + ".jar"); //$NON-NLS-1$ //$NON-NLS-2$ + JarOutputStream jos = new JarOutputStream(new FileOutputStream(file), m); + jos.flush(); + jos.close(); + return file; + } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java index 3795f5dd4..0c258a3fd 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java @@ -324,10 +324,8 @@ public class Storage { if (!currentRevision.getVersion().equals(newBuilder.getVersion())) { return true; } - // only do this advanced check if in dev mode - if (!equinoxContainer.getConfiguration().inDevelopmentMode()) { - return false; - } + + // Always do the advanced check for bug 432485 to make sure we have a consistent system bundle List currentCapabilities = currentRevision.getModuleCapabilities(null); List newCapabilities = newBuilder.getCapabilities(); if (currentCapabilities.size() != newCapabilities.size()) { -- cgit v1.2.3