コード例 #1
1
ファイル: Macro.java プロジェクト: bramk/bnd
  public String _range(String args[]) {
    verifyCommand(args, _rangeHelp, _rangePattern, 2, 3);
    Version version = null;
    if (args.length >= 3) version = new Version(args[2]);
    else {
      String v = domain.getProperty("@");
      if (v == null) return null;
      version = new Version(v);
    }
    String spec = args[1];

    Matcher m = RANGE_MASK.matcher(spec);
    m.matches();
    String floor = m.group(1);
    String floorMask = m.group(2);
    String ceilingMask = m.group(3);
    String ceiling = m.group(4);

    String left = version(version, floorMask);
    String right = version(version, ceilingMask);
    StringBuilder sb = new StringBuilder();
    sb.append(floor);
    sb.append(left);
    sb.append(",");
    sb.append(right);
    sb.append(ceiling);

    String s = sb.toString();
    VersionRange vr = new VersionRange(s);
    if (!(vr.includes(vr.getHigh()) || vr.includes(vr.getLow()))) {
      domain.error(
          "${range} macro created an invalid range %s from %s and mask %s", s, version, spec);
    }
    return sb.toString();
  }
コード例 #2
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
  public void addFilter(String ns, String name, String version, Attrs attrs) {
    List<String> parts = new ArrayList<String>();

    parts.add("(" + ns + "=" + name + ")");
    if (version != null && VersionRange.isOSGiVersionRange(version)) {
      VersionRange range = VersionRange.parseOSGiVersionRange(version);
      parts.add(range.toFilter());
    }

    String mandatory = attrs.get(Constants.MANDATORY_DIRECTIVE + ":");
    if (mandatory != null) {
      String mandatoryAttrs[] = mandatory.split("\\s*,\\s*");
      Arrays.sort(mandatoryAttrs);
      for (String mandatoryAttr : mandatoryAttrs) {
        String value = attrs.get(mandatoryAttr);
        if (value != null) {
          parts.add("(" + mandatoryAttr + "=" + escapeFilterValue(value) + ")");
        }
      }
    }

    StringBuilder sb = new StringBuilder();
    if (parts.size() > 0) sb.append("(&");
    for (String s : parts) {
      sb.append(s);
    }
    if (parts.size() > 0) sb.append(")");
    addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, sb.toString());
  }
コード例 #3
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
  public static RequirementBuilder createRequirementFromCapability(Capability cap) {
    RequirementBuilder req = new RequirementBuilder(cap.getNamespace());
    StringBuilder sb = new StringBuilder("(&");
    for (Entry<String, Object> e : cap.getAttributes().entrySet()) {
      Object v = e.getValue();
      if (v instanceof Version || e.getKey().equals("version")) {
        VersionRange r = new VersionRange(v.toString());
        String filter = r.toFilter();
        sb.append(filter);

      } else sb.append("(").append(e.getKey()).append("=").append(v).append(")");
    }
    sb.append(")");

    req.and(sb.toString());
    return req;
  }
コード例 #4
0
  public SortedSet<ResourceDescriptor> find(String repoId, String bsn, VersionRange range)
      throws Exception {
    TreeSet<ResourceDescriptor> result =
        new TreeSet<ResourceDescriptor>(RESOURCE_DESCRIPTOR_COMPARATOR);

    for (ResourceDescriptorImpl r : filter(repoId, null)) {
      if (!bsn.equals(r.bsn)) continue;

      if (range != null && !range.includes(r.version)) continue;

      result.add(r);
    }
    return result;
  }