Search in sources :

Example 1 with BundleRepository

use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.

the class BundleRepositoryManagerImpl method getAllBundleRepositories.

public Collection<BundleRepository> getAllBundleRepositories() {
    LOGGER.debug(LOG_ENTRY, "getAllBundleRepositories");
    ServiceCollection<BundleRepository> providers = new ArrayServiceList<BundleRepository>(bc);
    try {
        ServiceReference[] refs = bc.getServiceReferences(BundleRepository.class.getName(), null);
        if (refs != null) {
            for (ServiceReference ref : refs) {
                providers.addService(ref);
            }
        }
    } catch (InvalidSyntaxException e) {
        LOGGER.error(LOG_EXCEPTION, e);
    }
    LOGGER.debug(LOG_EXIT, "getAllBundleRepositories");
    return providers;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with BundleRepository

use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.

the class BundleRepositoryManagerImpl method getBundleSuggestions.

public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
    LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
    Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
    Iterator<DeploymentContent> it = content.iterator();
    while (it.hasNext()) {
        DeploymentContent bundleToFind = it.next();
        Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
        for (BundleRepository obj : providers) {
            BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
            if (suggestion != null) {
                List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
                if (suggestions == null) {
                    suggestions = new ArrayList<BundleSuggestion>();
                    bundlesuggestions.put(suggestion.getVersion(), suggestions);
                }
                suggestions.add(suggestion);
            }
        }
        BundleSuggestion suggestion = null;
        if (!!!bundlesuggestions.isEmpty()) {
            List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
            if (thoughts != null) {
                Collections.sort(thoughts, new Comparator<BundleSuggestion>() {

                    public int compare(BundleSuggestion o1, BundleSuggestion o2) {
                        return o1.getCost() - o2.getCost();
                    }
                });
                suggestion = thoughts.get(0);
            }
        }
        // add the suggestion to the list
        if (suggestion != null) {
            urlToBeInstalled.put(bundleToFind, suggestion);
        } else {
            throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
        }
    }
    LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
    return urlToBeInstalled;
}
Also used : HashMap(java.util.HashMap) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ContextException(org.apache.aries.application.management.spi.repository.ContextException) DeploymentContent(org.apache.aries.application.DeploymentContent) Version(org.osgi.framework.Version) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) ArrayList(java.util.ArrayList) List(java.util.List) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList)

Example 3 with BundleRepository

use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.

the class BundleRepositoryManagerImpl method getBundleRepositoryCollection.

public Collection<BundleRepository> getBundleRepositoryCollection(String appName, String appVersion) {
    LOGGER.debug(LOG_ENTRY, "getBundleRepositoryCollection", new Object[] { appName, appVersion });
    ServiceCollection<BundleRepository> providers = new ArrayServiceList<BundleRepository>(bc);
    String appScope = appName + "_" + appVersion;
    String filter = "(|(" + BundleRepository.REPOSITORY_SCOPE + "=" + BundleRepository.GLOBAL_SCOPE + ")(" + BundleRepository.REPOSITORY_SCOPE + "=" + appScope + "))";
    try {
        ServiceReference[] refs = bc.getServiceReferences(BundleRepository.class.getName(), filter);
        if (refs != null) {
            for (ServiceReference ref : refs) {
                providers.addService(ref);
            }
        }
    } catch (InvalidSyntaxException e) {
        LOGGER.error(LOG_EXCEPTION, e);
    }
    LOGGER.debug(LOG_EXIT, "getBundleRepositoryCollection");
    return providers;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList) ServiceReference(org.osgi.framework.ServiceReference)

Example 4 with BundleRepository

use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.

the class IsolationTestUtils method prepareSampleBundleV2.

/**
 * Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle,
 * which returns the message "hello brave new world" rather than "hello world"
 *
 * This means setting up a global bundle repository as well as a global OBR repository
 */
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
    BundleRepository repo = new BundleRepository() {

        public int getCost() {
            return 1;
        }

        public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
            if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
                return new BundleSuggestion() {

                    public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
                        File f = new File("sample_2.0.0.jar");
                        try {
                            return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
                        } catch (MalformedURLException mue) {
                            throw new RuntimeException(mue);
                        }
                    }

                    public Version getVersion() {
                        return new Version("2.0.0");
                    }

                    public Set<Content> getImportPackage() {
                        return Collections.emptySet();
                    }

                    public Set<Content> getExportPackage() {
                        return Collections.emptySet();
                    }

                    public int getCost() {
                        return 1;
                    }
                };
            } else {
                return null;
            }
        }
    };
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
    runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
    Attributes attrs = new Attributes();
    attrs.putValue("Bundle-ManifestVersion", "2");
    attrs.putValue("Bundle-Version", "2.0.0");
    attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
    attrs.putValue("Manifest-Version", "1");
    ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
    repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
    repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
Also used : MalformedURLException(java.net.MalformedURLException) Hashtable(java.util.Hashtable) AriesApplication(org.apache.aries.application.management.AriesApplication) Attributes(java.util.jar.Attributes) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) DeploymentContent(org.apache.aries.application.DeploymentContent) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Version(org.osgi.framework.Version) DeploymentContent(org.apache.aries.application.DeploymentContent) Content(org.apache.aries.application.Content) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

BundleRepository (org.apache.aries.application.management.spi.repository.BundleRepository)4 ArrayServiceList (org.apache.aries.application.utils.service.ArrayServiceList)3 DeploymentContent (org.apache.aries.application.DeploymentContent)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ServiceReference (org.osgi.framework.ServiceReference)2 Version (org.osgi.framework.Version)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Attributes (java.util.jar.Attributes)1 Content (org.apache.aries.application.Content)1 AriesApplication (org.apache.aries.application.management.AriesApplication)1 BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)1 BundleSuggestion (org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion)1 ContextException (org.apache.aries.application.management.spi.repository.ContextException)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1