private static boolean isSingleton(IPluginModelBase model) { if (model.getBundleDescription() == null || model.getBundleDescription().isSingleton()) { return true; } return false; }
private Map<ResolverBundle, Collection<ResolverBundle>> getCollisionMap(List<ResolverBundle> sameBSN) { Map<ResolverBundle, Collection<ResolverBundle>> result = new HashMap<ResolverBundle, Collection<ResolverBundle>>(); for (ResolverBundle singleton : sameBSN) { if (!singleton.getBundleDescription().isSingleton() || !singleton.isResolvable()) continue; // ignore non-singleton and non-resolvable List<ResolverBundle> collisionCandidates = new ArrayList<ResolverBundle>(sameBSN.size() - 1); List<BundleCapability> capabilities = new ArrayList<BundleCapability>(sameBSN.size() - 1); for (ResolverBundle collision : sameBSN) { if (collision == singleton || !collision.getBundleDescription().isSingleton() || !collision.isResolvable()) continue; // Ignore the bundle we are checking and non-singletons and non-resolvable collisionCandidates.add(collision); capabilities.add(getIdentity(collision)); } if (hook != null) hook.filterSingletonCollisions(getIdentity(singleton), asCapabilities(new ArrayMap<BundleCapability, ResolverBundle>(capabilities, collisionCandidates))); result.put(singleton, collisionCandidates); } return result; }
private Map<ResolverBundle, Collection<ResolverBundle>> getCollisionMap(List<ResolverBundle> sameBSN) { Map<ResolverBundle, Collection<ResolverBundle>> result = new HashMap<ResolverBundle, Collection<ResolverBundle>>(); for (ResolverBundle singleton : sameBSN) { if (!singleton.getBundleDescription().isSingleton() || !singleton.isResolvable()) continue; // ignore non-singleton and non-resolvable List<ResolverBundle> collisionCandidates = new ArrayList<ResolverBundle>(sameBSN.size() - 1); List<BundleCapability> capabilities = new ArrayList<BundleCapability>(sameBSN.size() - 1); for (ResolverBundle collision : sameBSN) { if (collision == singleton || !collision.getBundleDescription().isSingleton() || !collision.isResolvable()) continue; // Ignore the bundle we are checking and non-singletons and non-resolvable collisionCandidates.add(collision); capabilities.add(collision.getCapability()); } if (hook != null) hook.filterSingletonCollisions(singleton.getCapability(), asCapabilities(new ArrayMap<BundleCapability, ResolverBundle>(capabilities, collisionCandidates))); result.put(singleton, collisionCandidates); } return result; }
private Map<ResolverBundle, Collection<ResolverBundle>> getCollisionMap(List<ResolverBundle> sameBSN) { Map<ResolverBundle, Collection<ResolverBundle>> result = new HashMap<>(); for (ResolverBundle singleton : sameBSN) { if (!singleton.getBundleDescription().isSingleton() || !singleton.isResolvable()) continue; // ignore non-singleton and non-resolvable List<ResolverBundle> collisionCandidates = new ArrayList<>(sameBSN.size() - 1); List<BundleCapability> capabilities = new ArrayList<>(sameBSN.size() - 1); for (ResolverBundle collision : sameBSN) { if (collision == singleton || !collision.getBundleDescription().isSingleton() || !collision.isResolvable()) continue; // Ignore the bundle we are checking and non-singletons and non-resolvable collisionCandidates.add(collision); capabilities.add(getIdentity(collision)); } if (hook != null) hook.filterSingletonCollisions(getIdentity(singleton), asCapabilities(new ArrayMap<>(capabilities, collisionCandidates))); result.put(singleton, collisionCandidates); } return result; }
private Map<ResolverBundle, Collection<ResolverBundle>> getCollisionMap(List<ResolverBundle> sameBSN) { Map<ResolverBundle, Collection<ResolverBundle>> result = new HashMap<ResolverBundle, Collection<ResolverBundle>>(); for (ResolverBundle singleton : sameBSN) { if (!singleton.getBundleDescription().isSingleton() || !singleton.isResolvable()) continue; // ignore non-singleton and non-resolvable List<ResolverBundle> collisionCandidates = new ArrayList<ResolverBundle>(sameBSN.size() - 1); List<BundleCapability> capabilities = new ArrayList<BundleCapability>(sameBSN.size() - 1); for (ResolverBundle collision : sameBSN) { if (collision == singleton || !collision.getBundleDescription().isSingleton() || !collision.isResolvable()) continue; // Ignore the bundle we are checking and non-singletons and non-resolvable collisionCandidates.add(collision); capabilities.add(getIdentity(collision)); } if (hook != null) hook.filterSingletonCollisions(getIdentity(singleton), asCapabilities(new ArrayMap<BundleCapability, ResolverBundle>(capabilities, collisionCandidates))); result.put(singleton, collisionCandidates); } return result; }
public Map<Object, Object[]> getResolverErrors() { Set<String> alreadyDuplicated = new HashSet<>(); Map<Object, Object[]> map = new HashMap<>(); BundleDescription[] bundles = fState.getBundles(); for (int i = 0; i < bundles.length; i++) { BundleDescription desc = bundles[i]; if (!desc.isResolved()) { map.put(desc, fState.getResolverErrors(desc)); } else if (desc.isSingleton() && !alreadyDuplicated.contains(desc.getSymbolicName())) { BundleDescription[] dups = fState.getBundles(desc.getSymbolicName()); if (dups.length > 1) { // more than 1 singleton present alreadyDuplicated.add(desc.getSymbolicName()); MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, NLS.bind(PDECoreMessages.BundleValidationOperation_multiple_singletons, new String[] {Integer.toString(dups.length), desc.getSymbolicName()}), null); for (int j = 0; j < dups.length; j++) { status.add(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, dups[j].getLocation())); } map.put(desc, new Object[] {status}); } } } return map; }
private void writeBundleDescription(BundleDescription bundle, DataOutputStream out, boolean force) throws IOException { if (force && !forcedWrite.contains(bundle)) { int index = addToObjectTable(bundle); out.writeByte(StateReader.OBJECT); out.writeInt(index); forcedWrite.add(bundle); } else if (writePrefix(bundle, out)) return; // first write out non-lazy loaded data out.writeLong(bundle.getBundleId()); // ID must be the first thing writeBaseDescription(bundle, out); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataOffset()); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataSize()); out.writeBoolean(bundle.isResolved()); out.writeBoolean(bundle.isSingleton()); out.writeBoolean(bundle.hasDynamicImports()); out.writeBoolean(bundle.attachFragments()); out.writeBoolean(bundle.dynamicFragments()); writeList(out, (String[]) ((BundleDescriptionImpl) bundle).getDirective(Constants.MANDATORY_DIRECTIVE)); writeMap(out, bundle.getAttributes()); writeMap(out, ((BundleDescriptionImpl) bundle).getArbitraryDirectives()); writeHostSpec((HostSpecificationImpl) bundle.getHost(), out, force); List<BundleDescription> dependencies = ((BundleDescriptionImpl) bundle).getBundleDependencies(); out.writeInt(dependencies.size()); for (Iterator<BundleDescription> iter = dependencies.iterator(); iter.hasNext();) writeBundleDescription(iter.next(), out, force); // the rest is lazy loaded data }
private void writeBundleDescription(BundleDescription bundle, DataOutputStream out, boolean force) throws IOException { if (force && !forcedWrite.contains(bundle)) { int index = addToObjectTable(bundle); out.writeByte(StateReader.OBJECT); out.writeInt(index); forcedWrite.add(bundle); } else if (writePrefix(bundle, out)) return; // first write out non-lazy loaded data out.writeLong(bundle.getBundleId()); // ID must be the first thing writeBaseDescription(bundle, out); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataOffset()); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataSize()); out.writeBoolean(bundle.isResolved()); out.writeBoolean(bundle.isSingleton()); out.writeBoolean(bundle.hasDynamicImports()); out.writeBoolean(bundle.attachFragments()); out.writeBoolean(bundle.dynamicFragments()); writeList(out, (String[]) ((BundleDescriptionImpl) bundle).getDirective(Constants.MANDATORY_DIRECTIVE)); writeMap(out, bundle.getAttributes()); writeHostSpec((HostSpecificationImpl) bundle.getHost(), out, force); List<BundleDescription> dependencies = ((BundleDescriptionImpl) bundle).getBundleDependencies(); out.writeInt(dependencies.size()); for (Iterator<BundleDescription> iter = dependencies.iterator(); iter.hasNext();) writeBundleDescription(iter.next(), out, force); // the rest is lazy loaded data }
private void writeBundleDescription(BundleDescription bundle, DataOutputStream out, boolean force) throws IOException { if (force && !forcedWrite.contains(bundle)) { int index = addToObjectTable(bundle); out.writeByte(StateReader.OBJECT); out.writeInt(index); forcedWrite.add(bundle); } else if (writePrefix(bundle, out)) return; // first write out non-lazy loaded data out.writeLong(bundle.getBundleId()); // ID must be the first thing writeBaseDescription(bundle, out); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataOffset()); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataSize()); out.writeBoolean(bundle.isResolved()); out.writeBoolean(bundle.isSingleton()); out.writeBoolean(bundle.hasDynamicImports()); out.writeBoolean(bundle.attachFragments()); out.writeBoolean(bundle.dynamicFragments()); writeList(out, (String[]) ((BundleDescriptionImpl) bundle).getDirective(Constants.MANDATORY_DIRECTIVE)); writeMap(out, bundle.getAttributes()); writeMap(out, ((BundleDescriptionImpl) bundle).getArbitraryDirectives()); writeHostSpec((HostSpecificationImpl) bundle.getHost(), out, force); List<BundleDescription> dependencies = ((BundleDescriptionImpl) bundle).getBundleDependencies(); out.writeInt(dependencies.size()); for (Iterator<BundleDescription> iter = dependencies.iterator(); iter.hasNext();) writeBundleDescription(iter.next(), out, force); // the rest is lazy loaded data }
private void writeBundleDescription(BundleDescription bundle, DataOutputStream out, boolean force) throws IOException { if (force && !forcedWrite.contains(bundle)) { int index = addToObjectTable(bundle); out.writeByte(StateReader.OBJECT); out.writeInt(index); forcedWrite.add(bundle); } else if (writePrefix(bundle, out)) return; // first write out non-lazy loaded data out.writeLong(bundle.getBundleId()); // ID must be the first thing writeBaseDescription(bundle, out); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataOffset()); out.writeInt(((BundleDescriptionImpl) bundle).getLazyDataSize()); out.writeBoolean(bundle.isResolved()); out.writeBoolean(bundle.isSingleton()); out.writeBoolean(bundle.hasDynamicImports()); out.writeBoolean(bundle.attachFragments()); out.writeBoolean(bundle.dynamicFragments()); writeList(out, (String[]) ((BundleDescriptionImpl) bundle).getDirective(Constants.MANDATORY_DIRECTIVE)); writeMap(out, bundle.getAttributes()); writeMap(out, ((BundleDescriptionImpl) bundle).getArbitraryDirectives()); writeHostSpec((HostSpecificationImpl) bundle.getHost(), out, force); List<BundleDescription> dependencies = ((BundleDescriptionImpl) bundle).getBundleDependencies(); out.writeInt(dependencies.size()); for (Iterator<BundleDescription> iter = dependencies.iterator(); iter.hasNext();) writeBundleDescription(iter.next(), out, force); // the rest is lazy loaded data }
static GenericDescription createOsgiIdentityCapability(BundleDescription description) { if (description.getSymbolicName() == null) return null; GenericDescriptionImpl result = new GenericDescriptionImpl(); result.setType(IdentityNamespace.IDENTITY_NAMESPACE); Dictionary<String, Object> attributes = new Hashtable<String, Object>(description.getDeclaredAttributes()); // remove osgi.wiring.bundle and bundle-version attributes attributes.remove(BundleNamespace.BUNDLE_NAMESPACE); attributes.remove(Constants.BUNDLE_VERSION_ATTRIBUTE); attributes.put(IdentityNamespace.IDENTITY_NAMESPACE, description.getSymbolicName()); attributes.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, description.getHost() == null ? IdentityNamespace.TYPE_BUNDLE : IdentityNamespace.TYPE_FRAGMENT); attributes.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, description.getVersion()); result.setAttributes(attributes); Map<String, String> directives = new HashMap<String, String>(description.getDeclaredDirectives()); // remove defaults directive values if (!description.isSingleton()) directives.remove(Constants.SINGLETON_DIRECTIVE); if (description.attachFragments() && description.dynamicFragments()) directives.remove(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE); result.setDirectives(directives); return result; } }
static GenericDescription createOsgiIdentityCapability(BundleDescription description) { if (description.getSymbolicName() == null) return null; GenericDescriptionImpl result = new GenericDescriptionImpl(); result.setType(IdentityNamespace.IDENTITY_NAMESPACE); Dictionary<String, Object> attributes = new Hashtable<String, Object>(description.getDeclaredAttributes()); // remove osgi.wiring.bundle and bundle-version attributes attributes.remove(BundleNamespace.BUNDLE_NAMESPACE); attributes.remove(Constants.BUNDLE_VERSION_ATTRIBUTE); attributes.put(IdentityNamespace.IDENTITY_NAMESPACE, description.getSymbolicName()); attributes.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, description.getHost() == null ? IdentityNamespace.TYPE_BUNDLE : IdentityNamespace.TYPE_FRAGMENT); attributes.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, description.getVersion()); result.setAttributes(attributes); Map<String, String> directives = new HashMap<String, String>(description.getDeclaredDirectives()); // remove defaults directive values if (!description.isSingleton()) directives.remove(Constants.SINGLETON_DIRECTIVE); if (description.attachFragments() && description.dynamicFragments()) directives.remove(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE); result.setDirectives(directives); return result; } }
public IContributor createContributor(IPluginModelBase base) { BundleDescription desc = base == null ? null : base.getBundleDescription(); // return null if the IPluginModelBase does not have a BundleDescription (since then we won't have a valid 'id') if (desc == null) return null; String name = desc.getSymbolicName(); String id = Long.toString(desc.getBundleId()); String hostName = null; String hostId = null; HostSpecification host = desc.getHost(); // make sure model is a singleton. If it is a fragment, make sure host is singleton if (host != null && host.getBundle() != null && !host.getBundle().isSingleton() || host == null && !desc.isSingleton()) return null; if (host != null) { BundleDescription[] hosts = host.getHosts(); if (hosts.length != 1) { return null; } BundleDescription hostDesc = hosts[0]; hostName = hostDesc.getSymbolicName(); hostId = Long.toString(hostDesc.getBundleId()); } return new RegistryContributor(id, name, hostId, hostName); }
static GenericDescription createOsgiIdentityCapability(BundleDescription description) { if (description.getSymbolicName() == null) return null; GenericDescriptionImpl result = new GenericDescriptionImpl(); result.setType(IdentityNamespace.IDENTITY_NAMESPACE); Dictionary<String, Object> attributes = new Hashtable<>(description.getDeclaredAttributes()); // remove osgi.wiring.bundle and bundle-version attributes attributes.remove(BundleNamespace.BUNDLE_NAMESPACE); attributes.remove(Constants.BUNDLE_VERSION_ATTRIBUTE); attributes.put(IdentityNamespace.IDENTITY_NAMESPACE, description.getSymbolicName()); attributes.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, description.getHost() == null ? IdentityNamespace.TYPE_BUNDLE : IdentityNamespace.TYPE_FRAGMENT); attributes.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, description.getVersion()); result.setAttributes(attributes); Map<String, String> directives = new HashMap<>(description.getDeclaredDirectives()); // remove defaults directive values if (!description.isSingleton()) directives.remove(Constants.SINGLETON_DIRECTIVE); if (description.attachFragments() && description.dynamicFragments()) directives.remove(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE); result.setDirectives(directives); return result; } }
public boolean hasErrors() { if (fState.getHighestBundleId() > -1) { BundleDescription[] bundles = fState.getBundles(); for (int i = 0; i < bundles.length; i++) { BundleDescription desc = bundles[i]; if (!desc.isResolved()) { return true; } else if (desc.isSingleton()) { BundleDescription[] dups = fState.getBundles(desc.getSymbolicName()); if (dups.length > 1) { // more than one singleton return true; } } } } return false; }
@Override protected boolean shouldAddPlugin(BundleDescription bundle, Dictionary<String, String> environment) { // if there is an environment conflict boolean conflict = !super.shouldAddPlugin(bundle, environment); if (conflict) { // make a copy of the state if we haven't already if (fStateCopy == null) copyState(TargetPlatformHelper.getState()); // replace the current BundleDescription with a copy who does not have the platform filter. This will allow the plug-in to be resolved BundleDescription desc = fStateCopy.removeBundle(bundle.getBundleId()); BundleDescription newDesc = fStateCopy.getFactory().createBundleDescription(desc.getBundleId(), desc.getSymbolicName(), desc.getVersion(), desc.getLocation(), desc.getRequiredBundles(), desc.getHost(), desc.getImportPackages(), desc.getExportPackages(), desc.isSingleton(), desc.attachFragments(), desc.dynamicFragments(), null, desc.getExecutionEnvironments(), desc.getGenericRequires(), desc.getGenericCapabilities()); fStateCopy.addBundle(newDesc); } // always include plug-ins, even ones with environment conflicts return true; }
protected boolean shouldAddPlugin(BundleDescription bundle, Dictionary environment) { // if there is an environment conflict boolean conflict = !super.shouldAddPlugin(bundle, environment); if (conflict) { // make a copy of the state if we haven't already if (fStateCopy == null) copyState(TargetPlatformHelper.getState()); // replace the current BundleDescription with a copy who does not have the platform filter. This will allow the plug-in to be resolved BundleDescription desc = fStateCopy.removeBundle(bundle.getBundleId()); BundleDescription newDesc = fStateCopy.getFactory().createBundleDescription(desc.getBundleId(), desc.getSymbolicName(), desc.getVersion(), desc.getLocation(), desc.getRequiredBundles(), desc.getHost(), desc.getImportPackages(), desc.getExportPackages(), desc.isSingleton(), desc.attachFragments(), desc.dynamicFragments(), null, desc.getExecutionEnvironments(), desc.getGenericRequires(), desc.getGenericCapabilities()); fStateCopy.addBundle(newDesc); } // always include plug-ins, even ones with environment conflicts return true; }
if (original.getHost() != null) bundle.setHost(createHostSpecification(original.getHost())); bundle.setStateBit(BundleDescriptionImpl.SINGLETON, original.isSingleton()); bundle.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, original.attachFragments()); bundle.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, original.dynamicFragments());
if (original.getHost() != null) bundle.setHost(createHostSpecification(original.getHost())); bundle.setStateBit(BundleDescriptionImpl.SINGLETON, original.isSingleton()); bundle.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, original.attachFragments()); bundle.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, original.dynamicFragments());
if (original.getHost() != null) bundle.setHost(createHostSpecification(original.getHost())); bundle.setStateBit(BundleDescriptionImpl.SINGLETON, original.isSingleton()); bundle.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, original.attachFragments()); bundle.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, original.dynamicFragments());