Search in sources :

Example 16 with PutResult

use of aQute.bnd.service.RepositoryPlugin.PutResult 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 17 with PutResult

use of aQute.bnd.service.RepositoryPlugin.PutResult 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 18 with PutResult

use of aQute.bnd.service.RepositoryPlugin.PutResult 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

PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)18 File (java.io.File)17 FileInputStream (java.io.FileInputStream)13 BufferedInputStream (java.io.BufferedInputStream)8 PutOptions (aQute.bnd.service.RepositoryPlugin.PutOptions)7 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)6 HashMap (java.util.HashMap)6 Version (aQute.bnd.version.Version)4 Processor (aQute.bnd.osgi.Processor)3 IO.getFile (aQute.lib.io.IO.getFile)3 IOException (java.io.IOException)3 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)2 InputStream (java.io.InputStream)2 DownloadBlocker (aQute.bnd.build.DownloadBlocker)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Jar (aQute.bnd.osgi.Jar)1 JarResource (aQute.bnd.osgi.JarResource)1 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)1 DownloadListener (aQute.bnd.service.RepositoryPlugin.DownloadListener)1