From 91f3e5ad3b4ca53136a66f8d26111e8a04623f4d Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 11 Dec 2015 16:41:45 +0000 Subject: Plmerge takes an optional automatic_entries_file key, which distinguishes the automatic entries from the other plist files to be merged. -- MOS_MIGRATED_REVID=109998193 --- .../build/xcode/plmerge/MergingArguments.java | 16 +++++++ .../devtools/build/xcode/plmerge/PlMerge.java | 24 ++++------ .../devtools/build/xcode/plmerge/PlistMerging.java | 56 ++++++++++++++++------ 3 files changed, 65 insertions(+), 31 deletions(-) (limited to 'src/objc_tools') diff --git a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java index d278dc870a..9f92f65771 100644 --- a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java +++ b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java @@ -32,6 +32,7 @@ class MergingArguments { private final FileSystem fileSystem = FileSystems.getDefault(); private final List sourceFilePaths; + private final List immutableSourceFilePaths; private final String outFile; private final Map variableSubstitutions; private final String primaryBundleId; @@ -46,6 +47,13 @@ class MergingArguments { sourceFilePathsBuilder.add(fileSystem.getPath(pathString)); } sourceFilePaths = sourceFilePathsBuilder.build(); + + ImmutableList.Builder immutableSourceFilePathsBuilder = new Builder<>(); + for (String pathString : control.getImmutableSourceFileList()) { + immutableSourceFilePathsBuilder.add(fileSystem.getPath(pathString)); + } + immutableSourceFilePaths = immutableSourceFilePathsBuilder.build(); + outFile = control.getOutFile(); variableSubstitutions = control.getVariableSubstitutionMap(); primaryBundleId = control.getPrimaryBundleId(); @@ -62,6 +70,7 @@ class MergingArguments { } sourceFilePaths = sourceFilePathsBuilder.build(); + immutableSourceFilePaths = ImmutableList.of(); outFile = options.outFile; variableSubstitutions = ImmutableMap.of(); primaryBundleId = options.primaryBundleId; @@ -76,6 +85,13 @@ class MergingArguments { return sourceFilePaths; } + /* + * Returns paths to plist files with keys which may not be overwritten. + */ + public List getImmutableSourceFilePaths() { + return immutableSourceFilePaths; + } + /** * Returns path to the output file to merge relative to plmerge. */ diff --git a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java index 40eaa57ade..c0b5eb8f98 100644 --- a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java +++ b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java @@ -14,7 +14,6 @@ package com.google.devtools.build.xcode.plmerge; -import com.google.common.collect.ImmutableMap; import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.Options; @@ -22,8 +21,6 @@ import com.google.devtools.common.options.OptionsBase; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsParsingException; -import com.dd.plist.NSObject; - import java.io.IOException; import java.io.InputStream; import java.nio.file.FileSystem; @@ -35,19 +32,17 @@ import java.util.List; * Entry point for the {@code plmerge} tool, which merges the data from one or more plists into a * single binary plist. This tool's functionality is similar to that of the * {@code builtin-infoPlistUtility} in Xcode. - * - *

For backwards compatibility, PlMerge can consume either a control protobuf, passed using + * + *

For backwards compatibility, PlMerge can consume either a control protobuf, passed using * --control, or the command line arguments --source_file, --out_file, --primary_bundle_id, * and --fallback_bundle_id. If a --control is not provided, PlMerge will fall back on the other * command line arguments. If --control is provided, all other command line arguments are ignored. */ public class PlMerge { - /** * Options for {@link PlMerge}. */ public static class PlMergeOptions extends OptionsBase { - @Option( name = "source_file", help = @@ -90,9 +85,8 @@ public class PlMerge { ) public String controlPath; } - - public static void main(String[] args) throws OptionsParsingException, IOException { + public static void main(String[] args) throws OptionsParsingException, IOException { FileSystem fileSystem = FileSystems.getDefault(); OptionsParser parser = OptionsParser.newOptionsParser(PlMergeOptions.class); parser.parse(args); @@ -113,9 +107,7 @@ public class PlMerge { PlistMerging merging = PlistMerging.from( - data, - ImmutableMap.of(), - new KeysToRemoveIfEmptyString("CFBundleIconFile", "NSPrincipalClass")); + data, new KeysToRemoveIfEmptyString("CFBundleIconFile", "NSPrincipalClass")); if (data.getPrimaryBundleId() != null || data.getFallbackBundleId() != null) { // Only set the bundle identifier if we were passed arguments to do so. // This prevents CFBundleIdentifiers being put into strings files. @@ -131,12 +123,12 @@ public class PlMerge { missingArg("out_file"); } } - + private static void missingArg(String flag) { - throw new IllegalArgumentException(flag + " is required:\n" - + Options.getUsage(PlMergeOptions.class)); + throw new IllegalArgumentException( + flag + " is required:\n" + Options.getUsage(PlMergeOptions.class)); } - + private static boolean usingControlProtobuf(PlMergeOptions options) { return options.controlPath != null; } diff --git a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java index 4dae6fc7fb..00f211dd9e 100644 --- a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java +++ b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java @@ -173,36 +173,62 @@ public class PlistMerging extends Value { } /** - * Generates a Plistmerging combining values from sourceFiles and automaticEntries, and modifying - * them based on subsitutions and keysToRemoveIfEmptyString. + * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and + * modifying them based on substitutions and keysToRemoveIfEmptyString. */ public static PlistMerging from( MergingArguments mergingArguments, - Map automaticEntries, KeysToRemoveIfEmptyString keysToRemoveIfEmptyString) throws IOException { + return from( mergingArguments.getSourceFilePaths(), - automaticEntries, + mergingArguments.getImmutableSourceFilePaths(), mergingArguments.getVariableSubstitutions(), keysToRemoveIfEmptyString); } /** - * Generates a Plistmerging combining values from sourceFiles and automaticEntries, and modifying + * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and + * modifying them based on subsitutions and keysToRemoveIfEmptyString. + */ + public static PlistMerging from( + List sourceFiles, + List immutableSourceFiles, + Map substitutions, + KeysToRemoveIfEmptyString keysToRemoveIfEmptyString) + throws IOException { + return from( + sourceFiles, + PlistMerging.merge(immutableSourceFiles), + substitutions, + keysToRemoveIfEmptyString); + } + + /** + * Generates a Plistmerging combining values from sourceFiles and immutableEntries, and modifying * them based on subsitutions and keysToRemoveIfEmptyString. + * + * This version of from() is required until bundlemerge no longer uses this method. + * TODO (cpeyser): Remove this version to require from() accepts a list of immutable source file + * paths instead of an already-merged map of entries. */ - public static PlistMerging from(List sourceFiles, Map automaticEntries, - Map substitutions, KeysToRemoveIfEmptyString keysToRemoveIfEmptyString) - throws IOException { + public static PlistMerging from( + List sourceFiles, + Map immutableEntries, + Map substitutions, + KeysToRemoveIfEmptyString keysToRemoveIfEmptyString) + throws IOException { NSDictionary merged = PlistMerging.merge(sourceFiles); - Set conflictingEntries = Sets.intersection(automaticEntries.keySet(), merged.keySet()); + Set conflictingEntries = Sets.intersection(immutableEntries.keySet(), merged.keySet()); - Preconditions.checkArgument(conflictingEntries.isEmpty(), - "The following plist entries are generated automatically, but are present in more than one " - + "of the input lists: %s", conflictingEntries); - merged.putAll(automaticEntries); + Preconditions.checkArgument( + conflictingEntries.isEmpty(), + "The following plist entries may not be overridden, but are present in more than one " + + "of the input lists: %s", + conflictingEntries); + merged.putAll(immutableEntries); for (Map.Entry entry : merged.entrySet()) { if (entry.getValue().toJavaObject() instanceof String) { @@ -221,10 +247,10 @@ public class PlistMerging extends Value { // Info.plist files must contain a valid CFBundleVersion and a valid CFBundleShortVersionString, // or it will be rejected by Apple. // A valid Bundle Version is 18 characters or less, and only contains [0-9.] - // We know we have an info.plist file as opposed to a strings file if the automaticEntries + // We know we have an info.plist file as opposed to a strings file if the immutableEntries // have any values set. // TODO(bazel-team): warn user if we replace their values. - if (automaticEntries.size() > 0) { + if (!immutableEntries.isEmpty()) { Pattern versionPattern = Pattern.compile("[^0-9.]"); if (!merged.containsKey(BUNDLE_VERSION_PLIST_KEY)) { merged.put(BUNDLE_VERSION_PLIST_KEY, BUNDLE_VERSION_DEFAULT); -- cgit v1.2.3