com.android.tools.build.bundletool.model.ZipPath.startsWith()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中com.android.tools.build.bundletool.model.ZipPath.startsWith()方法的一些代码示例,展示了ZipPath.startsWith()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipPath.startsWith()方法的具体详情如下:
包路径:com.android.tools.build.bundletool.model.ZipPath
类名称:ZipPath
方法名:startsWith

ZipPath.startsWith介绍

暂无

代码示例

代码示例来源:origin: google/bundletool

/**
 * Returns all {@link ModuleEntry} whose relative module path is under the given path.
 *
 * <p>Note that special module files (eg. {@code AndroidManifest.xml} are NOT represented as
 * entries.
 */
public Stream<ModuleEntry> findEntriesUnderPath(ZipPath path) {
 return findEntries(p -> p.startsWith(path));
}

代码示例来源:origin: google/bundletool

@Override
public boolean startsWith(String p) {
 return startsWith(ZipPath.create(p));
}

代码示例来源:origin: google/bundletool

private static boolean hasNonResourceEntries(ModuleSplit split) {
 return split.getEntries().stream()
   .anyMatch(entry -> !entry.getPath().startsWith(RESOURCES_DIRECTORY));
}

代码示例来源:origin: google/bundletool

/** Returns all {@link ModuleEntry} that have a relative module path under a given path. */
public Stream<ModuleEntry> findEntriesUnderPath(String path) {
 return getEntries().stream().filter(entry -> entry.getPath().startsWith(path));
}

代码示例来源:origin: google/bundletool

private static ImmutableList<ModuleEntry> getEntriesForSplit(
  ImmutableList<ModuleEntry> inputEntries, String language, ResourceTable resourceTable) {
 ImmutableList<ModuleEntry> entriesFromResourceTable =
   ModuleSplit.filterResourceEntries(inputEntries, resourceTable);
 if (language.isEmpty()) { // The split with no specific language targeting.
  return ImmutableList.<ModuleEntry>builder()
    .addAll(entriesFromResourceTable)
    // Add non-resource entries.
    .addAll(
      inputEntries.stream()
        .filter(entry -> !entry.getPath().startsWith(RESOURCES_DIRECTORY))
        .collect(toImmutableList()))
    .build();
 } else {
  return entriesFromResourceTable;
 }
}

代码示例来源:origin: google/bundletool

/**
 * Creates a {@link ModuleSplit} only with the dex files with empty APK targeting and given
 * variant targeting.
 */
public static ModuleSplit forDex(BundleModule bundleModule, VariantTargeting variantTargeting) {
 return fromFeatureBundleModule(
   bundleModule,
   entry -> entry.getPath().startsWith(DEX_DIRECTORY),
   /* setResourceTable= */ false,
   variantTargeting);
}

代码示例来源:origin: google/bundletool

/**
 * Creates a {@link ModuleSplit} only with the resources entries with empty APK targeting and
 * given variant targeting.
 */
public static ModuleSplit forResources(
  BundleModule bundleModule, VariantTargeting variantTargeting) {
 return fromFeatureBundleModule(
   bundleModule,
   entry -> entry.getPath().startsWith(RESOURCES_DIRECTORY),
   /* setResourceTable= */ true,
   variantTargeting);
}

代码示例来源:origin: google/bundletool

/**
 * Creates a {@link ModuleSplit} only with the assets entries with empty APK targeting and given
 * variant targeting.
 */
public static ModuleSplit forAssets(
  BundleModule bundleModule, VariantTargeting variantTargeting) {
 return fromFeatureBundleModule(
   bundleModule,
   entry -> entry.getPath().startsWith(ASSETS_DIRECTORY),
   /* setResourceTable= */ false,
   variantTargeting);
}

代码示例来源:origin: google/bundletool

/**
 * Creates a {@link ModuleSplit} only with the native library entries with empty APK targeting and
 * given variant targeting.
 */
public static ModuleSplit forNativeLibraries(
  BundleModule bundleModule, VariantTargeting variantTargeting) {
 return fromFeatureBundleModule(
   bundleModule,
   entry -> entry.getPath().startsWith(LIB_DIRECTORY),
   /* setResourceTable= */ false,
   variantTargeting);
}

代码示例来源:origin: google/bundletool

public static ModuleSplit forRoot(BundleModule bundleModule, VariantTargeting variantTargeting) {
 return fromFeatureBundleModule(
   bundleModule,
   entry -> entry.getPath().startsWith(ROOT_DIRECTORY),
   /* setResourceTable= */ false,
   variantTargeting);
}

代码示例来源:origin: google/bundletool

/**
 * Indexes files under "lib/" based on the ABI directory (example keys are "lib/x86", "lib/mips").
 */
private static ImmutableMultimap<ZipPath, ModuleEntry> indexLibFilesByAbiDir(
  BundleModule module) {
 return module.getEntries().stream()
   .filter(entry -> entry.getPath().startsWith(LIB_DIRECTORY))
   .collect(
     toImmutableSetMultimap(entry -> entry.getPath().subpath(0, 2), Function.identity()));
}

代码示例来源:origin: google/bundletool

/**
 * Creates a {@link ModuleSplit} only with the apex image entries with empty APK targeting and
 * default L+ variant targeting.
 */
public static ModuleSplit forApex(BundleModule bundleModule) {
 return fromFeatureBundleModule(
   bundleModule,
   entry -> entry.getPath().startsWith(APEX_DIRECTORY),
   /* setResourceTable= */ false,
   lPlusVariantTargeting());
}

代码示例来源:origin: google/bundletool

