Search in sources :

Example 6 with Archive

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

the class IndexFile method saveIndexFile.

private void saveIndexFile() throws Exception {
    lock.writeLock().lock();
    try {
        File tmp = File.createTempFile("index", null);
        try (PrintWriter pw = new PrintWriter(tmp)) {
            List<Archive> archives = new ArrayList<>(this.descriptors.keySet());
            Collections.sort(archives);
            for (Archive archive : archives) {
                pw.println(archive);
            }
        }
        Files.move(tmp.toPath(), indexFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } finally {
        lock.writeLock().unlock();
    }
    lastModified = indexFile.lastModified();
}
Also used : Archive(aQute.maven.api.Archive) ArrayList(java.util.ArrayList) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 7 with Archive

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

the class PomRepositoryTest method assertAllBndCap.

void assertAllBndCap(Map<Archive, Resource> value) {
    for (Resource resource : value.values()) {
        List<Capability> capabilities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
        assertNotNull(capabilities);
        assertEquals(1, capabilities.size());
        capabilities = resource.getCapabilities("bnd.info");
        Capability c = capabilities.get(0);
        String a = (String) c.getAttributes().get("name");
        Archive archive = Archive.valueOf(a);
        assertNotNull(archive);
    }
}
Also used : Archive(aQute.maven.api.Archive) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource)

Example 8 with Archive

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

the class SnapshotReleaser method updateMetadata.

public void updateMetadata() throws Exception {
    revisionMetadata.group = revision.group;
    revisionMetadata.artifact = revision.artifact;
    revisionMetadata.version = revision.version;
    revisionMetadata.lastUpdated = programMetadata.lastUpdated;
    revisionMetadata.snapshot.buildNumber = build;
    revisionMetadata.snapshot.timestamp = dateStamp;
    for (Archive archive : upload) {
        SnapshotVersion snapshotVersion = new SnapshotVersion();
        snapshotVersion.extension = archive.extension;
        snapshotVersion.classifier = archive.classifier.isEmpty() ? null : archive.classifier;
        snapshotVersion.updated = programMetadata.lastUpdated;
        snapshotVersion.value = this.snapshotVersion;
        revisionMetadata.snapshotVersions.add(snapshotVersion);
    }
    File metafile = home.toLocalFile(revision.metadata(repo.id));
    IO.mkdirs(metafile.getParentFile());
    IO.store(revisionMetadata.toString(), metafile);
    repo.store(metafile, revision.metadata());
    super.updateMetadata();
}
Also used : Archive(aQute.maven.api.Archive) SnapshotVersion(aQute.maven.provider.MetadataParser.SnapshotVersion) File(java.io.File)

Example 9 with Archive

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

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

the class PomGenerator method build.

public Tag build() {
    prune();
    Tag project = new Tag("project");
    project.addAttribute("xmlns", "http://maven.apache.org/POM/4.0.0");
    project.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    project.addAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd");
    new Tag(project, "modelVersion", "4.0.0");
    if (parent != null) {
        Tag parent = new Tag(project, "parent");
        gav(parent, this.parent);
    }
    gav(project, name);
    Tag depType;
    if (dependencyManagement) {
        depType = new Tag(project, "dependencyManagement");
    } else
        depType = project;
    Tag dependencies = new Tag(depType, "dependencies");
    for (Archive dep : this.dependencies) {
        Tag dependency = new Tag(dependencies, "dependency");
        gav(dependency, dep.revision);
        if (dep.hasClassifier())
            new Tag(dependency, "classifier", dep.classifier);
        if (dep.hasExtension())
            new Tag(dependency, "type", dep.extension);
        if (!dependencyManagement)
            new Tag(dependency, "scope", "runtime");
    }
    return project;
}
Also used : Archive(aQute.maven.api.Archive) Tag(aQute.lib.tag.Tag)

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