com.android.tools.build.bundletool.model.ZipPath类的使用及代码示例

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

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

ZipPath介绍

[英]Path to an entry in a zip file.

The separator will always be a forward slash ("/") regardless of the platform being used.
[中]zip文件中条目的路径。
无论使用哪个平台,分隔符都将始终是正斜杠(“/”)。

代码示例

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

if (pathInModule.startsWith(DEX_DIRECTORY)) {
 checkArgument(
   pathInModule.getNameCount() == 2,
   "Only files directly in the dex directory are supported but found: %s.",
   pathInModule);
 checkFileHasExtension("File under dex/ directory", pathInModule, ".dex");
 return pathInModule.getFileName();
if (pathInModule.startsWith(ROOT_DIRECTORY)) {
 checkArgument(
   pathInModule.getNameCount() >= 2,
   "Only files inside the root directory are supported but found: %s",
   pathInModule);
 return pathInModule.subpath(1, pathInModule.getNameCount());
if (pathInModule.startsWith(APEX_DIRECTORY)) {
 checkArgument(
   pathInModule.getNameCount() >= 2,
   "Only files inside the apex directory are supported but found: %s",
   pathInModule);
 return ZipPath.create("apex_payload.img");

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

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

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

/**
 * Returns the {@link BundleModuleName} corresponding to the provided zip entry. If the zip entry
 * does not belong to a module, a null {@link BundleModuleName} is returned.
 */
public static Optional<BundleModuleName> extractModuleName(ZipEntry entry) {
 ZipPath path = ZipPath.create(entry.getName());
 // Ignoring bundle metadata files.
 if (path.startsWith(METADATA_DIRECTORY)) {
  return Optional.empty();
 }
 // Ignoring signature related files.
 if (path.startsWith("META-INF")) {
  return Optional.empty();
 }
 // Ignoring top-level files.
 if (path.getNameCount() <= 1) {
  return Optional.empty();
 }
 // Temporarily excluding .class files.
 if (path.toString().endsWith(".class")) {
  return Optional.empty();
 }
 return Optional.of(BundleModuleName.create(path.getName(0).toString()));
}

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

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

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

@Override
public ZipPath getFileName() {
 checkArgument(getNameCount() > 0, "Root does not have a file name.");
 return getName(getNameCount() - 1);
}

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

@Override
public void validateModuleFile(ZipPath file) {
 String fileName = file.getFileName().toString();
 if (file.startsWith(ASSETS_DIRECTORY)) {
 } else if (file.startsWith(DEX_DIRECTORY)) {
  if (!fileName.endsWith(".dex")) {
   throw new InvalidFileExtensionInDirectoryException(DEX_DIRECTORY, ".dex", file);
  if (file.getNameCount() != 2) {
   throw ValidationException.builder()
     .withMessage(
 } else if (file.startsWith(LIB_DIRECTORY)) {
  if (file.getNameCount() != 3) {
   throw new InvalidNativeLibraryPathException(LIB_DIRECTORY, file);
  String subDirName = file.getName(1).toString();
  if (!AbiName.fromPlatformName(subDirName).isPresent()) {
   throw InvalidNativeArchitectureNameException.createForDirectory(file.subpath(0, 2));
 } else if (file.startsWith(MANIFEST_DIRECTORY)) {
  if (!fileName.equals("AndroidManifest.xml")) {
   throw new InvalidFileNameInDirectoryException(MANIFEST_FILENAME, MANIFEST_DIRECTORY, file);
 } else if (file.startsWith(RESOURCES_DIRECTORY)) {
  if (file.getNameCount() == 2) {
   throw new FilesInResourceDirectoryRootException(RESOURCES_DIRECTORY, file);

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

public void apexModule_getsBestPossibleApk(
  @FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
 ZipPath x64Apk = ZipPath.create("standalones/standalone-x86_64.apk");
 ZipPath x64X86Apk = ZipPath.create("standalones/standalone-x86_64.x86.apk");
 ZipPath x64ArmApk = ZipPath.create("standalones/standalone-x86_64.arm64_v8a.apk");
  assertThat(matchedApks).containsExactly(inTempDirectory(x64X86Apk.toString()));
 } else {
  assertThat(matchedApks).containsExactly(inOutputDirectory(x64X86Apk.getFileName()));

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

@Override
@CheckReturnValue
public ZipPath resolve(String path) {
 return resolve(ZipPath.create(path));
}

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

@Override
public void validateModule(BundleModule module) {
 ImmutableList<String> orderedDexFiles =
   module
     .findEntriesUnderPath(BundleModule.DEX_DIRECTORY)
     .map(moduleEntry -> moduleEntry.getPath().getFileName().toString())
     .filter(fileName -> CLASSES_DEX_FILE_PATTERN.matcher(fileName).matches())
     .sorted(Comparator.comparingInt(DexFilesValidator::getClassesDexIndex))
     .collect(toImmutableList());
 validateDexNames(orderedDexFiles);
 validateHasCode(module, orderedDexFiles);
}

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

/** Check whether the given path is a valid metadata path. */
private static ZipPath checkMetadataPath(ZipPath path) {
 checkArgument(path.getNameCount() >= 2, "The metadata file path '%s' is too shallow.", path);
 checkArgument(
   path.getName(0).toString().contains("."),
   "Top-level directories for metadata files must be namespaced (eg. 'com.package'), "
     + "got %s'.",
   path.getName(0));
 return path;
}

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

@Override
@CheckReturnValue
public ZipPath resolveSibling(String path) {
 return resolveSibling(ZipPath.create(path));
}

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

@Test
public void testGetFileName() {
 assertThat((Object) ZipPath.create("foo").getFileName()).isEqualTo(ZipPath.create("foo"));
 assertThat((Object) ZipPath.create("foo/").getFileName()).isEqualTo(ZipPath.create("foo"));
 assertThat((Object) ZipPath.create("foo/bar").getFileName()).isEqualTo(ZipPath.create("bar"));
 assertThat((Object) ZipPath.create("foo/bar/").getFileName()).isEqualTo(ZipPath.create("bar"));
 assertThat((Object) ZipPath.create("foo/bar/test").getFileName())
   .isEqualTo(ZipPath.create("test"));
}

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

@Override
public ZipPath getPath() {
 ZipPath path = ZipPath.create(getZipEntry().getName());
 return path.subpath(getPathNamesToSkip(), path.getNameCount());
}

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

/**
 * Returns the base name of the subpath composed from the first element up to and including the
 * given element index.
 *
 * <p>See {@link ZipPath#subpath} and {@link TargetedDirectory#getPathBaseName}.
 */
public String getSubPathBaseName(int maxIndex) {
 return originalPath()
   .subpath(0, maxIndex + 1)
   .resolveSibling(getPathSegments().get(maxIndex).getName())
   .toString();
}

代码示例来源: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

@Test
public void testGetName() {
 ZipPath path = ZipPath.create("foo/bar");
 assertThat((Object) path.getName(0)).isEqualTo(ZipPath.create("foo"));
 assertThat((Object) path.getName(1)).isEqualTo(ZipPath.create("bar"));
}

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

@Test
public void testSubpath() {
 ZipPath path = ZipPath.create("foo/bar");
 assertThat((Object) path.subpath(0, 1)).isEqualTo(ZipPath.create("foo"));
 assertThat((Object) path.subpath(1, 2)).isEqualTo(ZipPath.create("bar"));
 assertThat((Object) path.subpath(0, 2)).isEqualTo(ZipPath.create("foo/bar"));
}

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

/**
 * Returns all {@link ModuleEntry} living directly under a given relative module directory path.
 *
 * <p>Entries inside subdirectories relative to the given directory are not returned.
 */
public Stream<ModuleEntry> findEntriesInsideDirectory(String directory) {
 return getEntries()
   .stream()
   .filter(entry -> entry.getPath().getParent().equals(ZipPath.create(directory)));
}

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

@Override
@CheckReturnValue
public ZipPath resolveSibling(Path path) {
 checkNotNull(path, "Path cannot be null.");
 checkState(!getNames().isEmpty(), "Root has not sibling.");
 return getParent().resolve(path);
}

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

private static ZipPath getUniqueResourcePath(ModuleSplit split) {
  return Stream.iterate(0, i -> i + 1)
    .map(number -> ZipPath.create(String.format(XML_PATH_PATTERN, number)))
    .filter(path -> !split.findEntry(path).isPresent())
    .findFirst()
    .get();
 }
}

相关文章