本文整理了Java中com.android.tools.build.bundletool.io.ZipBuilder.addDirectory()
方法的一些代码示例,展示了ZipBuilder.addDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipBuilder.addDirectory()
方法的具体详情如下:
包路径:com.android.tools.build.bundletool.io.ZipBuilder
类名称:ZipBuilder
方法名:addDirectory
[英]Lazily creates empty directory at the specified path.
Note that creating an empty directory is not required to add files into that directory.
Will throw an exception if the path is already taken.
[中]在指定路径上创建空目录。
请注意,将文件添加到该目录中不需要创建空目录。
如果路径已被占用,将引发异常。
代码示例来源:origin: google/bundletool
@Test
public void validateBundleZipFile_invokesRightSubValidatorMethods() throws Exception {
Path bundlePath =
new ZipBuilder()
.addDirectory(ZipPath.create("directory"))
.addFileWithContent(ZipPath.create("file.txt"), DUMMY_CONTENT)
.writeTo(tempFolder.resolve("bundle.aab"));
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
new ValidatorRunner(ImmutableList.of(validator)).validateBundleZipFile(bundleZip);
ArgumentCaptor<ZipEntry> zipEntryArgs = ArgumentCaptor.forClass(ZipEntry.class);
verify(validator).validateBundleZipFile(eq(bundleZip));
verify(validator, atLeastOnce())
.validateBundleZipEntry(eq(bundleZip), zipEntryArgs.capture());
verifyNoMoreInteractions(validator);
assertThat(zipEntryArgs.getAllValues().stream().map(ZipEntry::getName))
.containsExactly("directory/", "file.txt");
}
}
代码示例来源:origin: google/bundletool
@Test
public void validateModuleZipFile_invokesRightSubValidatorMethods() throws Exception {
Path modulePath =
new ZipBuilder()
.addDirectory(ZipPath.create("module"))
.addFileWithContent(ZipPath.create("module/file.txt"), DUMMY_CONTENT)
.writeTo(tempFolder.resolve("module.zip"));
try (ZipFile moduleZip = new ZipFile(modulePath.toFile())) {
new ValidatorRunner(ImmutableList.of(validator)).validateModuleZipFile(moduleZip);
verify(validator).validateModuleZipFile(eq(moduleZip));
verifyNoMoreInteractions(validator);
}
}
}
代码示例来源:origin: google/bundletool
@Test
public void validateBundleZipEntry_directory_throws() throws Exception {
Path bundlePath =
new ZipBuilder()
.addDirectory(ZipPath.create("directory"))
.writeTo(tempFolder.resolve("bundle.aab"));
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
ArrayList<? extends ZipEntry> entries = Collections.list(bundleZip.entries());
// Sanity check.
assertThat(entries).hasSize(1);
ValidationException exception =
assertThrows(
ValidationException.class,
() -> new BundleZipValidator().validateBundleZipEntry(bundleZip, entries.get(0)));
assertThat(exception).hasMessageThat().contains("zip file contains directory zip entry");
}
}
代码示例来源:origin: google/bundletool
@Test
public void directoryZipEntriesInModuleFiles_notIncludedInBundle() throws Exception {
Path tmpBaseModulePath = Files.move(buildSimpleModule("base"), tmpDir.resolve("base.zip.tmp"));
Path baseModulePath;
// Copy the valid bundle, only add a directory zip entry.
try (ZipFile tmpBaseModuleZip = new ZipFile(tmpBaseModulePath.toFile())) {
baseModulePath =
new ZipBuilder()
.copyAllContentsFromZip(ZipPath.create(""), tmpBaseModuleZip)
.addDirectory(ZipPath.create("directory-entry"))
.writeTo(tmpDir.resolve("base.zip"));
}
BuildBundleCommand.builder()
.setOutputPath(bundlePath)
.setModulesPaths(ImmutableList.of(baseModulePath))
.build()
.execute();
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
assertThat(Collections.list(bundleZip.entries()).stream().filter(ZipEntry::isDirectory))
.isEmpty();
}
}
代码示例来源:origin: google/bundletool
ZipPath entryPath = moduleDir.resolve(entry.getPath());
if (entry.isDirectory()) {
zipBuilder.addDirectory(entryPath);
} else {
zipBuilder.addFile(entryPath, entry.getContentSupplier(), compression);
代码示例来源:origin: google/bundletool
@Test
public void bundleWithDirectoryZipEntries_throws() throws Exception {
Path tmpBundlePath = FileUtils.getRandomFilePath(tmp, "bundle-", ".aab");
AppBundle tmpBundle =
new AppBundleBuilder()
.addModule("base", module -> module.setManifest(androidManifest("com.app")))
.build();
bundleSerializer.writeToDisk(tmpBundle, tmpBundlePath);
// Copy the valid bundle, only add a directory zip entry.
try (ZipFile tmpBundleZip = new ZipFile(tmpBundlePath.toFile())) {
bundlePath =
new ZipBuilder()
.copyAllContentsFromZip(ZipPath.create(""), tmpBundleZip)
.addDirectory(ZipPath.create("directory-entries-are-forbidden"))
.writeTo(FileUtils.getRandomFilePath(tmp, "bundle-", ".aab"));
}
BuildApksCommand command =
BuildApksCommand.builder()
.setBundlePath(bundlePath)
.setOutputFile(outputFilePath)
.setAapt2Command(aapt2Command)
.build();
ValidationException exception = assertThrows(ValidationException.class, () -> execute(command));
assertThat(exception)
.hasMessageThat()
.contains("zip file contains directory zip entry 'directory-entries-are-forbidden/'");
}
内容来源于网络,如有侵权,请联系作者删除!