Exemple #1
0
  private ImmutableList<Artifact> generatedOutputArtifacts(FileType newFileType) {
    ImmutableList.Builder<Artifact> builder = new ImmutableList.Builder<>();
    for (Artifact protoFile : getFilteredProtoSources()) {
      String protoFileName = FileSystemUtils.removeExtension(protoFile.getFilename());
      String generatedOutputName;
      if (attributes.outputsCpp()) {
        generatedOutputName = protoFileName;
      } else if (usesProtobufLibrary()) {
        // The protobuf library generates filenames with some slight modifications.
        generatedOutputName = generateProtobufFilename(protoFileName);
      } else {
        String lowerUnderscoreBaseName = protoFileName.replace('-', '_').toLowerCase();
        generatedOutputName = LOWER_UNDERSCORE.to(UPPER_CAMEL, lowerUnderscoreBaseName);
      }

      PathFragment generatedFilePath =
          new PathFragment(
              protoFile.getRootRelativePath().getParentDirectory(),
              new PathFragment(generatedOutputName));

      PathFragment outputFile =
          FileSystemUtils.appendExtension(generatedFilePath, newFileType.getExtensions().get(0));

      if (outputFile != null) {
        builder.add(
            ruleContext.getUniqueDirectoryArtifact(
                UNIQUE_DIRECTORY_NAME, outputFile, ruleContext.getBinOrGenfilesDirectory()));
      }
    }
    return builder.build();
  }
  /**
   * Generates an empty manifest for a rule that does not directly specify resources.
   *
   * <p><strong>Note:</strong> This generated manifest can then be used as the primary manifest when
   * merging with dependencies.
   *
   * @return the generated ApplicationManifest
   */
  public static ApplicationManifest generatedManifest(RuleContext ruleContext) {
    Artifact generatedManifest =
        ruleContext.getUniqueDirectoryArtifact(
            ruleContext.getRule().getName() + "_generated",
            new PathFragment("AndroidManifest.xml"),
            ruleContext.getBinOrGenfilesDirectory());

    String manifestPackage;
    if (ruleContext.attributes().isAttributeValueExplicitlySpecified("custom_package")) {
      manifestPackage = ruleContext.attributes().get("custom_package", Type.STRING);
    } else {
      manifestPackage =
          JavaUtil.getJavaFullClassname(ruleContext.getRule().getPackage().getNameFragment());
    }
    String contents =
        Joiner.on("\n")
            .join(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>",
                "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"",
                "          package=\"" + manifestPackage + "\">",
                "   <application>",
                "   </application>",
                "</manifest>");
    ruleContext
        .getAnalysisEnvironment()
        .registerAction(
            new FileWriteAction(
                ruleContext.getActionOwner(),
                generatedManifest,
                contents,
                false /* makeExecutable */));
    return new ApplicationManifest(generatedManifest);
  }
Exemple #3
0
  private static Artifact createResourceJarArtifact(
      RuleContext ruleContext, ResourceContainer container, String fileNameSuffix) {

    String artifactName = container.getLabel().getName() + fileNameSuffix;

    // Since the Java sources are generated by combining all resources with the
    // ones included in the binary, the path of the artifact has to be unique
    // per binary and per library (not only per library).
    Artifact artifact =
        ruleContext.getUniqueDirectoryArtifact(
            "resource_jars",
            container.getLabel().getPackageIdentifier().getPathFragment().getRelative(artifactName),
            ruleContext.getBinOrGenfilesDirectory());
    return artifact;
  }
 public ApplicationManifest mergeWith(
     RuleContext ruleContext, Iterable<ResourceContainer> resourceContainers) {
   if (!Iterables.isEmpty(getMergeeManifests(resourceContainers))) {
     Iterable<Artifact> exportedManifests = getMergeeManifests(resourceContainers);
     Artifact outputManifest =
         ruleContext.getUniqueDirectoryArtifact(
             ruleContext.getRule().getName() + "_merged",
             "AndroidManifest.xml",
             ruleContext.getBinOrGenfilesDirectory());
     AndroidManifestMergeHelper.createMergeManifestAction(
         ruleContext, getManifest(), exportedManifests, ImmutableList.of("all"), outputManifest);
     return new ApplicationManifest(outputManifest);
   }
   return this;
 }
Exemple #5
0
 private Artifact getProtoInputListFile() {
   return ruleContext.getUniqueDirectoryArtifact(
       "_protos", "_proto_input_files", ruleContext.getConfiguration().getGenfilesDirectory());
 }
 /**
  * Returns a static library archive with dead code/objects removed by J2ObjC dead code removal,
  * given the original unpruned static library containing J2ObjC-translated code.
  */
 public Artifact j2objcPrunedArchive(Artifact unprunedArchive) {
   PathFragment prunedSourceArtifactPath =
       FileSystemUtils.appendWithoutExtension(unprunedArchive.getRootRelativePath(), "_pruned");
   return ruleContext.getUniqueDirectoryArtifact(
       "_j2objc_pruned", prunedSourceArtifactPath, ruleContext.getBinOrGenfilesDirectory());
 }