use of org.osgi.framework.Bundle in project karaf by apache.
the class RunMojo method deploy.
private void deploy(BundleContext bundleContext) throws MojoExecutionException {
if (deployProjectArtifact) {
File artifact = project.getArtifact().getFile();
if (artifact != null && artifact.exists()) {
if (project.getPackaging().equals("bundle")) {
try {
Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString());
bundle.start();
} catch (Exception e) {
throw new MojoExecutionException("Can't deploy project artifact in container", e);
}
} else {
throw new MojoExecutionException("Packaging " + project.getPackaging() + " is not supported");
}
} else {
throw new MojoExecutionException("Project artifact doesn't exist");
}
}
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class EnvironmentDumpProvider method dumpOSGiInformation.
private void dumpOSGiInformation(final PrintWriter outPW) {
if (null == bundleContext) {
return;
}
outPW.println("OSGi:");
final Bundle[] bundles = bundleContext.getBundles();
for (final Bundle bundle : bundles) {
if (null == bundle || !!!"osgi.core".equals(bundle.getSymbolicName())) {
continue;
}
outPW.printf(INDENT_KEY_VALUE_FORMAT, "version", bundle.getVersion()).println();
break;
}
outPW.printf(INDENT_KEY_VALUE_FORMAT, "framework", bundleContext.getBundle(0).getSymbolicName() + " - " + bundleContext.getBundle(0).getVersion()).println();
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class ProxyLoginModule method initialize.
/* (non-Javadoc)
* @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)
*/
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
if (bundleContext == null) {
throw new IllegalStateException("ProxyLoginModule not initialized. Init must be called prior any invocation.");
}
Map<String, ?> newOptions = new HashMap<String, Object>(options);
String module = (String) newOptions.remove(PROPERTY_MODULE);
if (module == null) {
throw new IllegalStateException("Option " + PROPERTY_MODULE + " must be set to the name of the factory service");
}
String bundleId = (String) newOptions.remove(PROPERTY_BUNDLE);
if (bundleId == null) {
throw new IllegalStateException("Option " + PROPERTY_BUNDLE + " must be set to the name of the factory service");
}
Bundle bundle = bundleContext.getBundle(Long.parseLong(bundleId));
if (bundle == null) {
throw new IllegalStateException("No bundle found for id " + bundleId);
}
try {
target = (LoginModule) bundle.loadClass(module).newInstance();
} catch (Exception e) {
throw new IllegalStateException("Can not load or create login module " + module + " for bundle " + bundleId, e);
}
target.initialize(subject, callbackHandler, sharedState, newOptions);
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class ObrMBeanImpl method searchRepository.
private Resource[] searchRepository(RepositoryAdmin admin, String targetId, String targetVersion) throws InvalidSyntaxException {
// Try to see if the targetId is a bundle ID.
try {
Bundle bundle = bundleContext.getBundle(Long.parseLong(targetId));
targetId = bundle.getSymbolicName();
} catch (NumberFormatException ex) {
// It was not a number, so ignore.
}
// The targetId may be a bundle name or a bundle symbolic name,
// so create the appropriate LDAP query.
StringBuffer sb = new StringBuffer("(|(presentationname=");
sb.append(targetId);
sb.append(")(symbolicname=");
sb.append(targetId);
sb.append("))");
if (targetVersion != null) {
sb.insert(0, "(&");
sb.append("(version=");
sb.append(targetVersion);
sb.append("))");
}
return admin.discoverResources(sb.toString());
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class Exports method checkDuplicateExports.
private void checkDuplicateExports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageVersion> packageVersionMap = getDuplicatePackages(bundles);
ShellTable table = new ShellTable();
table.column(new Col("Package Name"));
table.column(new Col("Version"));
table.column(new Col("Exporting bundles (ID)"));
for (String key : packageVersionMap.keySet()) {
PackageVersion pVer = packageVersionMap.get(key);
if (pVer.getBundles().size() > 1) {
String pBundles = getBundlesSt(pVer.getBundles());
table.addRow().addContent(pVer.getPackageName(), pVer.getVersion().toString(), pBundles);
}
}
table.print(System.out, !noFormat);
}
Aggregations