use of aQute.bnd.osgi.resource.CapReqBuilder 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.osgi.resource.CapReqBuilder 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.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class ValidatorTest method testMultipleSameRequirements.
public void testMultipleSameRequirements() throws Exception {
try (ResolverValidator validator = new ResolverValidator()) {
ResourceBuilder system = new ResourceBuilder();
system.addEE(EE.JavaSE_1_8);
CapReqBuilder b1 = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
b1.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, "javax.script");
system.addCapability(b1.buildSyntheticCapability());
CapReqBuilder b2 = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
b2.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, "javax.script");
system.addCapability(b2.buildSyntheticCapability());
CapReqBuilder b3 = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
b3.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, "javax.script");
b3.addAttribute("version", "1.2");
system.addCapability(b3.buildSyntheticCapability());
system.addManifest(OSGI_CORE.R6_0_0.getManifest());
validator.setSystem(system.build());
validator.setTrace(true);
validator.addRepository(IO.getFile("testdata/repo1.index.xml").toURI());
validator.validate();
assertTrue(validator.check());
}
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class JpmRepoTest method testScr.
public void testScr() {
Repository repo = ws.getPlugin(Repository.class);
BndEditModel model = new BndEditModel();
model.setRunFw("org.apache.felix.framework");
List<Requirement> requires = new ArrayList<Requirement>();
CapReqBuilder capReq = CapReqBuilder.createSimpleRequirement("osgi.extender", "osgi.component", "[1.1,2)");
requires.add(capReq.buildSyntheticRequirement());
Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
assertNotNull(shell);
assertEquals(1, shell.size());
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class ResolveTest method testResolveWithDistro.
/**
* Test if we can resolve with a distro
*
* @throws ResolutionException
*/
public void testResolveWithDistro() throws ResolutionException {
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
BndEditModel model = new BndEditModel();
model.setDistro(Arrays.asList("testdata/distro.jar;version=file"));
List<Requirement> requires = new ArrayList<Requirement>();
CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
requires.add(capReq.buildSyntheticRequirement());
model.setRunRequires(requires);
BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
context.setLevel(0);
context.init();
Resolver resolver = new BndResolver(new ResolverLogger(4));
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
Set<Resource> resources = resolved.keySet();
Resource shell = getResource(resources, "org.apache.felix.gogo.shell", "0.10.0");
assertNotNull(shell);
}
Aggregations