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