use of aQute.bnd.service.RepositoryPlugin 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.service.RepositoryPlugin in project bnd by bndtools.
the class RepoCommand method _list.
@Description("List all artifacts from the current repositories with their versions")
public void _list(listOptions opts) throws Exception {
logger.debug("list");
Set<String> bsns = new HashSet<String>();
Instruction from = opts.from();
if (from == null)
from = new Instruction("*");
for (RepositoryPlugin repo : repos) {
if (from.matches(repo.getName()))
bsns.addAll(repo.list(opts.query()));
}
logger.debug("list {}", bsns);
for (String bsn : new SortedList<String>(bsns)) {
if (!opts.noversions()) {
Set<Version> versions = new TreeSet<Version>();
for (RepositoryPlugin repo : repos) {
logger.debug("get {} from {}", bsn, repo);
if (from.matches(repo.getName())) {
SortedSet<Version> result = repo.versions(bsn);
if (result != null)
versions.addAll(result);
}
}
bnd.out.printf("%-40s %s%n", bsn, versions);
} else {
bnd.out.printf("%s%n", bsn);
}
}
}
use of aQute.bnd.service.RepositoryPlugin 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.service.RepositoryPlugin in project bnd by bndtools.
the class RepoCommand method _diff.
@Description("Diff jars (or show tree)")
public void _diff(diffOptions options) throws UnsupportedEncodingException, IOException, Exception {
List<String> args = options._arguments();
String newer = args.remove(0);
String older = args.size() > 0 ? args.remove(0) : null;
RepositoryPlugin rnewer = findRepo(newer);
RepositoryPlugin rolder = older == null ? null : findRepo(older);
if (rnewer == null) {
bnd.messages.NoSuchRepository_(newer);
return;
}
if (older != null && rolder == null) {
bnd.messages.NoSuchRepository_(newer);
return;
}
PrintWriter pw = IO.writer(bnd.out, UTF_8);
Tree tNewer = RepositoryElement.getTree(rnewer);
if (rolder == null) {
if (options.json())
codec.enc().to(pw).put(tNewer.serialize()).flush();
else
DiffCommand.show(pw, tNewer, 0);
} else {
Tree tOlder = RepositoryElement.getTree(rolder);
Diff diff = new DiffImpl(tNewer, tOlder);
MultiMap<String, String> map = new MultiMap<String, String>();
for (Diff bsn : diff.getChildren()) {
for (Diff version : bsn.getChildren()) {
if (version.getDelta() == Delta.UNCHANGED)
continue;
if (options.remove() == false && options.added() == false || (//
options.remove() && version.getDelta() == Delta.REMOVED) || (options.added() && version.getDelta() == Delta.ADDED)) {
map.add(bsn.getName(), version.getName());
}
}
}
if (options.json())
codec.enc().to(pw).put(map).flush();
else if (!options.diff())
bnd.printMultiMap(map);
else
DiffCommand.show(pw, diff, 0, !options.full());
}
pw.flush();
}
use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.
the class RepoCommand method _repos.
@Description("List the current repositories")
public void _repos(@SuppressWarnings("unused") reposOptions opts) {
int n = 1;
for (RepositoryPlugin repo : repos) {
String location = "";
try {
location = repo.getLocation();
} catch (Throwable e) {
// Ignore
}
bnd.out.printf("%03d: %-20s %4s %-20s %s%n", n++, repo.getName(), repo.canWrite() ? "r/w" : "r/o", Descriptors.getShortName(repo.getClass().getName()), location);
}
}
Aggregations