Search in sources :

Example 6 with AndFilter

use of aQute.libg.filters.AndFilter in project bndtools by bndtools.

the class ResolutionSuccessPanel method resourceToRequirement.

private static Requirement resourceToRequirement(Resource resource) {
    Capability identity = ResourceUtils.getIdentityCapability(resource);
    String id = ResourceUtils.getIdentity(identity);
    Version version = ResourceUtils.getVersion(identity);
    Version dropQualifier = new Version(version.getMajor(), version.getMinor(), version.getMicro());
    AndFilter filter = new AndFilter();
    filter.addChild(new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, id));
    filter.addChild(new LiteralFilter(Filters.fromVersionRange(dropQualifier.toString())));
    Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
    return req;
}
Also used : LiteralFilter(aQute.libg.filters.LiteralFilter) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) AndFilter(aQute.libg.filters.AndFilter) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) SimpleFilter(aQute.libg.filters.SimpleFilter)

Example 7 with AndFilter

use of aQute.libg.filters.AndFilter in project bnd by bndtools.

the class CapReqBuilder method createSimpleRequirement.

public static CapReqBuilder createSimpleRequirement(String ns, String name, String range) {
    Filter filter;
    SimpleFilter bsnFilter = new SimpleFilter(ns, name);
    if (range != null)
        filter = new AndFilter().addChild(bsnFilter).addChild(new LiteralFilter(Filters.fromVersionRange(range)));
    else
        filter = bsnFilter;
    return new CapReqBuilder(ns).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
}
Also used : LiteralFilter(aQute.libg.filters.LiteralFilter) 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)

Example 8 with AndFilter

use of aQute.libg.filters.AndFilter in project bnd by bndtools.

the class Filters method fromVersionRange.

/**
	 * Generate an LDAP-style version filter from a version range, using a
	 * specific attribute name for the version; for example can be used to
	 * generate a range using the {@code bundle-version} attribute such as
	 * {@code (&(bundle-version>=1.0)(!(bundle-version>=2.0))}.
	 * 
	 * @param range
	 * @param versionAttr
	 * @return The generated filter
	 * @throws IllegalArgumentException If the supplied range is invalid.
	 */
public static String fromVersionRange(String range, String versionAttr) throws IllegalArgumentException {
    if (range == null)
        return null;
    VersionRange parsedRange = new VersionRange(range);
    Filter left;
    if (parsedRange.includeLow())
        left = new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, parsedRange.getLow().toString());
    else
        left = new NotFilter(new SimpleFilter(versionAttr, Operator.LessThanOrEqual, parsedRange.getLow().toString()));
    Filter right;
    if (!parsedRange.isRange())
        right = null;
    else if (parsedRange.includeHigh())
        right = new SimpleFilter(versionAttr, Operator.LessThanOrEqual, parsedRange.getHigh().toString());
    else
        right = new NotFilter(new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, parsedRange.getHigh().toString()));
    Filter result;
    if (right != null)
        result = new AndFilter().addChild(left).addChild(right);
    else
        result = left;
    return result.toString();
}
Also used : AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) VersionRange(aQute.bnd.version.VersionRange)

Example 9 with AndFilter

use of aQute.libg.filters.AndFilter in project bndtools by bndtools.

the class RunRequirementsPart method createRequirement.

private static Requirement createRequirement(Object elem) {
    String bsn = null;
    Version version = null;
    if (elem instanceof RepositoryBundle) {
        bsn = ((RepositoryBundle) elem).getBsn();
    } else if (elem instanceof RepositoryBundleVersion) {
        RepositoryBundleVersion rbv = (RepositoryBundleVersion) elem;
        bsn = rbv.getBsn();
        version = rbv.getVersion();
    } else if (elem instanceof ProjectBundle) {
        bsn = ((ProjectBundle) elem).getBsn();
    }
    if (bsn != null) {
        Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bsn);
        if (version != null) {
            filter = new AndFilter().addChild(filter).addChild(new SimpleFilter("version", Operator.GreaterThanOrEqual, version.toString()));
        }
        Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
        return req;
    }
    return null;
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) ProjectBundle(bndtools.model.repo.ProjectBundle) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) AndFilter(aQute.libg.filters.AndFilter) Requirement(org.osgi.resource.Requirement) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Version(aQute.bnd.version.Version) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) 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)

Example 10 with AndFilter

use of aQute.libg.filters.AndFilter 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)

Aggregations

AndFilter (aQute.libg.filters.AndFilter)11 SimpleFilter (aQute.libg.filters.SimpleFilter)11 Filter (aQute.libg.filters.Filter)10 LiteralFilter (aQute.libg.filters.LiteralFilter)9 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)6 Requirement (org.osgi.resource.Requirement)6 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 Version (aQute.bnd.version.Version)2 VersionRange (aQute.bnd.version.VersionRange)2 NotFilter (aQute.libg.filters.NotFilter)2 ProjectBundle (bndtools.model.repo.ProjectBundle)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)2 RepoBundleSelectionWizard (bndtools.wizards.repo.RepoBundleSelectionWizard)2 LinkedHashSet (java.util.LinkedHashSet)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Version (org.osgi.framework.Version)1 Capability (org.osgi.resource.Capability)1