use of aQute.bnd.version.Version in project bnd by bndtools.
the class ResourceUtils method toVersionClause.
/**
* Create a VersionedClause by applying a version range mask to the
* resource! Masks are defined by
* {@link aQute.bnd.osgi.Macro#_range(String[])}. If the resource should
* represent a project in the bnd workspace, then instead the VersionClause
* will refer to it as a snapshot version: e.g. <bsn>;version=snapshot
*/
public static VersionedClause toVersionClause(Resource resource, String mask) {
Capability idCap = getIdentityCapability(resource);
String identity = getIdentity(idCap);
String versionString;
if (resource.getCapabilities(WORKSPACE_NAMESPACE).isEmpty()) {
Macro macro = new Macro(new Processor());
Version version = getVersion(idCap);
versionString = macro._range(new String[] { "range", mask, version.toString() });
} else {
versionString = "snapshot";
}
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, versionString);
return new VersionedClause(identity, attribs);
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class ResourceUtils method toVersion.
public static Version toVersion(Object v) {
if (v instanceof Version)
return (Version) v;
if (v instanceof org.osgi.framework.Version) {
org.osgi.framework.Version o = (org.osgi.framework.Version) v;
String q = o.getQualifier();
return q.isEmpty() ? new Version(o.getMajor(), o.getMinor(), o.getMicro()) : new Version(o.getMajor(), o.getMinor(), o.getMicro(), q);
}
if (v instanceof String) {
if (!Version.isVersion((String) v))
return null;
return new Version((String) v);
}
return null;
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class Index method delete.
public boolean delete(String bsn, Version v) throws Exception {
init();
Map<Version, Library.RevisionRef> map = cache.get(bsn);
if (map != null) {
try {
Library.RevisionRef removed = map.remove(v);
if (removed != null) {
for (Iterator<RevisionRef> i = repo.revisionRefs.iterator(); i.hasNext(); ) {
RevisionRef other = i.next();
if (Arrays.equals(other.revision, removed.revision)) {
i.remove();
}
}
repo.revisionRefs.remove(removed);
dirty = true;
return true;
}
} finally {
if (map.isEmpty())
cache.remove(bsn);
}
}
return false;
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class Index method getRevisionRef.
@SuppressWarnings("deprecation")
public Library.RevisionRef getRevisionRef(String bsn, Version version) throws Exception {
init();
Map<Version, Library.RevisionRef> map = cache.get(bsn);
if (map == null)
return null;
// Fixup the change from ref.url to ref.urls ...
boolean save = false;
RevisionRef ref = map.get(version);
if (ref == null) {
return null;
}
if (ref.urls.isEmpty() && ref.url != null) {
ref.urls.add(ref.url);
ref.url = null;
save = true;
}
if (Boolean.getBoolean("jpm4j.in.test") == false) {
for (Iterator<URI> i = ref.urls.iterator(); i.hasNext(); ) {
URI uri = i.next();
if (uri.getScheme().equalsIgnoreCase("file")) {
i.remove();
save = true;
}
}
}
if (save)
save();
return ref;
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class Index method init.
private void init() throws Exception {
if (repo == null) {
cache = new TreeMap<String, TreeMap<Version, Library.RevisionRef>>();
if (indexFile.isFile() && indexFile.length() > 100) {
try (Decoder dec = codec.dec()) {
repo = dec.from(indexFile).get(new TypeReference<Repo>() {
});
for (Library.RevisionRef r : repo.revisionRefs) {
TreeMap<Version, Library.RevisionRef> map = cache.get(r.bsn);
if (map == null) {
map = new TreeMap<Version, Library.RevisionRef>(Collections.reverseOrder());
cache.put(r.bsn, map);
}
Version v = toVersion(r.baseline, r.qualifier);
map.put(v, r);
}
}
} else {
repo = new Repo();
}
}
}
Aggregations