use of java.util.ServiceConfigurationError in project aries by apache.
the class AriesRepositoryGenerator method startFramework.
/**
* Start OSGi framework and install the necessary bundles
* @return
* @throws BundleException
*/
public BundleContext startFramework() throws BundleException {
ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class, getClass().getClassLoader());
Iterator<FrameworkFactory> factoryIterator = factoryLoader.iterator();
//Map<String, String> osgiPropertyMap = new HashMap<String, String>();
if (!!!factoryIterator.hasNext()) {
System.out.println("Unable to locate the osgi jar");
}
try {
FrameworkFactory frameworkFactory = factoryIterator.next();
framework = frameworkFactory.newFramework(Collections.EMPTY_MAP);
} catch (ServiceConfigurationError sce) {
sce.printStackTrace();
}
framework.init();
framework.start();
// install the bundles in the current directory
Collection<Bundle> installedBundles = new ArrayList<Bundle>();
File bundleDir = new File(".");
File[] jars = bundleDir.listFiles();
try {
for (File jar : jars) {
if (jar.isFile() && (jar.getName().endsWith(".jar"))) {
String location = URLDecoder.decode(jar.toURI().toURL().toExternalForm(), "UTF-8");
if (shouldInstall(location, getIgnoreList())) {
installedBundles.add(framework.getBundleContext().installBundle("reference:" + location));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
ServiceReference paRef = framework.getBundleContext().getServiceReference(PackageAdmin.class.getCanonicalName());
if (paRef != null) {
try {
PackageAdmin admin = (PackageAdmin) framework.getBundleContext().getService(paRef);
admin.resolveBundles(installedBundles.toArray(new Bundle[installedBundles.size()]));
} finally {
framework.getBundleContext().ungetService(paRef);
}
} else {
System.out.println("Unable to find the service reference for package admin");
}
//loop through the list of installed bundles to start them
for (Bundle bundle : installedBundles) {
try {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
//start the bundle using its activiation policy
bundle.start(Bundle.START_ACTIVATION_POLICY);
} else {
//nothing to start, we have got a fragment
}
} catch (BundleException e) {
e.printStackTrace();
continue;
}
}
return framework.getBundleContext();
}
use of java.util.ServiceConfigurationError in project lucene-solr by apache.
the class SPIClassIterator method loadNextProfile.
private boolean loadNextProfile() {
ArrayList<String> lines = null;
while (profilesEnum.hasMoreElements()) {
if (lines != null) {
lines.clear();
} else {
lines = new ArrayList<>();
}
final URL url = profilesEnum.nextElement();
try {
final InputStream in = url.openStream();
boolean success = false;
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
final int pos = line.indexOf('#');
if (pos >= 0) {
line = line.substring(0, pos);
}
line = line.trim();
if (line.length() > 0) {
lines.add(line);
}
}
success = true;
} finally {
if (success) {
IOUtils.close(in);
} else {
IOUtils.closeWhileHandlingException(in);
}
}
} catch (IOException ioe) {
throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
}
if (!lines.isEmpty()) {
this.linesIterator = lines.iterator();
return true;
}
}
return false;
}
Aggregations