Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2009-01-30 04:59:54 +0000
committerPascal Rapicault2009-01-30 04:59:54 +0000
commit4536b7812a06c7affe7fb4b701a350a08adefec8 (patch)
treefd7b5391b9930152c9004c4c32dca88996431a8c /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator
parente0691a3c7359cbb0d1c0e96151956c66b73c9d96 (diff)
downloadrt.equinox.p2-4536b7812a06c7affe7fb4b701a350a08adefec8.tar.gz
rt.equinox.p2-4536b7812a06c7affe7fb4b701a350a08adefec8.tar.xz
rt.equinox.p2-4536b7812a06c7affe7fb4b701a350a08adefec8.zip
Adapt another test to the new infrastructure
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/AbstractSimpleConfiguratorTest.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java163
3 files changed, 23 insertions, 152 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/AbstractSimpleConfiguratorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/AbstractSimpleConfiguratorTest.java
index 77c100f1b..d76142885 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/AbstractSimpleConfiguratorTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/AbstractSimpleConfiguratorTest.java
@@ -70,7 +70,7 @@ public abstract class AbstractSimpleConfiguratorTest extends AbstractProvisionin
}
}
- protected BundleContext startFramework(File bundleInfo) {
+ protected BundleContext startFramework(File bundleInfo, File[] additionalBundle) {
try {
File simpleConfiguratorBundle = getLocation("org.eclipse.equinox.simpleconfigurator");
File osgiBundleLoc = getLocation("org.eclipse.osgi");
@@ -86,7 +86,13 @@ public abstract class AbstractSimpleConfiguratorTest extends AbstractProvisionin
frameworkProperties.put("osgi.framework", null);
frameworkProperties.put("osgi.install.area", installarea.toURL().toExternalForm());
frameworkProperties.put("osgi.configuration.area", configarea.toURL().toExternalForm());
- frameworkProperties.put("osgi.bundles", "reference:" + simpleConfiguratorBundle.toURL().toExternalForm() + "@1:start"); // should point to simple configurator
+ StringBuffer osgiBundles = new StringBuffer();
+ for (int i = 0; additionalBundle != null && i < additionalBundle.length; i++) {
+ osgiBundles.append("reference:").append(additionalBundle[i].toURL().toExternalForm()).append(",");
+ }
+ osgiBundles.append("reference:").append(simpleConfiguratorBundle.toURL().toExternalForm()).append("@1:start");
+ frameworkProperties.put("osgi.bundles", osgiBundles.toString());
+
frameworkProperties.put("org.eclipse.equinox.simpleconfigurator.configUrl", bundleInfo.toURL().toExternalForm());
frameworkProperties.put("osgi.dev", "bin/");
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
index 4e3e3f1de..70644a617 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
@@ -31,7 +31,7 @@ public class BundlesTxtTest extends AbstractSimpleConfiguratorTest {
}
public void testBundlesTxt() throws Exception {
- BundleContext equinoxContext = startFramework(bundleInfo);
+ BundleContext equinoxContext = startFramework(bundleInfo, null);
assertJarsInstalled(jars, equinoxContext.getBundles());
assertEquals(jars.length + 2, equinoxContext.getBundles().length);
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java
index 5df09358d..ecdcf3f2b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java
@@ -4,172 +4,37 @@
* 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 Corporation - initial API and implementation
* Red Hat, Inc. - tests
*******************************************************************************/
package org.eclipse.equinox.p2.tests.simpleconfigurator;
-import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.jar.JarFile;
-import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorConstants;
-import org.eclipse.equinox.p2.tests.*;
-import org.eclipse.equinox.p2.tests.embeddedequinox.EmbeddedEquinox;
-import org.osgi.framework.*;
+import java.io.File;
+import org.eclipse.equinox.p2.tests.TestData;
+import org.osgi.framework.BundleContext;
-public class NonExclusiveMode extends AbstractProvisioningTest {
-
- static String BUNDLE_JAR_DIRECTORY = "simpleConfiguratorTest/bundlesTxt";
- EmbeddedEquinox equinox = null;
- BundleContext equinoxContext = null;
+public class NonExclusiveMode extends AbstractSimpleConfiguratorTest {
+ private static String BUNDLE_JAR_DIRECTORY = "simpleConfiguratorTest/bundlesTxt";
+ private File[] jars = null;
+ private File bundleInfo = null;
protected void setUp() throws Exception {
super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- equinox.shutdown();
- }
-
- //Assert that all files are in the bundles
- private void assertJarsInstalled(File[] jars, Bundle[] bundles) {
- for (int i = 0; i < jars.length; i++) {
- boolean found = false;
- String jarName = getManifestEntry(jars[i], Constants.BUNDLE_SYMBOLICNAME);
- for (int j = 0; j < bundles.length; j++) {
- String bundleName = bundles[j].getSymbolicName();
- if (bundleName.equalsIgnoreCase(jarName))
- found = true;
- }
- if (!found)
- fail("Bundle should not be present: " + jarName);
- }
+ jars = getBundleJars(TestData.getFile(BUNDLE_JAR_DIRECTORY, ""));
+ bundleInfo = createBundlesTxt(jars);
}
public void testBundlesTxt() throws Exception {
- File[] jars = getBundleJars(TestData.getFile(BUNDLE_JAR_DIRECTORY, ""));
-
- // Create a bundles.info containing all the jars passed
- File bundlesTxt = createBundlesTxt(jars);
-
- // for test purposes create an install.area and configuration.area located in the local bundle data area.
- File installarea = TestActivator.context.getDataFile(getName() + "/eclipse");
- File configarea = new File(installarea, "configuration");
-
- File simpleConfiguratorBundle = getSimpleConfiguratorBundle(jars);
- URL osgiBundle = getFrameworkBundle(jars);
File otherBundle = getTestData("myBundle", "testData/simpleConfiguratorTest/myBundle_1.0.0.jar");
- Map frameworkProperties = new HashMap();
- // note that any properties you do not want to be inherited from the hosting Equinox will need
- // to be nulled out. Otherwise you will pick them up from the hosting env.
- frameworkProperties.put("osgi.framework", null);
- frameworkProperties.put("osgi.install.area", installarea.toURL().toExternalForm());
- frameworkProperties.put("osgi.configuration.area", configarea.toURL().toExternalForm());
- frameworkProperties.put("osgi.bundles", "reference:" + otherBundle.toURL().toExternalForm() + ",reference:" + simpleConfiguratorBundle.toURL().toExternalForm() + "@1:start"); // should point to simple configurator
- frameworkProperties.put("org.eclipse.equinox.simpleconfigurator.configUrl", bundlesTxt.toURL().toExternalForm());
- frameworkProperties.put(SimpleConfiguratorConstants.PROP_KEY_EXCLUSIVE_INSTALLATION, "false");
-
- try {
- equinox = new EmbeddedEquinox(frameworkProperties, new String[] {}, new URL[] {osgiBundle});
- equinoxContext = equinox.startFramework();
-
- assertJarsInstalled(jars, equinoxContext.getBundles());
- assertJarsInstalled(new File[] {otherBundle}, equinoxContext.getBundles());
- assertEquals(4, equinoxContext.getBundles().length);
- } finally {
- equinox.shutdown();
- }
- }
-
- private File getSimpleConfiguratorBundle(File[] jars) {
- for (int i = 0; i < jars.length; i++) {
- File bundleJar = jars[i];
- if (bundleJar.getName().startsWith("org.eclipse.equinox.simpleconfigurator"))
- return bundleJar;
- }
- return null;
- }
-
- private File createBundlesTxt(File[] jars) throws IOException {
- File bundlesTxt = File.createTempFile("bundles", ".txt");
- bundlesTxt.deleteOnExit();
-
- BufferedWriter bundlesTxtOut = new BufferedWriter(new FileWriter(bundlesTxt));
-
- for (int i = 0; i < jars.length; i++) {
- File bundleJar = jars[i];
- bundlesTxtOut.write(getBundlesTxtEntry(bundleJar) + "\n");
- }
-
- bundlesTxtOut.close();
-
- return bundlesTxt;
- }
-
- private String getBundlesTxtEntry(File bundleJar) {
- String name = getManifestEntry(bundleJar, Constants.BUNDLE_SYMBOLICNAME);
- String version = getManifestEntry(bundleJar, Constants.BUNDLE_VERSION);
- // <name>,<version>,file:<file>,<startlevel>,true
- return name + "," + version + "," + "file:" + bundleJar.getAbsolutePath() + "," + getStartLevel(name) + ",true";
- }
-
- private String getManifestEntry(File bundleFile, String entry) {
- try {
- JarFile bundleJar = new JarFile(bundleFile);
- String value = bundleJar.getManifest().getMainAttributes().getValue(entry);
- if (value.indexOf(";") > -1) {
- String[] valueElements = value.split(";");
- return valueElements[0];
- }
- return value;
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
-
- }
-
- private URL getFrameworkBundle(File[] bundleJars) {
- for (int i = 0; i < bundleJars.length; i++) {
- File bundleJar = bundleJars[i];
- if (bundleJar.getName().startsWith("org.eclipse.osgi"))
- try {
- return bundleJar.toURL();
- } catch (MalformedURLException e) {
- fail("Can't find the osgi bundle");
- }
- }
- return null;
- }
-
- private int getStartLevel(String bundleName) {
- int startLevel = 4;
- // some special case start levels
- if (bundleName.matches("org.eclipse.osgi")) {
- startLevel = -1;
- } else if (bundleName.matches("org.eclipse.equinox.common")) {
- startLevel = 2;
- } else if (bundleName.matches("org.eclipse.equinox.simpleconfigurator")) {
- startLevel = 1;
- }
- return startLevel;
- }
+ BundleContext equinoxContext = startFramework(bundleInfo, new File[] {otherBundle});
- private File[] getBundleJars(File directory) {
- FilenameFilter bundleFilter = new FilenameFilter() {
- public boolean accept(File directoryName, String filename) {
- return !filename.startsWith(".") && !filename.equals("CVS");
- }
- };
- return directory.listFiles(bundleFilter);
+ assertJarsInstalled(jars, equinoxContext.getBundles());
+ assertJarsInstalled(new File[] {otherBundle}, equinoxContext.getBundles());
+ assertEquals(4, equinoxContext.getBundles().length);
}
}

Back to the top