aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc_tools/plmerge
diff options
context:
space:
mode:
authorGravatar Peter Schmitt <schmitt@google.com>2015-03-20 17:59:21 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-03-23 11:55:43 +0000
commit5386fa1ef6585948b59daa8e7ab9698a844084c7 (patch)
treeac1af81a2a180c5f6307c9e96f8398d18c7a91b9 /src/objc_tools/plmerge
parent84ec4bfb479abea111acd2343c2602a44c09b3e5 (diff)
Remove common java code between objc tools and rules.
As we are releasing the tools somewhat independently of the rules these utility dependencies make life a lot harder. I'm sad about losing some of the enum type-safety but being able to treat the code independently is more than worth it. -- MOS_MIGRATED_REVID=89137624
Diffstat (limited to 'src/objc_tools/plmerge')
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java28
1 files changed, 17 insertions, 11 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 6b7f441945..558cf466f6 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,13 +17,16 @@ 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.collect.FluentIterable;
+import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+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.common.TargetDeviceFamily;
import com.google.devtools.build.xcode.util.Equaling;
-import com.google.devtools.build.xcode.util.Intersection;
import com.google.devtools.build.xcode.util.Mapping;
import com.google.devtools.build.xcode.util.Value;
@@ -46,6 +49,7 @@ 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;
@@ -58,6 +62,9 @@ import javax.xml.parsers.ParserConfigurationException;
public class PlistMerging extends Value<PlistMerging> {
private static final String BUNDLE_IDENTIFIER_PLIST_KEY = "CFBundleIdentifier";
+ private static final ImmutableBiMap<String, Integer> DEVICE_FAMILIES =
+ ImmutableBiMap.of("IPHONE", 1, "IPAD", 2);
+
/**
* Exception type thrown when validation of the plist file fails.
*/
@@ -145,14 +152,13 @@ public class PlistMerging extends Value<PlistMerging> {
* generated by Xcode automatically during the build process.
*/
public static Map<String, NSObject> automaticEntries(
- Iterable<TargetDeviceFamily> targetedDeviceFamily, Platform platform, String sdkVersion,
+ Collection<String> targetedDeviceFamily, Platform platform, String sdkVersion,
String minimumOsVersion) {
ImmutableMap.Builder<String, NSObject> result = new ImmutableMap.Builder<>();
- List<Integer> uiDeviceFamily =
- Mapping.of(
- TargetDeviceFamily.UI_DEVICE_FAMILY_VALUES,
- ImmutableSet.copyOf(targetedDeviceFamily))
- .get();
+ 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));
@@ -183,10 +189,10 @@ public class PlistMerging extends Value<PlistMerging> {
throws IOException {
NSDictionary merged = PlistMerging.merge(sourceFiles);
- Set<String> conflictingEntries = Intersection.of(automaticEntries.keySet(), merged.keySet());
+ Set<String> conflictingEntries = Sets.intersection(automaticEntries.keySet(), merged.keySet());
Preconditions.checkArgument(conflictingEntries.isEmpty(),
- "The following plist entries are generated automatically, but are present in one of the "
- + "input lists: %s", conflictingEntries);
+ "The following plist entries are generated automatically, but are present in more than one "
+ + "of the input lists: %s", conflictingEntries);
merged.putAll(automaticEntries);
for (Map.Entry<String, NSObject> entry : merged.entrySet()) {