aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java')
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java72
1 files changed, 7 insertions, 65 deletions
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 d4be46aa42..0463039fac 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
@@ -18,23 +18,16 @@ 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;
import com.dd.plist.BinaryPropertyListWriter;
-import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSObject;
import com.dd.plist.NSString;
@@ -54,7 +47,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -72,8 +64,6 @@ public class PlistMerging extends Value<PlistMerging> {
private static final String BUNDLE_VERSION_DEFAULT = "1.0.0";
private static final String BUNDLE_SHORT_VERSION_STRING_PLIST_KEY = "CFBundleShortVersionString";
private static final String BUNDLE_SHORT_VERSION_STRING_DEFAULT = "1.0";
- private static final ImmutableBiMap<String, Integer> DEVICE_FAMILIES =
- ImmutableBiMap.of("IPHONE", 1, "IPAD", 2);
/**
* Exception type thrown when validation of the plist file fails.
@@ -135,10 +125,11 @@ public class PlistMerging extends Value<PlistMerging> {
* Writes the results of a merge operation to a plist file.
* @param plistPath the path of the plist to write in binary format
*/
- public void writePlist(Path plistPath) throws IOException {
+ public PlistMerging writePlist(Path plistPath) throws IOException {
try (OutputStream out = Files.newOutputStream(plistPath)) {
BinaryPropertyListWriter.write(out, merged);
}
+ return this;
}
/**
@@ -146,42 +137,16 @@ public class PlistMerging extends Value<PlistMerging> {
* @param pkgInfoPath the path of the PkgInfo file to write. In many iOS apps, this file just
* contains the raw string {@code APPL????}.
*/
- public void writePkgInfo(Path pkgInfoPath) throws IOException {
+ public PlistMerging writePkgInfo(Path pkgInfoPath) throws IOException {
String pkgInfo =
Mapping.of(merged, "CFBundlePackageType").or(NSObject.wrap("APPL")).toString()
+ Mapping.of(merged, "CFBundleSignature").or(NSObject.wrap("????")).toString();
Files.write(pkgInfoPath, pkgInfo.getBytes(StandardCharsets.UTF_8));
- }
-
- /** Invokes {@link #writePlist(Path)} and {@link #writePkgInfo(Path)}. */
- public void write(Path plistPath, Path pkgInfoPath) throws IOException {
- writePlist(plistPath);
- writePkgInfo(pkgInfoPath);
- }
-
- /**
- * Returns a map containing entries that should be added to the merged plist. These are usually
- * generated by Xcode automatically during the build process.
- */
- public static Map<String, NSObject> automaticEntries(
- Collection<String> targetedDeviceFamily, Platform platform, String sdkVersion,
- String minimumOsVersion) {
- ImmutableMap.Builder<String, NSObject> result = new ImmutableMap.Builder<>();
- List<Integer> uiDeviceFamily = FluentIterable.from(targetedDeviceFamily)
- .transform(Maps.asConverter(DEVICE_FAMILIES))
- .toSortedList(Ordering.natural());
-
- result.put("UIDeviceFamily", NSObject.wrap(uiDeviceFamily.toArray()));
- result.put("DTPlatformName", NSObject.wrap(platform.getLowerCaseNameInPlist()));
- result.put("DTSDKName", NSObject.wrap(platform.getLowerCaseNameInPlist() + sdkVersion));
- result.put("CFBundleSupportedPlatforms", new NSArray(NSObject.wrap(platform.getNameInPlist())));
- result.put("MinimumOSVersion", NSObject.wrap(minimumOsVersion));
-
- return result.build();
+ return this;
}
/**
- * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
+ * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
* modifying them based on substitutions and keysToRemoveIfEmptyString.
*/
public static PlistMerging from(
@@ -190,7 +155,7 @@ public class PlistMerging extends Value<PlistMerging> {
throws IOException {
FileSystem fileSystem = FileSystems.getDefault();
-
+
ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<>();
for (String pathString : control.getSourceFileList()) {
sourceFilePathsBuilder.add(fileSystem.getPath(pathString));
@@ -219,31 +184,8 @@ public class PlistMerging extends Value<PlistMerging> {
KeysToRemoveIfEmptyString keysToRemoveIfEmptyString,
String executableName)
throws IOException {
- return from(
- sourceFiles,
- PlistMerging.merge(immutableSourceFiles),
- substitutions,
- keysToRemoveIfEmptyString,
- executableName);
- }
-
- /**
- * 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> immutableEntries,
- Map<String, String> substitutions,
- KeysToRemoveIfEmptyString keysToRemoveIfEmptyString,
- String executableName)
- throws IOException {
NSDictionary merged = PlistMerging.merge(sourceFiles);
-
+ NSDictionary immutableEntries = PlistMerging.merge(immutableSourceFiles);
Set<String> conflictingEntries = Sets.intersection(immutableEntries.keySet(), merged.keySet());
Preconditions.checkArgument(