Example #1
0
  /**
   * Constructs the feature configuration from a {@code CToolchain} protocol buffer.
   *
   * @param toolchain the toolchain configuration as specified by the user.
   * @throws InvalidConfigurationException if the configuration has logical errors.
   */
  CcToolchainFeatures(CToolchain toolchain) throws InvalidConfigurationException {
    // Build up the feature graph.
    // First, we build up the map of name -> features in one pass, so that earlier features can
    // reference later features in their configuration.
    ImmutableList.Builder<Feature> features = ImmutableList.builder();
    HashMap<String, Feature> featuresByName = new HashMap<>();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      Feature feature = new Feature(toolchainFeature);
      features.add(feature);
      if (featuresByName.put(feature.getName(), feature) != null) {
        throw new InvalidConfigurationException(
            "Invalid toolchain configuration: feature '"
                + feature.getName()
                + "' was specified multiple times.");
      }
    }
    this.features = features.build();
    this.featuresByName = ImmutableMap.copyOf(featuresByName);

    // Next, we build up all forward references for 'implies' and 'requires' edges.
    ImmutableMultimap.Builder<Feature, Feature> implies = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, ImmutableSet<Feature>> requires =
        ImmutableMultimap.builder();
    // We also store the reverse 'implied by' and 'required by' edges during this pass.
    ImmutableMultimap.Builder<Feature, Feature> impliedBy = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, Feature> requiredBy = ImmutableMultimap.builder();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      String name = toolchainFeature.getName();
      Feature feature = featuresByName.get(name);
      for (CToolchain.FeatureSet requiredFeatures : toolchainFeature.getRequiresList()) {
        ImmutableSet.Builder<Feature> allOf = ImmutableSet.builder();
        for (String requiredName : requiredFeatures.getFeatureList()) {
          Feature required = getFeatureOrFail(requiredName, name);
          allOf.add(required);
          requiredBy.put(required, feature);
        }
        requires.put(feature, allOf.build());
      }
      for (String impliedName : toolchainFeature.getImpliesList()) {
        Feature implied = getFeatureOrFail(impliedName, name);
        impliedBy.put(implied, feature);
        implies.put(feature, implied);
      }
    }
    this.implies = implies.build();
    this.requires = requires.build();
    this.impliedBy = impliedBy.build();
    this.requiredBy = requiredBy.build();
  }
  /**
   * Returns a newly-created {@code ListMetricsOptions} based on the contents of the {@code
   * Builder}.
   */
  @Override
  public Multimap<String, String> buildFormParameters() {
    ImmutableMultimap.Builder<String, String> formParameters =
        ImmutableMultimap.<String, String>builder();
    int dimensionIndex = 1;

    // If namespace isn't specified, don't include it
    if (namespace != null) {
      formParameters.put("Namespace", namespace);
    }
    // If metricName isn't specified, don't include it
    if (metricName != null) {
      formParameters.put("MetricName", metricName);
    }

    // If dimensions isn't specified, don't include it
    if (dimensions != null) {
      for (Dimension dimension : dimensions) {
        formParameters.put("Dimensions.member." + dimensionIndex + ".Name", dimension.getName());
        formParameters.put("Dimensions.member." + dimensionIndex + ".Value", dimension.getValue());
        dimensionIndex++;
      }
    }

    // If nextToken isn't specified, don't include it
    if (nextToken != null) {
      formParameters.put("NextToken", nextToken.toString());
    }

    return formParameters.build();
  }
Example #3
0
 @Value.Derived
 public ImmutableMultimap<Response, ResponseSet> responsesToContainingResponseSets() {
   final ImmutableMultimap.Builder<Response, ResponseSet> ret = ImmutableMultimap.builder();
   for (final ResponseSet responseSet : responseSets()) {
     for (final Response response : responseSet) {
       ret.put(response, responseSet);
     }
   }
   return ret.build();
 }
 /**
  * Parses a text file which is supposed to be in the following format: "file_path_without_spaces
  * file_hash ...." i.e. it parses the first two columns of each line and ignores the rest of it.
  *
  * @return A multi map from the file hash to its path, which equals the raw path resolved against
  *     {@code resolvePathAgainst}.
  */
 @VisibleForTesting
 static ImmutableMultimap<String, Path> parseExopackageInfoMetadata(
     Path metadataTxt, Path resolvePathAgainst, ProjectFilesystem filesystem) throws IOException {
   ImmutableMultimap.Builder<String, Path> builder = ImmutableMultimap.builder();
   for (String line : filesystem.readLines(metadataTxt)) {
     // ignore lines that start with '.'
     if (line.startsWith(".")) {
       continue;
     }
     List<String> parts = Splitter.on(' ').splitToList(line);
     if (parts.size() < 2) {
       throw new RuntimeException("Illegal line in metadata file: " + line);
     }
     builder.put(parts.get(1), resolvePathAgainst.resolve(parts.get(0)));
   }
   return builder.build();
 }
Example #5
0
 ImmutableMultimap<String, FilterHolder> getFilters() {
   return filters.build();
 }