Search in sources :

Example 1 with IRepositoryContentProvider

use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider in project bnd by bndtools.

the class AbstractIndexedRepo method init.

protected final synchronized void init(boolean ignoreCachedFile) throws Exception {
    if (!initialised) {
        clear();
        // Load the available providers from the workspace plugins.
        loadAllContentProviders();
        // Load the request repository content providers, if specified
        if (requestedContentProviderList != null && requestedContentProviderList.length() > 0) {
            generatingProviders.clear();
            // Find the requested providers from the available ones.
            StringTokenizer tokenizer = new StringTokenizer(requestedContentProviderList, "|");
            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken().trim();
                IRepositoryContentProvider provider = allContentProviders.get(token);
                if (provider == null) {
                    warning("Unknown repository content provider \"%s\".", token);
                } else {
                    generatingProviders.add(provider);
                }
            }
            if (generatingProviders.isEmpty()) {
                warning("No valid repository index generators were found, requested list was: [%s]", requestedContentProviderList);
            }
        }
        // Initialise index locations
        indexLocations = loadIndexes();
        // Create the callback for new referral and resource objects
        final URLConnector connector = getConnector();
        IRepositoryIndexProcessor processor = new IRepositoryIndexProcessor() {

            public void processResource(Resource resource) {
                identityMap.put(resource);
                capabilityIndex.addResource(resource);
            }

            public void processReferral(URI parentUri, Referral referral, int maxDepth, int currentDepth) {
                try {
                    URI indexLocation = new URI(referral.getUrl());
                    try {
                        CachingUriResourceHandle indexHandle = new CachingUriResourceHandle(indexLocation, getCacheDirectory(), connector, (String) null);
                        indexHandle.setReporter(reporter);
                        InputStream indexStream = GZipUtils.detectCompression(IO.stream(indexHandle.request()));
                        readIndex(indexLocation.getPath(), indexLocation, indexStream, allContentProviders.values(), this, logService);
                    } catch (Exception e) {
                        warning("Unable to read referral index at URL '%s' from parent index '%s': %s", indexLocation, parentUri, e);
                    }
                } catch (URISyntaxException e) {
                    warning("Invalid referral URL '%s' from parent index '%s': %s", referral.getUrl(), parentUri, e);
                }
            }
        };
        // Parse the indexes
        for (URI indexLocation : indexLocations) {
            try {
                CachingUriResourceHandle indexHandle = new CachingUriResourceHandle(indexLocation, getCacheDirectory(), connector, (String) null);
                // OR 2) online is false
                if (indexHandle.cachedFile != null && !ignoreCachedFile && ((System.currentTimeMillis() - indexHandle.cachedFile.lastModified() < this.cacheTimeoutSeconds * 1000) || !this.online)) {
                    indexHandle.sha = indexHandle.getCachedSHA();
                    if (indexHandle.sha != null && !this.online) {
                        System.out.println(String.format("Offline. Using cached %s.", indexLocation));
                    }
                }
                indexHandle.setReporter(reporter);
                File indexFile = indexHandle.request();
                InputStream indexStream = GZipUtils.detectCompression(IO.stream(indexFile));
                readIndex(indexFile.getName(), indexLocation, indexStream, allContentProviders.values(), processor, logService);
            } catch (Exception e) {
                error("Unable to read index at URL '%s': %s", indexLocation, e);
            }
        }
        initialised = true;
    }
}
Also used : IRepositoryIndexProcessor(aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor) InputStream(java.io.InputStream) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector) URLConnector(aQute.bnd.service.url.URLConnector) Resource(org.osgi.resource.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) StringTokenizer(java.util.StringTokenizer) Referral(aQute.bnd.deployer.repository.api.Referral) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) File(java.io.File)

Example 2 with IRepositoryContentProvider

use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider in project bnd by bndtools.

the class LocalIndexedRepo method loadIndexes.

@Override
protected synchronized List<URI> loadIndexes() throws Exception {
    Collection<URI> remotes = super.loadIndexes();
    List<URI> indexes = new ArrayList<URI>(remotes.size() + generatingProviders.size());
    for (IRepositoryContentProvider contentProvider : generatingProviders) {
        File indexFile = getIndexFile(contentProvider);
        try {
            if (indexFile.exists()) {
                indexes.add(indexFile.toURI());
            } else {
                if (contentProvider.supportsGeneration()) {
                    generateIndex(indexFile, contentProvider);
                    indexes.add(indexFile.toURI());
                }
            }
        } catch (Exception e) {
            logService.log(LogService.LOG_ERROR, String.format("Unable to load/generate index file '%s' for repository type %s", indexFile, contentProvider.getName()), e);
        }
    }
    indexes.addAll(remotes);
    return indexes;
}
Also used : ArrayList(java.util.ArrayList) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) URI(java.net.URI) File(java.io.File) IOException(java.io.IOException)

