use of org.osgi.service.resolver.Resolver in project aries by apache.
the class DependencyCalculator method calculateDependencies.
public List<Requirement> calculateDependencies() throws ResolutionException {
ArrayList<Requirement> result = new ArrayList<Requirement>();
Resolver resolver = Activator.getInstance().getResolver();
Map<Resource, List<Wire>> resolution = resolver.resolve(context);
for (List<Wire> wires : resolution.values()) for (Wire wire : wires) if (wire.getCapability() instanceof MissingCapability)
result.add(wire.getRequirement());
result.trimToSize();
return result;
}
use of org.osgi.service.resolver.Resolver in project fabric8 by jboss-fuse.
the class SubsystemResolver method resolve.
public Map<Resource, List<Wire>> resolve(MetadataBuilder builder, Set<String> overrides, String featureResolutionRange, final org.osgi.service.repository.Repository globalRepository) throws Exception {
if (root == null) {
return Collections.emptyMap();
}
// Download bundles
root.downloadBundles(manager, builder, overrides, featureResolutionRange);
// Populate digraph and resolve
digraph = new StandardRegionDigraph(null, null);
populateDigraph(digraph, root);
Resolver resolver = new ResolverImpl(new Slf4jResolverLog(LOGGER));
Downloader downloader = manager.createDownloader();
wiring = resolver.resolve(new SubsystemResolveContext(root, digraph, globalRepository, downloader));
downloader.await();
// Remove wiring to the fake environment resource
if (environmentResource != null) {
for (List<Wire> wires : wiring.values()) {
for (Iterator<Wire> iterator = wires.iterator(); iterator.hasNext(); ) {
Wire wire = iterator.next();
if (wire.getProvider() == environmentResource) {
iterator.remove();
}
}
}
}
// Fragments are always wired to their host only, so create fake wiring to
// the subsystem the host is wired to
associateFragments();
return wiring;
}
use of org.osgi.service.resolver.Resolver in project karaf by apache.
the class Builder method startupStage.
private Profile startupStage(Profile startupProfile, FeaturesProcessor processor) throws Exception {
LOGGER.info("Startup stage");
//
// Compute startup
//
Profile startupOverlay = Profiles.getOverlay(startupProfile, allProfiles, environment);
Profile startupEffective = Profiles.getEffective(startupOverlay, false);
// Load startup repositories
LOGGER.info(" Loading startup repositories");
Map<String, Features> startupRepositories = loadRepositories(manager, startupEffective.getRepositories(), false, processor);
//
// Resolve
//
LOGGER.info(" Resolving startup features and bundles");
LOGGER.info(" Features: " + String.join(", ", startupEffective.getFeatures()));
LOGGER.info(" Bundles: " + String.join(", ", startupEffective.getBundles()));
Map<String, Integer> bundles = resolve(manager, resolver, startupRepositories.values(), startupEffective.getFeatures(), startupEffective.getBundles(), startupEffective.getOptionals(), processor);
//
// Generate startup.properties
//
Properties startup = new Properties();
startup.setHeader(Collections.singletonList("# Bundles to be started on startup, with startlevel"));
Map<Integer, Set<String>> invertedStartupBundles = MapUtils.invert(bundles);
for (Map.Entry<Integer, Set<String>> entry : new TreeMap<>(invertedStartupBundles).entrySet()) {
String startLevel = Integer.toString(entry.getKey());
// ensure input order is respected whatever hashmap/set was in the middle of the processing
final List<String> value = new ArrayList<>(entry.getValue());
value.sort(comparing(bnd -> startupEffective.getBundles().indexOf(bnd)));
for (String location : value) {
if (useReferenceUrls) {
if (location.startsWith("mvn:")) {
location = "file:" + Parser.pathFromMaven(location);
}
if (location.startsWith("file:")) {
location = "reference:" + location;
}
}
if (location.startsWith("file:") && karafVersion == KarafVersion.v24) {
location = location.substring("file:".length());
}
startup.put(location, startLevel);
}
}
Path startupProperties = etcDirectory.resolve("startup.properties");
startup.save(startupProperties.toFile());
return startupEffective;
}
use of org.osgi.service.resolver.Resolver in project karaf by apache.
the class Activator method doStart.
protected void doStart() throws Exception {
BundleContext systemBundleContext = bundleContext.getBundle(0).getBundleContext();
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
int resolverThreads = getInt("resolverThreads", Runtime.getRuntime().availableProcessors());
executorService = new ThreadPoolExecutor(0, resolverThreads, 1L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), ThreadUtils.namedThreadFactory("resolver"));
Resolver resolver = new ResolverImpl(new Slf4jResolverLog(LoggerFactory.getLogger(ResolverImpl.class)), executorService);
URLStreamHandlerService mvnUrlHandler = getTrackedService(URLStreamHandlerService.class);
if (configurationAdmin == null || mvnUrlHandler == null) {
return;
}
StandardRegionDigraph dg = DigraphHelper.loadDigraph(bundleContext);
DigraphHelper.verifyUnmanagedBundles(bundleContext, dg);
registerRegionDiGraph(dg);
boolean configCfgStore = getBoolean("configCfgStore", FeaturesService.DEFAULT_CONFIG_CFG_STORE);
FeatureConfigInstaller configInstaller = new FeatureConfigInstaller(configurationAdmin, configCfgStore);
installSupport = new BundleInstallSupportImpl(bundleContext.getBundle(), bundleContext, systemBundleContext, getTrackedServiceRef(ConfigurationAdmin.class).getBundle(), configInstaller, dg);
register(RegionDigraphPersistence.class, () -> installSupport.saveDigraph());
FeatureRepoFinder featureFinder = new FeatureRepoFinder();
register(ManagedService.class, featureFinder, FeatureRepoFinder.getServiceProperties());
Repository globalRepository = getGlobalRepository();
FeaturesServiceConfig cfg = getConfig();
StateStorage stateStorage = createStateStorage();
featuresService = new FeaturesServiceImpl(stateStorage, featureFinder, configurationAdmin, resolver, installSupport, globalRepository, cfg);
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
featuresService.registerListener(eventAdminListener);
} catch (Throwable t) {
// No EventAdmin support in this case
}
register(FeaturesService.class, featuresService);
featuresListenerTracker = createFeatureListenerTracker();
featuresListenerTracker.open();
FeaturesServiceMBeanImpl featuresServiceMBean = new FeaturesServiceMBeanImpl();
featuresServiceMBean.setBundleContext(bundleContext);
featuresServiceMBean.setFeaturesService(featuresService);
registerMBean(featuresServiceMBean, "type=feature");
String[] featuresRepositories = getStringArray("featuresRepositories", "");
String featuresBoot = getString("featuresBoot", "");
boolean featuresBootAsynchronous = getBoolean("featuresBootAsynchronous", false);
BootFeaturesInstaller bootFeaturesInstaller = new BootFeaturesInstaller(bundleContext, featuresService, featuresRepositories, featuresBoot, featuresBootAsynchronous);
bootFeaturesInstaller.start();
}
Aggregations