<commit_before>/*
 * Copyright 2012-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.facebook.buck.android;

import com.facebook.buck.rules.AbstractBuildRuleBuilder;
import com.facebook.buck.rules.AbstractCachingBuildRule;
import com.facebook.buck.rules.AndroidResourceRule;
import com.facebook.buck.rules.BuildContext;
import com.facebook.buck.rules.BuildRule;
import com.facebook.buck.rules.BuildRuleParams;
import com.facebook.buck.rules.BuildRuleType;
import com.facebook.buck.rules.DependencyGraph;
import com.facebook.buck.step.Step;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class AndroidManifestRule extends AbstractCachingBuildRule {

  private final Optional<String> manifestFile;
  private final Optional<String> skeletonFile;
  private final AndroidTransitiveDependencyGraph transitiveDependencyGraph;
  private final ImmutableSet<BuildRule> buildRulesToExcludeFromDex;

  protected AndroidManifestRule(BuildRuleParams buildRuleParams,
                                Optional<String> skeletonFile,
                                Optional<String> manifestFile,
                                Set<BuildRule> buildRulesToExcludeFromDex) {
    super(buildRuleParams);
    this.manifestFile = manifestFile;
    this.skeletonFile = skeletonFile;
    this.buildRulesToExcludeFromDex = ImmutableSet.copyOf(buildRulesToExcludeFromDex);
    this.transitiveDependencyGraph =
        new AndroidTransitiveDependencyGraph(this, this.buildRulesToExcludeFromDex);
  }

  @Override
  public BuildRuleType getType() {
    return BuildRuleType.ANDROID_MANIFEST;
  }

  @Override
  protected List<String> getInputsToCompareToOutput(BuildContext context) {
    ImmutableList.Builder<String> inputsToConsiderForCachingPurposes = ImmutableList.builder();
    if (skeletonFile.isPresent() && manifestFile.isPresent()) {
      inputsToConsiderForCachingPurposes.add(skeletonFile.get());
      inputsToConsiderForCachingPurposes.add(manifestFile.get());
    }
    return inputsToConsiderForCachingPurposes.build();
  }

  @Override
  protected List<Step> buildInternal(BuildContext context) throws IOException {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    AndroidTransitiveDependencies transitiveDependencies =
        transitiveDependencyGraph.findDependencies(getAndroidResourceDepsInternal(
            context.getDependencyGraph()),
            Optional.of(context));

    if (skeletonFile.isPresent() && manifestFile.isPresent()) {
      commands.add(new GenerateManifestStep(
          skeletonFile.get(),
          manifestFile.get(),
          transitiveDependencies.manifestFiles));
    }
    return commands.build();
  }

  public static Builder newManifestMergeRuleBuilder() {
    return new Builder();
  }

  /**
   * @return a list of {@link com.facebook.buck.rules.AndroidResourceRule}s that should be passed,
   * in order, to {@code aapt} when generating the {@code R.java} files for this APK.
   */
  private ImmutableList<AndroidResourceRule> getAndroidResourceDepsInternal(
      DependencyGraph graph) {
    return AndroidResourceRule.getAndroidResourceDeps(this, graph);
  }
<commit_msg>Correct a javadoc link that does not need to be fully qualified. No logical changes<commit_after>/*
 * Copyright 2012-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.facebook.buck.android;

import com.facebook.buck.rules.AbstractBuildRuleBuilder;
import com.facebook.buck.rules.AbstractCachingBuildRule;
import com.facebook.buck.rules.AndroidResourceRule;
import com.facebook.buck.rules.BuildContext;
import com.facebook.buck.rules.BuildRule;
import com.facebook.buck.rules.BuildRuleParams;
import com.facebook.buck.rules.BuildRuleType;
import com.facebook.buck.rules.DependencyGraph;
import com.facebook.buck.step.Step;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class AndroidManifestRule extends AbstractCachingBuildRule {

  private final Optional<String> manifestFile;
  private final Optional<String> skeletonFile;
  private final AndroidTransitiveDependencyGraph transitiveDependencyGraph;
  private final ImmutableSet<BuildRule> buildRulesToExcludeFromDex;

  protected AndroidManifestRule(BuildRuleParams buildRuleParams,
                                Optional<String> skeletonFile,
                                Optional<String> manifestFile,
                                Set<BuildRule> buildRulesToExcludeFromDex) {
    super(buildRuleParams);
    this.manifestFile = manifestFile;
    this.skeletonFile = skeletonFile;
    this.buildRulesToExcludeFromDex = ImmutableSet.copyOf(buildRulesToExcludeFromDex);
    this.transitiveDependencyGraph =
        new AndroidTransitiveDependencyGraph(this, this.buildRulesToExcludeFromDex);
  }

  @Override
  public BuildRuleType getType() {
    return BuildRuleType.ANDROID_MANIFEST;
  }

  @Override
  protected List<String> getInputsToCompareToOutput(BuildContext context) {
    ImmutableList.Builder<String> inputsToConsiderForCachingPurposes = ImmutableList.builder();
    if (skeletonFile.isPresent() && manifestFile.isPresent()) {
      inputsToConsiderForCachingPurposes.add(skeletonFile.get());
      inputsToConsiderForCachingPurposes.add(manifestFile.get());
    }
    return inputsToConsiderForCachingPurposes.build();
  }

  @Override
  protected List<Step> buildInternal(BuildContext context) throws IOException {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    AndroidTransitiveDependencies transitiveDependencies =
        transitiveDependencyGraph.findDependencies(getAndroidResourceDepsInternal(
            context.getDependencyGraph()),
            Optional.of(context));

    if (skeletonFile.isPresent() && manifestFile.isPresent()) {
      commands.add(new GenerateManifestStep(
          skeletonFile.get(),
          manifestFile.get(),
          transitiveDependencies.manifestFiles));
    }
    return commands.build();
  }

  public static Builder newManifestMergeRuleBuilder() {
    return new Builder();
  }

  /**
   * @return a list of {@link AndroidResourceRule}s that should be passed,
   * in order, to {@code aapt} when generating the {@code R.java} files for this APK.
   */
  private ImmutableList<AndroidResourceRule> getAndroidResourceDepsInternal(
      DependencyGraph graph) {
    return AndroidResourceRule.getAndroidResourceDeps(this, graph);
  }

{'fraction_non_alphanumeric': 0.08324860193187596, 'fraction_numerical': 0.0020335536349771225, 'mean_word_length': 4.260026737967914, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2364826', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2058, 'n_words': 504}