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)); }
protected void addRequireBundleRequirement(List<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)); }
/** * Returns the set of String bundle names that are in the project's list of required * bundles. * * @return set of required bundle names, possibly empty */ private Set<String> getCurrentBundleNames() { IPluginModelBase base = PluginRegistry.findModel(fProject); if (base != null) { Set<String> bundleNames = new HashSet<>(); BundleSpecification[] reqBundles = base.getBundleDescription().getRequiredBundles(); for (BundleSpecification reqBundle : reqBundles) { bundleNames.add(reqBundle.getName()); } return bundleNames; } return Collections.emptySet(); }
private void hackRequireBundleManifestHeader(final BundleDescription bundleDescription, final List<BundleCapability> availableCapabilities, final Attributes mainAttributes) { StringBuilder hackedRequireBundleSB = new StringBuilder(); BundleSpecification[] requiredBundles = bundleDescription.getRequiredBundles(); for (BundleSpecification requiredBundle : requiredBundles) { if (hackedRequireBundleSB.length() > 0) { hackedRequireBundleSB.append(","); } hackedRequireBundleSB.append(requiredBundle.getName() + ";bundle-version=\"" + requiredBundle.getVersionRange() + "\""); if (requiredBundle.isOptional() || !requirementSatisfiable(requiredBundle.getRequirement(), availableCapabilities)) { if (!requiredBundle.isOptional()) { LOGGER.info( "[HACK]: Making Require-Bundle optional in bundle " + bundleDescription.toString() + ": " + hackedRequireBundleSB.toString()); } hackedRequireBundleSB.append(";").append(Constants.RESOLUTION_DIRECTIVE).append(":=") .append("\"") .append(Constants.RESOLUTION_OPTIONAL).append("\""); } } if (hackedRequireBundleSB.length() > 0) { mainAttributes.putValue(Constants.REQUIRE_BUNDLE, hackedRequireBundleSB.toString()); } }
private Set<String> findManifestPlugins(Set<String> ignorePkgs) { BundleSpecification[] bundles = fBase.getBundleDescription().getRequiredBundles(); Set<String> result = new HashSet<>((4 / 3) * (bundles.length) + 2); ArrayList<IPluginBase> plugins = new ArrayList<>(); for (BundleSpecification bundle : bundles) { String id = bundle.getName(); result.add(id); IPluginModelBase base = PluginRegistry.findModel(id); if (base != null) { ExportPackageDescription[] exportedPkgs = findExportedPackages(base.getBundleDescription()); for (ExportPackageDescription exportedPkg : exportedPkgs) ignorePkgs.add(exportedPkg.getName()); plugins.add(base.getPluginBase()); } } return result; }
@Override protected void addRequireBundleRequirement(List<IRequirement> reqsDeps, BundleSpecification requiredBundle, ManifestElement[] rawRequireBundleHeader) { if (optionalAction == OptionalResolutionAction.OPTIONAL) { super.addRequireBundleRequirement(reqsDeps, requiredBundle, rawRequireBundleHeader); return; } VersionRange versionRange = PublisherHelper.fromOSGiVersionRange(requiredBundle.getVersionRange()); final boolean required = !requiredBundle.isOptional() || optionalAction == OptionalResolutionAction.REQUIRE; if (required) { reqsDeps.add(MetadataFactory.createRequirement(CAPABILITY_NS_OSGI_BUNDLE, requiredBundle.getName(), versionRange, null, 1, 1, true /* greedy */)); } }
public void load(BundleSpecification importModel) { this.fID = importModel.getName(); this.reexported = importModel.isExported(); this.optional = importModel.isOptional(); VersionRange versionRange = importModel.getVersionRange(); if (versionRange == null || VersionRange.emptyRange.equals(versionRange)) { this.version = null; match = IMatchRules.NONE; } else { this.version = versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null; match = PluginBase.getMatchRule(versionRange); } }
public void load(BundleSpecification importModel) { this.fID = importModel.getName(); this.reexported = importModel.isExported(); this.optional = importModel.isOptional(); VersionRange versionRange = importModel.getVersionRange(); if (versionRange == null || VersionRange.emptyRange.equals(versionRange)) { this.version = null; match = IMatchRules.NONE; } else { this.version = versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null; match = PluginBase.getMatchRule(versionRange); } }
private void findRequireBundleReferences(ArrayList<TextFileChange> changes, IProgressMonitor monitor) throws CoreException { String oldId = fDesc.getSymbolicName(); BundleDescription[] dependents = fDesc.getDependents(); SubMonitor subMonitor = SubMonitor.convert(monitor, dependents.length); for (BundleDescription dependent : dependents) { BundleSpecification[] requires = dependent.getRequiredBundles(); SubMonitor iterationMonitor = subMonitor.split(1); for (BundleSpecification require : requires) { if (require.getName().equals(oldId)) { CreateHeaderChangeOperation op = new CreateHeaderChangeOperation(PluginRegistry.findModel(dependent), Constants.REQUIRE_BUNDLE, oldId, fNewId); op.run(iterationMonitor); TextFileChange change = op.getChange(); if (change != null) { changes.add(change); } break; } } } }
private void addDependency(State state, String bundleID, Set<String> set) { if (bundleID == null || !set.add(bundleID)) return; BundleDescription desc = state.getBundle(bundleID, null); if (desc == null) return; BundleDescription[] fragments = desc.getFragments(); for (BundleDescription fragment : fragments) { addDependency(state, fragment.getSymbolicName(), set); } BundleSpecification[] specs = desc.getRequiredBundles(); for (BundleSpecification spec : specs) { if (spec.isResolved() && spec.isExported()) { addDependency(state, spec.getName(), set); } } }
@Override public synchronized IRequiredComponentDescription[] getRequiredComponents() throws CoreException { if (fBundleDescription == null) { baselineDisposed(getBaseline()); } BundleSpecification[] requiredBundles = fBundleDescription.getRequiredBundles(); IRequiredComponentDescription[] req = new IRequiredComponentDescription[requiredBundles.length]; for (int i = 0; i < requiredBundles.length; i++) { BundleSpecification bundle = requiredBundles[i]; req[i] = new RequiredComponentDescription(bundle.getName(), new BundleVersionRange(bundle.getVersionRange()), bundle.isOptional(), bundle.isExported()); } return req; }
public BundleSpecification createBundleSpecification(BundleSpecification original) { BundleSpecificationImpl bundleSpec = new BundleSpecificationImpl(); bundleSpec.setName(original.getName()); bundleSpec.setVersionRange(original.getVersionRange()); bundleSpec.setExported(original.isExported()); bundleSpec.setOptional(original.isOptional()); if (original instanceof BundleSpecificationImpl) bundleSpec.setAttributes(((BundleSpecificationImpl) original).getAttributes()); return bundleSpec; }
public BundleSpecification createBundleSpecification(BundleSpecification original) { BundleSpecificationImpl bundleSpec = new BundleSpecificationImpl(); bundleSpec.setName(original.getName()); bundleSpec.setVersionRange(original.getVersionRange()); bundleSpec.setExported(original.isExported()); bundleSpec.setOptional(original.isOptional()); if (original instanceof BundleSpecificationImpl) { bundleSpec.setAttributes(((BundleSpecificationImpl) original).getAttributes()); bundleSpec.setArbitraryDirectives(((BundleSpecificationImpl) original).getArbitraryDirectives()); } return bundleSpec; }
public BundleSpecification createBundleSpecification(BundleSpecification original) { BundleSpecificationImpl bundleSpec = new BundleSpecificationImpl(); bundleSpec.setName(original.getName()); bundleSpec.setVersionRange(original.getVersionRange()); bundleSpec.setExported(original.isExported()); bundleSpec.setOptional(original.isOptional()); if (original instanceof BundleSpecificationImpl) { bundleSpec.setAttributes(((BundleSpecificationImpl) original).getAttributes()); bundleSpec.setArbitraryDirectives(((BundleSpecificationImpl) original).getArbitraryDirectives()); } return bundleSpec; }
public BundleSpecification createBundleSpecification(BundleSpecification original) { BundleSpecificationImpl bundleSpec = new BundleSpecificationImpl(); bundleSpec.setName(original.getName()); bundleSpec.setVersionRange(original.getVersionRange()); bundleSpec.setExported(original.isExported()); bundleSpec.setOptional(original.isOptional()); if (original instanceof BundleSpecificationImpl) { bundleSpec.setAttributes(((BundleSpecificationImpl) original).getAttributes()); bundleSpec.setArbitraryDirectives(((BundleSpecificationImpl) original).getArbitraryDirectives()); } return bundleSpec; }
boolean constraintsConflict(BundleDescription fragment, ImportPackageSpecification[] newImports, BundleSpecification[] newRequires, GenericSpecification[] newGenericRequires) { // this method iterates over all additional constraints from a fragment // if the host is resolved then the fragment is not allowed to add new constraints; // if the host is resolved and it already has a constraint of the same name then ensure the supplier satisfies the fragment's constraint boolean result = false; for (int i = 0; i < newImports.length; i++) { ResolverImport hostImport = getImport(newImports[i].getName()); ResolverExport resolvedExport = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier()); if ((resolvedExport == null && isResolved()) || (resolvedExport != null && !newImports[i].isSatisfiedBy(resolvedExport.getExportPackageDescription()))) { result = true; resolver.getState().addResolverError(fragment, ResolverError.FRAGMENT_CONFLICT, newImports[i].toString(), newImports[i]); } } for (int i = 0; i < newRequires.length; i++) { BundleConstraint hostRequire = getRequire(newRequires[i].getName()); ResolverBundle resolvedRequire = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier()); if ((resolvedRequire == null && isResolved()) || (resolvedRequire != null && !newRequires[i].isSatisfiedBy(resolvedRequire.getBundleDescription()))) { result = true; resolver.getState().addResolverError(fragment, ResolverError.FRAGMENT_CONFLICT, newRequires[i].toString(), newRequires[i]); } } // generic constraints cannot conflict; // only check that a fragment does not add generics constraints to an already resolved host if (isResolved() && newGenericRequires != null && newGenericRequires.length > 0) result = true; return result; }
private void stateResolveFragConstraints(ResolverBundle rb) { ResolverBundle host = (ResolverBundle) rb.getHost().getSelectedSupplier(); ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages(); for (int i = 0; i < imports.length; i++) { ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName()); ResolverExport export = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier()); BaseDescription supplier = export == null ? null : export.getExportPackageDescription(); state.resolveConstraint(imports[i], supplier); } BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles(); for (int i = 0; i < requires.length; i++) { BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName()); ResolverBundle bundle = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier()); BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription(); state.resolveConstraint(requires[i], supplier); } }
private void stateResolveFragConstraints(ResolverBundle rb) { ResolverBundle host = (ResolverBundle) rb.getHost().getSelectedSupplier(); ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages(); for (int i = 0; i < imports.length; i++) { ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName()); ResolverExport export = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier()); BaseDescription supplier = export == null ? null : export.getExportPackageDescription(); state.resolveConstraint(imports[i], supplier); } BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles(); for (int i = 0; i < requires.length; i++) { BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName()); ResolverBundle bundle = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier()); BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription(); state.resolveConstraint(requires[i], supplier); } GenericConstraint[] genericRequires = rb.getGenericRequires(); for (int i = 0; i < genericRequires.length; i++) { VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities(); if (matchingCapabilities == null) state.resolveConstraint(genericRequires[i].getVersionConstraint(), null); else for (int j = 0; j < matchingCapabilities.length; j++) state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription()); } }
private void stateResolveFragConstraints(ResolverBundle rb) { ResolverBundle host = (ResolverBundle) rb.getHost().getSelectedSupplier(); ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages(); for (int i = 0; i < imports.length; i++) { ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName()); ResolverExport export = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier()); BaseDescription supplier = export == null ? null : export.getExportPackageDescription(); state.resolveConstraint(imports[i], supplier); } BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles(); for (int i = 0; i < requires.length; i++) { BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName()); ResolverBundle bundle = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier()); BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription(); state.resolveConstraint(requires[i], supplier); } GenericConstraint[] genericRequires = rb.getGenericRequires(); for (int i = 0; i < genericRequires.length; i++) { VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities(); if (matchingCapabilities == null) state.resolveConstraint(genericRequires[i].getVersionConstraint(), null); else for (int j = 0; j < matchingCapabilities.length; j++) state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription()); } }
private void stateResolveFragConstraints(ResolverBundle rb) { ResolverBundle host = (ResolverBundle) rb.getHost().getSelectedSupplier(); ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages(); for (int i = 0; i < imports.length; i++) { ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName()); ResolverExport export = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier()); BaseDescription supplier = export == null ? null : export.getExportPackageDescription(); state.resolveConstraint(imports[i], supplier); } BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles(); for (int i = 0; i < requires.length; i++) { BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName()); ResolverBundle bundle = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier()); BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription(); state.resolveConstraint(requires[i], supplier); } GenericConstraint[] genericRequires = rb.getGenericRequires(); for (int i = 0; i < genericRequires.length; i++) { VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities(); if (matchingCapabilities == null) state.resolveConstraint(genericRequires[i].getVersionConstraint(), null); else for (int j = 0; j < matchingCapabilities.length; j++) state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription()); } }