Search in sources :

Example 6 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method getDescriptor.

/**
	 * Get a Resource Descriptor for a given bsn/version
	 * 
	 * @param bsn
	 * @param version
	 * @throws Exception
	 */
public ResourceDescriptor getDescriptor(String bsn, Version version) throws Exception {
    init();
    RevisionRef revisionRef = index.getRevisionRef(bsn, version);
    if (revisionRef == null)
        return null;
    return createResourceDescriptor(revisionRef);
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef)

Example 7 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method list.

@Override
public List<String> list(String query) throws Exception {
    init();
    Set<String> bsns = new HashSet<String>();
    if (query == null || query.trim().isEmpty())
        query = "*";
    else
        query = query.trim();
    Library.Phase phase = null;
    boolean negated = false;
    Matcher m = COMMAND_P.matcher(query);
    if (m.matches()) {
        query = m.group(1) + m.group(3);
        String cmd = m.group(2);
        if (cmd.startsWith("!")) {
            negated = true;
            cmd = cmd.substring(1);
        }
        char c = Character.toLowerCase(cmd.charAt(0));
        switch(c) {
            case 'l':
                phase = Library.Phase.LOCKED;
                break;
            case 'p':
                phase = Library.Phase.PENDING;
                break;
            case 's':
                phase = Library.Phase.STAGING;
                break;
            case 'm':
                phase = Library.Phase.MASTER;
                break;
            case 'r':
                phase = Library.Phase.RETIRED;
                break;
            case 'w':
                phase = Library.Phase.WITHDRAWN;
                break;
        }
        logger.debug("Phase is {} {}", c, phase);
    }
    Glob glob = null;
    try {
        glob = new Glob(query);
    } catch (Exception e) {
        glob = new Glob("*");
    }
    bsn: for (String bsn : index.getBsns()) {
        if (glob.matcher(bsn).matches()) {
            if (phase != null) {
                boolean hasPhase = false;
                revision: for (Version version : index.getVersions(bsn)) {
                    RevisionRef ref = index.getRevisionRef(bsn, version);
                    if (ref.phase == phase) {
                        hasPhase = true;
                        break revision;
                    }
                }
                if (hasPhase == negated)
                    continue bsn;
            }
            bsns.add(bsn);
        }
    }
    List<String> result = new ArrayList<String>(bsns);
    Collections.sort(result);
    return result;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SocketException(java.net.SocketException) IOException(java.io.IOException) RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) Glob(aQute.libg.glob.Glob) Library(aQute.service.library.Library) HashSet(java.util.HashSet)

Example 8 with RevisionRef

use of aQute.service.library.Library.RevisionRef in project bnd by bndtools.

the class Repository method getProgramActions.

/**
	 * @param bsn
	 * @param p
	 * @throws Exception
	 */
private Map<String, Runnable> getProgramActions(final String bsn, final Program p) throws Exception {
    Map<String, Runnable> map = new LinkedHashMap<String, Runnable>();
    if (p != null) {
        map.put("Inspect Program", new Runnable() {

            public void run() {
                open(url + "#!/p/osgi/" + bsn);
            }
        });
        final SortedSet<Version> versions = index.getVersions(bsn);
        if (versions.isEmpty())
            map.put("-Copy reference", null);
        else
            map.put("Copy reference", new Runnable() {

                @Override
                public void run() {
                    toClipboard(bsn, versions.first());
                }
            });
        RevisionRef ref = p.revisions.get(0);
        Version latest = toVersion(ref.baseline, ref.qualifier);
        for (Version v : index.getVersions(bsn)) {
            if (v.equals(latest)) {
                latest = null;
                break;
            }
        }
        final Version l = latest;
        String title = "Get Latest";
        if (latest == null)
            title = "-" + title;
        else
            title += " " + l + ref.phase;
        map.put(title, new Runnable() {

            public void run() {
                try {
                    add(bsn, l);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Runnable updateAction = getUpdateAction(p, bsn);
        if (updateAction != null)
            map.put("Update " + updateAction, updateAction);
        else
            map.put("-Update", null);
    } else {
        map.put("-Update (offline)", null);
    }
    map.put("Delete", new Runnable() {

        public void run() {
            try {
                delete(bsn);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
    return map;
}
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) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with RevisionRef

use of aQute.service.library.Library.RevisionRef 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 10 with RevisionRef

use of aQute.service.library.Library.RevisionRef 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)

Aggregations

RevisionRef (aQute.service.library.Library.RevisionRef)22 Version (aQute.bnd.version.Version)11 Revision (aQute.service.library.Library.Revision)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 SocketException (java.net.SocketException)5 URISyntaxException (java.net.URISyntaxException)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 Coordinate (aQute.service.library.Coordinate)4 Library (aQute.service.library.Library)4 ArrayList (java.util.ArrayList)4 Program (aQute.service.library.Library.Program)3 File (java.io.File)3 URI (java.net.URI)3 Formatter (java.util.Formatter)2 LinkedHashMap (java.util.LinkedHashMap)2 Container (aQute.bnd.build.Container)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1