Search in sources :

Example 1 with IPom

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

the class MavenBndRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    File binaryFile = File.createTempFile("put", ".jar");
    File pomFile = File.createTempFile("pom", ".xml");
    LocalPutResult result = new LocalPutResult();
    try {
        if (options == null)
            options = new PutOptions();
        else {
            result.options = options;
        }
        IO.copy(stream, binaryFile);
        if (options.digest != null) {
            byte[] digest = SHA1.digest(binaryFile).digest();
            if (!Arrays.equals(options.digest, digest))
                throw new IllegalArgumentException("The given sha-1 does not match the contents sha-1");
        }
        if (options.context == null) {
            options.context = registry.getPlugin(Workspace.class);
            if (options.context == null)
                options.context = new Processor();
        }
        ReleaseDTO instructions = getReleaseDTO(options.context);
        try (Jar binary = new Jar(binaryFile)) {
            Resource pomResource;
            if (instructions.pom.path != null) {
                File f = options.context.getFile(instructions.pom.path);
                if (!f.isFile())
                    throw new IllegalArgumentException("-maven-release specifies " + f + " as pom file but this file is not found");
                pomResource = new FileResource(f);
            } else {
                pomResource = getPomResource(binary);
                if (pomResource == null) {
                    pomResource = createPomResource(binary, options.context);
                    if (pomResource == null)
                        throw new IllegalArgumentException("No POM resource in META-INF/maven/... The Maven Bnd Repository requires this pom.");
                }
            }
            IO.copy(pomResource.openInputStream(), pomFile);
            IPom pom;
            try (InputStream fin = IO.stream(pomFile)) {
                pom = storage.getPom(fin);
            }
            Archive binaryArchive = pom.binaryArchive();
            checkRemotePossible(instructions, binaryArchive.isSnapshot());
            if (!binaryArchive.isSnapshot()) {
                releasePlugin.add(options.context, pom);
                if (storage.exists(binaryArchive)) {
                    logger.debug("Already released {} to {}", pom.getRevision(), this);
                    result.alreadyReleased = true;
                    return result;
                }
            }
            logger.debug("Put release {}", pom.getRevision());
            try (Release releaser = storage.release(pom.getRevision(), options.context.getProperties())) {
                if (releaser == null) {
                    logger.debug("Already released {}", pom.getRevision());
                    return result;
                }
                if (instructions.snapshot >= 0)
                    releaser.setBuild(instructions.snapshot, null);
                if (isLocal(instructions))
                    releaser.setLocalOnly();
                releaser.add(pom.getRevision().pomArchive(), pomFile);
                releaser.add(binaryArchive, binaryFile);
                result.binaryArchive = binaryArchive;
                result.pomArchive = pom.getRevision().pomArchive();
                if (!isLocal(instructions)) {
                    try (Tool tool = new Tool(options.context, binary)) {
                        if (instructions.javadoc != null) {
                            if (!NONE.equals(instructions.javadoc.path)) {
                                try (Jar jar = getJavadoc(tool, options.context, instructions.javadoc.path, instructions.javadoc.options, instructions.javadoc.packages == JavadocPackages.EXPORT)) {
                                    save(releaser, pom.getRevision(), jar, "javadoc");
                                }
                            }
                        }
                        if (instructions.sources != null) {
                            if (!NONE.equals(instructions.sources.path)) {
                                try (Jar jar = getSource(tool, options.context, instructions.sources.path)) {
                                    save(releaser, pom.getRevision(), jar, "sources");
                                }
                            }
                        }
                    }
                }
            }
            if (configuration.noupdateOnRelease() == false && !binaryArchive.isSnapshot())
                index.add(binaryArchive);
        }
        return result;
    } catch (Exception e) {
        result.failed = e.getMessage();
        throw e;
    } finally {
        IO.delete(binaryFile);
        IO.delete(pomFile);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) Archive(aQute.maven.api.Archive) InputStream(java.io.InputStream) IPom(aQute.maven.api.IPom) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) PomResource(aQute.bnd.maven.PomResource) FileResource(aQute.bnd.osgi.FileResource) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Release(aQute.maven.api.Release) Workspace(aQute.bnd.build.Workspace)

Example 2 with IPom

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

the class ReleasePluginImpl method createIndex.

private ResourcesRepository createIndex(List<IPom> releasedArtifacts, IMavenRepo storage, String prefix) throws Exception {
    ResourcesRepository repo = new ResourcesRepository();
    for (IPom pom : releasedArtifacts) {
        try {
            System.out.println("Indexing " + pom);
            Promise<File> promise = storage.get(pom.binaryArchive());
            File file = promise.getValue();
            ResourceBuilder rb = new ResourceBuilder();
            String uri = prefix + pom.binaryArchive().remotePath;
            rb.addFile(file, new URI(uri));
            repo.add(rb.build());
        } catch (Exception e) {
            indexProject.exception(e, "Failed to index artifact %s", pom.binaryArchive());
        }
    }
    return repo;
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) IPom(aQute.maven.api.IPom) File(java.io.File) URI(java.net.URI) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) IOException(java.io.IOException)

Example 3 with IPom

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

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

Aggregations

IPom (aQute.maven.api.IPom)4 IOException (java.io.IOException)3 Archive (aQute.maven.api.Archive)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Workspace (aQute.bnd.build.Workspace)1 PomResource (aQute.bnd.maven.PomResource)1 FileResource (aQute.bnd.osgi.FileResource)1 Jar (aQute.bnd.osgi.Jar)1 Processor (aQute.bnd.osgi.Processor)1 Resource (aQute.bnd.osgi.Resource)1 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)1 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)1 BundleDescriptor (aQute.bnd.repository.maven.provider.IndexFile.BundleDescriptor)1 Dependency (aQute.maven.api.IPom.Dependency)1 Program (aQute.maven.api.Program)1 Release (aQute.maven.api.Release)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1