org.osgi.framework.wiring.BundleWire Java Examples

The following examples show how to use org.osgi.framework.wiring.BundleWire. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Activator.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public void start(final BundleContext bundleContext) throws Exception {
    ProviderUtil.STARTUP_LOCK.lock();
    lockingProviderUtil = true;
    final BundleWiring self = bundleContext.getBundle().adapt(BundleWiring.class);
    final List<BundleWire> required = self.getRequiredWires(LoggerContextFactory.class.getName());
    for (final BundleWire wire : required) {
        loadProvider(bundleContext, wire.getProviderWiring());
    }
    bundleContext.addBundleListener(this);
    final Bundle[] bundles = bundleContext.getBundles();
    for (final Bundle bundle : bundles) {
        loadProvider(bundle);
    }
    unlockIfReady();
}
 
Example #2
Source File: NexusBundleTracker.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void prepareDependencies(final Bundle bundle) {
  final BundleWiring wiring = bundle.adapt(BundleWiring.class);
  final List<BundleWire> wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
  if (wires != null) {
    for (final BundleWire wire : wires) {
      try {
        final Bundle dependency = wire.getProviderWiring().getBundle();
        if (!visited.contains(dependency.getSymbolicName()) && hasComponents(dependency)) {
          if (!live(dependency)) {
            dependency.start();
          }
          if (live(dependency)) {
            // pseudo-event to trigger bundle activation
            addingBundle(dependency, null /* unused */);
          }
        }
      }
      catch (final Exception e) {
        log.warn("MISSING {}", wire, e);
      }
    }
  }
}
 
Example #3
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
protected final WireDTO getBundleWireDTO(BundleWire w){
	BundleWireDTO dto = new BundleWireDTO();
	dto.capability = new CapabilityRefDTO();
	dto.capability.capability = w.getCapability().hashCode();
	dto.capability.resource = w.getCapability().getResource().hashCode();
	
	dto.requirement = new RequirementRefDTO();
	dto.requirement.requirement = w.getRequirement().hashCode();
	dto.requirement.resource = w.getRequirement().getResource().hashCode();
	
	dto.provider = w.getProvider().hashCode();
	dto.requirer = w.getRequirer().hashCode();

	dto.providerWiring = w.getProviderWiring().hashCode();
	dto.requirerWiring = w.getRequirerWiring().hashCode();
	
	return dto;
}
 
Example #4
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.osgi.service.packageadmin.PackageAdmin#getHosts(org.osgi.framework.Bundle)
 */
public Bundle[] getHosts(final Bundle bundle) {
	final BundleWiring wiring = bundle.adapt(BundleWiring.class);

	if (wiring == null) {
		return null;
	}

	final List<BundleWire> wires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE);

	final ArrayList<Bundle> result = new ArrayList<Bundle>();

	for (final BundleWire wire : wires) {
		if (wire.getRequirer().getBundle() == bundle) {
			result.add(wire.getProvider().getBundle());
		}
	}

	return toArrayOrNull(result, Bundle.class);
}
 
Example #5
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.osgi.service.packageadmin.ExportedPackage#getImportingBundles()
 */
public Bundle[] getImportingBundles() {
	final ArrayList<Bundle> result = new ArrayList<Bundle>();

	final BundleWiring wiring = cap.getResource().getWiring();

	if (wiring != null) {
		final List<BundleWire> wires = wiring.getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE);

		for (final BundleWire wire : wires) {
			if (wire.getCapability().equals(cap)) {
				final Bundle b = wire.getRequirer().getBundle();
				if (b != cap.getResource().getBundle()) {
					result.add(wire.getRequirer().getBundle());
				}
			}
		}

		addRequiringBundles(wiring, result);
	}

	return toArrayOrNull(result, Bundle.class);
}
 
Example #6
Source File: Resources.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
void addWire(final BundleWire wire) {
	final Capability cap = wire.getCapability();
	final Requirement req = wire.getRequirement();
	if (wire.getProvider() == revision) {
		providedWires.insert(cap.getNamespace(), wire);
		inUseSet.add(wire.getRequirer());
		((ConciergeBundleWire) wire).providerWiring = this;
	} else {
		requiredWires.insert(req.getNamespace(), wire);
		if (HostNamespace.HOST_NAMESPACE.equals(wire.getRequirement()
				.getNamespace())) {
			inUseSet.add(wire.getProvider());
		}
		((ConciergeBundleWire) wire).requirerWiring = this;
	}
}
 
