Search in sources :

Example 16 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class ReleasePluginImpl method end.

/*
	 * End the release cyle. This will index all artifacts released to the
	 * repository since the begin.
	 */
void end(Project p, IMavenRepo storage) throws Exception {
    if (releasedArtifacts.isEmpty())
        return;
    if (p != indexProject)
        throw new IllegalArgumentException("Different project that started the release plugin then that ended it " + indexProject + ":" + p);
    if (master == null)
        throw new IllegalArgumentException("The index project was never released so GAV is unknown for index");
    Archive index = master.getRevision().archive("xml", "index");
    String prefix = makeDots(index.remotePath);
    ResourcesRepository repository = createIndex(releasedArtifacts, storage, prefix);
    saveToXml(p, storage, index, repository);
}
Also used : Archive(aQute.maven.api.Archive) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 17 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class RepoActions method addSources.

void addSources(final BundleDescriptor bd, Map<String, Runnable> map) throws Exception {
    Promise<File> pBinary = repo.storage.get(bd.archive);
    if (pBinary.getFailure() == null) {
        final File binary = pBinary.getValue();
        final File out = new File(binary.getParentFile(), "+" + binary.getName());
        if (!out.isFile()) {
            Archive a = bd.archive.revision.archive("jar", "sources");
            Promise<File> pSources = repo.storage.get(a);
            if (pSources.getFailure() == null) {
                final File sources = pSources.getValue();
                if (sources.isFile() && sources.length() > 1000) {
                    map.put("Add Sources", new Runnable() {

                        @Override
                        public void run() {
                            try {
                                try (Jar src = new Jar(sources)) {
                                    try (Jar bin = new Jar(binary)) {
                                        bin.setDoNotTouchManifest();
                                        for (String path : src.getResources().keySet()) bin.putResource("OSGI-OPT/src/" + path, src.getResource(path));
                                        bin.write(out);
                                    }
                                    out.setLastModified(System.currentTimeMillis());
                                }
                            } catch (Exception e) {
                                throw Exceptions.duck(e);
                            }
                        }
                    });
                    return;
                }
            }
        }
    }
    map.put("-Add Sources", null);
}
Also used : Archive(aQute.maven.api.Archive) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 18 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class MavenBndRepository method addPom.

private boolean addPom(URI uri) throws Exception {
    try {
        // http://search.maven.org/remotecontent?filepath=com/netflix/governator/governator-commons-cli/1.12.10/governator-commons-cli-1.12.10.pom
        IPom pom = storage.getPom(client.connect(uri.toURL()));
        Archive binaryArchive = pom.binaryArchive();
        index.add(binaryArchive);
        return true;
    } catch (FileNotFoundException e) {
        return false;
    } catch (Exception e) {
        logger.debug("Failure to parse {}", uri, e);
        return false;
    }
}
Also used : Archive(aQute.maven.api.Archive) IPom(aQute.maven.api.IPom) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 19 with Archive

use of aQute.maven.api.Archive 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)

Example 20 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class Traverser method parsePom.

private void parsePom(POM pom, String parent) throws Exception {
    Map<Program, Dependency> dependencies = pom.getDependencies(EnumSet.of(MavenScope.compile, MavenScope.runtime), false);
    for (Dependency d : dependencies.values()) {
        d.bindToVersion(repo);
        Archive archive = d.getArchive();
        if (archive == null) {
            logger.debug("pom {} has bad dependency {}", pom.getRevision(), d);
        } else
            parse(archive, parent);
    }
}
Also used : Program(aQute.maven.api.Program) Archive(aQute.maven.api.Archive) Dependency(aQute.maven.api.IPom.Dependency)

Aggregations

Archive (aQute.maven.api.Archive)25 File (java.io.File)13 Revision (aQute.maven.api.Revision)6 Program (aQute.maven.api.Program)5 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 Resource (org.osgi.resource.Resource)3 HttpClient (aQute.bnd.http.HttpClient)2 Jar (aQute.bnd.osgi.Jar)2 IPom (aQute.maven.api.IPom)2 Release (aQute.maven.api.Release)2 MavenRepository (aQute.maven.provider.MavenRepository)2 SnapshotVersion (aQute.maven.provider.MetadataParser.SnapshotVersion)2 InputStream (java.io.InputStream)2 Failure (org.osgi.util.promise.Failure)2 Promise (org.osgi.util.promise.Promise)2 Workspace (aQute.bnd.build.Workspace)1 HttpRequestException (aQute.bnd.http.HttpRequestException)1