use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class TargetingGenerator method generateTargetingForAssets.
/**
* Processes given asset directories, generating targeting based on their names.
*
* @param assetDirectories Names of directories under assets/, including the "assets/" prefix.
* @return Targeting for the given asset directories.
*/
public Assets generateTargetingForAssets(Collection<ZipPath> assetDirectories) {
for (ZipPath directory : assetDirectories) {
// Extra '/' to handle special case when the directory is just "assets".
checkRootDirectoryName(ASSETS_DIR, directory + "/");
}
// Stores all different targeting values for a given set of sibling targeted directories.
// Key: targeted directory base name {@link TargetedDirectory#getPathBaseName}
// Values: {@link AssetsDirectoryTargeting} targeting expressed as value for each sibling.
HashMultimap<String, AssetsDirectoryTargeting> targetingByBaseName = HashMultimap.create();
for (ZipPath assetDirectory : FileUtils.toPathWalkingOrder(assetDirectories)) {
TargetedDirectory targetedDirectory = TargetedDirectory.parse(assetDirectory);
targetingByBaseName.put(targetedDirectory.getPathBaseName(), targetedDirectory.getLastSegment().getTargeting());
}
validateDimensions(targetingByBaseName);
// Pass 2: Building the directory targeting proto using the targetingByBaseName map.
Assets.Builder assetsBuilder = Assets.newBuilder();
for (ZipPath assetDirectory : assetDirectories) {
AssetsDirectoryTargeting.Builder targeting = AssetsDirectoryTargeting.newBuilder();
TargetedDirectory targetedDirectory = TargetedDirectory.parse(assetDirectory);
// We will calculate targeting of each path segment and merge them together.
for (int i = 0; i < targetedDirectory.getPathSegments().size(); i++) {
TargetedDirectorySegment segment = targetedDirectory.getPathSegments().get(i);
// Set targeting values.
targeting.mergeFrom(segment.getTargeting());
// Set targeting alternatives.
if (segment.getTargeting().hasLanguage()) {
// identical language across resources and assets.
continue;
}
targeting.mergeFrom(// Remove oneself from the alternatives and merge them together.
Sets.difference(targetingByBaseName.get(targetedDirectory.getSubPathBaseName(i)), ImmutableSet.of(segment.getTargeting())).stream().map(TargetingProtoUtils::toAlternativeTargeting).reduce(AssetsDirectoryTargeting.newBuilder(), (builder, targetingValue) -> builder.mergeFrom(targetingValue), (builderA, builderB) -> builderA.mergeFrom(builderB.build())).build());
}
assetsBuilder.addDirectory(TargetedAssetsDirectory.newBuilder().setPath(assetDirectory.toString()).setTargeting(targeting));
}
return assetsBuilder.build();
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class SplitsXmlInjector method injectSplitsXml.
private static ModuleSplit injectSplitsXml(ModuleSplit split, XmlNode xmlNode) {
ZipPath resourcePath = getUniqueResourcePath(split);
ResourceInjector resourceInjector = ResourceInjector.fromModuleSplit(split);
ResourceId resourceId = resourceInjector.addResource(XML_TYPE_NAME, createXmlEntry(resourcePath));
return split.toBuilder().setResourceTable(resourceInjector.build()).setEntries(ImmutableList.<ModuleEntry>builder().addAll(split.getEntries()).add(ModuleEntry.builder().setPath(resourcePath).setContent(ByteSource.wrap(xmlNode.toByteArray())).build()).build()).setAndroidManifest(split.getAndroidManifest().toEditor().addMetaDataResourceId(METADATA_KEY, resourceId.getFullResourceId()).save()).build();
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class FileUtils method getFileExtension.
/**
* Gets the extension of the path file.
*/
public static String getFileExtension(ZipPath path) {
if (path.getNameCount() == 0) {
return "";
}
ZipPath name = path.getFileName();
// null for empty paths and root-only paths
if (name == null) {
return "";
}
String fileName = name.toString();
int dotIndex = fileName.lastIndexOf('.');
return dotIndex == -1 ? "" : fileName.substring(dotIndex + 1);
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ResultUtilsTest method createInstantVariant.
private Variant createInstantVariant() {
ZipPath apkLBase = ZipPath.create("instant/apkL-base.apk");
ZipPath apkLFeature = ZipPath.create("instant/apkL-feature.apk");
ZipPath apkLOther = ZipPath.create("instant/apkL-other.apk");
return createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createInstantApkSet("base", ApkTargeting.getDefaultInstance(), apkLBase), createInstantApkSet("feature", ApkTargeting.getDefaultInstance(), apkLFeature), createInstantApkSet("other", ApkTargeting.getDefaultInstance(), apkLOther));
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ResultUtilsTest method createSplitVariant.
private Variant createSplitVariant() {
ZipPath apkL = ZipPath.create("splits/apkL.apk");
ZipPath apkLx86 = ZipPath.create("splits/apkL-x86.apk");
return createVariant(variantSdkTargeting(sdkVersionFrom(21)), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkL), createApkDescription(apkAbiTargeting(AbiAlias.X86, ImmutableSet.of()), apkLx86, /* isMasterSplit= */
false)));
}
Aggregations