Search in sources :

Example 6 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 7 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 8 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)

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