aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-07-06 13:51:24 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-07-07 08:38:54 +0000
commit8a0fbb88c958eb86f75dddd37f2221d0873c7ac2 (patch)
tree10e4049c62d8c628343cf89cb5f6a5ec19defce5 /src/tools/android/java/com/google
parentbc16f72f22a6ba1e1d95ec91f973974826ffe0b4 (diff)
Remove .9 from nine-patch FullyQualifiedNames
In the end, foo.9.png should result in an R.java field R.drawable.foo (not R.drawable.foo_9). Also, given foo.9.png and foo.png, aapt will give an error: res/drawable/foo.png:0: error: Resource entry foo is already defined. res/drawable/foo.9.png:0: Originally defined here. So it seems like we should generate a merge conflict warning as well. Adjust FQN accordingly. -- MOS_MIGRATED_REVID=126693820
Diffstat (limited to 'src/tools/android/java/com/google')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/DataValueFile.java12
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java45
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java20
3 files changed, 44 insertions, 33 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/DataValueFile.java b/src/tools/android/java/com/google/devtools/build/android/DataValueFile.java
index c5e9bf6e36..2f41931d32 100644
--- a/src/tools/android/java/com/google/devtools/build/android/DataValueFile.java
+++ b/src/tools/android/java/com/google/devtools/build/android/DataValueFile.java
@@ -83,7 +83,7 @@ public class DataValueFile implements DataResource, DataAsset {
@Override
public void writeResource(FullyQualifiedName key, AndroidDataWritingVisitor mergedDataWriter)
throws IOException, MergingException {
- mergedDataWriter.copyResource(source, key.toPathString(getSourceExtension()));
+ mergedDataWriter.copyResource(source, key.toPathString(source));
}
@Override
@@ -96,16 +96,6 @@ public class DataValueFile implements DataResource, DataAsset {
+ value.getSerializedSize();
}
- private String getSourceExtension() {
- // TODO(corysmith): Find out if there is a filename parser utility.
- String fileName = source.getFileName().toString();
- int extensionStart = fileName.lastIndexOf('.');
- if (extensionStart > 0) {
- return fileName.substring(extensionStart);
- }
- return "";
- }
-
@Override
public DataResource combineWith(DataResource resource) {
throw new IllegalArgumentException(getClass() + " does not combine.");
diff --git a/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java b/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java
index eeebbbcfab..db697d0bdc 100644
--- a/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java
+++ b/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java
@@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@@ -246,6 +247,44 @@ public class FullyQualifiedName implements DataKey, Comparable<FullyQualifiedNam
return FullyQualifiedName.of(
parsedPackage == null ? pkg : parsedPackage, qualifiers, resourceType, resourceName);
}
+
+ /**
+ * Generates a FullyQualifiedName for a file-based resource given the source Path.
+ *
+ * @param sourcePath the path of the file-based resource.
+ * @throws IllegalArgumentException if the file-based resource has an invalid filename
+ */
+ public FullyQualifiedName parse(Path sourcePath) {
+ return parse(deriveRawFullyQualifiedName(sourcePath));
+ }
+
+ private static String deriveRawFullyQualifiedName(Path source) {
+ if (source.getNameCount() < 2) {
+ throw new IllegalArgumentException(
+ String.format(
+ "The resource path %s is too short. "
+ + "The path is expected to be <resource type>/<file name>.",
+ source));
+ }
+ String pathWithExtension =
+ source.subpath(source.getNameCount() - 2, source.getNameCount()).toString();
+ int extensionStart = pathWithExtension.indexOf('.');
+ if (extensionStart > 0) {
+ return pathWithExtension.substring(0, extensionStart);
+ }
+ return pathWithExtension;
+ }
+
+ // Grabs the extension portion of the path removed by deriveRawFullyQualifiedName.
+ private static String getSourceExtension(Path source) {
+ // TODO(corysmith): Find out if there is a filename parser utility.
+ String fileName = source.getFileName().toString();
+ int extensionStart = fileName.indexOf('.');
+ if (extensionStart > 0) {
+ return fileName.substring(extensionStart);
+ }
+ return "";
+ }
}
public static boolean isOverwritable(FullyQualifiedName name) {
@@ -306,11 +345,11 @@ public class FullyQualifiedName implements DataKey, Comparable<FullyQualifiedNam
* Non-values Android Resource have a well defined file layout: From the resource directory, they
* reside in &lt;resource type&gt;[-&lt;qualifier&gt;]/&lt;resource name&gt;[.extension]
*
- * @param sourceExtension The extension of the resource represented by the FullyQualifiedName
+ * @param source The original source of the file-based resource's FullyQualifiedName
* @return A string representation of the FullyQualifiedName with the provided extension.
*/
- public String toPathString(String sourceExtension) {
- // TODO(corysmith): Does the extension belong in the FullyQualifiedName?
+ public String toPathString(Path source) {
+ String sourceExtension = FullyQualifiedName.Factory.getSourceExtension(source);
return Paths.get(
DASH_JOINER.join(
ImmutableList.<String>builder()
diff --git a/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java
index abe1dfd395..876e4afa30 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java
+++ b/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java
@@ -282,23 +282,6 @@ public class ParsedAndroidData {
this.parseIds = parseIds;
}
- private static String deriveRawFullyQualifiedName(Path path) {
- if (path.getNameCount() < 2) {
- throw new IllegalArgumentException(
- String.format(
- "The resource path %s is too short. "
- + "The path is expected to be <resource type>/<file name>.",
- path));
- }
- String pathWithExtension =
- path.subpath(path.getNameCount() - 2, path.getNameCount()).toString();
- int extensionStart = pathWithExtension.lastIndexOf('.');
- if (extensionStart > 0) {
- return pathWithExtension.substring(0, extensionStart);
- }
- return pathWithExtension;
- }
-
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
@@ -325,8 +308,7 @@ public class ParsedAndroidData {
DataResourceXml.parse(
xmlInputFactory, path, fqnFactory, overwritingConsumer, combiningResources);
} else if (folderType != null) {
- String rawFqn = deriveRawFullyQualifiedName(path);
- FullyQualifiedName key = fqnFactory.parse(rawFqn);
+ FullyQualifiedName key = fqnFactory.parse(path);
if (parseIds
&& ID_PROVIDING_RESOURCE_TYPES.contains(folderType)
&& path.getFileName().toString().endsWith(SdkConstants.DOT_XML)) {