Example #7
Source File: Resources.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
HashMap<String, BundleWire> getPackageImportWires() {
	final List<BundleWire> list = getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
	final HashMap<String, BundleWire> result = new HashMap<String, BundleWire>();

	if (list != null) {
		for (final BundleWire wire : list) {
			result.put((String) wire.getCapability().getAttributes()
					.get(PackageNamespace.PACKAGE_NAMESPACE), wire);
		}
	}

	return result;
}
 
Example #8
Source File: HadoopClientServicesImpl.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
private void loadBundleFilesLocations() {
  sqoopBundleFileLocations.clear();
  String bundleLocation = bundleContext.getBundle().getDataFile( "" ).getParent();
  sqoopBundleFileLocations.add( bundleLocation );
  BundleWiring wiring = bundleContext.getBundle().adapt( BundleWiring.class );
  List<BundleWire> fragments = wiring.getProvidedWires( "osgi.wiring.host" );
  for ( BundleWire fragment : fragments ) {
    Bundle fragmentBundle = fragment.getRequirerWiring().getBundle();
    String fragmentBundleLocation = fragmentBundle.getDataFile( "" ).getParent();
    sqoopBundleFileLocations.add( fragmentBundleLocation );
  }
}
 
Example #9
Source File: BundleImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
ConciergeBundleWiring addAdditionalWires(final List<Wire> wires) {
	for (final Wire wire : wires) {
		wiring.addWire((BundleWire) wire);
	}

	packageImportWires = wiring.getPackageImportWires();
	requireBundleWires = wiring.getRequireBundleWires();
	return wiring;
}
 
Example #10
Source File: Resources.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
public List<BundleWire> getRequiredWires(final String namespace) {
	if (!isInUse()) {
		return null;
	}

	return namespace == null ? requiredWires.getAllValues()
			: requiredWires.lookup(namespace);
}
 
Example #11
Source File: Resources.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
public List<BundleWire> getProvidedWires(final String namespace) {
	if (!isInUse()) {
		return null;
	}

	return namespace == null ? providedWires.getAllValues()
			: providedWires.lookup(namespace);
}
 
Example #12
Source File: RascalManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void collectClassPathForBundle(Bundle bundle, List<URL> classPath,
		List<String> compilerClassPath) {
	try {
		File file = FileLocator.getBundleFile(bundle);
		URL url = file.toURI().toURL();

		if (classPath.contains(url)) {
			return; // kill infinite loop
		}
		classPath.add(0, url);
		compilerClassPath.add(0, file.getAbsolutePath());
		
		BundleWiring wiring = bundle.adapt(BundleWiring.class);
		for (BundleWire dep : wiring.getRequiredWires(null)) {
			collectClassPathForBundle(dep.getProviderWiring().getBundle(),
					classPath, compilerClassPath);
		}

		List<String> requiredLibs = new RascalBundleManifest().getRequiredLibraries(bundle);
		if (requiredLibs != null) {
			for (String lib : requiredLibs) {
				classPath.add(bundle.getResource(lib));
			}
		}

	} 
	catch (IOException e) {
		Rasctivator.logException("error while tracing dependencies", e);
	} 
}
 
Example #13
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.osgi.service.packageadmin.PackageAdmin#getFragments(org.osgi.framework.Bundle)
 */
public Bundle[] getFragments(final Bundle bundle) {
	final BundleWiring wiring = bundle.adapt(BundleWiring.class);
	// this will happen if a bundle has no current revision, e.g.
	// is INSTALLED only
	if (wiring == null) {
		// System.err.println("o.e.c.service.packageadmin: getFragments has
		// no wiring for bundle "
		// + bundle.getSymbolicName());
		return null;
	}
	final List<BundleWire> wires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);

	if (wires == null || wires.isEmpty()) {
		return null;
	}

	final Bundle[] result = new Bundle[wires.size()];

	final Iterator<BundleWire> iter = wires.iterator();
	for (int i = 0; i < result.length; i++) {
		final BundleWire wire = iter.next();
		result[i] = wire.getRequirer().getBundle();
	}

	return result;
}
 
Example #14
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
private void addRequiringBundles(final BundleWiring wiring, final ArrayList<Bundle> result) {
	final List<BundleWire> wires = wiring.getProvidedWires(BundleNamespace.BUNDLE_NAMESPACE);

	for (final BundleWire wire : wires) {
		result.add(wire.getRequirer().getBundle());
		if (BundleNamespace.VISIBILITY_REEXPORT.equals(
				wire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE))) {
			addRequiringBundles(wire.getRequirer().getWiring(), result);
		}
	}
}
 
