diff options
author | Yue Gan <yueg@google.com> | 2016-06-13 09:58:03 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2016-06-13 11:20:15 +0000 |
commit | 5160d196e62bf6f8fa56b32746a01b182729c5c8 (patch) | |
tree | bce2a225d4417a92a4745e96fb1b0a2fc7c704ac /src/tools/android/java/com/google/devtools/build/android/xml | |
parent | 8d23e6061ce110971d75f7a15015a60d6e49a4d4 (diff) |
Rollback of commit 4f854d47888d011354357e965fd3c7bf1d74b95f.
*** Reason for rollback ***
Breakage: http://ci.bazel.io/view/Bazel%20bootstrap%20and%20maintenance/job/Bazel/601/
*** Original change description ***
Xml processing fixes:
* Support for <item name="foo" type="id">7x0000</item>
* Adds <eat-comment/> after source attributions to ensure they are not sent to the final binary
* Store attributes for arrays to the string translatable=false case
--
MOS_MIGRATED_REVID=124708349
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/xml')
3 files changed, 31 insertions, 76 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java index 8ccb55d1d9..0a07a5daad 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java @@ -18,7 +18,6 @@ import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.devtools.build.android.AndroidDataWritingVisitor; import com.google.devtools.build.android.FullyQualifiedName; import com.google.devtools.build.android.XmlResourceValue; @@ -31,7 +30,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map.Entry; import java.util.Objects; import javax.annotation.Nullable; @@ -96,19 +94,8 @@ public class ArrayXmlResourceValue implements XmlResourceValue { String.format("%s not found in %s", tagQName, Arrays.toString(values()))); } - String openTag(FullyQualifiedName key, ImmutableMap<String, String> attributes) { - StringBuilder xmlString = new StringBuilder("<"); - xmlString.append(tagName.getLocalPart()); - xmlString.append(" name='").append(key.name()).append("'"); - for (Entry<String, String> entry : attributes.entrySet()) { - xmlString - .append(" ") - .append(entry.getKey()) - .append("='") - .append(entry.getValue()) - .append("'"); - } - return xmlString.append(">").toString(); + String openTag(FullyQualifiedName key) { + return String.format("<%s name='%s'>", tagName.getLocalPart(), key.name()); } String closeTag() { @@ -118,13 +105,10 @@ public class ArrayXmlResourceValue implements XmlResourceValue { private final ImmutableList<String> values; private final ArrayType arrayType; - private final ImmutableMap<String, String> attributes; - private ArrayXmlResourceValue( - ArrayType arrayType, ImmutableList<String> values, ImmutableMap<String, String> attributes) { + private ArrayXmlResourceValue(ArrayType arrayType, ImmutableList<String> values) { this.arrayType = arrayType; this.values = values; - this.attributes = attributes; } @VisibleForTesting @@ -133,19 +117,11 @@ public class ArrayXmlResourceValue implements XmlResourceValue { } public static XmlResourceValue of(ArrayType arrayType, List<String> values) { - return of(arrayType, values, ImmutableMap.<String, String>of()); - } - - public static XmlResourceValue of( - ArrayType arrayType, List<String> values, ImmutableMap<String, String> attributes) { - return new ArrayXmlResourceValue(arrayType, ImmutableList.copyOf(values), attributes); + return new ArrayXmlResourceValue(arrayType, ImmutableList.copyOf(values)); } public static XmlResourceValue from(SerializeFormat.DataValueXml proto) { - return of( - ArrayType.valueOf(proto.getValueType()), - proto.getListValueList(), - ImmutableMap.copyOf(proto.getMappedStringValueMap())); + return of(ArrayType.valueOf(proto.getValueType()), proto.getListValueList()); } @Override @@ -154,8 +130,7 @@ public class ArrayXmlResourceValue implements XmlResourceValue { mergedDataWriter.writeToValuesXml( key, FluentIterable.from( - ImmutableList.of( - String.format("<!-- %s -->", source), arrayType.openTag(key, attributes))) + ImmutableList.of(String.format("<!-- %s -->", source), arrayType.openTag(key))) .append(FluentIterable.from(values).transform(ITEM_TO_XML)) .append(arrayType.closeTag())); } @@ -169,13 +144,12 @@ public class ArrayXmlResourceValue implements XmlResourceValue { SerializeFormat.DataValueXml.newBuilder() .addAllListValue(values) .setType(SerializeFormat.DataValueXml.XmlType.ARRAY) - .putAllMappedStringValue(attributes) .setValueType(arrayType.toString()))); } @Override public int hashCode() { - return Objects.hash(arrayType, values, attributes); + return Objects.hash(arrayType, values); } @Override @@ -184,9 +158,7 @@ public class ArrayXmlResourceValue implements XmlResourceValue { return false; } ArrayXmlResourceValue other = (ArrayXmlResourceValue) obj; - return Objects.equals(arrayType, other.arrayType) - && Objects.equals(values, other.values) - && Objects.equals(attributes, other.attributes); + return Objects.equals(arrayType, other.arrayType) && Objects.equals(values, other.values); } @Override @@ -194,7 +166,6 @@ public class ArrayXmlResourceValue implements XmlResourceValue { return MoreObjects.toStringHelper(getClass()) .add("arrayType", arrayType) .add("values", values) - .add("attributes", attributes) .toString(); } @@ -214,16 +185,13 @@ public class ArrayXmlResourceValue implements XmlResourceValue { throw new XMLStreamException( String.format("Expected start element %s", element), element.getLocation()); } - String contents = - XmlResourceValues.readContentsAsString(eventReader, element.asStartElement().getName()); + String contents = XmlResourceValues.readContentsAsString(eventReader, + element.asStartElement().getName()); values.add(contents != null ? contents : ""); } } try { - return of( - ArrayType.fromTagName(start), - values, - ImmutableMap.copyOf(XmlResourceValues.parseTagAttributes(start))); + return of(ArrayType.fromTagName(start), values); } catch (IllegalArgumentException e) { throw new XMLStreamException(e.getMessage(), start.getLocation()); } diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java index cdf140e6d2..07b8855f4b 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java @@ -289,39 +289,21 @@ public class AttrXmlResourceValue implements XmlResourceValue { @Override public void write( FullyQualifiedName key, Path source, AndroidDataWritingVisitor mergedDataWriter) { - ImmutableList<String> formatKeys = Ordering.natural().immutableSortedCopy(formats.keySet()); - if (formatKeys.isEmpty()) { - mergedDataWriter.writeToValuesXml(key, - ImmutableList.of( - String.format("<!-- %s -->", source), - String.format( - "<attr name='%s'/>", - key.name()))); - } else if (formats.containsKey(FLAGS) || formats.containsKey(ENUM)) { - FluentIterable<String> iterable = - FluentIterable.from( - ImmutableList.of( - String.format("<!-- %s -->", source), - formatKeys.isEmpty() - ? String.format("<attr name='%s'>", key.name()) - : String.format( - "<attr format='%s' name='%s' >", - Joiner.on('|').join(formatKeys), key.name()))); - for (String formatKey : formatKeys) { - iterable = formats.get(formatKey).appendTo(iterable); - } - mergedDataWriter.writeToValuesXml(key, iterable.append("</attr>")); - } else { - mergedDataWriter.writeToValuesXml(key, - ImmutableList.of( - String.format("<!-- %s -->", source), - String.format( - "<attr format='%s' name='%s'/>", - Joiner.on('|').join(formatKeys), - key.name() - ))); - } + FluentIterable<String> iterable = + FluentIterable.from( + ImmutableList.of( + String.format("<!-- %s -->", source), + formatKeys.isEmpty() + ? String.format("<attr name='%s'>", key.name()) + : String.format( + "<attr name='%s' format='%s'>", + key.name(), + Joiner.on('|').join(formatKeys)))); + for (String formatKey : formatKeys) { + iterable = formats.get(formatKey).appendTo(iterable); + } + mergedDataWriter.writeToValuesXml(key, iterable.append("</attr>")); } @Override diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java index 987a25d16f..9169401c21 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java @@ -175,6 +175,11 @@ public class SimpleXmlResourceValue implements XmlResourceValue { return withAttributes(Type.ITEM, ImmutableMap.of("type", resourceType.getName())); } + @Deprecated + public static XmlResourceValue of(Type valueType, @Nullable String value) { + return of(valueType, ImmutableMap.<String, String>of(), value); + } + public static XmlResourceValue of( Type valueType, ImmutableMap<String, String> attributes, @Nullable String value) { return new SimpleXmlResourceValue(valueType, attributes, value); @@ -221,7 +226,7 @@ public class SimpleXmlResourceValue implements XmlResourceValue { public static XmlResourceValue from(SerializeFormat.DataValueXml proto) { return of( Type.valueOf(proto.getValueType()), - ImmutableMap.copyOf(proto.getMappedStringValueMap()), + ImmutableMap.copyOf(proto.getMappedStringValue()), proto.hasValue() ? proto.getValue() : null); } |