aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
diff options
context:
space:
mode:
authorGravatar corysmith <corysmith@google.com>2018-04-19 09:16:09 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-19 09:17:29 -0700
commitdecb8be0e30355d4fba1987d43f4870a3822fd5b (patch)
tree7056f73d41ad38efbed9645906e180b457237050 /src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
parentd8dfd7882585fafc2be60d42ae996a4a536ac469 (diff)
Add the --pseudo-localize flag to resource compilation, gated by the --generatePseudoLocale flag.
Cleaned up the CompileLIbraryResourcesAction to use the Aapt2ConfigOptions. RELNOTES: PiperOrigin-RevId: 193525850
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
index 4d7bb6a492..b845536e21 100644
--- a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
+++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
@@ -82,16 +82,19 @@ public class ResourceCompiler {
private final Path compiledResourcesOut;
private final Path aapt2;
private final Revision buildToolsVersion;
+ private final boolean generatePseudoLocale;
private CompileTask(
Path file,
Path compiledResourcesOut,
Path aapt2,
- Revision buildToolsVersion) {
+ Revision buildToolsVersion,
+ boolean generatePseudoLocale) {
this.file = file;
this.compiledResourcesOut = compiledResourcesOut;
this.aapt2 = aapt2;
this.buildToolsVersion = buildToolsVersion;
+ this.generatePseudoLocale = generatePseudoLocale;
}
@Override
@@ -103,6 +106,8 @@ public class ResourceCompiler {
.add("compile")
.add("-v")
.add("--legacy")
+ .when(generatePseudoLocale)
+ .thenAdd("--pseudo-localize")
.add("-o", compiledResourcesOut.toString())
.add(file.toString())
.execute("Compiling " + file));
@@ -150,8 +155,7 @@ public class ResourceCompiler {
XmlResourceValues.iterateAttributesFrom(rootElement);
if (attributeIterator.hasNext()) {
- results.add(
- createAttributesProto(type, filename, attributeIterator));
+ results.add(createAttributesProto(type, filename, attributeIterator));
}
} finally {
if (xmlEventReader != null) {
@@ -171,10 +175,7 @@ public class ResourceCompiler {
}
private Path createAttributesProto(
- String type,
- String filename,
- Iterator<Attribute> attributeIterator)
- throws IOException {
+ String type, String filename, Iterator<Attribute> attributeIterator) throws IOException {
AndroidDataSerializer serializer = AndroidDataSerializer.create();
final Path resourcesAttributesPath =
@@ -188,10 +189,7 @@ public class ResourceCompiler {
QName qName = new QName(namespaceUri, localPart, prefix);
Namespaces namespaces = Namespaces.from(qName);
- String attributeName =
- namespaceUri.isEmpty()
- ? localPart
- : prefix + ":" + localPart;
+ String attributeName = namespaceUri.isEmpty() ? localPart : prefix + ":" + localPart;
final String[] dirNameAndQualifiers = type.split(SdkConstants.RES_QUALIFIER_SEP);
Factory fqnFactory = Factory.fromDirectoryName(dirNameAndQualifiers);
@@ -222,16 +220,19 @@ public class ResourceCompiler {
private final List<ListenableFuture<List<Path>>> tasks = new ArrayList<>();
private final Path aapt2;
private final Revision buildToolsVersion;
+ private final boolean generatePseudoLocale;
public CompilingVisitor(
ListeningExecutorService executorService,
Path compiledResources,
Path aapt2,
- Revision buildToolsVersion) {
+ Revision buildToolsVersion,
+ boolean generatePseudoLocale) {
this.executorService = executorService;
this.compiledResources = compiledResources;
this.aapt2 = aapt2;
this.buildToolsVersion = buildToolsVersion;
+ this.generatePseudoLocale = generatePseudoLocale;
}
@Override
@@ -240,39 +241,38 @@ public class ResourceCompiler {
if (!Files.isDirectory(file) && !file.getFileName().toString().startsWith(".")) {
// Creates a relative output path based on the input path under the
// compiledResources path.
- Path outputDirectory = Files.createDirectories(
- compiledResources.resolve(
- (file.isAbsolute() ? file.getRoot().relativize(file) : file)
- .getParent()
- .getParent()));
+ Path outputDirectory =
+ Files.createDirectories(
+ compiledResources.resolve(
+ (file.isAbsolute() ? file.getRoot().relativize(file) : file)
+ .getParent()
+ .getParent()));
String resFolder = file.getParent().getFileName().toString().toLowerCase();
// Aapt cannot interpret these regions so we rename them to get them to compile
- String renamedResFolder = resFolder
- .replaceFirst("sr[_\\-]r?latn", "b+sr+Latn")
- .replaceFirst("es[_\\-]r?419", "b+es+419");
+ String renamedResFolder =
+ resFolder
+ .replaceFirst("sr[_\\-]r?latn", "b+sr+Latn")
+ .replaceFirst("es[_\\-]r?419", "b+es+419");
if (!renamedResFolder.equals(resFolder)) {
- file = Files.copy(
- file,
- Files.createDirectories(
- outputDirectory.resolve(renamedResFolder))
- .resolve(file.getFileName()));
+ file =
+ Files.copy(
+ file,
+ Files.createDirectories(outputDirectory.resolve(renamedResFolder))
+ .resolve(file.getFileName()));
}
tasks.add(
executorService.submit(
new CompileTask(
- file,
- outputDirectory,
- aapt2,
- buildToolsVersion)));
+ file, outputDirectory, aapt2, buildToolsVersion, generatePseudoLocale)));
}
return super.visitFile(file, attrs);
}
- List<Path> getCompiledArtifacts() throws InterruptedException, ExecutionException {
+ List<Path> getCompiledArtifacts() {
Builder<Path> builder = ImmutableList.builder();
List<Throwable> compilationErrors = new ArrayList<>();
for (ListenableFuture<List<Path>> task : tasks) {
@@ -294,9 +294,11 @@ public class ResourceCompiler {
ListeningExecutorService executorService,
Path compiledResources,
Path aapt2,
- Revision buildToolsVersion) {
+ Revision buildToolsVersion,
+ boolean generatePseudoLocale) {
return new ResourceCompiler(
- new CompilingVisitor(executorService, compiledResources, aapt2, buildToolsVersion));
+ new CompilingVisitor(
+ executorService, compiledResources, aapt2, buildToolsVersion, generatePseudoLocale));
}
private ResourceCompiler(CompilingVisitor compilingVisitor) {