Search in sources :

Example 1 with SdkBundleValidator

use of com.android.tools.build.bundletool.validation.SdkBundleValidator in project bundletool by google.

the class BuildApksCommand method validateSdkBundles.

private void validateSdkBundles(Closer closer) throws IOException {
    SdkBundleValidator sdkBundleValidator = SdkBundleValidator.create();
    ImmutableSet.Builder<ZipFile> sdkBundleZipsBuilder = ImmutableSet.builder();
    for (Path sdkBundlePath : getRuntimeEnabledSdkBundlePaths()) {
        sdkBundleZipsBuilder.add(closer.register(new ZipFile(sdkBundlePath.toFile())));
    }
    ImmutableSet<ZipFile> sdkBundleZips = sdkBundleZipsBuilder.build();
    sdkBundleZips.forEach(sdkBundleValidator::validateFile);
    ImmutableSet<SdkBundle> sdkBundles = sdkBundleZips.stream().map(sdkBundleZip -> SdkBundle.buildFromZip(sdkBundleZip, /* versionCode= */
    0)).collect(toImmutableSet());
    sdkBundles.forEach(sdkBundleValidator::validate);
}
Also used : Path(java.nio.file.Path) RandomAccessFile(java.io.RandomAccessFile) DataSource(com.android.apksig.util.DataSource) Arrays(java.util.Arrays) SYSTEM(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) DaggerAppBundlePreprocessorComponent(com.android.tools.build.bundletool.preprocessors.DaggerAppBundlePreprocessorComponent) AppBundlePreprocessorManager(com.android.tools.build.bundletool.preprocessors.AppBundlePreprocessorManager) SYSTEM_PATH_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.SYSTEM_PATH_VARIABLE) DeviceSpec(com.android.bundle.Devices.DeviceSpec) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleValidator(com.android.tools.build.bundletool.validation.SdkBundleValidator) Flag(com.android.tools.build.bundletool.flags.Flag) ZipFile(java.util.zip.ZipFile) FilePreconditions.checkFileHasExtension(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileHasExtension) Path(java.nio.file.Path) SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) SigningConfigurationProvider(com.android.tools.build.bundletool.model.SigningConfigurationProvider) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ZipException(java.util.zip.ZipException) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) Aapt2Command(com.android.tools.build.bundletool.androidtools.Aapt2Command) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) DIRECTORY(com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.DIRECTORY) Executors(java.util.concurrent.Executors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) KeystoreProperties(com.android.tools.build.bundletool.model.KeystoreProperties) UncheckedIOException(java.io.UncheckedIOException) ByteOrder(java.nio.ByteOrder) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) Password(com.android.tools.build.bundletool.model.Password) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) AppBundleRecompressor(com.android.tools.build.bundletool.preprocessors.AppBundleRecompressor) SubValidator(com.android.tools.build.bundletool.validation.SubValidator) AutoValue(com.google.auto.value.AutoValue) APK_SET(com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.APK_SET) FilePreconditions.checkFileDoesNotExist(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist) Optional(java.util.Optional) FilePreconditions.checkFileExistsAndReadable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) ApkModifier(com.android.tools.build.bundletool.model.ApkModifier) ApkListener(com.android.tools.build.bundletool.model.ApkListener) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) ImmutableList(com.google.common.collect.ImmutableList) DefaultSystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider) Closer(com.google.common.io.Closer) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ApkFormatException(com.android.apksig.apk.ApkFormatException) AdbServer(com.android.tools.build.bundletool.device.AdbServer) AppBundleValidator(com.android.tools.build.bundletool.validation.AppBundleValidator) PrintStream(java.io.PrintStream) ANDROID_HOME_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE) FilePreconditions.checkFileExistsAndExecutable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndExecutable) DeviceSpecParser(com.android.tools.build.bundletool.device.DeviceSpecParser) Files(java.nio.file.Files) ARCHIVE(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.ARCHIVE) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Ascii(com.google.common.base.Ascii) ANDROID_SERIAL_VARIABLE(com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE) IOException(java.io.IOException) DataSources(com.android.apksig.util.DataSources) DEFAULT(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.DEFAULT) File(java.io.File) P7ZipCommand(com.android.tools.build.bundletool.androidtools.P7ZipCommand) MoreFiles(com.google.common.io.MoreFiles) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagDescription(com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription) AppBundle(com.android.tools.build.bundletool.model.AppBundle) FileUtils(com.android.tools.build.bundletool.model.utils.files.FileUtils) CommandDescription(com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription) ZipReader(com.android.tools.build.bundletool.io.ZipReader) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ZipFile(java.util.zip.ZipFile) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleValidator(com.android.tools.build.bundletool.validation.SdkBundleValidator)

Example 2 with SdkBundleValidator

use of com.android.tools.build.bundletool.validation.SdkBundleValidator in project bundletool by google.

the class BuildSdkApksCommand method execute.

public void execute() {
    validateInput();
    try (ZipFile bundleZip = new ZipFile(getSdkBundlePath().toFile());
        ZipReader zipReader = ZipReader.createFromFile(getSdkBundlePath());
        TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {
        SdkBundleValidator bundleValidator = SdkBundleValidator.create();
        bundleValidator.validateFile(bundleZip);
        SdkBundle sdkBundle = SdkBundle.buildFromZip(bundleZip, getVersionCode());
        bundleValidator.validate(sdkBundle);
        DaggerBuildSdkApksManagerComponent.builder().setBuildSdkApksCommand(this).setTempDirectory(tempDir).setSdkBundle(sdkBundle).setZipReader(zipReader).setUseBundleCompression(false).build().create().execute();
    } catch (ZipException e) {
        throw InvalidBundleException.builder().withCause(e).withUserMessage("The SDK Bundle is not a valid zip file.").build();
    } catch (IOException e) {
        throw new UncheckedIOException("An error occurred when validating the Sdk Bundle.", e);
    } finally {
        if (isExecutorServiceCreatedByBundleTool()) {
            getExecutorService().shutdown();
        }
    }
}
Also used : TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) ZipFile(java.util.zip.ZipFile) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleValidator(com.android.tools.build.bundletool.validation.SdkBundleValidator) ZipReader(com.android.tools.build.bundletool.io.ZipReader) ZipException(java.util.zip.ZipException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)2 ZipReader (com.android.tools.build.bundletool.io.ZipReader)2 SdkBundle (com.android.tools.build.bundletool.model.SdkBundle)2 SdkBundleValidator (com.android.tools.build.bundletool.validation.SdkBundleValidator)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ZipException (java.util.zip.ZipException)2 ZipFile (java.util.zip.ZipFile)2 SigningCertificateLineage (com.android.apksig.SigningCertificateLineage)1 ApkFormatException (com.android.apksig.apk.ApkFormatException)1 DataSource (com.android.apksig.util.DataSource)1 DataSources (com.android.apksig.util.DataSources)1 DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 Aapt2Command (com.android.tools.build.bundletool.androidtools.Aapt2Command)1 P7ZipCommand (com.android.tools.build.bundletool.androidtools.P7ZipCommand)1 ARCHIVE (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.ARCHIVE)1 DEFAULT (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.DEFAULT)1 SYSTEM (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM)1 UNIVERSAL (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL)1 APK_SET (com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.APK_SET)1