use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class NativeCodeFinder method getNativePaths.
private List<String> getNativePaths() {
ModuleRevision revision = generation.getRevision();
ModuleWiring wiring = revision.getWiring();
if (wiring == null) {
// unresolved? should not be possible
return Collections.emptyList();
}
if ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
List<ModuleWire> hosts = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
if (hosts == null) {
// unresolved or invalid? should not be possible
return Collections.emptyList();
}
if (!hosts.isEmpty()) {
// just use the first host wiring
wiring = hosts.get(0).getProviderWiring();
}
}
List<ModuleWire> nativeCode = wiring.getRequiredModuleWires(NativeNamespace.NATIVE_NAMESPACE);
if (nativeCode.isEmpty()) {
return Collections.emptyList();
}
// just taking the first paths for the revision, we sorted correctly when transforming to the requirement
for (ModuleWire moduleWire : nativeCode) {
if (moduleWire.getRequirement().getRevision().equals(revision)) {
@SuppressWarnings("unchecked") List<String> result = (List<String>) nativeCode.get(0).getRequirement().getAttributes().get(REQUIREMENT_NATIVE_PATHS_ATTRIBUTE);
if (result != null)
return result;
// this must be a multi-clause Bundle-NativeCode header, need to check for the correct one in the index
try {
FilterImpl filter = FilterImpl.newInstance(moduleWire.getRequirement().getDirectives().get(NativeNamespace.REQUIREMENT_FILTER_DIRECTIVE));
int index = -1;
Map<String, Object> capabilityAttrs = moduleWire.getCapability().getAttributes();
for (FilterImpl child : filter.getChildren()) {
index++;
if (child.matches(capabilityAttrs)) {
break;
}
}
if (index != -1) {
@SuppressWarnings("unchecked") List<String> indexResult = (List<String>) nativeCode.get(0).getRequirement().getAttributes().get(REQUIREMENT_NATIVE_PATHS_ATTRIBUTE + '.' + index);
if (indexResult != null)
return indexResult;
}
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
}
}
return Collections.emptyList();
}
use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class StateBuilder method createOSGiRequires.
static List<GenericSpecification> createOSGiRequires(ManifestElement[] osgiRequires, List<GenericSpecification> result) throws BundleException {
if (osgiRequires == null)
return result;
if (result == null)
result = new ArrayList<>();
for (ManifestElement element : osgiRequires) {
String[] namespaces = element.getValueComponents();
for (String namespace : namespaces) {
GenericSpecificationImpl spec = new GenericSpecificationImpl();
spec.setType(namespace);
String filterSpec = element.getDirective(Constants.FILTER_DIRECTIVE);
if (filterSpec != null) {
try {
FilterImpl filter = FilterImpl.newInstance(filterSpec);
spec.setMatchingFilter(filter);
String name = filter.getPrimaryKeyValue(namespace);
if (name != null)
spec.setName(name);
} catch (InvalidSyntaxException e) {
String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, Constants.REQUIRE_CAPABILITY, element.toString());
// $NON-NLS-1$
throw new BundleException(message + " : filter", BundleException.MANIFEST_ERROR, e);
}
}
String resolutionDirective = element.getDirective(Constants.RESOLUTION_DIRECTIVE);
int resolution = 0;
if (Constants.RESOLUTION_OPTIONAL.equals(resolutionDirective))
resolution |= GenericSpecification.RESOLUTION_OPTIONAL;
String cardinality = element.getDirective(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
if (Namespace.CARDINALITY_MULTIPLE.equals(cardinality))
resolution |= GenericSpecification.RESOLUTION_MULTIPLE;
spec.setResolution(resolution);
spec.setAttributes(getAttributes(element, DEFINED_REQUIRE_CAPABILITY_ATTRS));
spec.setArbitraryDirectives(getDirectives(element, DEFINED_REQUIRE_CAPABILITY_DIRECTIVES));
result.add(spec);
}
}
return result;
}
use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class StateConverter method createOSGiRequirement.
private String createOSGiRequirement(Requirement requirement, String namespace, 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 parser;
try {
parser = FilterImpl.newInstance(filter);
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
throw new IllegalArgumentException("Invalid filter directive", e);
}
Map<String, String> matchingAttributes = parser.getStandardOSGiAttributes(versions);
String name = matchingAttributes.remove(namespace);
if (name == null)
// $NON-NLS-1$
throw new IllegalArgumentException("Invalid requirement: " + requirement);
// $NON-NLS-1$ //$NON-NLS-2$
return name + toString(matchingAttributes, "=", true) + toString(directives, ":=", true);
}
use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class StateImpl method addBundle.
public boolean addBundle(BundleDescription description) {
synchronized (this.monitor) {
if (!basicAddBundle(description))
return false;
String platformFilter = description.getPlatformFilter();
if (platformFilter != null) {
try {
// add any new platform filter propery keys this bundle is using
FilterImpl filter = FilterImpl.newInstance(platformFilter);
addPlatformPropertyKeys(filter.getAttributes());
} catch (InvalidSyntaxException e) {
// ignore this is handled in another place
}
}
NativeCodeSpecification nativeCode = description.getNativeCodeSpecification();
if (nativeCode != null) {
NativeCodeDescription[] suppliers = nativeCode.getPossibleSuppliers();
for (int i = 0; i < suppliers.length; i++) {
FilterImpl filter = (FilterImpl) suppliers[i].getFilter();
if (filter != null)
addPlatformPropertyKeys(filter.getAttributes());
}
}
resolved = false;
getDelta().recordBundleAdded((BundleDescriptionImpl) description);
if (getSystemBundle().equals(description.getSymbolicName()))
resetAllSystemCapabilities();
if (resolver != null)
resolver.bundleAdded(description);
updateTimeStamp();
return true;
}
}
use of org.eclipse.osgi.internal.framework.FilterImpl in project rt.equinox.framework by eclipse.
the class StateBuilder method convertBREEs.
static List<GenericSpecification> convertBREEs(String[] brees, List<GenericSpecification> result) throws BundleException {
if (brees == null || brees.length == 0)
return result;
if (result == null)
result = new ArrayList<>(brees.length);
List<String> breeFilters = new ArrayList<>();
for (String bree : brees) breeFilters.add(createOSGiEERequirementFilter(bree));
String filterSpec;
if (breeFilters.size() == 1) {
filterSpec = breeFilters.get(0);
} else {
// $NON-NLS-1$
StringBuffer filterBuf = new StringBuffer("(|");
for (String breeFilter : breeFilters) {
filterBuf.append(breeFilter);
}
// $NON-NLS-1$
filterSpec = filterBuf.append(")").toString();
}
GenericSpecificationImpl spec = new GenericSpecificationImpl();
spec.setResolution(GenericSpecificationImpl.RESOLUTION_FROM_BREE);
spec.setType(StateImpl.OSGI_EE_NAMESPACE);
try {
FilterImpl filter = FilterImpl.newInstance(filterSpec);
spec.setMatchingFilter(filter);
String name = filter.getPrimaryKeyValue(spec.getType());
if (name != null)
spec.setName(name);
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
throw new BundleException("Error converting required execution environment.", e);
}
result.add(spec);
return result;
}
Aggregations