Example 3 with IRepositoryContentProvider

use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider in project bndtools by bndtools.

the class GitOBRRepo method put.

@Override
public synchronized PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    try {
        repository.incrementOpen();
        Git git = Git.wrap(repository);
        // Pull remote repository
        PullResult pullResult = git.pull().call();
        // Check result
        MergeResult mergeResult = pullResult.getMergeResult();
        if (mergeResult != null && (mergeResult.getMergeStatus() == MergeStatus.CONFLICTING || mergeResult.getMergeStatus() == MergeStatus.FAILED)) {
            // TODO: How to report failure
            throw new RuntimeException(String.format("Failed to merge changes from %s", gitUri));
        }
        // TODO: Check if jar already exists, is it ok to overwrite in all repositories?
        PutResult result = super.put(stream, options);
        if (result.artifact != null) {
            File newFile = new File(result.artifact);
            // Add, Commit and Push
            for (IRepositoryContentProvider provider : generatingProviders) {
                if (!provider.supportsGeneration())
                    continue;
                git.add().addFilepattern(getRelativePath(gitRootDir, newFile)).addFilepattern(getRelativePath(gitRootDir, new File(provider.getDefaultIndexName(pretty)))).call();
            }
            git.commit().setMessage("bndtools added bundle : " + getRelativePath(gitRootDir, newFile)).call();
            git.push().setCredentialsProvider(CredentialsProvider.getDefault()).call();
            // Re-read the index
            reset();
            init();
        }
        return result;
    } finally {
        if (repository != null) {
            repository.close();
        }
    }
}
Also used : Git(org.eclipse.jgit.api.Git) MergeResult(org.eclipse.jgit.api.MergeResult) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) File(java.io.File) PullResult(org.eclipse.jgit.api.PullResult)

Example 4 with IRepositoryContentProvider

use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider in project bnd by bndtools.

the class RepoResourceUtils method readIndex.

public static void readIndex(String name, URI baseUri, InputStream stream, Collection<IRepositoryContentProvider> contentProviders, IRepositoryIndexProcessor listener, LogService log) throws Exception {
    // Make sure we have a buffering stream
    try (InputStream bufferedStream = stream.markSupported() ? stream : new BufferedInputStream(stream)) {
        // Find a compatible content provider for the input
        IRepositoryContentProvider selectedProvider = null;
        IRepositoryContentProvider maybeSelectedProvider = null;
        for (IRepositoryContentProvider provider : contentProviders) {
            CheckResult checkResult;
            try {
                bufferedStream.mark(READ_AHEAD_MAX);
                checkResult = provider.checkStream(name, new ProtectedStream(bufferedStream));
            } finally {
                bufferedStream.reset();
            }
            if (checkResult.getDecision() == Decision.accept) {
                selectedProvider = provider;
                break;
            } else if (checkResult.getDecision() == Decision.undecided) {
                log.log(LogService.LOG_WARNING, String.format("Content provider '%s' was unable to determine compatibility with index at URL '%s': %s", provider.getName(), baseUri, checkResult.getMessage()));
                if (maybeSelectedProvider == null)
                    maybeSelectedProvider = provider;
            }
        }
        // undecided provider, with an appropriate warning.
        if (selectedProvider == null) {
            if (maybeSelectedProvider != null) {
                selectedProvider = maybeSelectedProvider;
                log.log(LogService.LOG_WARNING, String.format("No content provider matches the specified index unambiguously. Selected '%s' arbitrarily.", selectedProvider.getName()));
            } else {
                throw new IOException("Invalid repository index: no configured content provider understands the specified index.");
            }
        }
        // Finally, parse the damn file.
        selectedProvider.parseIndex(bufferedStream, baseUri, listener, log);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) CheckResult(aQute.bnd.deployer.repository.api.CheckResult) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) IOException(java.io.IOException)

Aggregations

IRepositoryContentProvider (aQute.bnd.deployer.repository.api.IRepositoryContentProvider)4 File (java.io.File)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 DefaultURLConnector (aQute.bnd.deployer.http.DefaultURLConnector)1 CheckResult (aQute.bnd.deployer.repository.api.CheckResult)1 IRepositoryIndexProcessor (aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor)1 Referral (aQute.bnd.deployer.repository.api.Referral)1 URLConnector (aQute.bnd.service.url.URLConnector)1 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Git (org.eclipse.jgit.api.Git)1 MergeResult (org.eclipse.jgit.api.MergeResult)1 PullResult (org.eclipse.jgit.api.PullResult)1 Resource (org.osgi.resource.Resource)1