use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class ResolutionWizard method resourceToRunBundle.
private static VersionedClause resourceToRunBundle(Resource resource) {
Capability idCap = ResourceUtils.getIdentityCapability(resource);
String identity = ResourceUtils.getIdentity(idCap);
// Map version range string, using "latest" for any workspace resources
Attrs attribs = new Attrs();
String versionRangeStr;
if (isWorkspace(resource)) {
versionRangeStr = VERSION_SNAPSHOT;
} else {
Version version = ResourceUtils.getVersion(idCap);
VersionRange versionRange = createVersionRange(version);
versionRangeStr = versionRange.toString();
}
attribs.put(Constants.VERSION_ATTRIBUTE, versionRangeStr);
return new VersionedClause(identity, attribs);
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class EnrouteProjectTemplate method generateBndFile.
private Resource generateBndFile(String projectName, String pkg) {
BndEditModel model = new BndEditModel();
model.setPrivatePackages(Arrays.asList(new String[] { pkg + ".provider" }));
model.setExportedPackages(Arrays.asList(new ExportedPackage(projectName + ".api", new Attrs())));
model.setBundleDescription("${warning:please explain what this bundle does}");
model.setBundleVersion("1.0.0.${tstamp}");
List<VersionedClause> buildPath = new ArrayList<VersionedClause>();
List<VersionedClause> tmp;
tmp = model.getBuildPath();
if (tmp != null)
buildPath.addAll(tmp);
Attrs attrs = new Attrs();
attrs.put("version", "@1.0");
buildPath.add(new VersionedClause("osgi.enroute.base.api", attrs));
buildPath.add(new VersionedClause("osgi.enroute.base.junit", attrs));
model.setBuildPath(buildPath);
Document doc = new Document("");
model.saveChangesTo(doc);
StringResource bndBndResource = new StringResource(doc.get());
return bndBndResource;
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class RunRequirementsPart method doAddBundle.
private void doAddBundle() {
try {
RepoBundleSelectionWizard wizard = new RepoBundleSelectionWizard(new ArrayList<VersionedClause>(), DependencyPhase.Run);
wizard.setSelectionPageTitle("Add Bundle Requirement");
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<VersionedClause> result = wizard.getSelectedBundles();
Set<Requirement> adding = new LinkedHashSet<Requirement>(result.size());
for (VersionedClause bundle : result) {
Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bundle.getName());
String versionRange = bundle.getVersionRange();
if (versionRange != null && !"latest".equals(versionRange)) {
filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
}
Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
adding.add(req);
}
updateViewerWithNewRequirements(adding);
}
} catch (Exception e) {
ErrorDialog.openError(getSection().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error selecting bundles.", e));
}
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class RunBlacklistPart method doAddBundle.
private void doAddBundle() {
try {
RepoBundleSelectionWizard wizard = new RepoBundleSelectionWizard(new ArrayList<VersionedClause>(), DependencyPhase.Run);
wizard.setSelectionPageTitle("Add Bundle Blacklist");
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<VersionedClause> result = wizard.getSelectedBundles();
Set<Requirement> adding = new LinkedHashSet<Requirement>(result.size());
for (VersionedClause bundle : result) {
Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bundle.getName());
String versionRange = bundle.getVersionRange();
if (versionRange != null && !"latest".equals(versionRange)) {
filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
}
Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
adding.add(req);
}
updateViewerWithNewBlacklist(adding);
}
} catch (Exception e) {
ErrorDialog.openError(getSection().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error selecting bundles for blacklist.", e));
}
}
use of aQute.bnd.build.model.clauses.VersionedClause 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);
}
}
Aggregations