diff options
author | Andrew Niefer | 2009-05-12 20:21:28 +0000 |
---|---|---|
committer | Andrew Niefer | 2009-05-12 20:21:28 +0000 |
commit | dcc433f038dda66c44e22a82d6bcb86476c88303 (patch) | |
tree | 1f2e503fde24e750c6e07a47646f0c25cd87208b /bundles | |
parent | f86dbfb4063fdb068b4a05617cc0e1796032749b (diff) | |
download | rt.equinox.p2-dcc433f038dda66c44e22a82d6bcb86476c88303.tar.gz rt.equinox.p2-dcc433f038dda66c44e22a82d6bcb86476c88303.tar.xz rt.equinox.p2-dcc433f038dda66c44e22a82d6bcb86476c88303.zip |
bug 252743 - CU filters need to agree with host
Diffstat (limited to 'bundles')
5 files changed, 196 insertions, 34 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java index 8f3caadd1..0a85207f8 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java @@ -11,8 +11,10 @@ package org.eclipse.equinox.internal.p2.publisher.eclipse; import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; +import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; public class GeneratorBundleInfo extends BundleInfo { + private IInstallableUnit iu = null; private String specialConfigCommands; private String specialUnconfigCommands; @@ -39,6 +41,14 @@ public class GeneratorBundleInfo extends BundleInfo { this.specialConfigCommands = specialConfigCommands; } + public void setIU(IInstallableUnit iu) { + this.iu = iu; + } + + public IInstallableUnit getIU() { + return iu; + } + public String getSpecialUnconfigCommands() { return specialUnconfigCommands; } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java index a4255075c..9c422bcaa 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java @@ -28,6 +28,8 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.query.LatestIUVersio import org.eclipse.equinox.internal.provisional.p2.query.*; import org.eclipse.equinox.p2.publisher.actions.*; import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; +import org.osgi.framework.Filter; +import org.osgi.framework.InvalidSyntaxException; public abstract class AbstractPublisherAction implements IPublisherAction { public static final String CONFIG_ANY = "ANY"; //$NON-NLS-1$ @@ -110,6 +112,26 @@ public abstract class AbstractPublisherAction implements IPublisherAction { return null; } + protected boolean filterMatches(String filter, String configSpec) { + if (filter == null) + return true; + + Filter ldapFilter = null; + try { + ldapFilter = Activator.context.createFilter(filter); + } catch (InvalidSyntaxException e) { + // TODO true or false on error? + return true; + } + + String[] config = parseConfigSpec(configSpec); + Dictionary environment = new Hashtable(3); + environment.put("osgi.ws", config[0]); //$NON-NLS-1$ + environment.put("osgi.os", config[1]); //$NON-NLS-1$ + environment.put("osgi.arch", config[2]); //$NON-NLS-1$ + return ldapFilter.match(environment); + } + /** * Returns the normalized string form of the given config spec. This is useful for putting * in IU ids etc. Note that the result is not intended to be machine readable (i.e., parseConfigSpec diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java index 787bb8f7b..a76e5034f 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java @@ -19,9 +19,6 @@ import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; import org.eclipse.equinox.internal.provisional.p2.core.Version; import org.eclipse.equinox.internal.provisional.p2.metadata.*; import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; -import org.eclipse.equinox.internal.provisional.p2.query.Collector; -import org.eclipse.equinox.internal.provisional.p2.query.Query; import org.eclipse.equinox.p2.publisher.*; import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; import org.eclipse.osgi.util.ManifestElement; @@ -41,6 +38,7 @@ public class ConfigCUsAction extends AbstractPublisherAction { protected Version version; protected String id; protected String flavor; + IPublisherResult outerResults = null; // TODO consider moving this filtering to the LaunchingAdvice and ConfigAdvice so // it is not hardcoded in the action. @@ -88,6 +86,8 @@ public class ConfigCUsAction extends AbstractPublisherAction { public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) { IPublisherResult innerResult = new PublisherResult(); + this.outerResults = results; + this.info = info; // we have N platforms, generate a CU for each // TODO try and find common properties across platforms String[] configSpecs = info.getConfigurations(); @@ -301,10 +301,16 @@ public class ConfigCUsAction extends AbstractPublisherAction { } for (int i = 0; i < bundles.length; i++) { - GeneratorBundleInfo bundle = createGeneratorBundleInfo(info, bundles[i], result); + GeneratorBundleInfo bundle = createGeneratorBundleInfo(bundles[i], result); if (bundle == null) continue; + IInstallableUnit iu = bundle.getIU(); + + // If there is no host, or the filters don't match, skip this one. + if (iu == null || !filterMatches(iu.getFilter(), configSpec)) + continue; + // TODO need to factor this out into its own action if (bundle.getSymbolicName().equals(ORG_ECLIPSE_UPDATE_CONFIGURATOR)) { bundle.setStartLevel(BundleInfo.NO_LEVEL); @@ -316,7 +322,7 @@ public class ConfigCUsAction extends AbstractPublisherAction { continue; } - IInstallableUnit cu = BundlesAction.createBundleConfigurationUnit(bundle.getSymbolicName(), new Version(bundle.getVersion()), false, bundle, flavor + cuIdPrefix, filter); + IInstallableUnit cu = BundlesAction.createBundleConfigurationUnit(bundle.getSymbolicName(), Version.parseVersion(bundle.getVersion()), false, bundle, flavor + cuIdPrefix, filter); if (cu != null) { // Product Query will run against the repo, make sure these CUs are in before then // TODO review the aggressive addition to the metadata repo. perhaps the query can query the result as well. @@ -329,27 +335,30 @@ public class ConfigCUsAction extends AbstractPublisherAction { } } - protected GeneratorBundleInfo createGeneratorBundleInfo(IPublisherInfo info, BundleInfo bundleInfo, IPublisherResult result) { - if (bundleInfo.getLocation() != null || bundleInfo.getVersion() != null) - return new GeneratorBundleInfo(bundleInfo); - + protected GeneratorBundleInfo createGeneratorBundleInfo(BundleInfo bundleInfo, IPublisherResult result) { String name = bundleInfo.getSymbolicName(); - //easy case: do we have a matching IU? - IInstallableUnit iu = result.getIU(name, null); + //query for a matching IU + IInstallableUnit iu = queryForIU(outerResults, name, Version.create(bundleInfo.getVersion())); if (iu != null) { - bundleInfo.setVersion(iu.getVersion().toString()); - return new GeneratorBundleInfo(bundleInfo); + if (iu.getVersion() == null) + bundleInfo.setVersion("0.0.0"); //$NON-NLS-1$ + else + bundleInfo.setVersion(iu.getVersion().toString()); + GeneratorBundleInfo newInfo = new GeneratorBundleInfo(bundleInfo); + newInfo.setIU(iu); + return newInfo; } + if (bundleInfo.getLocation() != null || bundleInfo.getVersion() != null) + return new GeneratorBundleInfo(bundleInfo); //harder: try id_version int i = name.indexOf('_'); while (i > -1) { - Version version = null; try { - version = new Version(name.substring(i)); + Version bundleVersion = Version.parseVersion(name.substring(i)); bundleInfo.setSymbolicName(name.substring(0, i)); - bundleInfo.setVersion(version.toString()); + bundleInfo.setVersion(bundleVersion.toString()); return new GeneratorBundleInfo(bundleInfo); } catch (IllegalArgumentException e) { // the '_' found was probably part of the symbolic id @@ -357,22 +366,6 @@ public class ConfigCUsAction extends AbstractPublisherAction { } } - //Query the repo - Query query = new InstallableUnitQuery(name); - Collector collector = new Collector(); - Iterator matches = info.getMetadataRepository().query(query, collector, null).iterator(); - //pick the newest match - IInstallableUnit newest = null; - while (matches.hasNext()) { - IInstallableUnit candidate = (IInstallableUnit) matches.next(); - if (newest == null || (newest.getVersion().compareTo(candidate.getVersion()) < 0)) - newest = candidate; - } - if (newest != null) { - bundleInfo.setVersion(newest.getVersion().toString()); - return new GeneratorBundleInfo(bundleInfo); - } - return null; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java index d62b33aba..162d9912e 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java @@ -105,20 +105,21 @@ public class ConfigCUsActionTest extends ActionTest { ConfigAdvice configAdvice = new ConfigAdvice(configData, configSpec); ArrayList configList = new ArrayList(); configList.add(configAdvice); - expect(publisherInfo.getAdvice(EasyMock.matches(configSpec), EasyMock.eq(false), (String) EasyMock.anyObject(), (Version) EasyMock.anyObject(), EasyMock.eq(IConfigAdvice.class))).andReturn(configList); + expect(publisherInfo.getAdvice(EasyMock.matches(configSpec), EasyMock.eq(false), (String) EasyMock.anyObject(), (Version) EasyMock.anyObject(), EasyMock.eq(IConfigAdvice.class))).andReturn(configList).anyTimes(); //configure ILaunchingAdvice LauncherData launcherData = loader.getLauncherData(); LaunchingAdvice launchingAdvice = new LaunchingAdvice(launcherData, configSpec); ArrayList launchingList = new ArrayList(); launchingList.add(launchingAdvice); - expect(publisherInfo.getAdvice(EasyMock.matches(configSpec), EasyMock.eq(false), (String) EasyMock.anyObject(), (Version) EasyMock.anyObject(), EasyMock.eq(IExecutableAdvice.class))).andReturn(launchingList); + expect(publisherInfo.getAdvice(EasyMock.matches(configSpec), EasyMock.eq(false), (String) EasyMock.anyObject(), (Version) EasyMock.anyObject(), EasyMock.eq(IExecutableAdvice.class))).andReturn(launchingList).anyTimes(); //setup metadata repository IInstallableUnit[] ius = {mockIU("foo", null), mockIU("bar", null)}; //$NON-NLS-1$ //$NON-NLS-2$ metadataRepo = new TestMetadataRepository(ius); expect(publisherInfo.getMetadataRepository()).andReturn(metadataRepo).anyTimes(); + expect(publisherInfo.getContextMetadataRepository()).andReturn(null).anyTimes(); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java index f968a4b4f..e9e64b260 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java @@ -23,6 +23,8 @@ import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile; import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; import org.eclipse.equinox.internal.provisional.p2.core.Version; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory; +import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; import org.eclipse.equinox.internal.provisional.p2.query.Collector; import org.eclipse.equinox.p2.publisher.*; @@ -34,6 +36,9 @@ import org.eclipse.equinox.p2.tests.publisher.TestArtifactRepository; @SuppressWarnings( {"unchecked"}) public class ProductActionTest extends ActionTest { + private String winFitler = "(& (osgi.ws=win32)(osgi.os=win32)(osgi.arch=x86))"; + private String linuxFilter = "(& (osgi.ws=gtk)(osgi.os=linux)(osgi.arch=x86))"; + File executablesFeatureLocation = null; String productLocation = ""; private Capture<RootIUAdvice> rootIUAdviceCapture; @@ -159,15 +164,146 @@ public class ProductActionTest extends ActionTest { info.setConfigurations(getArrayFromString(configSpec, COMMA_SEPARATOR)); PublisherResult results = new PublisherResult(); + InstallableUnitDescription iuDescription = new InstallableUnitDescription(); + iuDescription.setId("org.eclipse.core.runtime"); + iuDescription.setVersion(Version.create("4.0.0")); + IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDescription); + + results.addIU(iu, IPublisherResult.NON_ROOT); ProductAction action1 = new ProductAction(null, productFile1, flavorArg, executablesFeatureLocation); ProductAction action2 = new ProductAction(null, productFile2, flavorArg, executablesFeatureLocation); action1.perform(info, results, new NullProgressMonitor()); results = new PublisherResult(); + + results.addIU(iu, IPublisherResult.NON_ROOT); + action2.perform(info, results, new NullProgressMonitor()); Collector collector = results.query(new InstallableUnitQuery(flavorArg + configSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); assertEquals("1.0", 1, collector.size()); } + public void testMultiPlatformCUs_DifferentPlatforms() throws Exception { + ProductFile productFile2 = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString()); + PublisherInfo info = new PublisherInfo(); + String windowsConfigSpec = AbstractPublisherAction.createConfigSpec("win32", "win32", "x86"); + String linuxConfigSpec = AbstractPublisherAction.createConfigSpec("gtk", "linux", "x86"); + info.setConfigurations(getArrayFromString(linuxConfigSpec, COMMA_SEPARATOR)); + PublisherResult results = new PublisherResult(); + + InstallableUnitDescription iuDescription = new InstallableUnitDescription(); + iuDescription.setId("org.eclipse.core.runtime"); + iuDescription.setVersion(Version.create("0.0.0")); + iuDescription.setFilter(winFitler); + IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDescription); + + results.addIU(iu, IPublisherResult.NON_ROOT); + ProductAction action = new ProductAction(null, productFile2, flavorArg, executablesFeatureLocation); + + action.perform(info, results, new NullProgressMonitor()); + + Collector collector = results.query(new InstallableUnitQuery(flavorArg + linuxConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("1.0", 0, collector.size()); + + collector = results.query(new InstallableUnitQuery(flavorArg + windowsConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("2.0", 0, collector.size()); + } + + public void testMultiPlatformCUs_SamePlatforms() throws Exception { + ProductFile productFile2 = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString()); + PublisherInfo info = new PublisherInfo(); + String windowsConfigSpec = AbstractPublisherAction.createConfigSpec("win32", "win32", "x86"); + String linuxConfigSpec = AbstractPublisherAction.createConfigSpec("gtk", "linux", "x86"); + info.setConfigurations(getArrayFromString(linuxConfigSpec, COMMA_SEPARATOR)); + PublisherResult results = new PublisherResult(); + + InstallableUnitDescription iuDescription = new InstallableUnitDescription(); + iuDescription.setId("org.eclipse.core.runtime"); + iuDescription.setVersion(Version.create("0.0.0")); + iuDescription.setFilter(linuxFilter); + IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDescription); + + results.addIU(iu, IPublisherResult.NON_ROOT); + ProductAction action = new ProductAction(null, productFile2, flavorArg, executablesFeatureLocation); + + action.perform(info, results, new NullProgressMonitor()); + + Collector collector = results.query(new InstallableUnitQuery(flavorArg + linuxConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("1.0", 1, collector.size()); + + collector = results.query(new InstallableUnitQuery(flavorArg + windowsConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("2.0", 0, collector.size()); + } + + public void testMultiPlatformCUs_SamePlatforms_NoVersion() throws Exception { + ProductFile productFile2 = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString()); + PublisherInfo info = new PublisherInfo(); + String windowsConfigSpec = AbstractPublisherAction.createConfigSpec("win32", "win32", "x86"); + String linuxConfigSpec = AbstractPublisherAction.createConfigSpec("gtk", "linux", "x86"); + info.setConfigurations(getArrayFromString(linuxConfigSpec, COMMA_SEPARATOR)); + PublisherResult results = new PublisherResult(); + + InstallableUnitDescription iuDescription = new InstallableUnitDescription(); + iuDescription.setId("org.eclipse.core.runtime"); + iuDescription.setFilter(linuxFilter); + IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDescription); + + results.addIU(iu, IPublisherResult.NON_ROOT); + ProductAction action = new ProductAction(null, productFile2, flavorArg, executablesFeatureLocation); + + action.perform(info, results, new NullProgressMonitor()); + + Collector collector = results.query(new InstallableUnitQuery(flavorArg + linuxConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("1.0", 1, collector.size()); + + collector = results.query(new InstallableUnitQuery(flavorArg + windowsConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("2.0", 0, collector.size()); + } + + public void testMultiPlatformCUs_SamePlatforms_BoundedVersions() throws Exception { + ProductFile productFile2 = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString()); + PublisherInfo info = new PublisherInfo(); + String windowsConfigSpec = AbstractPublisherAction.createConfigSpec("win32", "win32", "x86"); + String linuxConfigSpec = AbstractPublisherAction.createConfigSpec("gtk", "linux", "x86"); + info.setConfigurations(getArrayFromString(linuxConfigSpec, COMMA_SEPARATOR)); + PublisherResult results = new PublisherResult(); + + InstallableUnitDescription iuDescription = new InstallableUnitDescription(); + iuDescription.setId("org.eclipse.core.runtime"); + iuDescription.setVersion(Version.create("4.0.0")); // Set a specific version number, the one in the .product file uses 0.0.0. Let's see if it binds properly + iuDescription.setFilter("(osgi.os=linux)"); //filter is different from linuxConfigSpec, but will still match + IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDescription); + + results.addIU(iu, IPublisherResult.NON_ROOT); + ProductAction action = new ProductAction(null, productFile2, flavorArg, executablesFeatureLocation); + + action.perform(info, results, new NullProgressMonitor()); + + Collector collector = results.query(new InstallableUnitQuery(flavorArg + linuxConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("1.0", 1, collector.size()); + + collector = results.query(new InstallableUnitQuery(flavorArg + windowsConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("2.0", 0, collector.size()); + } + + public void testCUNoHost() throws Exception { + ProductFile productFile2 = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString()); + PublisherInfo info = new PublisherInfo(); + String windowsConfigSpec = AbstractPublisherAction.createConfigSpec("win32", "win32", "x86"); + String linuxConfigSpec = AbstractPublisherAction.createConfigSpec("gtk", "linux", "x86"); + info.setConfigurations(getArrayFromString(linuxConfigSpec, COMMA_SEPARATOR)); + PublisherResult results = new PublisherResult(); + + ProductAction action = new ProductAction(null, productFile2, flavorArg, executablesFeatureLocation); + + action.perform(info, results, new NullProgressMonitor()); + + Collector collector = results.query(new InstallableUnitQuery(flavorArg + linuxConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("1.0", 0, collector.size()); + + collector = results.query(new InstallableUnitQuery(flavorArg + windowsConfigSpec + "org.eclipse.core.runtime"), new Collector(), new NullProgressMonitor()); + assertEquals("2.0", 0, collector.size()); + } + public void testMultiConfigspecProductPublishing() throws IOException, Exception { ProductFile productFile = new ProductFile(TestData.getFile("ProductActionTest", "platform.product").toString()); PublisherInfo info = new PublisherInfo(); |