Search in sources :

Example 1 with DownloadCallback

use of org.apache.karaf.features.internal.download.DownloadCallback in project karaf by apache.

the class VerifyMojo method loadRepositories.

public static Map<String, Features> loadRepositories(DownloadManager manager, Set<String> uris) throws Exception {
    final Map<String, Features> loaded = new HashMap<>();
    final Downloader downloader = manager.createDownloader();
    for (String repository : uris) {
        downloader.download(repository, new DownloadCallback() {

            @Override
            public void downloaded(final StreamProvider provider) throws Exception {
                try (InputStream is = provider.open()) {
                    Features featuresModel = JaxbUtil.unmarshal(provider.getUrl(), is, false);
                    synchronized (loaded) {
                        loaded.put(provider.getUrl(), featuresModel);
                        for (String innerRepository : featuresModel.getRepository()) {
                            downloader.download(innerRepository, this);
                        }
                    }
                }
            }
        });
    }
    downloader.await();
    return loaded;
}
Also used : StreamProvider(org.apache.karaf.features.internal.download.StreamProvider) HashMap(java.util.HashMap) DownloadCallback(org.apache.karaf.features.internal.download.DownloadCallback) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Downloader(org.apache.karaf.features.internal.download.Downloader) Features(org.apache.karaf.features.internal.model.Features) MultiException(org.apache.karaf.features.internal.util.MultiException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ResolutionException(org.osgi.service.resolver.ResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 2 with DownloadCallback

use of org.apache.karaf.features.internal.download.DownloadCallback in project karaf by apache.

the class Builder method loadRepositories.

private Map<String, Features> loadRepositories(DownloadManager manager, Collection<String> repositories, final boolean install) throws Exception {
    final Map<String, Features> loaded = new HashMap<>();
    final Downloader downloader = manager.createDownloader();
    final List<String> blacklist = new ArrayList<>();
    blacklist.addAll(blacklistedBundles);
    blacklist.addAll(blacklistedFeatures);
    final List<String> blacklistRepos = new ArrayList<>();
    blacklistRepos.addAll(blacklistedRepositories);
    final Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
    final Clause[] clausesRepos = org.apache.felix.utils.manifest.Parser.parseClauses(blacklistRepos.toArray(new String[blacklistRepos.size()]));
    for (String repository : repositories) {
        downloader.download(repository, new DownloadCallback() {

            @Override
            public void downloaded(final StreamProvider provider) throws Exception {
                String url = provider.getUrl();
                if (Blacklist.isBlacklisted(clausesRepos, url, TYPE_REPOSITORY)) {
                    return;
                }
                synchronized (loaded) {
                    if (!loaded.containsKey(provider.getUrl())) {
                        if (install) {
                            synchronized (provider) {
                                Path path = pathFromProviderUrl(url);
                                Files.createDirectories(path.getParent());
                                Files.copy(provider.getFile().toPath(), path, StandardCopyOption.REPLACE_EXISTING);
                            }
                        }
                        try (InputStream is = provider.open()) {
                            Features featuresModel = JaxbUtil.unmarshal(url, is, false);
                            if (blacklistPolicy == BlacklistPolicy.Discard) {
                                Blacklist.blacklist(featuresModel, clauses);
                            }
                            loaded.put(provider.getUrl(), featuresModel);
                            for (String innerRepository : featuresModel.getRepository()) {
                                downloader.download(innerRepository, this);
                            }
                        }
                    }
                }
            }
        });
    }
    downloader.await();
    return loaded;
}
Also used : StreamProvider(org.apache.karaf.features.internal.download.StreamProvider) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DownloadCallback(org.apache.karaf.features.internal.download.DownloadCallback) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Downloader(org.apache.karaf.features.internal.download.Downloader) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Features(org.apache.karaf.features.internal.model.Features) Clause(org.apache.felix.utils.manifest.Clause)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ZipInputStream (java.util.zip.ZipInputStream)2 DownloadCallback (org.apache.karaf.features.internal.download.DownloadCallback)2 Downloader (org.apache.karaf.features.internal.download.Downloader)2 StreamProvider (org.apache.karaf.features.internal.download.StreamProvider)2 Features (org.apache.karaf.features.internal.model.Features)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Clause (org.apache.felix.utils.manifest.Clause)1 MultiException (org.apache.karaf.features.internal.util.MultiException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 BundleException (org.osgi.framework.BundleException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ResolutionException (org.osgi.service.resolver.ResolutionException)1