Bundletool.newBuilder() .setVersion(BundleToolVersion.getCurrentVersion().toString())) .build();
@Test public void buildingViaFlagsAndBuilderHasSameResult_optionalBundleConfig() throws Exception { Path modulePath = createSimpleBaseModule(); Path bundleConfigJsonPath = tmpDir.resolve("BundleConfig.pb.json"); Files.write( bundleConfigJsonPath, ("{ \"compression\": { \"uncompressedGlob\": [\"foo\"] } }").getBytes(UTF_8)); BuildBundleCommand commandViaBuilder = BuildBundleCommand.builder() .setOutputPath(bundlePath) .setModulesPaths(ImmutableList.of(modulePath)) // Optional values. .setBundleConfig( BundleConfig.newBuilder() .setCompression(Compression.newBuilder().addUncompressedGlob("foo")) .build()) .build(); BuildBundleCommand commandViaFlags = BuildBundleCommand.fromFlags( new FlagParser() .parse( "--output=" + bundlePath, "--modules=" + modulePath, // Optional values. "--config=" + bundleConfigJsonPath)); assertThat(commandViaBuilder).isEqualTo(commandViaFlags); }
private static BundleConfig parseBundleConfigJson(Path bundleConfigJsonPath) { BundleConfig.Builder bundleConfig = BundleConfig.newBuilder(); try (Reader bundleConfigReader = BufferedIo.reader(bundleConfigJsonPath)) { JsonFormat.parser().merge(bundleConfigReader, bundleConfig); } catch (InvalidProtocolBufferException e) { throw CommandExecutionException.builder() .withCause(e) .withMessage("The file '%s' is not a valid BundleConfig JSON file.", bundleConfigJsonPath) .build(); } catch (IOException e) { throw CommandExecutionException.builder() .withCause(e) .withMessage( "An error occurred while trying to read the file '%s'.", bundleConfigJsonPath) .build(); } return bundleConfig.build(); }
public BundleConfig build() { return builder.build(); } }