Search in sources :

Example 56 with Version

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

the class Repository method getUpdateAction.

/**
	 * Find a RevisionRef from the Program. We are looking for a version with
	 * the same baseline but a higher qualifier or different phase.
	 * 
	 * @param p
	 * @param currentVersion
	 * @throws Exception
	 */
private Runnable getUpdateAction(Program program, final RevisionRef current) throws Exception {
    RevisionRef candidateRef = null;
    Version candidate = toVersion(current.baseline, current.qualifier);
    for (RevisionRef r : program.revisions) {
        Version refVersion = toVersion(r.baseline, r.qualifier);
        if (eq(r.classifier, current.classifier)) {
            if (refVersion.compareTo(candidate) >= 0) {
                candidate = refVersion;
                candidateRef = r;
            }
        }
    }
    if (candidateRef == null)
        //
        return new Runnable() {

            @Override
            public void run() {
                try {
                    index.delete(current.bsn, toVersion(current.baseline, current.qualifier));
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            public String toString() {
                return "[delete]";
            }
        };
    //
    if (!candidateRef.version.equals(current.version)) {
        final RevisionRef toAdd = candidateRef;
        return new Runnable() {

            //
            // Replace the current version
            //
            public void run() {
                try {
                    index.delete(current.bsn, toVersion(current.baseline, current.qualifier));
                    index.addRevision(toAdd);
                    index.save();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            public String toString() {
                return toAdd.version;
            }
        };
    }
    //
    if (candidateRef.phase != current.phase) {
        final RevisionRef toChange = candidateRef;
        return new Runnable() {

            @Override
            public void run() {
                try {
                    index.delete(current.bsn, toVersion(current.baseline, current.qualifier));
                    index.addRevision(toChange);
                    index.save();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            public String toString() {
                return "-> " + toChange.phase;
            }
        };
    }
    return null;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 57 with Version

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

the class Repository method add.

void add(RevisionRef ref) throws Exception {
    // Cleanup existing versions
    // We remove everything between [mask(v), v)
    Version newVersion = toVersion(ref.baseline, ref.qualifier);
    logger.debug("New version {} {}", ref.bsn, newVersion);
    Version newMask = mask(newVersion);
    List<Version> toBeDeleted = new ArrayList<Version>();
    for (Version existingVersion : index.getVersions(ref.bsn)) {
        Version existingMask = mask(existingVersion);
        if (newMask.equals(existingMask)) {
            logger.debug("delete {}-{}", ref.bsn, existingVersion);
            toBeDeleted.add(existingVersion);
        }
    }
    for (Version v : toBeDeleted) index.delete(ref.bsn, v);
    logger.debug("add {}-{}", ref.bsn, newVersion);
    index.addRevision(ref);
    getLocal(ref, null, new LocalDownloadListener());
    if (index.isRecurse()) {
        Iterable<RevisionRef> refs = getClosure(ref);
        for (RevisionRef r : refs) {
            index.addRevision(r);
            getLocal(ref, null, new LocalDownloadListener());
        }
    }
    index.save();
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) ArrayList(java.util.ArrayList)

Example 58 with Version

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

the class Repository method getRevisionRef.

/**
	 * Find a revisionref for a bsn/version
	 * 
	 * @param bsn
	 * @param version
	 * @throws Exception
	 */
private RevisionRef getRevisionRef(String bsn, Version version) throws Exception {
    // Handle when we have a sha reference
    String id = bsn + "-" + version;
    if (notfoundref.contains(id))
        return null;
    if (isSha(bsn) && version.equals(Version.LOWEST)) {
        Revision r = getRevision(new Coordinate(bsn));
        if (r == null)
            return null;
        return new RevisionRef(r);
    }
    logger.debug("Looking for {}-{}", bsn, version);
    for (RevisionRef r : getRevisionRefs(bsn)) {
        Version v = toVersion(r.baseline, r.qualifier);
        if (v.equals(version))
            return r;
    }
    notfoundref.add(id);
    return null;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Revision(aQute.service.library.Library.Revision) Coordinate(aQute.service.library.Coordinate) Version(aQute.bnd.version.Version)

Example 59 with Version

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

the class Repository method title.

@Override
public String title(Object... target) throws Exception {
    init();
    if (target == null || target.length == 0)
        return getName();
    if (target.length == 1 && target[0] instanceof String) {
        String bsn = (String) target[0];
        String title = bsn;
        if (bsn.indexOf("__") > 0)
            title += " [!]";
        return title;
    }
    if (target.length == 2 && target[0] instanceof String && target[1] instanceof Version) {
        String bsn = (String) target[0];
        Version version = (Version) target[1];
        Library.RevisionRef resource = index.getRevisionRef(bsn, version);
        if (resource == null)
            return "[deleted " + version + "]";
        String title = getPhase(resource.phase.toString()) + " " + version.toString();
        File path = getCache().getPath(bsn, version.toString(), resource.revision);
        if (path.isFile() && path.length() == resource.size) {
            title += DOWN_ARROW;
        }
        if (getCache().getPath(bsn, version.toString(), resource.revision, true).isFile())
            title += "+";
        return title;
    }
    return null;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) Library(aQute.service.library.Library) File(java.io.File)

Example 60 with Version

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

the class GenericResolveContextResolveTest method getResource.

private static Resource getResource(Set<Resource> resources, String bsn, String versionString) {
    for (Resource resource : resources) {
        List<Capability> identities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
        if (identities != null && identities.size() == 1) {
            Capability idCap = identities.get(0);
            Object id = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
            Object version = idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            if (bsn.equals(id)) {
                if (versionString == null) {
                    return resource;
                }
                Version requested = Version.parseVersion(versionString);
                Version current;
                if (version instanceof Version) {
                    current = (Version) version;
                } else {
                    current = Version.parseVersion("" + version);
                }
                if (requested.equals(current)) {
                    return resource;
                }
            }
        }
    }
    return null;
}
Also used : Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) Resource(org.osgi.resource.Resource)

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