use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class RepoResourceUtils method narrowVersionsByVersionRange.
public static List<Resource> narrowVersionsByVersionRange(SortedMap<Version, Resource> versionMap, String rangeStr) {
List<Resource> result;
if (aQute.bnd.osgi.Constants.VERSION_ATTR_LATEST.equals(rangeStr)) {
Version highest = versionMap.lastKey();
result = Create.list(versionMap.get(highest));
} else {
VersionRange range = rangeStr != null ? new VersionRange(rangeStr) : null;
// optimisation: skip versions definitely less than the range
if (range != null && range.getLow() != null)
versionMap = versionMap.tailMap(range.getLow());
result = new ArrayList<Resource>(versionMap.size());
for (Entry<Version, Resource> entry : versionMap.entrySet()) {
Version version = entry.getKey();
if (range == null || range.includes(version))
result.add(entry.getValue());
// optimisation: skip versions definitely higher than the range
if (range != null && range.isRange() && version.compareTo(range.getHigh()) >= 0)
break;
}
}
return result;
}
use of aQute.bnd.version.VersionRange in project bndtools by bndtools.
the class PackageSearchPanel method validate.
private void validate() {
try {
String filter = null;
if (packageName == null || packageName.trim().isEmpty()) {
setError(null);
setRequirement(null);
return;
}
VersionRange versionRange = null;
if (versionRangeStr != null && versionRangeStr.trim().length() > 0) {
try {
versionRange = new VersionRange(versionRangeStr);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid version range: " + e.getMessage());
}
}
filter = formatPackageRequirement(packageName, versionRange);
if (filter != null)
setRequirement(new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE).addDirective(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter).buildSyntheticRequirement());
setError(null);
} catch (Exception e) {
setError(e.getMessage());
setRequirement(null);
}
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class RunconfigToDistributionTask method execute.
@Override
public void execute() throws BuildException {
try {
createReleaseDir();
BndEditModel model = new BndEditModel();
model.loadFrom(bndFile);
Project bndProject = new Project(new Workspace(rootDir), buildProject, bndFile);
List<RepositoryPlugin> repositories = bndProject.getPlugins(RepositoryPlugin.class);
if (allowSnapshots) {
snapshots = indexBundleSnapshots();
}
for (VersionedClause runBundle : model.getRunBundles()) {
String bsn = runBundle.getName();
if (bsn.endsWith(".jar")) {
bsn = bsn.substring(0, bsn.indexOf(".jar"));
}
if (allowSnapshots && snapshots.containsKey(bsn)) {
Jar jar = snapshots.get(bsn);
jar.write(new File(outputDir, jar.getName() + "-" + jar.getVersion() + ".jar"));
} else {
Version version = null;
File foundJar = null;
for (RepositoryPlugin repo : repositories) {
SortedSet<Version> versions = repo.versions(bsn);
for (Version availableVersion : versions) {
VersionRange range = null;
if (runBundle.getVersionRange() != null && !runBundle.getVersionRange().equals(Constants.VERSION_ATTR_LATEST)) {
range = new VersionRange(runBundle.getVersionRange());
}
boolean rangeMatches = range == null || range.includes(availableVersion);
boolean availableMatches = version == null || availableVersion.compareTo(version) > 0;
if (rangeMatches && availableMatches) {
version = availableVersion;
foundJar = repo.get(bsn, version, null);
}
}
}
if (foundJar != null) {
File outputFile = new File(outputDir, foundJar.getName());
Files.copy(foundJar.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else {
log(bsn + " could not be found in any repository");
}
}
}
bndProject.close();
} catch (Exception e) {
e.printStackTrace();
throw new BuildException(e);
}
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class RepoCommand method _get.
/**
* get a file from the repo
*
* @param opts
*/
@Description("Get an artifact from a repository.")
public void _get(getOptions opts) throws Exception {
Instruction from = opts.from();
if (from == null)
from = new Instruction("*");
List<String> args = opts._arguments();
if (args.isEmpty()) {
bnd.error("Get needs at least a bsn");
return;
}
String bsn = args.remove(0);
String range = null;
if (!args.isEmpty()) {
range = args.remove(0);
if (!args.isEmpty()) {
bnd.error("Extra args %s", args);
}
}
VersionRange r = new VersionRange(range == null ? "0" : range);
Map<Version, RepositoryPlugin> index = new HashMap<Version, RepositoryPlugin>();
for (RepositoryPlugin repo : repos) {
if (from.matches(repo.getName())) {
SortedSet<Version> versions = repo.versions(bsn);
if (versions != null)
for (Version v : versions) {
if (r.includes(v))
index.put(v, repo);
}
}
}
SortedList<Version> l = new SortedList<Version>(index.keySet());
if (l.isEmpty()) {
bnd.out.printf("No versions found for %s%n", bsn);
return;
}
Version v;
if (opts.lowest())
v = l.first();
else
v = l.last();
RepositoryPlugin repo = index.get(v);
File file = repo.get(bsn, v, null);
File dir = bnd.getBase();
String name = file.getName();
if (opts.output() != null) {
File f = bnd.getFile(opts.output());
if (f.isDirectory())
dir = f;
else {
dir = f.getParentFile();
name = f.getName();
}
}
IO.mkdirs(dir);
IO.copy(file, new File(dir, name));
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class WorkspaceRepository method matchVersion.
private boolean matchVersion(String range, Version version, boolean exact) {
if (range == null || range.trim().length() == 0)
return true;
VersionRange vr = new VersionRange(range);
boolean result;
if (exact) {
if (vr.isRange())
result = false;
else
result = vr.getHigh().equals(version);
} else {
result = vr.includes(version);
}
return result;
}
Aggregations