Search in sources :

Example 76 with Version

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

the class Macro method version.

String version(Version version, String mask) {
    if (version == null) {
        String v = domain.getProperty("@");
        if (v == null) {
            return LITERALVALUE;
        }
        version = new Version(v);
    }
    StringBuilder sb = new StringBuilder();
    String del = "";
    for (int i = 0; i < mask.length(); i++) {
        char c = mask.charAt(i);
        String result = null;
        if (c != '~') {
            if (i == 3) {
                result = version.getQualifier();
                MavenVersion mv = new MavenVersion(version);
                if (c == 'S') {
                    // we have a request for a Maven snapshot
                    if (mv.isSnapshot())
                        return sb.append("-SNAPSHOT").toString();
                } else if (c == 's') {
                    // we have a request for a Maven snapshot
                    if (mv.isSnapshot())
                        return sb.append("-SNAPSHOT").toString();
                    else
                        return sb.toString();
                }
            } else if (Character.isDigit(c)) {
                // Handle masks like +00, =+0
                result = String.valueOf(c);
            } else {
                int x = version.get(i);
                switch(c) {
                    case '+':
                        x++;
                        break;
                    case '-':
                        x--;
                        break;
                    case '=':
                        break;
                }
                result = Integer.toString(x);
            }
            if (result != null) {
                sb.append(del);
                del = ".";
                sb.append(result);
            }
        }
    }
    return sb.toString();
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion)

Example 77 with Version

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

the class Jar method getTimelessDigest.

public byte[] getTimelessDigest() throws Exception {
    check();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    OutputStream dout = new DigestOutputStream(IO.nullStream, md);
    // dout = System.out;
    Manifest m = getManifest();
    if (m != null) {
        Manifest m2 = new Manifest(m);
        Attributes main = m2.getMainAttributes();
        String lastmodified = (String) main.remove(new Attributes.Name(Constants.BND_LASTMODIFIED));
        String version = main.getValue(new Attributes.Name(Constants.BUNDLE_VERSION));
        if (version != null && Verifier.isVersion(version)) {
            Version v = new Version(version);
            main.putValue(Constants.BUNDLE_VERSION, v.getWithoutQualifier().toString());
        }
        writeManifest(m2, dout);
        for (Map.Entry<String, Resource> entry : getResources().entrySet()) {
            String path = entry.getKey();
            if (path.equals(manifestName))
                continue;
            Resource resource = entry.getValue();
            dout.write(path.getBytes(UTF_8));
            resource.write(dout);
        }
    }
    return md.digest();
}
Also used : Version(aQute.bnd.version.Version) DigestOutputStream(java.security.DigestOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) DigestOutputStream(java.security.DigestOutputStream) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Attributes(java.util.jar.Attributes) MessageDigest(java.security.MessageDigest) Manifest(java.util.jar.Manifest) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 78 with Version

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

the class Macro method _version.

public String _version(String[] args) {
    verifyCommand(args, _versionHelp, null, 2, 3);
    String mask = args[1];
    Version version = null;
    if (args.length >= 3) {
        if (isLocalTarget(args[2]))
            return LITERALVALUE;
        version = Version.parseVersion(args[2]);
    }
    return version(version, mask);
}
Also used : Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion)

Example 79 with Version

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

the class AgainstNexusTest method testBasic.

public void testBasic() throws Exception {
    if (skip)
        return;
    config(null);
    assertEquals("[group:artifact]", repo.list(null).toString());
    assertEquals("[1.0.0.SNAPSHOT]", repo.versions("group:artifact").toString());
    File f = repo.get("group:artifact", new Version("1.0.0.SNAPSHOT"), null);
    assertEquals(1497, f.length());
    System.out.println(f);
}
Also used : Version(aQute.bnd.version.Version) File(java.io.File)

Example 80 with Version

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

the class TestWrapper method augmentTest.

private void augmentTest(InfoRepository repo) throws Exception, IOException {
    assertNotNull(repo.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
    InfoRepositoryWrapper iw = new InfoRepositoryWrapper(tmp, Collections.singleton(repo));
    Properties augments = new UTF8Properties();
    augments.load(new StringReader("biz.aQute.jpm.daemon: cap=test;test=1\n"));
    iw.addAugment(augments);
    //
    // Get the test and identity capability
    //
    Requirement testreq = new CapReqBuilder("test").filter("(test=1)").buildSyntheticRequirement();
    Requirement identity = new CapReqBuilder("osgi.identity").filter("(osgi.identity=biz.aQute.jpm.daemon)").buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> result = iw.findProviders(Arrays.asList(testreq, identity));
    assertNotNull(result);
    assertEquals(2, result.size());
    //
    // Test if they come from the same resource
    //
    Capability testcap = result.get(testreq).iterator().next();
    Capability identitycap = result.get(identity).iterator().next();
    assertNotNull(testcap);
    assertNotNull(identitycap);
    assertEquals(testcap.getResource(), identitycap.getResource());
    iw.close();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) StringReader(java.io.StringReader) Collection(java.util.Collection) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Aggregations

Version (aQute.bnd.version.Version)171 File (java.io.File)67 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)29 ArrayList (java.util.ArrayList)21 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)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