本文整理了Java中com.android.tools.build.bundletool.model.ZipPath.resolve()
方法的一些代码示例,展示了ZipPath.resolve()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipPath.resolve()
方法的具体详情如下:
包路径:com.android.tools.build.bundletool.model.ZipPath
类名称:ZipPath
方法名:resolve
暂无
代码示例来源:origin: google/bundletool
/**
* Iterates over the given {@code proposedName} by suffixing the name with an increasing integer
* until an unused path is found, then returns this path.
*/
private synchronized ZipPath findAndClaimUnusedPath(
ZipPath directory, String proposedName, String fileExtension) {
ZipPath apkPath = directory.resolve(proposedName + fileExtension);
int serialNumber = 1;
while (usedPaths.contains(apkPath)) {
serialNumber++;
String fileName = String.format("%s_%d", proposedName, serialNumber);
apkPath = directory.resolve(fileName + fileExtension);
}
usedPaths.add(apkPath);
return apkPath;
}
代码示例来源:origin: google/bundletool
@Override
@CheckReturnValue
public ZipPath resolve(String path) {
return resolve(ZipPath.create(path));
}
代码示例来源:origin: google/bundletool
/**
* Copies all file entries from <code>srcZipFile</code> to <code>toDirectory</code> inside the
* output being built. This operation cannot rewrite any already existing entry.
*
* <p>Note that zip directory entries (including empty directories) are not copied.
*/
public ZipBuilder copyAllContentsFromZip(
ZipPath toDirectory, ZipFile srcZipFile, EntryOption... entryOptions) {
Enumeration<? extends ZipEntry> zipEntries = srcZipFile.entries();
while (zipEntries.hasMoreElements()) {
ZipEntry zipEntry = zipEntries.nextElement();
if (!zipEntry.isDirectory()) {
addFileFromZip(toDirectory.resolve(zipEntry.getName()), srcZipFile, zipEntry, entryOptions);
}
}
return this;
}
代码示例来源: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 ModuleEntry createEntryForAbi(Abi abi) {
return InMemoryModuleEntry.ofFile(
BundleModule.LIB_DIRECTORY
.resolve(AbiName.fromProto(abi.getAlias()).getPlatformName())
.resolve("libplaceholder.so"),
new byte[0]);
}
}
代码示例来源:origin: google/bundletool
/** Converts the arguments to a valid key for {@link #getFileDataMap()}. */
private static ZipPath toMetadataPath(String namespacedDir, String fileName) {
return checkMetadataPath(ZipPath.create(namespacedDir).resolve(fileName));
}
代码示例来源:origin: google/bundletool
/**
* Adds the given file as metadata to the bundle into directory {@code
* BUNDLE-METADATA/<namespaced-dir>/<file-name>}.
*
* <p>Optional. Throws when the given file does not exist. Adding duplicate metadata files (same
* directory and filename) will result in exception being thrown by {@link #build()}.
*
* <p>See {@link BundleMetadata} for well-known metadata namespaces and file names.
*
* @param metadataDirectory namespaced directory inside the bundle metadata directory
* @param fileName name of the file to be added to the metadata directory
* @param file path to file containing the data
*/
public Builder addMetadataFile(String metadataDirectory, String fileName, Path file) {
addMetadataFileInternal(ZipPath.create(metadataDirectory).resolve(fileName), file);
return this;
}
代码示例来源:origin: google/bundletool
private static void checkModuleHasAndroidManifest(
ZipFile zipFile, ZipPath moduleBaseDir, String moduleName) {
ZipPath moduleManifestPath =
moduleBaseDir.resolve(SpecialModuleEntry.ANDROID_MANIFEST.getPath());
if (zipFile.getEntry(moduleManifestPath.toString()) == null) {
throw new MandatoryModuleFileMissingException(
moduleName, SpecialModuleEntry.ANDROID_MANIFEST.getPath());
}
}
}
代码示例来源:origin: google/bundletool
private Collection<ModuleEntry> mergeDexFilesAndCache(
ListMultimap<BundleModuleName, ModuleEntry> dexFilesToMergeByModule,
BundleMetadata bundleMetadata,
AndroidManifest androidManifest,
Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> mergedDexCache) {
if (dexFilesToMergeByModule.keySet().size() <= 1) {
// Don't merge if all dex files live inside a single module. If that module contains multiple
// dex files, it should have been built with multi-dex support.
return dexFilesToMergeByModule.values();
} else {
ImmutableList<ModuleEntry> dexEntries =
ImmutableList.copyOf(dexFilesToMergeByModule.values());
ImmutableList<Path> mergedDexFiles =
mergedDexCache.computeIfAbsent(
ImmutableSet.copyOf(dexEntries),
key -> mergeDexFiles(dexEntries, bundleMetadata, androidManifest));
// Names of the merged dex files need to be preserved ("classes.dex", "classes2.dex" etc.).
return mergedDexFiles
.stream()
.map(
filePath ->
FileSystemModuleEntry.ofFile(
/* entryPath= */ DEX_DIRECTORY.resolve(filePath.getFileName().toString()),
/* fileSystemPath= */ filePath))
.collect(toImmutableList());
}
}
代码示例来源:origin: google/bundletool
@Test
public void testResolveForbiddenNames_throws() {
ZipPath path = ZipPath.create("foo");
assertThrows(IllegalArgumentException.class, () -> path.resolve(".."));
assertThrows(IllegalArgumentException.class, () -> path.resolve("."));
assertThrows(IllegalArgumentException.class, () -> path.resolve("a/.."));
assertThrows(IllegalArgumentException.class, () -> path.resolve("a/."));
}
代码示例来源:origin: google/bundletool
void printManifest(BundleModuleName moduleName, Optional<String> xPathExpression) {
// Extract the manifest from the bundle.
ZipPath manifestPath =
ZipPath.create(moduleName.getName()).resolve(SpecialModuleEntry.ANDROID_MANIFEST.getPath());
XmlProtoNode manifestProto =
new XmlProtoNode(extractAndParse(bundlePath, manifestPath, XmlNode::parseFrom));
// Convert the proto to real XML.
Document document = XmlProtoToXmlConverter.convert(manifestProto);
// Select the output.
String output;
if (xPathExpression.isPresent()) {
try {
XPath xPath = XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(new XmlNamespaceContext(manifestProto));
XPathExpression compiledXPathExpression = xPath.compile(xPathExpression.get());
XPathResult xPathResult = XPathResolver.resolve(document, compiledXPathExpression);
output = xPathResult.toString();
} catch (XPathExpressionException e) {
throw new ValidationException("Error in the XPath expression: " + xPathExpression, e);
}
} else {
output = XmlUtils.documentToString(document);
}
// Print the output.
printStream.println(output.trim());
}
代码示例来源:origin: google/bundletool
@Test
public void testResolveNull_throws() {
ZipPath path = ZipPath.create("foo");
assertThrows(NullPointerException.class, () -> path.resolve((String) null));
assertThrows(NullPointerException.class, () -> path.resolve((Path) null));
}
代码示例来源:origin: google/bundletool
@Test
public void testResolve_fromString() {
assertThat((Object) ZipPath.create("foo/bar/hello").resolve(""))
.isEqualTo(ZipPath.create("foo/bar/hello"));
assertThat((Object) ZipPath.create("foo/bar").resolve("hello"))
.isEqualTo(ZipPath.create("foo/bar/hello"));
assertThat((Object) ZipPath.create("foo").resolve("bar/hello"))
.isEqualTo(ZipPath.create("foo/bar/hello"));
}
代码示例来源:origin: google/bundletool
@Test
public void testResolve_fromEmptyPath() {
assertThat((Object) ZipPath.create("").resolve("foo")).isEqualTo(ZipPath.create("foo"));
assertThat((Object) ZipPath.create("").resolve("foo/bar")).isEqualTo(ZipPath.create("foo/bar"));
}
代码示例来源:origin: google/bundletool
@Test
public void testResolve_fromPath() {
assertThat((Object) ZipPath.create("foo/bar/hello").resolve(ZipPath.create("")))
.isEqualTo(ZipPath.create("foo/bar/hello"));
assertThat((Object) ZipPath.create("foo/bar").resolve(ZipPath.create("hello")))
.isEqualTo(ZipPath.create("foo/bar/hello"));
assertThat((Object) ZipPath.create("foo").resolve(ZipPath.create("bar/hello")))
.isEqualTo(ZipPath.create("foo/bar/hello"));
}
代码示例来源:origin: google/bundletool
bundle.getBundleMetadata().getFileDataMap().entrySet()) {
zipBuilder.addFile(
METADATA_DIRECTORY.resolve(metadataEntry.getKey()),
metadataEntry.getValue(),
compression);
ZipPath entryPath = moduleDir.resolve(entry.getPath());
if (entry.isDirectory()) {
zipBuilder.addDirectory(entryPath);
moduleDir.resolve(SpecialModuleEntry.ANDROID_MANIFEST.getPath()),
module.getAndroidManifest().getManifestRoot().getProto(),
compression);
assetsConfig ->
zipBuilder.addFileWithProtoContent(
moduleDir.resolve(SpecialModuleEntry.ASSETS_TABLE.getPath()),
assetsConfig,
compression));
nativeConfig ->
zipBuilder.addFileWithProtoContent(
moduleDir.resolve(SpecialModuleEntry.NATIVE_LIBS_TABLE.getPath()),
nativeConfig,
compression));
resourceTable ->
zipBuilder.addFileWithProtoContent(
moduleDir.resolve(SpecialModuleEntry.RESOURCE_TABLE.getPath()),
内容来源于网络,如有侵权,请联系作者删除!