Search in sources :

Example 61 with CapReqBuilder

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));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) RepoBundleSelectionWizard(bndtools.wizards.repo.RepoBundleSelectionWizard) LiteralFilter(aQute.libg.filters.LiteralFilter) Requirement(org.osgi.resource.Requirement) AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 62 with CapReqBuilder

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));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) RepoBundleSelectionWizard(bndtools.wizards.repo.RepoBundleSelectionWizard) LiteralFilter(aQute.libg.filters.LiteralFilter) Requirement(org.osgi.resource.Requirement) AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 63 with CapReqBuilder

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());
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder)

Example 64 with CapReqBuilder

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());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 65 with CapReqBuilder

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);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel)

Aggregations

CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)69 Requirement (org.osgi.resource.Requirement)53 Capability (org.osgi.resource.Capability)35 BndEditModel (aQute.bnd.build.model.BndEditModel)32 MockRegistry (test.lib.MockRegistry)28 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)23 Resource (org.osgi.resource.Resource)18 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 Repository (org.osgi.service.repository.Repository)9 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)8 HashMap (java.util.HashMap)8 File (java.io.File)7 List (java.util.List)7 AndFilter (aQute.libg.filters.AndFilter)6 LiteralFilter (aQute.libg.filters.LiteralFilter)6 SimpleFilter (aQute.libg.filters.SimpleFilter)6 Parameters (aQute.bnd.header.Parameters)5 InfoRepository (aQute.bnd.service.repository.InfoRepository)5 Version (aQute.bnd.version.Version)5