本文整理了Java中com.android.tools.build.bundletool.model.ZipPath.getFileName()
方法的一些代码示例,展示了ZipPath.getFileName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipPath.getFileName()
方法的具体详情如下:
包路径:com.android.tools.build.bundletool.model.ZipPath
类名称:ZipPath
方法名:getFileName
暂无
代码示例来源:origin: google/bundletool
private static void validateMultiAbiFileName(ZipPath file) {
ImmutableList<String> tokens =
ImmutableList.copyOf(ABI_SPLITTER.splitToList(file.getFileName().toString()));
int nAbis = tokens.size() - 1;
// This was validated above.
checkState(tokens.get(nAbis).equals("img"), "File under 'apex/' does not have suffix 'img'");
ImmutableList<Optional<AbiName>> abis =
// Do not include the suffix "img".
tokens.stream().limit(nAbis).map(AbiName::fromPlatformName).collect(toImmutableList());
if (!abis.stream().allMatch(Optional::isPresent)) {
throw InvalidNativeArchitectureNameException.createForFile(file);
}
ImmutableSet<AbiName> uniqueAbis = abis.stream().map(Optional::get).collect(toImmutableSet());
if (uniqueAbis.size() != nAbis) {
throw ValidationException.builder()
.withMessage("Repeating architectures in APEX system image file '%s'.", file)
.build();
}
}
}
代码示例来源: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
private ImmutableList<Path> extractMatchedApksFromApksArchive(
ImmutableList<ZipPath> matchedApkPaths) {
Path outputDirectoryPath =
getOutputDirectory().orElseGet(ExtractApksCommand::createTempDirectory);
checkDirectoryExists(outputDirectoryPath);
ImmutableList.Builder<Path> builder = ImmutableList.builder();
try (ZipFile apksArchive = new ZipFile(getApksArchivePath().toFile())) {
for (ZipPath matchedApk : matchedApkPaths) {
ZipEntry entry = apksArchive.getEntry(matchedApk.toString());
checkNotNull(entry);
Path extractedApkPath = outputDirectoryPath.resolve(matchedApk.getFileName().toString());
try (InputStream inputStream = BufferedIo.inputStream(apksArchive, entry);
OutputStream outputApk = BufferedIo.outputStream(extractedApkPath)) {
ByteStreams.copy(inputStream, outputApk);
builder.add(extractedApkPath);
} catch (IOException e) {
throw new UncheckedIOException(
String.format("Error while extracting APK '%s' from the APK Set.", matchedApk), e);
}
}
} catch (IOException e) {
throw new UncheckedIOException(
String.format("Error while processing the APK Set archive '%s'.", getApksArchivePath()),
e);
}
System.err.printf(
"The APKs have been extracted in the directory: %s%n", outputDirectoryPath.toString());
return builder.build();
}
代码示例来源:origin: google/bundletool
@Test
public void testGetFileNameForRoot_throws() {
assertThrows(IllegalArgumentException.class, () -> ZipPath.create("").getFileName());
assertThrows(IllegalArgumentException.class, () -> ZipPath.create("/").getFileName());
}
}
代码示例来源: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
if (path.startsWith(APEX_DIRECTORY)) {
apexImagesBuilder.add(path.toString());
apexFileNamesBuilder.add(path.getFileName().toString());
} else if (!path.equals(APEX_MANIFEST_PATH)) {
throw ValidationException.builder()
代码示例来源:origin: google/bundletool
pathInModule);
checkFileHasExtension("File under dex/ directory", pathInModule, ".dex");
return pathInModule.getFileName();
代码示例来源:origin: google/bundletool
/**
* Generates APEX targeting based on the names of the APEX image files.
*
* @param apexImageFiles names of all files under apex/, including the "apex/" prefix.
* @return Targeting for all APEX image files.
*/
public ApexImages generateTargetingForApexImages(Collection<ZipPath> apexImageFiles) {
ImmutableMap<ZipPath, MultiAbi> targetingByPath =
Maps.toMap(apexImageFiles, path -> buildMultiAbi(path.getFileName().toString()));
ApexImages.Builder apexImages = ApexImages.newBuilder();
ImmutableSet<MultiAbi> allTargeting = ImmutableSet.copyOf(targetingByPath.values());
targetingByPath.forEach(
(imagePath, targeting) ->
apexImages.addImage(
TargetedApexImage.newBuilder()
.setPath(imagePath.toString())
.setTargeting(buildApexTargetingWithAlternatives(targeting, allTargeting))));
return apexImages.build();
}
代码示例来源:origin: google/bundletool
private static Entry createXmlEntry(ZipPath resourcePath) {
return Entry.newBuilder()
// Set filename without ".xml" as resource name.
.setName(resourcePath.getFileName().toString().split("\\.", 2)[0])
.addConfigValue(
ConfigValue.newBuilder()
.setValue(
Value.newBuilder()
.setItem(
Item.newBuilder()
.setFile(
FileReference.newBuilder()
.setPath(resourcePath.toString())
.setType(FileReference.Type.PROTO_XML)))))
.build();
}
代码示例来源:origin: google/bundletool
assertThat(matchedApks).containsExactly(inTempDirectory(x64X86Apk.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(x64X86Apk.getFileName()));
代码示例来源:origin: google/bundletool
@Override
public void validateModuleFile(ZipPath file) {
String fileName = file.getFileName().toString();
代码示例来源:origin: google/bundletool
@Test
@Theory
public void oneModule_Ldevice_matchesLmasterSplit(
@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
ZipPath apkOne = ZipPath.create("apk_one.apk");
BuildApksResult tableOfContentsProto =
BuildApksResult.newBuilder()
.addVariant(
createVariantForSingleSplitApk(
variantSdkTargeting(sdkVersionFrom(21)),
ApkTargeting.getDefaultInstance(),
apkOne))
.build();
Path apksPath = createApks(tableOfContentsProto, apksInDirectory);
DeviceSpec deviceSpec = deviceWithSdk(21);
ExtractApksCommand.Builder extractedApksCommand =
ExtractApksCommand.builder().setApksArchivePath(apksPath).setDeviceSpec(deviceSpec);
if (!apksInDirectory) {
extractedApksCommand.setOutputDirectory(tmpDir);
}
ImmutableList<Path> matchedApks = extractedApksCommand.build().execute();
if (apksInDirectory) {
assertThat(matchedApks).containsExactly(inTempDirectory(apkOne.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkOne.getFileName()));
}
for (Path matchedApk : matchedApks) {
checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
}
}
代码示例来源:origin: google/bundletool
assertThat(ZipPath.create(shard.getPath()).getFileName())
.isEqualTo(ZipPath.create("standalone.apk"));
try (ZipFile shardZip =
代码示例来源:origin: google/bundletool
assertThat(matchedApks).containsExactly(inTempDirectory(apkL.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkL.getFileName()));
代码示例来源:origin: google/bundletool
assertThat(matchedApks).containsExactly(inTempDirectory(apkM.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkM.getFileName()));
代码示例来源:origin: google/bundletool
assertThat(matchedApks).containsExactly(inTempDirectory(apkPreL.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkPreL.getFileName()));
代码示例来源:origin: google/bundletool
@Test
public void buildApksCommand_standalone_oneModuleOneVariant() throws Exception {
bundlePath = FileUtils.getRandomFilePath(tmp, "bundle-", ".aab");
AppBundle appBundle =
new AppBundleBuilder()
.addModule(
"base",
builder ->
builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")))
.build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
BuildApksCommand command =
BuildApksCommand.builder()
.setBundlePath(bundlePath)
.setOutputFile(outputFilePath)
.setAapt2Command(aapt2Command)
.build();
Path apkSetFilePath = execute(command);
ZipFile apkSetFile = new ZipFile(apkSetFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant standaloneApkVariant = standaloneApkVariants(result).get(0);
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1);
ApkSet shards = standaloneApkVariant.getApkSet(0);
assertThat(shards.getModuleMetadata().getName()).isEqualTo("base");
assertThat(shards.getApkDescriptionList()).hasSize(1);
assertThat(ZipPath.create(shards.getApkDescription(0).getPath()).getFileName())
.isEqualTo(ZipPath.create("standalone.apk"));
assertThat(apkSetFile).hasFile(shards.getApkDescription(0).getPath());
}
内容来源于网络,如有侵权,请联系作者删除!