Search in sources :

Example 51 with Version

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

the class Index method addRevision.

public boolean addRevision(Library.RevisionRef ref) throws Exception {
    init();
    Version v = toVersion(ref.baseline, ref.qualifier);
    TreeMap<Version, Library.RevisionRef> map = cache.get(ref.bsn);
    if (map == null) {
        map = new TreeMap<Version, Library.RevisionRef>();
        cache.put(ref.bsn, map);
    }
    map.put(v, ref);
    dirty = true;
    repo.revisionRefs.add(ref);
    return true;
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version)

Example 52 with Version

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

the class Repository method getUpdateAction.

/**
	 * Update a bsn
	 * 
	 * @throws Exception
	 */
Runnable getUpdateAction(Program program, String bsn) throws Exception {
    final List<Runnable> update = new ArrayList<Runnable>();
    for (Version v : index.getVersions(bsn)) {
        RevisionRef resource = index.getRevisionRef(bsn, v);
        Runnable updateAction = getUpdateAction(program, resource);
        if (updateAction != null)
            update.add(updateAction);
    }
    if (update.isEmpty())
        return null;
    return new Runnable() {

        @Override
        public void run() {
            for (Runnable r : update) {
                r.run();
            }
        }

        @Override
        public String toString() {
            return update.toString();
        }
    };
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) Version(aQute.bnd.version.Version) ArrayList(java.util.ArrayList)

Example 53 with Version

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

the class Repository method update.

/**
	 * Compare a list of versions against the available versions and return the
	 * desired list. This will remove all staged version that are 'below' a
	 * master.
	 */
public SortedSet<Version> update(SortedSet<Version> input, Program p) throws Exception {
    Map<Version, Version> mapped = new HashMap<Version, Version>();
    for (RevisionRef ref : p.revisions) {
        Version a = toVersion(ref.baseline, ref.qualifier);
        Version mask = mask(a);
        Version highest = mapped.get(mask);
        if (highest == null || a.compareTo(highest) > 0 || ref.phase == Library.Phase.MASTER)
            mapped.put(mask, a);
    }
    HashSet<Version> output = new HashSet<Version>();
    for (Version i : input) {
        Version mask = mask(i);
        Version found = mapped.get(mask);
        if (found != null)
            output.add(found);
        else
            reporter.error("[update] Missing version %s for bsn %s", mask, p.last.bsn);
    }
    return new SortedList<Version>(output);
}
Also used : RevisionRef(aQute.service.library.Library.RevisionRef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Version(aQute.bnd.version.Version) SortedList(aQute.lib.collections.SortedList) HashSet(java.util.HashSet)

Example 54 with Version

use of aQute.bnd.version.Version 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 55 with Version

use of aQute.bnd.version.Version 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)

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