.orElse(BundleConfig.getDefaultInstance()) .toBuilder() .setBundletool( 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(); } }
public BundleConfigBuilder clearCompression() { builder.clearCompression(); return this; }
public BundleConfigBuilder addResourcePinnedToMasterSplit(int resourceId) { builder.getMasterResourcesBuilder().addResourceIds(resourceId); return this; }
public BundleConfigBuilder addSplitDimension(SplitDimension splitDimension) { builder.getOptimizationsBuilder().getSplitsConfigBuilder().addSplitDimension(splitDimension); return this; }
public BundleConfigBuilder setVersion(String versionString) { builder.setBundletool(Bundletool.newBuilder().setVersion(versionString)); return this; }
public BundleConfigBuilder setUncompressDexFiles(boolean enabled) { builder.getOptimizationsBuilder().getUncompressDexFilesBuilder().setEnabled(enabled); return this; }
public BundleConfigBuilder clearVersion() { builder.getBundletoolBuilder().clearVersion(); return this; }
public BundleConfigBuilder addUncompressedGlob(String uncompressedGlob) { builder.getCompressionBuilder().addUncompressedGlob(uncompressedGlob); return this; }
public BundleConfigBuilder clearOptimizations() { builder.clearOptimizations(); return this; }
public BundleConfigBuilder setUncompressNativeLibraries(boolean enabled) { builder.getOptimizationsBuilder().getUncompressNativeLibrariesBuilder().setEnabled(enabled); return this; }