Example #15
Source File: Resources.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
List<BundleWire> getRequireBundleWires() {
	return getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE);
}
 
Example #16
Source File: Resources.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
public List<Wire> getProvidedResourceWires(final String namespace) {
	final List<BundleWire> bwires = getProvidedWires(namespace);
	return bwires == null ? null : new ArrayList<Wire>(bwires);
}
 
Example #17
Source File: Resources.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
public List<Wire> getRequiredResourceWires(final String namespace) {
	final List<BundleWire> bwires = getRequiredWires(namespace);
	return bwires == null ? null : new ArrayList<Wire>(bwires);
}
 
Example #18
Source File: MockBundle.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public List<BundleWire> getProvidedWires(String p1) {
    throw new UnsupportedOperationException();
}
 
Example #19
Source File: MockBundle.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public List<BundleWire> getRequiredWires(String p1) {
    throw new UnsupportedOperationException();
}
 
Example #20
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
private Collection<Bundle> getDependencies(final Collection<Bundle> bundles,
		final boolean allRevisions) {
	// build up the dependency graph. See specs for details.
	final ArrayList<Bundle> toProcess = new ArrayList<Bundle>(bundles);

	final Set<Bundle> dependencySet = new HashSet<Bundle>();
	while (!toProcess.isEmpty()) {
		final Bundle b = toProcess.remove(0);

		if (b == this) {
			dependencySet.add(b);
			continue;
		}

		if (dependencySet.contains(b)) {
			continue;
		}

		if (!(b instanceof BundleImpl)) {
			throw new IllegalArgumentException(
					"Bundles were not created by this framework instance "
							+ b.getClass().getName());
		}

		dependencySet.add(b);

		final BundleImpl bundle = (BundleImpl) b;

		for (final BundleRevision brev : bundle.revisions) {
			final BundleWiring wiring = brev.getWiring();

			// all package exports
			if (wiring != null) {

				for (final BundleRevision rev : ((ConciergeBundleWiring) wiring).inUseSet) {
					toProcess.add(rev.getBundle());
				}

				/*
				 * final List<BundleWire> importWires = wiring
				 * .getProvidedWires(null);
				 * 
				 * if (importWires != null) { for (final BundleWire
				 * importWire : importWires) {
				 * toProcess.add(importWire.getRequirer().getBundle()); } }
				 */
				final List<BundleWire> hostWires = wiring
						.getRequiredWires(HostNamespace.HOST_NAMESPACE);
				if (hostWires != null) {
					for (final BundleWire hostWire : hostWires) {
						toProcess.add(hostWire.getProvider().getBundle());
					}
				}
			}
		}
	}

	return dependencySet;
}
 
Example #21
Source File: ClassLoaderOsgiFramework.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public List<BundleWire> getProvidedWires(String p1) {
    throw new UnsupportedOperationException();
}
 
Example #22
Source File: ClassLoaderOsgiFramework.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public List<BundleWire> getRequiredWires(String p1) {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: AuthHttpContext.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
private Set<Bundle> getBundlesInClassSpace(BundleContext context,
                                                  Bundle bundle, Set<Bundle> bundleSet) {
    Set<Bundle> bundles = new HashSet<>(); // The set containing the
    // bundles either being
    // imported or required
    if (bundle == null) {
        log.error("Incoming bundle is null");
        return bundles;
    }
    if (context == null) {
        log.error("Incoming context is null");
        return bundles;
    }

    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    if (bundleWiring == null) {
        log.error("BundleWiring is null for: " + bundle);
        return bundles;
    }

    // This will give us all required Wires (including require-bundle)
    List<BundleWire> requiredWires = bundleWiring.getRequiredWires(null);
    for (BundleWire bundleWire : requiredWires) {
        Bundle exportingBundle = bundleWire.getCapability().getRevision()
                .getBundle();

        if (exportingBundle.getBundleId() == 0) {
            continue; // system bundle is skipped this one isn't needed
        }
        if (!bundles.contains(exportingBundle)) {
            bundles.add(exportingBundle);
        }
    }

    if (!bundleSet.containsAll(bundles)) { // now let's scan transitively
        bundles.removeAll(bundleSet);
        bundleSet.addAll(bundles);
    }

    // Sanity checkpoint to remove uninstalled bundles
    bundleSet.removeIf(auxBundle -> auxBundle.getState() == Bundle.UNINSTALLED);

    return bundleSet;
}