use of org.osgi.framework.InvalidSyntaxException in project rt.equinox.framework by eclipse.
the class Storage method listEntryPaths.
/**
* Returns the names of resources available from a list of bundle files.
* No duplicate resource names are returned, each name is unique.
* @param bundleFiles the list of bundle files to search in
* @param path The path name in which to look.
* @param filePattern The file name pattern for selecting resource names in
* the specified path.
* @param options The options for listing resource names.
* @return a list of resource names. If no resources are found then
* the empty list is returned.
* @see BundleWiring#listResources(String, String, int)
*/
public static List<String> listEntryPaths(List<BundleFile> bundleFiles, String path, String filePattern, int options) {
// Use LinkedHashSet for optimized performance of contains() plus
// ordering guarantees.
LinkedHashSet<String> pathList = new LinkedHashSet<>();
Filter patternFilter = null;
Hashtable<String, String> patternProps = null;
if (filePattern != null) {
// Avoid pattern matching and use BundleFile.getEntry() if recursion was not requested.
if ((options & BundleWiring.FINDENTRIES_RECURSE) == 0 && filePattern.indexOf('*') == -1 && filePattern.indexOf('\\') == -1) {
if (path.length() == 0)
path = filePattern;
else
path += path.charAt(path.length() - 1) == '/' ? filePattern : '/' + filePattern;
for (BundleFile bundleFile : bundleFiles) {
if (bundleFile.getEntry(path) != null && !pathList.contains(path))
pathList.add(path);
}
return new ArrayList<>(pathList);
}
// For when the file pattern includes a wildcard.
try {
// create a file pattern filter with 'filename' as the key
// $NON-NLS-1$ //$NON-NLS-2$
patternFilter = FilterImpl.newInstance("(filename=" + sanitizeFilterInput(filePattern) + ")");
// create a single hashtable to be shared during the recursive search
patternProps = new Hashtable<>(2);
} catch (InvalidSyntaxException e) {
// eventPublisher.publishFrameworkEvent(FrameworkEvent.ERROR, b, e);
return new ArrayList<>(pathList);
}
}
// find the entry paths for the datas
for (BundleFile bundleFile : bundleFiles) {
listEntryPaths(bundleFile, path, patternFilter, patternProps, options, pathList);
}
return new ArrayList<>(pathList);
}
use of org.osgi.framework.InvalidSyntaxException 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.osgi.framework.InvalidSyntaxException in project rt.equinox.framework by eclipse.
the class StateBuilder method createNativeCodeDescription.
private static NativeCodeDescriptionImpl createNativeCodeDescription(ManifestElement manifestElement) throws BundleException {
NativeCodeDescriptionImpl result = new NativeCodeDescriptionImpl();
result.setName(Constants.BUNDLE_NATIVECODE);
result.setNativePaths(manifestElement.getValueComponents());
result.setOSNames(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_OSNAME));
result.setProcessors(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_PROCESSOR));
result.setOSVersions(createVersionRanges(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_OSVERSION)));
result.setLanguages(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_LANGUAGE));
try {
result.setFilter(manifestElement.getAttribute(Constants.SELECTION_FILTER_ATTRIBUTE));
} catch (InvalidSyntaxException e) {
String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, Constants.BUNDLE_NATIVECODE, manifestElement.toString());
// $NON-NLS-1$
throw new BundleException(message + " : " + Constants.SELECTION_FILTER_ATTRIBUTE, BundleException.MANIFEST_ERROR, e);
}
return result;
}
use of org.osgi.framework.InvalidSyntaxException in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle08.
public void testSystemBundle08() {
// create/start/stop/start/stop test
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_1");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
// $NON-NLS-1$
config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_2");
configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
equinox = new Equinox(configuration);
try {
equinox.init();
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
ServiceReference[] refs = null;
try {
// $NON-NLS-1$
refs = equinox.getBundleContext().getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
fail("Unexpected syntax error", e);
}
// $NON-NLS-1$
assertNotNull("Configuration Location refs is null", refs);
// $NON-NLS-1$
assertEquals("config refs length is wrong", 1, refs.length);
Location configLocation = (Location) equinox.getBundleContext().getService(refs[0]);
URL configURL = configLocation.getURL();
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle08_2/"));
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
use of org.osgi.framework.InvalidSyntaxException in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug258209_1.
public void testBug258209_1() throws BundleException {
// create a framework to test thread context class loaders
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
ClassLoader current = Thread.currentThread().getContextClassLoader();
Equinox equinox = new Equinox(configuration);
equinox.init();
Thread.currentThread().setContextClassLoader(current);
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
Bundle testTCCL = systemContext.installBundle(installer.getBundleLocation("test.tccl"));
equinox.adapt(FrameworkWiring.class).resolveBundles(Arrays.asList(testTCCL));
try {
testTCCL.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception starting bundle", e);
}
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.RESOLVED, testTCCL.getState());
// this will start the framework on the current thread; test that the correct tccl is used
equinox.start();
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
// test that the correct tccl is used for framework update
try {
equinox.update();
checkActive(testTCCL);
} catch (Exception e) {
// $NON-NLS-1$
fail("Unexpected exception", e);
}
systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
// test that the correct tccl is used for refresh packages
equinox.adapt(FrameworkWiring.class).refreshBundles(Arrays.asList(testTCCL));
checkActive(testTCCL);
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
// use the tccl service to start the test bundle.
ClassLoader serviceTCCL = null;
try {
// $NON-NLS-1$
serviceTCCL = (ClassLoader) systemContext.getService(systemContext.getServiceReferences(ClassLoader.class.getName(), "(equinox.classloader.type=contextClassLoader)")[0]);
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
fail("Unexpected", e);
}
current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(serviceTCCL);
try {
testTCCL.stop();
testTCCL.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unepected", e);
} finally {
Thread.currentThread().setContextClassLoader(current);
}
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected error stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
}
Aggregations