summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Oberlies2012-09-23 09:04:16 (EDT)
committerTobias Oberlies2012-09-24 10:57:19 (EDT)
commit1ab5536d572eec552f3105d08e1deef1f3f5aea7 (patch)
treec5951e05f8a5c5da94cefc9f92cb96f59252d376
parentb1df469a2938fd2d98cba299ca8d9a88cbdaf0f9 (diff)
downloadrt.equinox.p2-1ab5536d572eec552f3105d08e1deef1f3f5aea7.zip
rt.equinox.p2-1ab5536d572eec552f3105d08e1deef1f3f5aea7.tar.gz
rt.equinox.p2-1ab5536d572eec552f3105d08e1deef1f3f5aea7.tar.bz2
388566 Refactorings in JREAction(Test)
- Extract methods in JREAction. - In JREActionTest, split verify method for metadata and config IU. - Dropped config IU tests where config IU is empty anyway. Bug: 388566 JREAction: Publish osgi.ee capabilities in 'a.jre' IUs
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java46
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java63
2 files changed, 62 insertions, 47 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java
index b043647..dae3d05 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Code 9 and others. All rights reserved. This
+ * Copyright (c) 2008, 2012 Code 9 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
@@ -13,8 +13,7 @@ package org.eclipse.equinox.p2.publisher.actions;
import java.io.*;
import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
@@ -110,29 +109,32 @@ public class JREAction extends AbstractPublisherAction {
return PublisherHelper.createArtifactDescriptor(info, key, jreLocation);
}
- private IProvidedCapability[] generateJRECapability(String id, Version version) {
+ private List<IProvidedCapability> generateJRECapability(String id, Version version) {
if (profileProperties == null)
- return new IProvidedCapability[0];
+ return Collections.emptyList();
+ List<IProvidedCapability> result = new ArrayList<IProvidedCapability>();
+ result.add(PublisherHelper.createSelfCapability(id, version));
+ generateProvidedPackages(result);
+ return result;
+ }
+
+ private void generateProvidedPackages(List<IProvidedCapability> result) {
String packages = profileProperties.get(PROFILE_SYSTEM_PACKAGES);
- if (packages == null || (packages.trim().length() == 0))
- return new IProvidedCapability[] {PublisherHelper.createSelfCapability(id, version)};
+ if (packages != null && (packages.trim().length() > 0)) {
- try {
- ManifestElement[] jrePackages = ManifestElement.parseHeader(PROFILE_SYSTEM_PACKAGES, packages);
- IProvidedCapability[] exportedPackageAsCapabilities = new IProvidedCapability[jrePackages.length + 1];
- exportedPackageAsCapabilities[0] = PublisherHelper.createSelfCapability(id, version);
- for (int i = 1; i <= jrePackages.length; i++) {
- String packageName = jrePackages[i - 1].getValue();
- Version packageVersion = Version.create(jrePackages[i - 1].getAttribute("version")); //$NON-NLS-1$
- exportedPackageAsCapabilities[i] = MetadataFactory.createProvidedCapability(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, packageName, packageVersion);
+ try {
+ ManifestElement[] jrePackages = ManifestElement.parseHeader(PROFILE_SYSTEM_PACKAGES, packages);
+ for (int i = 0; i < jrePackages.length; i++) {
+ String packageName = jrePackages[i].getValue();
+ Version packageVersion = Version.create(jrePackages[i].getAttribute("version")); //$NON-NLS-1$
+ result.add(MetadataFactory.createProvidedCapability(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, packageName, packageVersion));
+ }
+ } catch (BundleException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- return exportedPackageAsCapabilities;
- } catch (BundleException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
- return new IProvidedCapability[0];
}
private void generateJREIUData(InstallableUnitDescription iu) {
@@ -173,8 +175,8 @@ public class JREAction extends AbstractPublisherAction {
profileName = profileName.replace('_', '.');
iu.setId("a.jre." + profileName.toLowerCase()); //$NON-NLS-1$
- IProvidedCapability[] capabilities = generateJRECapability(iu.getId(), iu.getVersion());
- iu.setCapabilities(capabilities);
+ List<IProvidedCapability> capabilities = generateJRECapability(iu.getId(), iu.getVersion());
+ iu.addProvidedCapabilities(capabilities);
}
private void initialize(IPublisherInfo publisherInfo) {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
index 645f19d..d26bc77 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Code 9 and others. All rights reserved. This
+ * Copyright (c) 2008, 2012 Code 9 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
@@ -12,6 +12,7 @@
package org.eclipse.equinox.p2.tests.publisher.actions;
import static org.easymock.EasyMock.expect;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
@@ -46,31 +47,40 @@ public class JREActionTest extends ActionTest {
setupPublisherResult();
}
+ // TODO this name is misleading: the test doesn't test the real Java 1.4 JRE IU but a broken local copy of the 1.4 profile
public void test14() throws Exception {
testAction = new JREAction(J14);
testAction.perform(publisherInfo, publisherResult, new NullProgressMonitor());
- verifyResults("a.jre.j2se", 92, Version.create("1.4.0"), true); //$NON-NLS-1$
+ Version jreVersion = Version.create("1.4.0");
+ verifyMetadataIU("a.jre.j2se", 91, jreVersion);
+ verifyConfigIU("a.jre.j2se", jreVersion); //$NON-NLS-1$
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.j2se,1.4.0"), J14, "J2SE-1.4.profile"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void test15() throws Exception {
testAction = new JREAction(J15);
testAction.perform(publisherInfo, publisherResult, new NullProgressMonitor());
- verifyResults("a.jre.j2se", 119, Version.create("1.5.0"), true); //$NON-NLS-1$
+ Version jreVersion = Version.create("1.5.0");
+ verifyMetadataIU("a.jre.j2se", 118, jreVersion);
+ verifyConfigIU("a.jre.j2se", jreVersion); //$NON-NLS-1$
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.j2se,1.5.0"), J15, "J2SE-1.5.profile"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void test16() throws Exception {
testAction = new JREAction(J16);
testAction.perform(publisherInfo, publisherResult, new NullProgressMonitor());
- verifyResults("a.jre.javase", 117, Version.create("1.6.0"), true); //$NON-NLS-1$
+ Version jreVersion = Version.create("1.6.0");
+ verifyMetadataIU("a.jre.javase", 116, jreVersion);
+ verifyConfigIU("a.jre.javase", jreVersion); //$NON-NLS-1$
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.javase,1.6.0"), J16, "JavaSE-1.6.profile"); //$NON-NLS-1$//$NON-NLS-2$
}
public void testOSGiMin() throws Exception {
testAction = new JREAction("OSGi/Minimum-1.2");
testAction.perform(publisherInfo, publisherResult, new NullProgressMonitor());
- verifyResults("a.jre.osgi.minimum", 2, Version.create("1.2.0"), false); //$NON-NLS-1$
+ Version jreVersion = Version.create("1.2.0");
+ verifyMetadataIU("a.jre.osgi.minimum", 1, jreVersion);
+ // verifyConfigIU("a.jre.osgi.minimum", jreVersion); // TODO config IU is not needed!?
}
public void testPackageVersionsFromJreFolder() throws Exception {
@@ -99,11 +109,12 @@ public class JREActionTest extends ActionTest {
// this could be avoided by making the respective static properties of JREAction class public but doing so for test purposes only is questionable
final String DEFAULT_JRE_NAME = "a.jre.javase"; //$NON-NLS-1$
final Version DEFAULT_JRE_VERSION = Version.parseVersion("1.6"); //$NON-NLS-1$
- final int DEFAULT_NUM_PROVIDED_CAPABILITIES = 159;
+ final int DEFAULT_NUM_PROVIDED_PACKAGES = 158;
testAction = new JREAction((File) null);
testAction.perform(publisherInfo, publisherResult, new NullProgressMonitor());
- verifyResults(DEFAULT_JRE_NAME, DEFAULT_NUM_PROVIDED_CAPABILITIES, DEFAULT_JRE_VERSION, false);
+ verifyMetadataIU(DEFAULT_JRE_NAME, DEFAULT_NUM_PROVIDED_PACKAGES, DEFAULT_JRE_VERSION);
+ // verifyConfigIU(DEFAULT_JRE_NAME, DEFAULT_JRE_VERSION); // TODO config IU is not needed!?
}
public void testNonExistingJreLocation() {
@@ -119,13 +130,11 @@ public class JREActionTest extends ActionTest {
}
}
- private void verifyResults(String id, int numProvidedCapabilities, Version JREVersion, boolean testInstructions) {
- ArrayList fooIUs = new ArrayList(publisherResult.getIUs(id, IPublisherResult.ROOT)); //$NON-NLS-1$
- assertTrue(fooIUs.size() == 1);
- IInstallableUnit foo = (IInstallableUnit) fooIUs.get(0);
+ private void verifyMetadataIU(String id, int expectedProvidedPackages, Version jreVersion) {
+ IInstallableUnit foo = getPublishedUnit(id);
// check version
- assertTrue(foo.getVersion().equals(JREVersion));
+ assertTrue(foo.getVersion().equals(jreVersion));
// check touchpointType
assertTrue(foo.getTouchpointType().getId().equalsIgnoreCase("org.eclipse.equinox.p2.native")); //$NON-NLS-1$
@@ -133,28 +142,26 @@ public class JREActionTest extends ActionTest {
// check provided capabilities
Collection<IProvidedCapability> fooProvidedCapabilities = foo.getProvidedCapabilities();
- assertTrue(fooProvidedCapabilities.size() == numProvidedCapabilities);
+ assertThat(fooProvidedCapabilities.size(), is(1 + expectedProvidedPackages));
+ }
- ArrayList barIUs = new ArrayList(publisherResult.getIUs("config." + id, IPublisherResult.ROOT)); //$NON-NLS-1$
- assertTrue(barIUs.size() == 1);
- IInstallableUnit bar = (IInstallableUnit) barIUs.get(0);
+ private void verifyConfigIU(String id, Version jreVersion) {
+ IInstallableUnit bar = getPublishedUnit("config." + id);
- if (testInstructions) {
- Map instructions = bar.getTouchpointData().iterator().next().getInstructions();
- assertTrue(((ITouchpointInstruction) instructions.get("install")).getBody().equals("unzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$//$NON-NLS-2$
- assertTrue(((ITouchpointInstruction) instructions.get("uninstall")).getBody().equals("cleanupzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ Map instructions = bar.getTouchpointData().iterator().next().getInstructions();
+ assertTrue(((ITouchpointInstruction) instructions.get("install")).getBody().equals("unzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$//$NON-NLS-2$
+ assertTrue(((ITouchpointInstruction) instructions.get("uninstall")).getBody().equals("cleanupzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(bar instanceof IInstallableUnitFragment);
Collection<IRequirement> requiredCapability = ((IInstallableUnitFragment) bar).getHost();
- verifyRequiredCapability(requiredCapability, IInstallableUnit.NAMESPACE_IU_ID, id, new VersionRange(JREVersion, true, Version.MAX_VERSION, true)); //$NON-NLS-1$
+ verifyRequiredCapability(requiredCapability, IInstallableUnit.NAMESPACE_IU_ID, id, new VersionRange(jreVersion, true, Version.MAX_VERSION, true)); //$NON-NLS-1$
assertTrue(requiredCapability.size() == 1);
Collection<IProvidedCapability> providedCapability = bar.getProvidedCapabilities();
- verifyProvidedCapability(providedCapability, IInstallableUnit.NAMESPACE_IU_ID, "config." + id, JREVersion); //$NON-NLS-1$
+ verifyProvidedCapability(providedCapability, IInstallableUnit.NAMESPACE_IU_ID, "config." + id, jreVersion); //$NON-NLS-1$
assertTrue(providedCapability.size() == 1);
assertTrue(bar.getProperty("org.eclipse.equinox.p2.type.fragment").equals("true")); //$NON-NLS-1$//$NON-NLS-2$
- assertTrue(bar.getVersion().equals(JREVersion));
+ assertTrue(bar.getVersion().equals(jreVersion));
}
private void verifyArtifactRepository(IArtifactKey key, File JRELocation, final String fileName) throws IOException {
@@ -174,9 +181,15 @@ public class JREActionTest extends ActionTest {
TestData.assertContains(fileMap, zipInputStream, true);
}
+ private IInstallableUnit getPublishedUnit(String id) {
+ Collection<IInstallableUnit> units = publisherResult.getIUs(id, IPublisherResult.ROOT);
+ assertThat(units.size(), is(1));
+ return units.iterator().next();
+ }
+
private Collection<IProvidedCapability> getPublishedCapabilitiesOf(String id) {
Collection<IInstallableUnit> ius = publisherResult.getIUs(id, IPublisherResult.ROOT);
- assertTrue(ius.size() == 1);
+ assertThat(ius.size(), is(1));
IInstallableUnit iu = ius.iterator().next();
return iu.getProvidedCapabilities();
}