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;
}
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();
}
};
}
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);
}
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;
}
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;
}
Aggregations