use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class Verifier method verifyImports.
/**
* Verify that the imports properly use version ranges.
*/
private void verifyImports() {
if (isStrict()) {
Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE));
Set<String> noimports = new HashSet<String>();
Set<String> toobroadimports = new HashSet<String>();
for (Entry<String, Attrs> e : map.entrySet()) {
String version = e.getValue().get(Constants.VERSION_ATTRIBUTE);
if (version == null) {
if (!e.getKey().startsWith("javax.")) {
noimports.add(e.getKey());
}
} else {
if (!VERSIONRANGE.matcher(version).matches()) {
Location location = error("Import Package %s has an invalid version range syntax %s", e.getKey(), version).location();
location.header = Constants.IMPORT_PACKAGE;
location.context = e.getKey();
} else {
try {
VersionRange range = new VersionRange(version);
if (!range.isRange()) {
toobroadimports.add(e.getKey());
}
if (range.includeHigh() == false && range.includeLow() == false && range.getLow().equals(range.getHigh())) {
Location location = error("Import Package %s has an empty version range syntax %s, likely want to use [%s,%s]", e.getKey(), version, range.getLow(), range.getHigh()).location();
location.header = Constants.IMPORT_PACKAGE;
location.context = e.getKey();
}
// TODO check for exclude low, include high?
} catch (Exception ee) {
Location location = exception(ee, "Import Package %s has an invalid version range syntax %s: %s", e.getKey(), version, ee).location();
location.header = Constants.IMPORT_PACKAGE;
location.context = e.getKey();
}
}
}
}
if (!noimports.isEmpty()) {
Location location = error("Import Package clauses without version range (excluding javax.*): %s", noimports).location();
location.header = Constants.IMPORT_PACKAGE;
}
if (!toobroadimports.isEmpty()) {
Location location = error("Import Package clauses which use a version instead of a version range. This imports EVERY later package and not as many expect until the next major number: %s", toobroadimports).location();
location.header = Constants.IMPORT_PACKAGE;
}
}
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class LocalIndexedRepo method actions.
public Map<String, Runnable> actions(Object... target) throws Exception {
Map<String, Runnable> map = new HashMap<String, Runnable>();
map.put("Refresh", new Runnable() {
public void run() {
regenerateAllIndexes();
}
});
if (target.length == 3) {
String bsn = (String) target[1];
String version = (String) target[2];
@SuppressWarnings("deprecation") aQute.bnd.filerepo.FileRepo storageRepo = new aQute.bnd.filerepo.FileRepo(storageDir);
@SuppressWarnings("deprecation") final File f = storageRepo.get(bsn, new VersionRange(version, version), 0);
if (f != null) {
map.put("Delete", new Runnable() {
public void run() {
deleteEntry(f);
regenerateAllIndexes();
}
private void deleteEntry(final File f) {
File parent = f.getParentFile();
IO.delete(f);
File[] listFiles = parent.listFiles();
if (listFiles.length == 1 && listFiles[0].getName().endsWith("-latest.jar"))
IO.delete(listFiles[0]);
listFiles = parent.listFiles();
if (listFiles.length == 0)
IO.delete(parent);
}
});
}
}
return map;
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class AbstractIndexedRepo method findExactMatch.
ResourceHandle findExactMatch(String identity, String version) throws Exception {
VersionRange range = new VersionRange(version);
if (range.isRange())
return null;
Resource resource = identityMap.getExact(identity, range.getLow());
if (resource == null)
return null;
return mapResourceToHandle(resource);
}
use of aQute.bnd.version.VersionRange in project bndtools by bndtools.
the class BndBuilderCapReqLoader method createVersionFilter.
private static final String createVersionFilter(String ns, String value, String rangeStr, String versionAttr) {
SimpleFilter pkgNameFilter = new SimpleFilter(ns, value);
Filter filter = pkgNameFilter;
if (rangeStr != null) {
VersionRange range = new VersionRange(rangeStr);
Filter left;
if (range.includeLow())
left = new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, range.getLow().toString());
else
left = new NotFilter(new SimpleFilter(versionAttr, Operator.LessThanOrEqual, range.getLow().toString()));
Filter right;
if (!range.isRange())
right = null;
else if (range.includeHigh())
right = new SimpleFilter(versionAttr, Operator.LessThanOrEqual, range.getHigh().toString());
else
right = new NotFilter(new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, range.getHigh().toString()));
AndFilter combined = new AndFilter().addChild(pkgNameFilter).addChild(left);
if (right != null)
combined.addChild(right);
filter = combined;
}
return filter.toString();
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class RepoCommand method findMatchingVersion.
private DownloadBlocker findMatchingVersion(RepositoryPlugin dest, String bsn, Version version) throws Exception {
Version floor = version.getWithoutQualifier();
Version ceiling = new Version(floor.getMajor() + 1, 0, 0);
VersionRange range = new VersionRange(true, floor, ceiling, false);
SortedSet<Version> versions = dest.versions(bsn);
if (versions == null || versions.isEmpty())
return null;
for (Version v : range.filter(versions)) {
// First one is highest
// TODO Diff
}
return null;
}
Aggregations