@Override
public void execute() throws BuildException {
try {
createReleaseDir();
Project bndProject = new Project(new Workspace(rootDir), buildProject, bndFile);
List<RepositoryPlugin> repositories = bndProject.getPlugins(RepositoryPlugin.class);
if (allowSnapshots) {
snapshots = indexBundleSnapshots();
}
for (Container runBundle : bndProject.getRunbundles()) {
String bsn = runBundle.getBundleSymbolicName();
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, runBundle.getFile().getName()));
} else {
Version version = null;
File foundJar = null;
for (RepositoryPlugin repo : repositories) {
SortedSet<Version> versions = repo.versions(bsn);
if (!versions.isEmpty()) {
Version foundVersion = versions.last();
if (version == null || foundVersion.compareTo(version) == 1) {
version = foundVersion;
foundJar = repo.get(bsn, version, null);
}
}
}
if (foundJar != null) {
File outputFile = new File(outputDir, foundJar.getName());
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(foundJar).getChannel();
destination = new FileOutputStream(outputFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
} else {
log(bsn + " could not be found in any repository");
}
}
}
bndProject.close();
}
catch (Exception e) {
e.printStackTrace();
}
}