aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc_tools
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-12-11 16:41:45 +0000
committerGravatar David Chen <dzc@google.com>2015-12-11 17:08:45 +0000
commit91f3e5ad3b4ca53136a66f8d26111e8a04623f4d (patch)
treed517ddce7cd7d030bf292fdf79af1d0c3dba1d5e /src/objc_tools
parent9ee7c311f7231b1801b965f52de75fa95e47aec3 (diff)
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
Diffstat (limited to 'src/objc_tools')
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java16
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java24
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java56
3 files changed, 65 insertions, 31 deletions
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<Path> sourceFilePaths;
+ private final List<Path> immutableSourceFilePaths;
private final String outFile;
private final Map<String, String> variableSubstitutions;
private final String primaryBundleId;
@@ -46,6 +47,13 @@ class MergingArguments {
sourceFilePathsBuilder.add(fileSystem.getPath(pathString));
}
sourceFilePaths = sourceFilePathsBuilder.build();
+
+ ImmutableList.Builder<Path> 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.<Path>of();
outFile = options.outFile;
variableSubstitutions = ImmutableMap.<String, String>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<Path> 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.
- *
- * <p>For backwards compatibility, PlMerge can consume either a control protobuf, passed using
+ *
+ * <p>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.<String, NSObject>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<PlistMerging> {
}
/**
- * 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<String, NSObject> 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<Path> sourceFiles,
+ List<Path> immutableSourceFiles,
+ Map<String, String> 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<Path> sourceFiles, Map<String, NSObject> automaticEntries,
- Map<String, String> substitutions, KeysToRemoveIfEmptyString keysToRemoveIfEmptyString)
- throws IOException {
+ public static PlistMerging from(
+ List<Path> sourceFiles,
+ Map<String, NSObject> immutableEntries,
+ Map<String, String> substitutions,
+ KeysToRemoveIfEmptyString keysToRemoveIfEmptyString)
+ throws IOException {
NSDictionary merged = PlistMerging.merge(sourceFiles);
- Set<String> conflictingEntries = Sets.intersection(automaticEntries.keySet(), merged.keySet());
+ Set<String> 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<String, NSObject> entry : merged.entrySet()) {
if (entry.getValue().toJavaObject() instanceof String) {
@@ -221,10 +247,10 @@ public class PlistMerging extends Value<PlistMerging> {
// 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);