Search in sources :

Example 11 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class RepoCommand method _copy.

public void _copy(CopyOptions options) throws Exception {
    List<String> args = options._arguments();
    String srcName = args.remove(0);
    String dstName = args.remove(0);
    RepositoryPlugin source = workspace.getRepository(srcName);
    RepositoryPlugin dest = workspace.getRepository(dstName);
    if (source == null) {
        bnd.error("No such source repository: %s, available repos %s", srcName, workspace.getRepositories());
    }
    if (dest == null) {
        bnd.error("No such destination repository: %s, available repos %s", dstName, workspace.getRepositories());
    } else if (!dest.canWrite())
        bnd.error("Destination repository cannot write: %s", dest);
    if (!bnd.isOk() || source == null || dest == null) {
        return;
    }
    logger.debug("src = {} -> {}", srcName, source);
    logger.debug("dst = {} -> {}", dstName, dest);
    @SuppressWarnings("unused")
    class Spec {

        DownloadBlocker src;

        DownloadBlocker dst;

        String bsn;

        Version version;

        public byte[] digest;
    }
    List<Spec> sources = new ArrayList<Spec>();
    for (String bsn : source.list(null)) {
        for (Version version : source.versions(bsn)) {
            logger.debug("src: {} {}", bsn, version);
            Spec spec = new Spec();
            spec.bsn = bsn;
            spec.version = version;
            spec.src = new DownloadBlocker(bnd);
            File src = source.get(bsn, version, null, spec.src);
            if (src == null) {
                bnd.error("No such entry: %s-%s", bsn, version);
            } else {
                spec.dst = findMatchingVersion(dest, bsn, version);
                sources.add(spec);
            }
        }
    }
    for (Spec spec : sources) {
        String reason = spec.src.getReason();
        if (reason != null) {
            bnd.error("Failed to find %s because: %s", spec.src.getFile(), reason);
        }
        File src = spec.src.getFile();
        if (!src.isFile()) {
            bnd.error("Not a valid file %s", spec.src.getFile());
        }
        spec.digest = SHA1.digest(src).digest();
    }
    //
    // See if we can prune the list by diffing
    //
    ResourceRepository resources = null;
    if (dest instanceof ResourceRepository)
        resources = (ResourceRepository) dest;
    nextFile: for (Iterator<Spec> i = sources.iterator(); i.hasNext(); ) {
        Spec spec = i.next();
        if (resources != null) {
            ResourceDescriptor rd = resources.getResourceDescriptor(spec.digest);
            if (rd != null)
                // Already exists
                continue nextFile;
        }
    // TODO Diff
    }
    if (!bnd.isOk())
        return;
    for (Spec spec : sources) {
        File src = spec.src.getFile();
        if (!options.dry()) {
            try (InputStream fin = IO.stream(src)) {
                PutResult put = dest.put(fin, null);
                if (put.digest != null) {
                    if (!Arrays.equals(spec.digest, put.digest)) {
                        bnd.error("Digest error in upload %s", src);
                    }
                }
            } catch (Exception e) {
                bnd.exception(e, "Exception %s in upload %s", e, src);
            }
        }
    }
    for (String bsn : source.list(null)) {
        for (Version version : source.versions(bsn)) {
            System.out.println(bsn + ";version=" + version);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) DownloadBlocker(aQute.bnd.build.DownloadBlocker) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Version(aQute.bnd.version.Version) Iterator(java.util.Iterator) ResourceRepository(aQute.bnd.service.repository.ResourceRepository) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 12 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class RepoCommand method findMatchingVersion.

private DownloadBlocker findMatchingVersion(RepositoryPlugin dest, String bsn, Version version) throws Exception {
    Version floor = version.getWithoutQualifier();
    Version ceiling = new Version(floor.getMajor() + 1, 0, 0);
    VersionRange range = new VersionRange(true, floor, ceiling, false);
    SortedSet<Version> versions = dest.versions(bsn);
    if (versions == null || versions.isEmpty())
        return null;
    for (Version v : range.filter(versions)) {
    // First one is highest
    // TODO Diff
    }
    return null;
}
Also used : Version(aQute.bnd.version.Version) VersionRange(aQute.bnd.version.VersionRange)

Example 13 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class MavenVersionTest method testNull.

public void testNull() {
    MavenVersion mv = MavenVersion.parseString(null);
    assertEquals(new Version(0, 0, 0), mv.getOSGiVersion());
    assertFalse(mv.isSnapshot());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion)

Example 14 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class ProjectTest method testBumpIncludeFile.

public void testBumpIncludeFile() throws Exception {
    Workspace ws = getWorkspace("testresources/ws");
    Project project = ws.getProject("bump-included");
    project.setTrace(true);
    Version old = new Version(project.getProperty("Bundle-Version"));
    assertEquals(new Version(1, 0, 0), old);
    project.bump("=+0");
    Processor processor = new Processor();
    processor.setProperties(project.getFile("include.txt"));
    Version newv = new Version(processor.getProperty("Bundle-Version"));
    System.err.println("New version " + newv);
    assertEquals(1, newv.getMajor());
    assertEquals(1, newv.getMinor());
    assertEquals(0, newv.getMicro());
}
Also used : Project(aQute.bnd.build.Project) Processor(aQute.bnd.osgi.Processor) Version(aQute.bnd.version.Version) Workspace(aQute.bnd.build.Workspace)

Example 15 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class ProjectTest method testBump.

public void testBump() throws Exception {
    Workspace ws = getWorkspace("testresources/ws");
    Project project = ws.getProject("p1");
    int size = project.getProperties().size();
    Version old = new Version(project.getProperty("Bundle-Version"));
    System.err.println("Old version " + old);
    project.bump("=+0");
    Version newv = new Version(project.getProperty("Bundle-Version"));
    System.err.println("New version " + newv);
    assertEquals(old.getMajor(), newv.getMajor());
    assertEquals(old.getMinor() + 1, newv.getMinor());
    assertEquals(0, newv.getMicro());
    assertEquals(size, project.getProperties().size());
    assertEquals("sometime", newv.getQualifier());
}
Also used : Project(aQute.bnd.build.Project) Version(aQute.bnd.version.Version) Workspace(aQute.bnd.build.Workspace)

Aggregations

Version (aQute.bnd.version.Version)168 File (java.io.File)64 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)27 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)19 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Jar (aQute.bnd.osgi.Jar)16 Workspace (aQute.bnd.build.Workspace)13 Project (aQute.bnd.build.Project)12 RevisionRef (aQute.service.library.Library.RevisionRef)12 Matcher (java.util.regex.Matcher)12 Parameters (aQute.bnd.header.Parameters)11 VersionRange (aQute.bnd.version.VersionRange)11 SortedList (aQute.lib.collections.SortedList)9 Processor (aQute.bnd.osgi.Processor)8 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)8 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8