下面列出了怎么用com.google.common.collect.ImmutableMultimap.Builder的API类实例代码及写法,或者点击链接到github查看源代码。
private void buildInternal(ImmutableList.Builder<Step> steps) {
Preconditions.checkState(newInputsHash != null, "Must call checkIsCached first!");
createDxStepForDxPseudoRule(
androidPlatformTarget,
steps,
buildContext,
filesystem,
srcs,
outputPath,
dxOptions,
xzCompressionLevel,
dxMaxHeapSize,
dexTool,
classpathFiles,
useDexBuckedId,
minSdkVersion);
steps.add(
new WriteFileStep(filesystem, newInputsHash, outputHashPath, /* executable */ false));
}
private static Predicate<@NonNull Map<@NonNull String, @NonNull Object>> multiToMapPredicate(Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>> predicate) {
return map -> {
Builder<@NonNull String, @NonNull Object> builder = ImmutableMultimap.builder();
map.forEach((key, value) -> builder.put(key, value));
return predicate.test(Objects.requireNonNull(builder.build()));
};
}
private Map<String, String> createPartitionSpec() {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (HCatFieldSchema partitionColumn : partitionColumns) {
String name = partitionColumn.getName();
Object value = get(name);
checkState(value != null, "Value for partition column %s must not be null.", name);
builder.put(name, value.toString());
}
return builder.build();
}
private ImmutableMultimap<Path, Path> createXzsOutputsToInputs(
Multimap<Path, Path> outputToInputs) {
// Concatenate if solid compression is specified.
// create a mapping of the xzs file target and the dex.jar files that go into it
ImmutableMultimap.Builder<Path, Path> xzsMultimapBuilder = ImmutableMultimap.builder();
for (Path p : outputToInputs.keySet()) {
if (DexStore.XZS.matchesPath(p)) {
String[] matches = p.getFileName().toString().split("-");
Path output = p.getParent().resolve(matches[0].concat(SECONDARY_SOLID_DEX_EXTENSION));
xzsMultimapBuilder.put(output, p);
}
}
return xzsMultimapBuilder.build();
}
/**
* Once the {@code .class} files have been split into separate zip files, each must be converted
* to a {@code .dex} file.
*/
private Stream<ImmutableList<Step>> generateDxCommands(
ProjectFilesystem filesystem, Multimap<Path, Path> outputToInputs) {
ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesProvider.getDexInputHashes();
ImmutableSet<Path> allDexInputPaths = ImmutableSet.copyOf(outputToInputs.values());
return outputToInputs.asMap().entrySet().stream()
.map(
outputInputsPair ->
new DxPseudoRule(
androidPlatformTarget,
buildContext,
filesystem,
dexInputHashes,
ImmutableSet.copyOf(outputInputsPair.getValue()),
outputInputsPair.getKey(),
successDir.resolve(outputInputsPair.getKey().getFileName()),
dxOptions,
xzCompressionLevel,
dxMaxHeapSize,
dexTool,
desugarInterfaceMethods
? Sets.union(
Sets.difference(
allDexInputPaths, ImmutableSet.copyOf(outputInputsPair.getValue())),
additonalDesugarDeps.orElse(ImmutableSet.of()))
: null,
useDexBuckedId,
minSdkVersion))
.filter(dxPseudoRule -> !dxPseudoRule.checkIsCached())
.map(
dxPseudoRule -> {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
dxPseudoRule.buildInternal(steps);
return steps.build();
});
}
public static <K, V> Map<K, V> toMap(Collection<Entry<K, V>> value) {
ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
value.stream().map(Entry::toEntry).forEach(builder::put);
return builder.build();
}
public static <K, V> Multimap<K, V> toMultimap(Collection<Entry<K, V>> value) {
Builder<K, V> builder = ImmutableMultimap.builder();
value.stream().map(Entry::toEntry).forEach(builder::put);
return builder.build();
}
/**
* @param primaryOutputPath Path for the primary dex artifact.
* @param primaryInputsToDex Set of paths to include as inputs for the primary dex artifact.
* @param secondaryOutputDir Directory path for the secondary dex artifacts, if there are any.
* Note that this directory will be pruned such that only those secondary outputs generated by
* this command will remain in the directory!
* @param secondaryInputsToDex List of paths to input jar files, to use as dx input, keyed by the
* corresponding output dex file. Note that for each output file (key), a separate dx
* invocation will be started with the corresponding jar files (value) as the input.
* @param successDir Directory where success artifacts are written.
* @param executorService The thread pool to execute the dx command on.
* @param minSdkVersion
*/
public SmartDexingStep(
AndroidPlatformTarget androidPlatformTarget,
BuildContext buildContext,
ProjectFilesystem filesystem,
Optional<Path> primaryOutputPath,
Optional<Supplier<Set<Path>>> primaryInputsToDex,
Optional<Supplier<List<String>>> primaryDexWeightsSupplier,
Optional<Path> secondaryOutputDir,
Optional<Supplier<Multimap<Path, Path>>> secondaryInputsToDex,
DexInputHashesProvider dexInputHashesProvider,
Path successDir,
EnumSet<Option> dxOptions,
ListeningExecutorService executorService,
int xzCompressionLevel,
Optional<String> dxMaxHeapSize,
String dexTool,
boolean desugarInterfaceMethods,
boolean useDexBuckedId,
Optional<Set<Path>> additonalDesugarDeps,
BuildTarget buildTarget,
Optional<Integer> minSdkVersion) {
this.androidPlatformTarget = androidPlatformTarget;
this.buildContext = buildContext;
this.filesystem = filesystem;
this.desugarInterfaceMethods = desugarInterfaceMethods;
this.outputToInputsSupplier =
MoreSuppliers.memoize(
() -> {
Builder<Path, Path> map = ImmutableMultimap.builder();
if (primaryInputsToDex.isPresent()) {
map.putAll(primaryOutputPath.get(), primaryInputsToDex.get().get());
}
if (secondaryInputsToDex.isPresent()) {
map.putAll(secondaryInputsToDex.get().get());
}
return map.build();
});
this.primaryDexWeightsSupplier = primaryDexWeightsSupplier;
this.secondaryOutputDir = secondaryOutputDir;
this.dexInputHashesProvider = dexInputHashesProvider;
this.successDir = successDir;
this.dxOptions = dxOptions;
this.executorService = executorService;
this.xzCompressionLevel = xzCompressionLevel;
this.dxMaxHeapSize = dxMaxHeapSize;
this.dexTool = dexTool;
this.useDexBuckedId = useDexBuckedId;
this.additonalDesugarDeps = additonalDesugarDeps;
this.buildTarget = buildTarget;
this.minSdkVersion = minSdkVersion;
}