use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class ModuleRevisionBuilder method addRevision.
/**
* Used by the container to build a new revision for a module.
* This builder is used to build a new {@link Module#getCurrentRevision() current}
* revision for the specified module.
* @param module the module to build a new revision for
* @param revisionInfo the revision info for the new revision, may be {@code null}
* @return the new new {@link Module#getCurrentRevision() current} revision.
*/
ModuleRevision addRevision(Module module, Object revisionInfo) {
Collection<?> systemNames = Collections.emptyList();
Module systemModule = module.getContainer().getModule(0);
if (systemModule != null) {
ModuleRevision systemRevision = systemModule.getCurrentRevision();
List<ModuleCapability> hostCapabilities = systemRevision.getModuleCapabilities(HostNamespace.HOST_NAMESPACE);
for (ModuleCapability hostCapability : hostCapabilities) {
Object hostNames = hostCapability.getAttributes().get(HostNamespace.HOST_NAMESPACE);
if (hostNames instanceof Collection) {
systemNames = (Collection<?>) hostNames;
} else if (hostNames instanceof String) {
systemNames = Arrays.asList(hostNames);
}
}
}
ModuleRevisions revisions = module.getRevisions();
ModuleRevision revision = new ModuleRevision(symbolicName, version, types, capabilityInfos, requirementInfos, revisions, revisionInfo);
revisions.addRevision(revision);
module.getContainer().getAdaptor().associateRevision(revision, revisionInfo);
try {
List<ModuleRequirement> hostRequirements = revision.getModuleRequirements(HostNamespace.HOST_NAMESPACE);
for (ModuleRequirement hostRequirement : hostRequirements) {
FilterImpl f = null;
String filterSpec = hostRequirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
if (filterSpec != null) {
try {
f = FilterImpl.newInstance(filterSpec);
String hostName = f.getPrimaryKeyValue(HostNamespace.HOST_NAMESPACE);
if (hostName != null) {
if (systemNames.contains(hostName)) {
Bundle b = module.getBundle();
if (b != null && !b.hasPermission(new AllPermission())) {
// $NON-NLS-1$
SecurityException se = new SecurityException("Must have AllPermission granted to install an extension bundle");
// TODO this is such a hack: making the cause a bundle exception so we can throw the right one later
BundleException be = new BundleException(se.getMessage(), BundleException.SECURITY_ERROR, se);
se.initCause(be);
throw se;
}
module.getContainer().checkAdminPermission(module.getBundle(), AdminPermission.EXTENSIONLIFECYCLE);
}
}
} catch (InvalidSyntaxException e) {
continue;
}
}
}
module.getContainer().checkAdminPermission(module.getBundle(), AdminPermission.LIFECYCLE);
} catch (SecurityException e) {
revisions.removeRevision(revision);
throw e;
}
return revision;
}
use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class ModuleRequirement method matches.
@Override
public boolean matches(BundleCapability capability) {
if (!namespace.equals(capability.getNamespace()))
return false;
String filterSpec = directives.get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
FilterImpl f = null;
if (filterSpec != null) {
try {
f = FilterImpl.newInstance(filterSpec);
} catch (InvalidSyntaxException e) {
return false;
}
}
boolean matchMandatory = PackageNamespace.PACKAGE_NAMESPACE.equals(namespace) || BundleNamespace.BUNDLE_NAMESPACE.equals(namespace) || HostNamespace.HOST_NAMESPACE.equals(namespace);
return Capabilities.matches(f, capability, matchMandatory);
}
use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class ModuleResolutionReport method createOSGiRequirement.
private static String createOSGiRequirement(Requirement requirement, String... versions) {
Map<String, String> directives = new HashMap<>(requirement.getDirectives());
String filter = directives.remove(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
if (filter == null)
// $NON-NLS-1$
throw new IllegalArgumentException("No filter directive found:" + requirement);
FilterImpl filterImpl;
try {
filterImpl = FilterImpl.newInstance(filter);
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
throw new IllegalArgumentException("Invalid filter directive", e);
}
Map<String, String> matchingAttributes = filterImpl.getStandardOSGiAttributes(versions);
String name = matchingAttributes.remove(requirement.getNamespace());
if (name == null)
// $NON-NLS-1$
throw new IllegalArgumentException("Invalid requirement: " + requirement);
return name + ModuleRevision.toString(matchingAttributes, false, true) + ModuleRevision.toString(directives, true, true);
}
Aggregations