/**
 * Generates a single {@link ModuleSplit} setting the compression of dex entries.
 *
 * <p>Dex entries are only compressed for pre P devices.
 */
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
 ImmutableSet<ModuleEntry> dexEntries =
   moduleSplit.getEntries().stream()
     .filter(entry -> entry.getPath().startsWith(DEX_DIRECTORY))
     .collect(toImmutableSet());
 if (dexEntries.isEmpty()) {
  return ImmutableList.of(moduleSplit);
 }
 // Only APKs targeting devices below Android P should be compressed.
 boolean shouldCompress = targetsPreP(moduleSplit);
 return ImmutableList.of(
   createModuleSplit(
     moduleSplit, mergeAndSetCompression(dexEntries, moduleSplit, shouldCompress)));
}

代码示例来源:origin: google/bundletool

private static BundleMetadata readBundleMetadata(ZipFile bundleFile) {
 BundleMetadata.Builder metadata = BundleMetadata.builder();
 ZipUtils.allFileEntries(bundleFile)
   .filter(entry -> ZipPath.create(entry.getName()).startsWith(METADATA_DIRECTORY))
   .forEach(
     zipEntry -> {
      ZipPath bundlePath = ZipPath.create(zipEntry.getName());
      // Strip the top-level metadata directory.
      ZipPath metadataPath = bundlePath.subpath(1, bundlePath.getNameCount());
      metadata.addFile(metadataPath, BufferedIo.inputStreamSupplier(bundleFile, zipEntry));
     });
 return metadata.build();
}

代码示例来源:origin: google/bundletool

@Override
 public ImmutableCollection<VariantTargeting> generate(BundleModule module) {
  if (!apkGenerationConfiguration.getEnableDexCompressionSplitter()
    || apkGenerationConfiguration.isForInstantAppVariants()) {
   return ImmutableList.of();
  }
  ImmutableSet<ModuleEntry> dexEntries =
    module.getEntries().stream()
      .filter(entry -> entry.getPath().startsWith(DEX_DIRECTORY))
      .collect(toImmutableSet());

  if (dexEntries.isEmpty()) {
   return ImmutableList.of();
  }

  return ImmutableList.of(
    variantTargeting(sdkVersionTargeting(sdkVersionFrom(ANDROID_P_API_VERSION))));
 }
}

代码示例来源:origin: google/bundletool

/** Extracts paths of all files having the given path prefix. */
public static ImmutableList<String> filesUnderPath(ZipFile zipFile, ZipPath pathPrefix) {
 return zipFile.stream()
   .map(ZipEntry::getName)
   .filter(entryName -> ZipPath.create(entryName).startsWith(pathPrefix))
   .collect(toImmutableList());
}

代码示例来源:origin: google/bundletool

@Test
public void testStartsWith() {
 ZipPath path = ZipPath.create("foo/bar");
 // Positive results.
 assertThat(path.startsWith(ZipPath.create(""))).isTrue();
 assertThat(path.startsWith(ZipPath.create("foo"))).isTrue();
 assertThat(path.startsWith(ZipPath.create("foo/bar"))).isTrue();
 // Negative results.
 assertThat(path.startsWith(ZipPath.create("fo"))).isFalse();
 assertThat(path.startsWith(ZipPath.create("foo2"))).isFalse();
 assertThat(path.startsWith(ZipPath.create("foo/ba"))).isFalse();
 assertThat(path.startsWith(ZipPath.create("foo/bar2"))).isFalse();
 assertThat(path.startsWith(ZipPath.create("foo/bar/hello"))).isFalse();
}

代码示例来源:origin: google/bundletool

private static BundleModule sanitizedModule(
  BundleModule module, ImmutableMultimap<ZipPath, ModuleEntry> libFilesByAbiDirToKeep) {
 // Construct new module by making minimal modifications to the existing module.
 BundleModule.Builder newModule = module.toBuilder();
 if (module.getNativeConfig().isPresent()) {
  NativeLibraries newNativeConfig =
    filterNativeTargeting(module.getNativeConfig().get(), libFilesByAbiDirToKeep);
  newModule.setNativeConfig(newNativeConfig);
 }
 newModule.setEntryMap(
   module.getEntries().stream()
     .filter(
       entry ->
         !entry.getPath().startsWith(LIB_DIRECTORY)
           || libFilesByAbiDirToKeep.containsValue(entry))
     .collect(toImmutableMap(ModuleEntry::getPath, Function.identity())));
 return newModule.build();
}

代码示例来源:origin: google/bundletool

@Test
public void testStartsWith_everythingStartsWithRoot() {
 ZipPath root = ZipPath.create("");
 assertThat(ZipPath.create("").startsWith(root)).isTrue();
 assertThat(ZipPath.create("foo").startsWith(root)).isTrue();
 assertThat(ZipPath.create("foo/bar").startsWith(root)).isTrue();
}

代码示例来源:origin: google/bundletool

private void validateTargeting(BundleModule module, Assets assets) {
  for (TargetedAssetsDirectory targetedDirectory : assets.getDirectoryList()) {
   ZipPath path = ZipPath.create(targetedDirectory.getPath());

   if (!path.startsWith(ASSETS_DIRECTORY)) {
    throw ValidationException.builder()
      .withMessage(
        "Path of targeted assets directory must start with 'assets/' but found '%s'.", path)
      .build();
   }

   if (BundleValidationUtils.directoryContainsNoFiles(module, path)) {
    throw ValidationException.builder()
      .withMessage("Targeted directory '%s' is empty.", path)
      .build();
   }
  }
 }
}

相关文章