aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc_tools
diff options
context:
space:
mode:
authorGravatar Dave MacLachlan <dmaclach@google.com>2016-02-23 23:54:17 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-02-24 17:57:38 +0000
commite3f5387155026da2194eefed2723b773ae62051d (patch)
treead9a703b9ba5b76118739a58205e5cad9ec2330f /src/objc_tools
parentb8d6b780d421be550ca42329e2eefc70c35c8153 (diff)
Simplify plmerge getting rid of command line options that are no longer used.
-- MOS_MIGRATED_REVID=115393203
Diffstat (limited to 'src/objc_tools')
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java146
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java82
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java31
3 files changed, 42 insertions, 217 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
deleted file mode 100644
index cf6373afc3..0000000000
--- a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/MergingArguments.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.xcode.plmerge;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.common.collect.ImmutableMap;
-import com.google.devtools.build.xcode.plmerge.PlMerge.PlMergeOptions;
-import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control;
-
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Container for data consumed by plmerge
- */
-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;
- private final String fallbackBundleId;
- private final String executableName;
-
- /**
- * Build MergingArguments from a plmerge protobuf.
- */
- public MergingArguments(Control control) {
- ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<>();
- for (String pathString : control.getSourceFileList()) {
- 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 = Strings.emptyToNull(control.getPrimaryBundleId());
- fallbackBundleId = Strings.emptyToNull(control.getFallbackBundleId());
- executableName = Strings.emptyToNull(control.getExecutableName());
- }
-
- /**
- * Build MergingArguments from command line arguments passed to the plmerge executable.
- */
- public MergingArguments(PlMergeOptions options) {
- ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<Path>();
- for (String sourceFile : options.sourceFiles) {
- sourceFilePathsBuilder.add(fileSystem.getPath(sourceFile));
- }
-
- sourceFilePaths = sourceFilePathsBuilder.build();
- immutableSourceFilePaths = ImmutableList.<Path>of();
- outFile = options.outFile;
- variableSubstitutions = ImmutableMap.<String, String>of();
- primaryBundleId = options.primaryBundleId;
- fallbackBundleId = options.fallbackBundleId;
- executableName = null;
- }
-
- /**
- * Returns paths to the plist files to merge relative to plmerge. These can be
- * binary, XML, or ASCII format.
- */
- public List<Path> getSourceFilePaths() {
- 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.
- */
- public String getOutFile() {
- return outFile;
- }
-
- /**
- * Returns a reverse-DNS string identifier for this bundle associated with output
- * binary plist. Overrides the bundle id specified in the CFBundleIdentifier
- * plist field.
- */
- public String getPrimaryBundleId() {
- return primaryBundleId;
- }
-
- /**
- * Returns a fallback reverse-DNS string identifier for this bundle when bundle
- * identifier is not specified in primary_bundle_id or an associated plist
- * file.
- */
- public String getFallbackBundleId() {
- return fallbackBundleId;
- }
-
- /**
- * Returns key-value substitutions to support templating for plists. A substitution
- * is made if the substitution key appears as a value for any key-value pair
- * in any source_file.
- * For example, a plist with the entry:
- * <pre><key>CFBundleExectuable</key>
- * <string>EXECUTABLE_NAME</string></pre>
- * could be templated by passing a variable substitution like
- * {"EXECUTABLE_NAME", "PrenotCalculator"}
- */
- public Map<String, String> getVariableSubstitutions() {
- return variableSubstitutions;
- }
-
- /**
- * Returns the name of the executable for the bundle the merged plist is intended for, or null
- * if no such executable exists.
- */
- public String getExecutableName() {
- return executableName;
- }
-}
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 c0b5eb8f98..c204e2f53d 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,6 +14,7 @@
package com.google.devtools.build.xcode.plmerge;
+import com.google.common.base.Strings;
import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.Options;
@@ -26,17 +27,13 @@ import java.io.InputStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
-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
- * --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.
+ * <p>--control is a control protobuf.
*/
public class PlMerge {
/**
@@ -44,43 +41,8 @@ public class PlMerge {
*/
public static class PlMergeOptions extends OptionsBase {
@Option(
- name = "source_file",
- help =
- "Paths to the plist files to merge. These can be binary, XML, or ASCII format. "
- + "Repeat this flag to specify multiple files. Required.",
- allowMultiple = true,
- defaultValue = "null"
- )
- public List<String> sourceFiles;
-
- @Option(name = "out_file", help = "Path to the output file. Required.", defaultValue = "null")
- public String outFile;
-
- @Option(
- name = "primary_bundle_id",
- help =
- "A reverse-DNS string identifier for this bundle associated with output binary "
- + "plist. This flag overrides the bundle id specified in field CFBundleIdentifier in "
- + "the associated plist file.",
- defaultValue = "null"
- )
- public String primaryBundleId;
-
- @Option(
- name = "fallback_bundle_id",
- help =
- "A fallback reverse-DNS string identifier for this bundle when the bundle "
- + "identifier is not specified in flag primary_bundle_id or associated plist file",
- defaultValue = "null"
- )
- public String fallbackBundleId;
-
- @Option(
name = "control",
- help =
- "Absolute path of the Control protobuf. Data can be passed to plmerge through this "
- + "protobuf or through source_file, out_file, primary_bundle_id and "
- + "fallback_bundle_id.",
+ help = "Absolute path of the Control protobuf.",
defaultValue = "null"
)
public String controlPath;
@@ -92,28 +54,28 @@ public class PlMerge {
parser.parse(args);
PlMergeOptions options = parser.getOptions(PlMergeOptions.class);
- MergingArguments data = null;
-
- if (usingControlProtobuf(options)) {
- InputStream in = Files.newInputStream(fileSystem.getPath(options.controlPath));
- Control control = Control.parseFrom(in);
- validateControl(control);
- data = new MergingArguments(control);
- } else if (usingCommandLineArgs(options)) {
- data = new MergingArguments(options);
- } else {
- missingArg("Either --control or --out_file and at least one --source_file");
+ if (options.controlPath == null) {
+ missingArg("control");
}
+ InputStream in = Files.newInputStream(fileSystem.getPath(options.controlPath));
+ Control control = Control.parseFrom(in);
+ validateControl(control);
+
PlistMerging merging =
PlistMerging.from(
- data, new KeysToRemoveIfEmptyString("CFBundleIconFile", "NSPrincipalClass"));
- if (data.getPrimaryBundleId() != null || data.getFallbackBundleId() != null) {
+ control, new KeysToRemoveIfEmptyString("CFBundleIconFile", "NSPrincipalClass"));
+
+ String primaryBundleId = Strings.emptyToNull(control.getPrimaryBundleId());
+ String fallbackBundleId = Strings.emptyToNull(control.getFallbackBundleId());
+
+
+ if (primaryBundleId != null || fallbackBundleId != null) {
// Only set the bundle identifier if we were passed arguments to do so.
// This prevents CFBundleIdentifiers being put into strings files.
- merging.setBundleIdentifier(data.getPrimaryBundleId(), data.getFallbackBundleId());
+ merging.setBundleIdentifier(primaryBundleId, fallbackBundleId);
}
- merging.writePlist(fileSystem.getPath(data.getOutFile()));
+ merging.writePlist(fileSystem.getPath(control.getOutFile()));
}
private static void validateControl(Control control) {
@@ -128,12 +90,4 @@ public class PlMerge {
throw new IllegalArgumentException(
flag + " is required:\n" + Options.getUsage(PlMergeOptions.class));
}
-
- private static boolean usingControlProtobuf(PlMergeOptions options) {
- return options.controlPath != null;
- }
-
- private static boolean usingCommandLineArgs(PlMergeOptions options) {
- return (!options.sourceFiles.isEmpty()) && (options.outFile != 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 6a39870910..d4be46aa42 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
@@ -17,14 +17,18 @@ package com.google.devtools.build.xcode.plmerge;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableBiMap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.io.ByteSource;
import com.google.devtools.build.xcode.common.Platform;
+import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control;
import com.google.devtools.build.xcode.util.Equaling;
import com.google.devtools.build.xcode.util.Mapping;
import com.google.devtools.build.xcode.util.Value;
@@ -44,6 +48,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
@@ -179,18 +185,29 @@ public class PlistMerging extends Value<PlistMerging> {
* modifying them based on substitutions and keysToRemoveIfEmptyString.
*/
public static PlistMerging from(
- MergingArguments mergingArguments,
+ Control control,
KeysToRemoveIfEmptyString keysToRemoveIfEmptyString)
throws IOException {
-
+
+ FileSystem fileSystem = FileSystems.getDefault();
+
+ ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<>();
+ for (String pathString : control.getSourceFileList()) {
+ sourceFilePathsBuilder.add(fileSystem.getPath(pathString));
+ }
+ ImmutableList.Builder<Path> immutableSourceFilePathsBuilder = new Builder<>();
+ for (String pathString : control.getImmutableSourceFileList()) {
+ immutableSourceFilePathsBuilder.add(fileSystem.getPath(pathString));
+ }
+
return from(
- mergingArguments.getSourceFilePaths(),
- mergingArguments.getImmutableSourceFilePaths(),
- mergingArguments.getVariableSubstitutions(),
+ sourceFilePathsBuilder.build(),
+ immutableSourceFilePathsBuilder.build(),
+ control.getVariableSubstitutionMap(),
keysToRemoveIfEmptyString,
- mergingArguments.getExecutableName());
+ Strings.emptyToNull(control.getExecutableName()));
}
-
+
/**
* Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
* modifying them based on subsitutions and keysToRemoveIfEmptyString.