use of org.osgi.framework.InvalidSyntaxException in project bnd by bndtools.
the class OSGiTestCase method assertSvcAvail.
/**
* Asserts that at least one service of the specified type is currently
* available. If not, an {@link AssertionFailedError} is thrown with the
* given message.
*
* @param message
* @param service The service interface type.
* @param filter An additional service filter, which may be {@code
* null}.
*/
protected void assertSvcAvail(String message, Class<?> service, String filter) {
BundleContext context = getBundleContext();
ServiceReference[] refs = null;
try {
refs = context.getServiceReferences(service.getName(), filter);
} catch (InvalidSyntaxException e) {
fail("Invalid filter syntax");
}
if (refs == null || refs.length == 0) {
fail(message);
return;
}
Object svcObj = context.getService(refs[0]);
if (svcObj == null)
fail(message);
try {
if (!service.isInstance(svcObj))
fail(message);
} finally {
context.ungetService(refs[0]);
}
}
use of org.osgi.framework.InvalidSyntaxException in project bnd by bndtools.
the class AnalyzerTracker method addingService.
@Override
public TrackingStruct addingService(ServiceReference<ResourceAnalyzer> reference) {
TrackingStruct struct = new TrackingStruct();
try {
String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;
ResourceAnalyzer analyzer = context.getService(reference);
if (analyzer == null)
return null;
struct = new TrackingStruct();
struct.analyzer = analyzer;
struct.filter = filter;
struct.valid = true;
indexer.addAnalyzer(analyzer, filter);
} catch (InvalidSyntaxException e) {
struct.valid = false;
log.log(reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e);
}
return struct;
}
use of org.osgi.framework.InvalidSyntaxException in project bnd by bndtools.
the class AnalyzerTracker method modifiedService.
@Override
public void modifiedService(ServiceReference<ResourceAnalyzer> reference, TrackingStruct struct) {
if (struct.valid) {
indexer.removeAnalyzer(struct.analyzer, struct.filter);
}
try {
String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;
struct = new TrackingStruct();
struct.filter = filter;
struct.valid = true;
indexer.addAnalyzer(struct.analyzer, filter);
} catch (InvalidSyntaxException e) {
struct.valid = false;
log.log(reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e);
}
}
use of org.osgi.framework.InvalidSyntaxException in project rt.equinox.framework by eclipse.
the class LocationAreaSessionTest method doLock.
static void doLock(String testLocationDir, boolean release, boolean succeed) {
if (testLocationDir == null)
fail("The testLocationDir is not set");
ServiceReference[] refs = null;
try {
refs = OSGiTestsActivator.getContext().getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
} catch (InvalidSyntaxException e) {
fail("failed to create filter", e);
}
// this is test code so we are not very careful; just assume there is at lease one service. Do not copy and paste this code!!!
Location configLocation = (Location) OSGiTestsActivator.getContext().getService(refs[0]);
Location testLocation = null;
try {
testLocation = configLocation.createLocation(null, new File(testLocationDir).toURL(), false);
testLocation.setURL(testLocation.getDefault(), false);
// try locking location
if (succeed ? testLocation.isLocked() : !testLocation.isLocked())
fail("location should " + (succeed ? "not " : "") + "be locked");
if (succeed ? !testLocation.lock() : testLocation.lock())
fail((succeed ? "Could not" : "Could") + " lock location");
if (!testLocation.isLocked())
fail("location should be locked");
} catch (MalformedURLException e) {
fail("failed to create the location URL", e);
} catch (IOException e) {
fail("failed to lock with IOExcetpion", e);
} finally {
if (release && testLocation != null)
testLocation.release();
if (!release)
lockedTestLocation = testLocation;
OSGiTestsActivator.getContext().ungetService(refs[0]);
}
}
use of org.osgi.framework.InvalidSyntaxException 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();
}
Aggregations