Search in sources :

Example 26 with Resolver

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;
}
Also used : Requirement(org.osgi.resource.Requirement) Resolver(org.osgi.service.resolver.Resolver) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) List(java.util.List) Wire(org.osgi.resource.Wire)

Example 27 with Resolver

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;
}
Also used : Resolver(org.osgi.service.resolver.Resolver) Slf4jResolverLog(io.fabric8.agent.resolver.Slf4jResolverLog) Downloader(io.fabric8.agent.download.Downloader) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Wire(org.osgi.resource.Wire) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Example 28 with Resolver

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;
}
Also used : Manifest(java.util.jar.Manifest) Profile(org.apache.karaf.profile.Profile) Arrays(java.util.Arrays) MultiException(org.apache.karaf.features.internal.util.MultiException) FeaturesProcessorImpl(org.apache.karaf.features.internal.service.FeaturesProcessorImpl) Constants(org.osgi.framework.Constants) FeaturePattern(org.apache.karaf.features.FeaturePattern) KarafPropertiesEditor(org.apache.karaf.tools.utils.KarafPropertiesEditor) LoggerFactory(org.slf4j.LoggerFactory) FeaturesService(org.apache.karaf.features.FeaturesService) Collections.singletonList(java.util.Collections.singletonList) DownloadManagerHelper(org.apache.karaf.features.internal.download.impl.DownloadManagerHelper) Clause(org.apache.felix.utils.manifest.Clause) ByteArrayInputStream(java.io.ByteArrayInputStream) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) URI(java.net.URI) Repository(org.osgi.service.repository.Repository) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) ResourceBuilder(org.apache.felix.utils.resource.ResourceBuilder) BundleRevision(org.osgi.framework.wiring.BundleRevision) MavenResolver(org.ops4j.pax.url.mvn.MavenResolver) BundleInfo(org.apache.karaf.features.BundleInfo) Blacklist(org.apache.karaf.features.internal.service.Blacklist) Deployer(org.apache.karaf.features.internal.service.Deployer) MapUtils(org.apache.karaf.features.internal.util.MapUtils) Collection(java.util.Collection) Set(java.util.Set) MANIFEST_NAME(java.util.jar.JarFile.MANIFEST_NAME) UUID(java.util.UUID) Library(org.apache.karaf.features.Library) FileSystem(java.nio.file.FileSystem) Attributes(java.util.jar.Attributes) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ThreadUtils(org.apache.karaf.util.ThreadUtils) List(java.util.List) PropertiesLoader(org.apache.karaf.util.config.PropertiesLoader) org.apache.karaf.features.internal.model(org.apache.karaf.features.internal.model) Properties(org.apache.felix.utils.properties.Properties) Pattern(java.util.regex.Pattern) DownloadManager(org.apache.karaf.features.internal.download.DownloadManager) Dictionary(java.util.Dictionary) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DownloadCallback(org.apache.karaf.features.internal.download.DownloadCallback) HashMap(java.util.HashMap) Kar(org.apache.karaf.kar.internal.Kar) Function(java.util.function.Function) TreeSet(java.util.TreeSet) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StreamProvider(org.apache.karaf.features.internal.download.StreamProvider) ProfileBuilder(org.apache.karaf.profile.ProfileBuilder) Parser(org.apache.karaf.util.maven.Parser) FeaturesProcessor(org.apache.karaf.features.internal.service.FeaturesProcessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MavenResolvers(org.ops4j.pax.url.mvn.MavenResolvers) Downloader(org.apache.karaf.features.internal.download.Downloader) Comparator.comparing(java.util.Comparator.comparing) LinkedList(java.util.LinkedList) Hashtable(java.util.Hashtable) LinkedHashSet(java.util.LinkedHashSet) LocationPattern(org.apache.karaf.features.LocationPattern) Logger(org.slf4j.Logger) Profiles(org.apache.karaf.profile.impl.Profiles) MalformedURLException(java.net.MalformedURLException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Resource(org.osgi.resource.Resource) Version(org.apache.karaf.util.Version) FileWriter(java.io.FileWriter) BaseRepository(org.apache.felix.utils.repository.BaseRepository) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Resolver(org.osgi.service.resolver.Resolver) KarafPropertyEdits(org.apache.karaf.tools.utils.model.KarafPropertyEdits) File(java.io.File) Overrides(org.apache.karaf.features.internal.service.Overrides) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) Startup(org.apache.karaf.profile.assembly.Builder.Stage.Startup) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) InputStream(java.io.InputStream) Path(java.nio.file.Path) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Properties(org.apache.felix.utils.properties.Properties) Profile(org.apache.karaf.profile.Profile) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 29 with Resolver

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();
}
Also used : FeaturesServiceImpl(org.apache.karaf.features.internal.service.FeaturesServiceImpl) BootFeaturesInstaller(org.apache.karaf.features.internal.service.BootFeaturesInstaller) Resolver(org.osgi.service.resolver.Resolver) URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) StateStorage(org.apache.karaf.features.internal.service.StateStorage) BundleInstallSupportImpl(org.apache.karaf.features.internal.service.BundleInstallSupportImpl) ResolverImpl(org.apache.felix.resolver.ResolverImpl) FeatureRepoFinder(org.apache.karaf.features.internal.service.FeatureRepoFinder) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) FeaturesServiceMBeanImpl(org.apache.karaf.features.internal.management.FeaturesServiceMBeanImpl) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph) EventAdminListener(org.apache.karaf.features.internal.service.EventAdminListener) FeatureConfigInstaller(org.apache.karaf.features.internal.service.FeatureConfigInstaller) XmlRepository(org.apache.karaf.features.internal.repository.XmlRepository) Repository(org.osgi.service.repository.Repository) JsonRepository(org.apache.karaf.features.internal.repository.JsonRepository) AggregateRepository(org.apache.felix.utils.repository.AggregateRepository) FeaturesServiceConfig(org.apache.karaf.features.internal.service.FeaturesServiceConfig) Slf4jResolverLog(org.apache.karaf.features.internal.resolver.Slf4jResolverLog) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Resolver (org.osgi.service.resolver.Resolver)29 ArrayList (java.util.ArrayList)24 Resource (org.osgi.resource.Resource)24 List (java.util.List)22 Requirement (org.osgi.resource.Requirement)22 Capability (org.osgi.resource.Capability)16 HashMap (java.util.HashMap)15 ResolverImpl (org.apache.felix.resolver.ResolverImpl)15 Logger (org.apache.felix.resolver.Logger)12 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)11 Wire (org.osgi.resource.Wire)11 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)10 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)10 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)10 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)10 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)10 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)10 Test (org.junit.Test)10 Wiring (org.osgi.resource.Wiring)10 Repository (org.osgi.service.repository.Repository)8