コード例 #1
0
  /** Packages up the manifest with resource and assets from the rule and dependent resources. */
  public ResourceApk packWithDataAndResources(
      Artifact resourceApk,
      RuleContext ruleContext,
      NestedSet<ResourceContainer> resourceContainers,
      Artifact rTxt,
      Artifact symbolsTxt,
      List<String> configurationFilters,
      List<String> uncompressedExtensions,
      List<String> densities,
      String applicationId,
      String versionCode,
      String versionName,
      boolean incremental,
      Artifact proguardCfg) {
    try {
      LocalResourceContainer data =
          new LocalResourceContainer.Builder()
              .withAssets(
                  AndroidCommon.getAssetDir(ruleContext),
                  ruleContext.getPrerequisites(
                      // TODO(bazel-team): Remove the ResourceType construct.
                      ResourceType.ASSETS.getAttribute(), Mode.TARGET, FileProvider.class))
              .withResources(
                  ruleContext.getPrerequisites("resource_files", Mode.TARGET, FileProvider.class))
              .build();

      return createApk(
          resourceApk,
          ruleContext,
          resourceContainers,
          rTxt,
          symbolsTxt,
          configurationFilters,
          uncompressedExtensions,
          densities,
          applicationId,
          versionCode,
          versionName,
          incremental,
          data,
          proguardCfg);
    } catch (InvalidAssetPath e) {
      ruleContext.attributeError(ResourceType.ASSETS.getAttribute(), e.getMessage());
      throw new RuleConfigurationException();
    } catch (InvalidResourcePath e) {
      ruleContext.attributeError("resource_files", e.getMessage());
      throw new RuleConfigurationException();
    }
  }
コード例 #2
0
  /** Packages up the manifest with assets from the rule and dependent resources. */
  public ResourceApk packWithAssets(
      Artifact resourceApk,
      RuleContext ruleContext,
      NestedSet<ResourceContainer> resourceContainers,
      Artifact rTxt,
      boolean incremental,
      Artifact proguardCfg) {
    try {
      LocalResourceContainer data =
          new LocalResourceContainer.Builder()
              .withAssets(
                  AndroidCommon.getAssetDir(ruleContext),
                  ruleContext.getPrerequisites(
                      // TODO(bazel-team): Remove the ResourceType construct.
                      ResourceType.ASSETS.getAttribute(), Mode.TARGET, FileProvider.class))
              .build();

      return createApk(
          resourceApk,
          ruleContext,
          resourceContainers,
          rTxt,
          null, /* configurationFilters */
          ImmutableList.<String>of(), /* uncompressedExtensions */
          ImmutableList.<String>of(), /* densities */
          ImmutableList.<String>of(), /* String applicationId */
          null, /* String versionCode */
          null, /* String versionName */
          null, /* Artifact symbolsTxt */
          incremental,
          data,
          proguardCfg);
    } catch (InvalidAssetPath e) {
      ruleContext.attributeError(ResourceType.ASSETS.getAttribute(), e.getMessage());
      throw new RuleConfigurationException();
    }
  }
コード例 #3
0
 /**
  * Retrieves the asset {@link Artifact} and asset root {@link PathFragment}.
  *
  * @param assetsDir The common directory for the assets, used to get the directory roots and
  *     verify the artifacts are located beneath the assetsDir
  * @param targets {@link FileProvider}s for a given set of assets.
  * @return The Builder.
  */
 public LocalResourceContainer.Builder withAssets(
     PathFragment assetsDir, Iterable<? extends TransitiveInfoCollection> targets) {
   for (TransitiveInfoCollection target : targets) {
     for (Artifact file : target.getProvider(FileProvider.class).getFilesToBuild()) {
       PathFragment packageFragment =
           file.getArtifactOwner().getLabel().getPackageIdentifier().getSourceRoot();
       PathFragment packageRelativePath = file.getRootRelativePath().relativeTo(packageFragment);
       if (packageRelativePath.startsWith(assetsDir)) {
         PathFragment relativePath = packageRelativePath.relativeTo(assetsDir);
         assetRoots.add(trimTail(file.getExecPath(), relativePath));
       } else {
         ruleContext.attributeError(
             ResourceType.ASSETS.getAttribute(),
             String.format(
                 "'%s' (generated by '%s') is not beneath '%s'",
                 file.getRootRelativePath(), target.getLabel(), assetsDir));
         return this;
       }
       assets.add(file);
     }
   }
   return this;
 }