Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-11-16 18:33:14 +0000
committerPascal Rapicault2011-11-22 03:33:17 +0000
commit71ea2a1c53d8758b5be8fe3e58f0bda552f0b292 (patch)
treee94f255d0d6551ccc5a6f466babafda3231d9373
parent7c00035bdbef0d6f5fd1e5664fd744c95a984a7b (diff)
downloadrt.equinox.p2-71ea2a1c53d8758b5be8fe3e58f0bda552f0b292.tar.gz
rt.equinox.p2-71ea2a1c53d8758b5be8fe3e58f0bda552f0b292.tar.xz
rt.equinox.p2-71ea2a1c53d8758b5be8fe3e58f0bda552f0b292.zip
Allow customization of bundle requirements generationv20111122-0333
Introduced protected addImportPackageRequirement and addRequireBundleRequirement. The idea is to allow subclasses to generate requirements differently. For example, in Tycho we sometimes need to treat optional dependencies as required and sometimes need to completely ignore optional dependencies. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java52
1 files changed, 32 insertions, 20 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
index b6f352938..2c88cb7a0 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
@@ -80,8 +80,8 @@ public class BundlesAction extends AbstractPublisherAction {
public static final String TYPE_ECLIPSE_SOURCE = "source"; //$NON-NLS-1$
public static final String OSGI_BUNDLE_CLASSIFIER = "osgi.bundle"; //$NON-NLS-1$
- private static final String CAPABILITY_NS_OSGI_BUNDLE = "osgi.bundle"; //$NON-NLS-1$
- private static final String CAPABILITY_NS_OSGI_FRAGMENT = "osgi.fragment"; //$NON-NLS-1$
+ public static final String CAPABILITY_NS_OSGI_BUNDLE = "osgi.bundle"; //$NON-NLS-1$
+ public static final String CAPABILITY_NS_OSGI_FRAGMENT = "osgi.fragment"; //$NON-NLS-1$
public static final IProvidedCapability BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(PublisherHelper.NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_BUNDLE, Version.createOSGi(1, 0, 0));
public static final IProvidedCapability SOURCE_BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(PublisherHelper.NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_SOURCE, Version.createOSGi(1, 0, 0));
@@ -151,6 +151,10 @@ public class BundlesAction extends AbstractPublisherAction {
}
public static IInstallableUnit createBundleIU(BundleDescription bd, IArtifactKey key, IPublisherInfo info) {
+ return new BundlesAction(new BundleDescription[] {bd}).doCreateBundleIU(bd, key, info);
+ }
+
+ protected IInstallableUnit doCreateBundleIU(BundleDescription bd, IArtifactKey key, IPublisherInfo info) {
@SuppressWarnings("unchecked")
Map<String, String> manifest = (Map<String, String>) bd.getUserObject();
Map<Locale, Map<String, String>> manifestLocalizations = null;
@@ -178,13 +182,7 @@ public class BundlesAction extends AbstractPublisherAction {
ManifestElement[] rawRequireBundleHeader = parseManifestHeader(Constants.REQUIRE_BUNDLE, manifest, bd.getLocation());
for (BundleSpecification requiredBundle : requiredBundles) {
- final boolean optional = requiredBundle.isOptional();
- final boolean greedy;
- if (optional)
- greedy = INSTALLATION_GREEDY.equals(getInstallationDirective(requiredBundle.getName(), rawRequireBundleHeader));
- else
- greedy = true;
- reqsDeps.add(MetadataFactory.createRequirement(CAPABILITY_NS_OSGI_BUNDLE, requiredBundle.getName(), PublisherHelper.fromOSGiVersionRange(requiredBundle.getVersionRange()), null, optional ? 0 : 1, 1, greedy));
+ addRequireBundleRequirement(reqsDeps, requiredBundle, rawRequireBundleHeader);
}
// Process the import packages
@@ -195,15 +193,7 @@ public class BundlesAction extends AbstractPublisherAction {
ImportPackageSpecification importSpec = osgiImports[i];
if (isDynamicImport(importSpec))
continue;
- VersionRange versionRange = PublisherHelper.fromOSGiVersionRange(importSpec.getVersionRange());
- final boolean optional = isOptional(importSpec);
- final boolean greedy;
- if (optional)
- greedy = INSTALLATION_GREEDY.equals(getInstallationDirective(importSpec.getName(), rawImportPackageHeader));
- else
- greedy = true;
- //TODO this needs to be refined to take into account all the attribute handled by imports
- reqsDeps.add(MetadataFactory.createRequirement(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, importSpec.getName(), versionRange, null, optional ? 0 : 1, 1, greedy));
+ addImportPackageRequirement(reqsDeps, importSpec, rawImportPackageHeader);
}
iu.setRequirements(reqsDeps.toArray(new IRequirement[reqsDeps.size()]));
@@ -269,6 +259,28 @@ public class BundlesAction extends AbstractPublisherAction {
return MetadataFactory.createInstallableUnit(iu);
}
+ protected void addImportPackageRequirement(ArrayList<IRequirement> reqsDeps, ImportPackageSpecification importSpec, ManifestElement[] rawImportPackageHeader) {
+ VersionRange versionRange = PublisherHelper.fromOSGiVersionRange(importSpec.getVersionRange());
+ final boolean optional = isOptional(importSpec);
+ final boolean greedy;
+ if (optional)
+ greedy = INSTALLATION_GREEDY.equals(getInstallationDirective(importSpec.getName(), rawImportPackageHeader));
+ else
+ greedy = true;
+ //TODO this needs to be refined to take into account all the attribute handled by imports
+ reqsDeps.add(MetadataFactory.createRequirement(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, importSpec.getName(), versionRange, null, optional ? 0 : 1, 1, greedy));
+ }
+
+ protected void addRequireBundleRequirement(ArrayList<IRequirement> reqsDeps, BundleSpecification requiredBundle, ManifestElement[] rawRequireBundleHeader) {
+ final boolean optional = requiredBundle.isOptional();
+ final boolean greedy;
+ if (optional)
+ greedy = INSTALLATION_GREEDY.equals(getInstallationDirective(requiredBundle.getName(), rawRequireBundleHeader));
+ else
+ greedy = true;
+ reqsDeps.add(MetadataFactory.createRequirement(CAPABILITY_NS_OSGI_BUNDLE, requiredBundle.getName(), PublisherHelper.fromOSGiVersionRange(requiredBundle.getVersionRange()), null, optional ? 0 : 1, 1, greedy));
+ }
+
static VersionRange computeUpdateRange(org.osgi.framework.Version base) {
VersionRange updateRange = null;
if (!base.equals(org.osgi.framework.Version.emptyVersion)) {
@@ -404,7 +416,7 @@ public class BundlesAction extends AbstractPublisherAction {
return importedPackage.getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_DYNAMIC);
}
- private static boolean isOptional(ImportPackageSpecification importedPackage) {
+ protected static boolean isOptional(ImportPackageSpecification importedPackage) {
return importedPackage.getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_OPTIONAL);
}
@@ -743,7 +755,7 @@ public class BundlesAction extends AbstractPublisherAction {
if (bundleIU == null) {
createAdviceFileAdvice(bundleDescriptions[i], info);
// Create the bundle IU according to any shape advice we have
- bundleIU = createBundleIU(bd, key, info);
+ bundleIU = doCreateBundleIU(bd, key, info);
}
File location = new File(bd.getLocation());

Back to the top