Search in sources :

Example 1 with BundleDescriptor

use of aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor in project bnd by bndtools.

the class MavenBndRepository method getBundleDescriptor.

BundleDescriptor getBundleDescriptor(Object... target) throws Exception {
    String bsn = (String) target[0];
    Version version = (Version) target[1];
    BundleDescriptor bd = getDescriptor(bsn, version);
    return bd;
}
Also used : BundleDescriptor(aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor) Version(aQute.bnd.version.Version)

Example 2 with BundleDescriptor

use of aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor in project bnd by bndtools.

the class MavenBndRepository method title.

@Override
public String title(Object... target) throws Exception {
    switch(target.length) {
        case 0:
            String name = getName();
            int n = index.getErrors(null);
            if (n > 0)
                return name += " [" + n + "!]";
            return name;
        case 1:
            name = (String) target[0];
            n = index.getErrors(name);
            if (n > 0)
                name += " [!]";
            return name;
        case 2:
            BundleDescriptor bd = getBundleDescriptor(target);
            if (bd.error != null)
                return bd.version + " [" + bd.error + "]";
            else if (isLocal(bd.archive)) {
                return bd.version.toString();
            } else
                return bd.version.toString() + " [?]";
        default:
    }
    return null;
}
Also used : BundleDescriptor(aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor)

Example 3 with BundleDescriptor

use of aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor in project bnd by bndtools.

the class RepoActions method addDependency.

private void addDependency(Archive archive, MavenScope scope) throws Exception {
    IPom pom = repo.storage.getPom(archive.revision);
    Map<Program, Dependency> dependencies = pom.getDependencies(scope, false);
    for (Dependency d : dependencies.values()) {
        BundleDescriptor add = repo.index.add(d.program.version(d.version).archive("jar", null));
        if (d.error != null)
            add.error = d.error;
    }
}
Also used : BundleDescriptor(aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor) Program(aQute.maven.api.Program) IPom(aQute.maven.api.IPom) Dependency(aQute.maven.api.IPom.Dependency)

Example 4 with BundleDescriptor

use of aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor in project bnd by bndtools.

the class MavenBndRepository method tooltip.

@Override
public String tooltip(Object... target) throws Exception {
    switch(target.length) {
        case 0:
            try (Formatter f = new Formatter()) {
                f.format("%s\n", getName());
                f.format("Revisions %s\n", index.descriptors.size());
                for (MavenBackingRepository mbr : storage.getReleaseRepositories()) f.format("Release %s  (%s)\n", mbr, getUser(mbr));
                for (MavenBackingRepository mbr : storage.getSnapshotRepositories()) f.format("Snapshot %s (%s)\n", mbr, getUser(mbr));
                f.format("Storage %s\n", localRepo);
                f.format("Index %s\n", index.indexFile);
                f.format("Index Cache %s\n", index.cacheDir);
                return f.toString();
            }
        case 1:
            try (Formatter f = new Formatter()) {
                String name = (String) target[0];
                Set<aQute.maven.api.Program> programs = index.getProgramsForBsn(name);
                return programs.toString();
            }
        case 2:
            BundleDescriptor bd = getBundleDescriptor(target);
            try (Formatter f = new Formatter()) {
                f.format("%s\n", bd.archive);
                f.format("Bundle-Version %s\n", bd.version);
                f.format("Last Modified %s\n", new Date(bd.lastModified));
                f.format("URL %s\n", bd.url);
                f.format("SHA-1 %s\n", Hex.toHexString(bd.id).toLowerCase());
                f.format("SHA-256 %s\n", Hex.toHexString(bd.sha256).toLowerCase());
                File localFile = storage.toLocalFile(bd.archive);
                f.format("Local %s%s\n", localFile, localFile.isFile() ? "" : " ?");
                if (bd.description != null)
                    f.format("Description\n%s", bd.description);
                return f.toString();
            }
        default:
    }
    return null;
}
Also used : MavenBackingRepository(aQute.maven.provider.MavenBackingRepository) BundleDescriptor(aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor) Formatter(java.util.Formatter) File(java.io.File) Date(java.util.Date)

Example 5 with BundleDescriptor

use of aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor in project bnd by bndtools.

the class MavenBndRepository method get.

@Override
public File get(String bsn, Version version, Map<String, String> properties, final DownloadListener... listeners) throws Exception {
    init();
    BundleDescriptor descriptor = index.getDescriptor(bsn, version);
    if (descriptor == null)
        return null;
    Archive archive = descriptor.archive;
    if (archive != null) {
        final File file = storage.toLocalFile(archive);
        final File withSources = new File(file.getParentFile(), "+" + file.getName());
        if (withSources.isFile() && withSources.lastModified() > file.lastModified()) {
            if (listeners.length == 0)
                return withSources;
            for (DownloadListener dl : listeners) dl.success(withSources);
            return withSources;
        }
        Promise<File> promise = index.updateAsync(descriptor, storage.get(archive));
        if (listeners.length == 0)
            return promise.getValue();
        promise.then(new Success<File, Void>() {

            @Override
            public Promise<Void> call(Promise<File> resolved) throws Exception {
                File value = resolved.getValue();
                if (value == null) {
                    throw new FileNotFoundException("Download failed");
                }
                for (DownloadListener dl : listeners) {
                    try {
                        dl.success(value);
                    } catch (Exception e) {
                        reporter.exception(e, "Download listener failed in success callback %s", dl);
                    }
                }
                return null;
            }
        }).then(null, new Failure() {

            @Override
            public void fail(Promise<?> resolved) throws Exception {
                String reason = Exceptions.toString(resolved.getFailure());
                for (DownloadListener dl : listeners) {
                    try {
                        dl.failure(file, reason);
                    } catch (Exception e) {
                        reporter.exception(e, "Download listener failed in failure callback %s", dl);
                    }
                }
            }
        });
        return file;
    }
    return null;
}
Also used : Archive(aQute.maven.api.Archive) FileNotFoundException(java.io.FileNotFoundException) Success(org.osgi.util.promise.Success) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BundleDescriptor(aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor) Promise(org.osgi.util.promise.Promise) File(java.io.File) Failure(org.osgi.util.promise.Failure)

Aggregations

BundleDescriptor (aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor)5 File (java.io.File)2 Version (aQute.bnd.version.Version)1 Archive (aQute.maven.api.Archive)1 IPom (aQute.maven.api.IPom)1 Dependency (aQute.maven.api.IPom.Dependency)1 Program (aQute.maven.api.Program)1 MavenBackingRepository (aQute.maven.provider.MavenBackingRepository)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 Formatter (java.util.Formatter)1 Failure (org.osgi.util.promise.Failure)1 Promise (org.osgi.util.promise.Promise)1 Success (org.osgi.util.promise.Success)1