Search in sources :

Example 76 with Bundle

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");
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Bundle(org.osgi.framework.Bundle) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 77 with Bundle

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();
}
Also used : Bundle(org.osgi.framework.Bundle)

Example 78 with Bundle

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);
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) LoginException(javax.security.auth.login.LoginException)

Example 79 with Bundle

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());
}
Also used : Bundle(org.osgi.framework.Bundle)

Example 80 with Bundle

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);
}
Also used : Col(org.apache.karaf.shell.support.table.Col) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Bundle(org.osgi.framework.Bundle) PackageVersion(org.apache.karaf.packages.core.PackageVersion)

Aggregations

Bundle (org.osgi.framework.Bundle)2490 Test (org.junit.Test)659 URL (java.net.URL)388 BundleContext (org.osgi.framework.BundleContext)311 File (java.io.File)298 ArrayList (java.util.ArrayList)292 IOException (java.io.IOException)278 BundleException (org.osgi.framework.BundleException)270 HashMap (java.util.HashMap)149 ServiceReference (org.osgi.framework.ServiceReference)145 Path (org.eclipse.core.runtime.Path)126 Hashtable (java.util.Hashtable)124 HashSet (java.util.HashSet)95 InputStream (java.io.InputStream)94 IStatus (org.eclipse.core.runtime.IStatus)86 Status (org.eclipse.core.runtime.Status)82 List (java.util.List)80 Map (java.util.Map)74 BundleWiring (org.osgi.framework.wiring.BundleWiring)74 Version (org.osgi.framework.Version)73