Search in sources :

Example 1 with PutOptions

use of aQute.bnd.service.RepositoryPlugin.PutOptions in project bnd by bndtools.

the class Project method install.

private void install(File f, RepositoryPlugin repo, Attrs value) throws Exception {
    try (Processor p = new Processor()) {
        p.getProperties().putAll(value);
        PutOptions options = new PutOptions();
        options.context = p;
        try (InputStream in = IO.stream(f)) {
            repo.put(in, options);
        } catch (Exception e) {
            exception(e, "Cannot install %s into %s because %s", f, repo.getName(), e);
        }
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) IOException(java.io.IOException)

Example 2 with PutOptions

use of aQute.bnd.service.RepositoryPlugin.PutOptions in project bnd by bndtools.

the class FileRepoTest method testBundleNotModifiedOnPut.

public void testBundleNotModifiedOnPut() throws Exception {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    File dstBundle = null;
    try {
        File srcBundle = IO.getFile("testresources/test.jar");
        byte[] srcSha = calculateHash(sha1, srcBundle);
        PutOptions options = new RepositoryPlugin.PutOptions();
        options.digest = srcSha;
        PutResult r = testRepo.put(new BufferedInputStream(new FileInputStream(srcBundle)), options);
        dstBundle = new File(r.artifact);
        assertEquals(hashToString(srcSha), hashToString(r.digest));
        assertTrue(MessageDigest.isEqual(srcSha, r.digest));
    } finally {
        if (dstBundle != null) {
            delete(dstBundle.getParentFile());
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) MessageDigest(java.security.MessageDigest) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) FileInputStream(java.io.FileInputStream)

Example 3 with PutOptions

use of aQute.bnd.service.RepositoryPlugin.PutOptions in project bnd by bndtools.

the class Project method releaseRepo.

private URI releaseRepo(RepositoryPlugin releaseRepo, String jarName, InputStream jarStream) throws Exception {
    logger.debug("release to {}", releaseRepo.getName());
    try {
        PutOptions putOptions = new RepositoryPlugin.PutOptions();
        // TODO find sub bnd that is associated with this thing
        putOptions.context = this;
        PutResult r = releaseRepo.put(jarStream, putOptions);
        logger.debug("Released {} to {} in repository {}", jarName, r.artifact, releaseRepo);
        return r.artifact;
    } catch (Exception e) {
        msgs.Release_Into_Exception_(jarName, releaseRepo, e);
        return null;
    }
}
Also used : PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) IOException(java.io.IOException)

Example 4 with PutOptions

use of aQute.bnd.service.RepositoryPlugin.PutOptions in project bnd by bndtools.

the class Project method copy.

public void copy(RepositoryPlugin source, Instructions filter, RepositoryPlugin destination) throws Exception {
    assert source != null;
    assert destination != null;
    logger.info("copy from repo {} to {} with filter {}", source, destination, filter);
    for (String bsn : source.list(null)) {
        for (Version version : source.versions(bsn)) {
            if (filter == null || filter.matches(bsn)) {
                logger.info("copy {}:{}", bsn, version);
                File file = source.get(bsn, version, null);
                if (file.getName().endsWith(".jar")) {
                    try (InputStream in = IO.stream(file)) {
                        PutOptions po = new PutOptions();
                        po.bsn = bsn;
                        po.context = null;
                        po.type = "bundle";
                        po.version = version;
                        PutResult put = destination.put(in, po);
                    } catch (Exception e) {
                        logger.error("Failed to copy {}-{}", e, bsn, version);
                        error("Failed to copy %s:%s from %s to %s, error: %s", bsn, version, source, destination, e);
                    }
                }
            }
        }
    }
}
Also used : Version(aQute.bnd.version.Version) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) IOException(java.io.IOException)

Example 5 with PutOptions

use of aQute.bnd.service.RepositoryPlugin.PutOptions in project bnd by bndtools.

the class MavenBndRepoTest method testPutRemoteSnapshot.

public void testPutRemoteSnapshot() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("releaseUrl", null);
    map.put("snapshotUrl", fnx.getBaseURI() + "/repo/");
    config(map);
    File jar = IO.getFile("testresources/snapshot.jar");
    try (Processor context = new Processor()) {
        context.setProperty("-maven-release", "remote;snapshot=1");
        PutOptions put = new PutOptions();
        put.context = context;
        PutResult r = repo.put(new FileInputStream(jar), put);
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT.jar");
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT.pom");
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT-sources.jar");
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT-javadoc.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1.pom");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1-sources.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1-javadoc.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/maven-metadata.xml");
        File f = IO.getFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/maven-metadata.xml");
        String s = IO.collect(f);
        assertTrue(s.contains("3.2.0-19700101.000000"));
    }
    try (Processor context = new Processor()) {
        context.setProperty("-maven-release", "remote;snapshot=10000");
        PutOptions put = new PutOptions();
        put.context = context;
        PutResult r = repo.put(new FileInputStream(jar), put);
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT.jar");
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT.pom");
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT-sources.jar");
        assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT-javadoc.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1.pom");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1-sources.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000000-1-javadoc.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/maven-metadata.xml");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000010-2.pom");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000010-2.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000010-2-sources.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-19700101.000010-2-javadoc.jar");
        assertIsFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/maven-metadata.xml");
        File f = IO.getFile(remote, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/maven-metadata.xml");
        String s = IO.collect(f);
        assertTrue(s.contains("<value>3.2.0-19700101.000000-1</value>"));
        assertTrue(s.contains("<value>3.2.0-19700101.000010-2</value>"));
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) FileInputStream(java.io.FileInputStream)

Aggregations

PutOptions (aQute.bnd.service.RepositoryPlugin.PutOptions)8 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)5 Processor (aQute.bnd.osgi.Processor)4 BufferedInputStream (java.io.BufferedInputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 InputStream (java.io.InputStream)2 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Version (aQute.bnd.version.Version)1 IO.getFile (aQute.lib.io.IO.getFile)1 MessageDigest (java.security.MessageDigest)1