示例#1
0
  private static void ruleErrorDuplicateAlias(String alias, RuleContext ruleContext) {
    Iterable<XcodeVersionProvider> xcodeVersionProviders =
        ruleContext.getPrerequisites(
            XcodeConfigRule.VERSIONS_ATTR_NAME, Mode.TARGET, XcodeVersionProvider.class);

    ImmutableList.Builder<Label> labelsContainingAlias = ImmutableList.builder();
    for (XcodeVersionProvider versionProvider : xcodeVersionProviders) {
      if (versionProvider.getAliases().contains(alias)
          || versionProvider.getVersion().toString().equals(alias)) {
        labelsContainingAlias.add(versionProvider.getLabel());
      }
    }
    ruleContext.ruleError(
        String.format(
            "'%s' is registered to multiple labels (%s) in a single xcode version "
                + "configuration",
            alias, Joiner.on(", ").join(labelsContainingAlias.build())));
  }
示例#2
0
  private static Map<String, DottedVersion> aliasesToVersionMap(RuleContext ruleContext) {
    Iterable<XcodeVersionProvider> xcodeVersionProviders =
        ruleContext.getPrerequisites(
            XcodeConfigRule.VERSIONS_ATTR_NAME, Mode.TARGET, XcodeVersionProvider.class);

    Map<String, DottedVersion> aliasesToVersionMap = Maps.newLinkedHashMap();
    for (XcodeVersionProvider versionProvider : xcodeVersionProviders) {
      for (String alias : versionProvider.getAliases()) {
        if (aliasesToVersionMap.put(alias, versionProvider.getVersion()) != null) {
          ruleErrorDuplicateAlias(alias, ruleContext);
        }
      }
      if (aliasesToVersionMap.put(
              versionProvider.getVersion().toString(), versionProvider.getVersion())
          != null) {
        ruleErrorDuplicateAlias(versionProvider.getVersion().toString(), ruleContext);
      }
    }
    return aliasesToVersionMap;
  }