From 6b47b094cb3410ce54e978d16f4121d92027f3bf Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Sat, 24 Oct 2015 00:05:57 +0000 Subject: Change default bundle ids that are generated in plists to be RFC1034 compliant. In general this means taking bad characters [^-0-9A-Za-z.] and converting them to "-". So com.foo.bar_bam becomes com.foo.bar-bam. This is essentially equivalent to what Xcode does internally. RELNOTES:none -- MOS_MIGRATED_REVID=106191981 --- .../devtools/build/xcode/plmerge/PlistMerging.java | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/objc_tools') 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 e35255c57c..1ba520f9ba 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 @@ -230,23 +230,29 @@ public class PlistMerging extends Value { return new PlistMerging(merged); } - // Assume that if an RFC 1034 format string is specified, the value is RFC 1034 compliant. private static String substituteEnvironmentVariable( Map substitutions, String string) { // The substitution is *not* performed recursively. for (Map.Entry variable : substitutions.entrySet()) { - for (String variableNameWithFormatString : withFormatStrings(variable.getKey())) { - string = string - .replace("${" + variableNameWithFormatString + "}", variable.getValue()) - .replace("$(" + variableNameWithFormatString + ")", variable.getValue()); - } + String key = variable.getKey(); + String value = variable.getValue(); + string = string + .replace("${" + key + "}", value) + .replace("$(" + key + ")", value); + key = key + ":rfc1034identifier"; + value = convertToRFC1034(value); + string = string + .replace("${" + key + "}", value) + .replace("$(" + key + ")", value); } return string; } - private static ImmutableSet withFormatStrings(String variableName) { - return ImmutableSet.of(variableName, variableName + ":rfc1034identifier"); + // Force RFC1034 compliance by changing any "bad" character to a '-' + // This is essentially equivalent to what Xcode does. + private static String convertToRFC1034(String value) { + return value.replaceAll("[^-0-9A-Za-z.]", "-"); } @VisibleForTesting @@ -291,10 +297,10 @@ public class PlistMerging extends Value { NSString bundleIdentifier = (NSString) merged.get(BUNDLE_IDENTIFIER_PLIST_KEY); if (primaryIdentifier != null) { - merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, primaryIdentifier); + merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, convertToRFC1034(primaryIdentifier)); } else if (bundleIdentifier == null) { if (fallbackIdentifier != null) { - merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, fallbackIdentifier); + merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, convertToRFC1034(fallbackIdentifier)); } else { // TODO(bazel-team): We shouldn't be generating an info.plist in this case. merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, BUNDLE_IDENTIFIER_DEFAULT); -- cgit v1.2.3