diff options
author | 2017-12-18 08:24:12 -0800 | |
---|---|---|
committer | 2017-12-18 08:25:32 -0800 | |
commit | 094caa508fa74081d861e9e8f8eb50934811bf65 (patch) | |
tree | c6911010ba0c7dea50fa13ee718f93719b43eb8a /src/tools | |
parent | 310fe150811c6abe0c52232eb5cb0e4380a6e084 (diff) |
Automatic formatting cleanup of Android *.java files.
RELNOTES: None.
PiperOrigin-RevId: 179425421
Diffstat (limited to 'src/tools')
53 files changed, 419 insertions, 484 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java index c2ddb7cd9f..90487a3c42 100644 --- a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java @@ -120,8 +120,7 @@ public class Aapt2ResourcePackagingAction { dataDeserializer, options.throwOnResourceConflict) .filter( - new DensitySpecificResourceFilter( - densities, filteredResources, mergedResources), + new DensitySpecificResourceFilter(densities, filteredResources, mergedResources), new DensitySpecificManifestProcessor(densities, densityManifest)); profiler.recordEndOf("merging"); diff --git a/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java b/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java index 4a7e711b0a..094d13622c 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java +++ b/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java @@ -127,9 +127,10 @@ public class AaptCommandBuilder { if (values.size() > 200) { add( flag, - "@" + Files.write( - Files.createDirectories(workingDirectory).resolve("params" + flag), - ImmutableList.of(values.stream().collect(Collectors.joining(" "))))); + "@" + + Files.write( + Files.createDirectories(workingDirectory).resolve("params" + flag), + ImmutableList.of(values.stream().collect(Collectors.joining(" "))))); } else { addRepeated(flag, values); } diff --git a/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java b/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java index 6e57cc58dc..20e9e6c9d7 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java @@ -53,6 +53,7 @@ import java.util.zip.ZipOutputStream; * Action to generate an AAR archive for an Android library. * * <p> + * * <pre> * Example Usage: * java/com/google/build/android/AarGeneratorAction\ @@ -128,12 +129,14 @@ public class AarGeneratorAction { ) public Path aarOutput; - @Option(name = "throwOnResourceConflict", - defaultValue = "false", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "If passed, resource merge conflicts will be treated as errors instead of warnings") + @Option( + name = "throwOnResourceConflict", + defaultValue = "false", + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "If passed, resource merge conflicts will be treated as errors instead of warnings" + ) public boolean throwOnResourceConflict; } @@ -167,8 +170,7 @@ public class AarGeneratorAction { VariantType.LIBRARY, null, /* filteredResources= */ ImmutableList.<String>of(), - options.throwOnResourceConflict - ); + options.throwOnResourceConflict); logger.fine(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); writeAar(options.aarOutput, mergedData, options.manifest, options.rtxt, options.classes); @@ -200,8 +202,7 @@ public class AarGeneratorAction { throw new IllegalArgumentException( String.format( "%s must be specified. Building an .aar without %s is unsupported.", - Joiner.on(", ").join(nullFlags), - Joiner.on(", ").join(nullFlags))); + Joiner.on(", ").join(nullFlags), Joiner.on(", ").join(nullFlags))); } } @@ -209,8 +210,8 @@ public class AarGeneratorAction { static void writeAar( Path aar, final MergedAndroidData data, Path manifest, Path rtxt, Path classes) throws IOException { - try (final ZipOutputStream zipOut = new ZipOutputStream( - new BufferedOutputStream(Files.newOutputStream(aar)))) { + try (final ZipOutputStream zipOut = + new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(aar)))) { ZipEntry manifestEntry = new ZipEntry("AndroidManifest.xml"); manifestEntry.setTime(EPOCH); zipOut.putNextEntry(manifestEntry); diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java index 020d2cf78d..6ca066d06d 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java @@ -49,7 +49,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; /** Deserializes {@link DataKey}, {@link DataValue} entries from compiled resource files. */ -public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ +public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer { private static final Logger logger = Logger.getLogger(AndroidCompiledDataDeserializer.class.getName()); @@ -105,11 +105,7 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ List<ConfigValue> configValues = resource.getConfigValueList(); Preconditions.checkArgument(configValues.size() == 1); - int sourceIndex = - configValues.get(0) - .getValue() - .getSource() - .getPathIdx(); + int sourceIndex = configValues.get(0).getValue().getSource().getPathIdx(); String source = sourcePool.get(sourceIndex); @@ -120,8 +116,8 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ new SimpleEntry<FullyQualifiedName, Boolean>(fqn, packageName.isEmpty())); if (packageName.isEmpty()) { - DataResourceXml dataResourceXml = DataResourceXml - .from(resourceValue, dataSource, resourceType, fullyQualifiedNames); + DataResourceXml dataResourceXml = + DataResourceXml.from(resourceValue, dataSource, resourceType, fullyQualifiedNames); if (resourceType == ResourceType.ID || resourceType == ResourceType.PUBLIC || resourceType == ResourceType.STYLEABLE) { @@ -137,10 +133,11 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ /** * Reads compiled resource data files and adds them to consumers - * @param compiledFileStream First byte is number of compiled files represented in this file. - * Next 8 bytes is a long indicating the length of the metadata describing the compiled file. - * Next N bytes is the metadata describing the compiled file. - * The remaining bytes are the actual original file. + * + * @param compiledFileStream First byte is number of compiled files represented in this file. Next + * 8 bytes is a long indicating the length of the metadata describing the compiled file. Next + * N bytes is the metadata describing the compiled file. The remaining bytes are the actual + * original file. * @param consumers * @param fqnFactory * @throws IOException @@ -192,10 +189,13 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ String fileZipPath = resourceFile.getName(); int resourceSubdirectoryIndex = fileZipPath.indexOf('_', fileZipPath.lastIndexOf('/')); - Path filePath = Paths.get(String.format("%s%c%s", - fileZipPath.substring(0, resourceSubdirectoryIndex), - '/', - fileZipPath.substring(resourceSubdirectoryIndex + 1))); + Path filePath = + Paths.get( + String.format( + "%s%c%s", + fileZipPath.substring(0, resourceSubdirectoryIndex), + '/', + fileZipPath.substring(resourceSubdirectoryIndex + 1))); String shortPath = filePath.getParent().getFileName() + "/" + filePath.getFileName(); @@ -206,8 +206,8 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ continue; } - final String[] dirNameAndQualifiers = filePath.getParent().getFileName().toString() - .split(SdkConstants.RES_QUALIFIER_SEP); + final String[] dirNameAndQualifiers = + filePath.getParent().getFileName().toString().split(SdkConstants.RES_QUALIFIER_SEP); Factory fqnFactory = Factory.fromDirectoryName(dirNameAndQualifiers); LittleEndianDataInputStream dataInputStream = @@ -241,7 +241,7 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ int stringCount = byteBuffer.getInt(8); boolean isUtf8 = (byteBuffer.getInt(16) & (1 << 8)) != 0; int stringsStart = byteBuffer.getInt(20); - //Position the ByteBuffer after the metadata + // Position the ByteBuffer after the metadata byteBuffer.position(28); List<String> strings = new ArrayList<>(); @@ -288,5 +288,4 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer{ return strings; } - } diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java index 88ae2be56b..155d7b39d7 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java @@ -34,10 +34,9 @@ import java.util.logging.Logger; /** * Provides an entry point for the compiled resource merging action. * - * <p>This action merges compiled intermediate resource files from aapt2 - * and reports merge conflicts. It also provides a merged manifest file - * to {@link ValidateAndLinkResourcesAction} and builds the resource class - * jar for the lib jar + * <p>This action merges compiled intermediate resource files from aapt2 and reports merge + * conflicts. It also provides a merged manifest file to {@link ValidateAndLinkResourcesAction} and + * builds the resource class jar for the lib jar */ public class AndroidCompiledResourceMergingAction { @@ -92,14 +91,15 @@ public class AndroidCompiledResourceMergingAction { AndroidResourceOutputs.createClassJar(generatedSources, options.classJarOutput); logger.fine( - String.format( - "Create classJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); + String.format("Create classJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); // Until enough users with manifest placeholders migrate to the new manifest merger, // we need to replace ${applicationId} and ${packageName} with options.packageForR to make // the manifests compatible with the old manifest merger. - processedManifest = AndroidManifestProcessor.with(stdLogger) - .processLibraryManifest(options.packageForR, options.primaryManifest, processedManifest); + processedManifest = + AndroidManifestProcessor.with(stdLogger) + .processLibraryManifest( + options.packageForR, options.primaryManifest, processedManifest); Files.createDirectories(options.manifestOutput.getParent()); Files.copy(processedManifest, options.manifestOutput); @@ -117,5 +117,4 @@ public class AndroidCompiledResourceMergingAction { } logger.fine(String.format("Resources merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS))); } - } diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataDeserializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataDeserializer.java index 60212bdb20..400c9032f4 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataDeserializer.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataDeserializer.java @@ -15,8 +15,9 @@ package com.google.devtools.build.android; import java.nio.file.Path; -/** Represents a deserializer to deserialize {@link DataKey} - * and {@link DataValue} from a path and feed to it consumers. +/** + * Represents a deserializer to deserialize {@link DataKey} and {@link DataValue} from a path and + * feed to it consumers. */ public interface AndroidDataDeserializer { diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java index 16b43b848e..2a8c298335 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java @@ -232,8 +232,7 @@ class AndroidDataMerger { * the ultimate source of truth, provided it doesn't conflict with itself. * @return An UnwrittenMergedAndroidData, containing DataResource objects that can be written to * disk for aapt processing or serialized for future merge passes. - * @throws MergingException if there are issues with parsing resources from - * primaryData. + * @throws MergingException if there are issues with parsing resources from primaryData. * @throws MergeConflictException if there are merge conflicts */ UnwrittenMergedAndroidData merge( diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java index f43bc7b7ef..cb19f78dca 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java @@ -31,9 +31,7 @@ import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; -/** - * Serializes {@link DataKey},{@link DataValue} entries to a binary file. - */ +/** Serializes {@link DataKey},{@link DataValue} entries to a binary file. */ public class AndroidDataSerializer { private static final Logger logger = Logger.getLogger(AndroidDataSerializer.class.getName()); @@ -48,7 +46,9 @@ public class AndroidDataSerializer { /** * Writes all of the collected DataKey -> DataValue. * - * The binary format will be: <pre> + * <p>The binary format will be: + * + * <pre> * {@link Header} * {@link com.google.devtools.build.android.proto.SerializeFormat.DataKey} keys... * {@link com.google.devtools.build.android.proto.SerializeFormat.DataValue} entries... @@ -68,22 +68,19 @@ public class AndroidDataSerializer { Files.newOutputStream(out, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE))) { // Set the header for the deserialization process. - SerializeFormat.Header.Builder headerBuilder = Header.newBuilder() - .setEntryCount(entries.size()); + SerializeFormat.Header.Builder headerBuilder = + Header.newBuilder().setEntryCount(entries.size()); // Create table of source paths to allow references in the serialization format via an index. ByteArrayOutputStream sourceTableOutputStream = new ByteArrayOutputStream(2048); DataSourceTable sourceTable = DataSourceTable.createAndWrite(entries, sourceTableOutputStream, headerBuilder); - headerBuilder - .build() - .writeDelimitedTo(outStream); + headerBuilder.build().writeDelimitedTo(outStream); writeKeyValuesTo(entries, outStream, sourceTable, sourceTableOutputStream.toByteArray()); } - logger.fine( - String.format("Serialized merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS))); + logger.fine(String.format("Serialized merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS))); } private void writeKeyValuesTo( @@ -100,8 +97,8 @@ public class AndroidDataSerializer { // TODO(corysmith): Tune the size of the byte array. ByteArrayOutputStream valuesOutputStream = new ByteArrayOutputStream(2048); for (Map.Entry<DataKey, DataValue> entry : entries) { - orderedValueSizes[valueSizeIndex++] = entry.getValue() - .serializeTo(entry.getKey(), sourceTable, valuesOutputStream); + orderedValueSizes[valueSizeIndex++] = + entry.getValue().serializeTo(entry.getKey(), sourceTable, valuesOutputStream); } // Serialize all the keys in sorted order valueSizeIndex = 0; diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java index 91de790772..38d38f3aa0 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java @@ -189,7 +189,7 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { /** * Creates a new, naive writer for testing. * - * This writer has "assets" and a "res" directory from the destination directory, as well as a + * <p>This writer has "assets" and a "res" directory from the destination directory, as well as a * noop png cruncher and a {@link ExecutorService} of 1 thread. * * @param destination The base directory to derive all paths. @@ -212,7 +212,7 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { * @param resourceDirectory The directory to copy resources into. * @param assetsDirectory The directory to copy assets into. * @param cruncher The cruncher for png files. If the cruncher is null, it will be replaced with a - * noop cruncher. + * noop cruncher. * @param executorService An execution service for multi-threaded writing. * @return A new {@link AndroidDataWriter}. */ @@ -268,9 +268,7 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { writeTasks.add(executorService.submit(new CopyTask(sourcePath, destinationPath))); } - /** - * Finalizes all operations and flushes the buffers. - */ + /** Finalizes all operations and flushes the buffers. */ @Override public void flush() throws IOException { for (Entry<String, ResourceValuesDefinitions> entry : valueTags.entrySet()) { @@ -312,9 +310,7 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { valueTags.get(valuesPath).addAllNamespaces(namespaces); } - /** - * A container for the {@linkplain Segment}s of a values.xml file. - */ + /** A container for the {@linkplain Segment}s of a values.xml file. */ private static class ResourceValuesDefinitions { private static final class WritingTask implements Callable<Boolean> { @@ -589,8 +585,8 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { @Override public ValuesResourceDefinition endTag() { - Preconditions.checkArgument(!tagStack.isEmpty(), - "Unable to endTag, as no tag has been started."); + Preconditions.checkArgument( + !tagStack.isEmpty(), "Unable to endTag, as no tag has been started."); mapper.add("</" + tagStack.pop() + ">"); return this; } @@ -685,8 +681,11 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { @Override public Path write(Path previousSource, Writer writer) throws IOException { Path source = previousSource; - Preconditions.checkArgument(segmentsByName.containsKey(fqn), "%s has no segment in %s", - fqn.toPrettyString(), segmentsByName.keySet()); + Preconditions.checkArgument( + segmentsByName.containsKey(fqn), + "%s has no segment in %s", + fqn.toPrettyString(), + segmentsByName.keySet()); for (Segment s : segmentsByName.get(fqn)) { // not recording the source source = s.write(source, writer); diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataWritingVisitor.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataWritingVisitor.java index cbc60364b8..1ada80c1c1 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataWritingVisitor.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataWritingVisitor.java @@ -26,9 +26,7 @@ import javax.xml.namespace.QName; /** An interface for visiting android data for writing. */ public interface AndroidDataWritingVisitor extends Flushable { - /** - * Copies the AndroidManifest to the destination directory. - */ + /** Copies the AndroidManifest to the destination directory. */ Path copyManifest(Path sourceManifest) throws IOException; /** @@ -71,8 +69,7 @@ public interface AndroidDataWritingVisitor extends Flushable { /** * Provides a fluent interface to generate an xml resource for the values directory. * - * <p>Example usage: - * <code> + * <p>Example usage: <code> * writer.define(key) * .derivedFrom(source) * .startTag(tagName) @@ -112,8 +109,8 @@ public interface AndroidDataWritingVisitor extends Flushable { * Takes another values xml resource and writes it as a child tag here. * * <p>This allows xml elements from other {@link XmlResourceValue} to be moved in the stream. - * Currently, this is only necessary for {@link StyleableXmlResourceValue} which can have - * {@link AttrXmlResourceValue} defined as child elements (yet, they are merged and treated as + * Currently, this is only necessary for {@link StyleableXmlResourceValue} which can have {@link + * AttrXmlResourceValue} defined as child elements (yet, they are merged and treated as * independent resources.) * * @param fqn The {@link FullyQualifiedName} of the {@link XmlResourceValue} to be adopted. This diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidFrameworkAttrIdProvider.java b/src/tools/android/java/com/google/devtools/build/android/AndroidFrameworkAttrIdProvider.java index 522dca5974..1ff8039e53 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidFrameworkAttrIdProvider.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidFrameworkAttrIdProvider.java @@ -13,16 +13,12 @@ // limitations under the License. package com.google.devtools.build.android; -/** - * Provides the android.R.attr field IDs. - */ +/** Provides the android.R.attr field IDs. */ public interface AndroidFrameworkAttrIdProvider { int getAttrId(String attrName) throws AttrLookupException; - /** - * Exception thrown when lookup fails. - */ + /** Exception thrown when lookup fails. */ final class AttrLookupException extends Exception { AttrLookupException(Throwable t) { diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidManifestProcessor.java b/src/tools/android/java/com/google/devtools/build/android/AndroidManifestProcessor.java index 490d24587a..f870d6c7df 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidManifestProcessor.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidManifestProcessor.java @@ -131,7 +131,8 @@ public class AndroidManifestProcessor { Map<String, String> values, String customPackage, Path output, - Path logFile) throws ManifestProcessingException { + Path logFile) + throws ManifestProcessingException { if (mergeeManifests.isEmpty() && values.isEmpty() && Strings.isNullOrEmpty(customPackage)) { return manifest; } @@ -253,7 +254,11 @@ public class AndroidManifestProcessor { if (versionCode != -1 || versionName != null || applicationId != null) { processManifest( - versionCode, versionName, manifest, processedManifest, MergeType.APPLICATION, + versionCode, + versionName, + manifest, + processedManifest, + MergeType.APPLICATION, applicationId); return processedManifest; } @@ -262,9 +267,7 @@ public class AndroidManifestProcessor { /** Processes the manifest for a library and return the manifest Path. */ public Path processLibraryManifest( - String newManifestPackage, - Path manifest, - Path processedManifest) { + String newManifestPackage, Path manifest, Path processedManifest) { if (newManifestPackage != null) { processManifest( @@ -402,11 +405,15 @@ public class AndroidManifestProcessor { public static Path writeDummyManifestForAapt(Path dummyManifest, String packageForR) { try { Files.createDirectories(dummyManifest.getParent()); - return Files.write(dummyManifest, String.format( - "<?xml version=\"1.0\" encoding=\"utf-8\"?>" - + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"" - + " package=\"%s\">" - + "</manifest>", packageForR).getBytes(UTF_8)); + return Files.write( + dummyManifest, + String.format( + "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"" + + " package=\"%s\">" + + "</manifest>", + packageForR) + .getBytes(UTF_8)); } catch (IOException e) { throw new ManifestProcessingException(e); } diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidParsedDataDeserializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidParsedDataDeserializer.java index 71787b4b39..e704c06552 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidParsedDataDeserializer.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidParsedDataDeserializer.java @@ -122,10 +122,7 @@ public class AndroidParsedDataDeserializer implements AndroidDataDeserializer { } private void readEntriesSegment( - KeyValueConsumers consumers, - InputStream in, - FileSystem currentFileSystem, - Header header) + KeyValueConsumers consumers, InputStream in, FileSystem currentFileSystem, Header header) throws IOException { int numberOfEntries = header.getEntryCount(); Map<DataKey, KeyValueConsumer<DataKey, ? extends DataValue>> keys = @@ -211,5 +208,3 @@ public class AndroidParsedDataDeserializer implements AndroidDataDeserializer { return builder.build(); } } - - diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java index ec7a3286c9..b9458fb05b 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java @@ -33,7 +33,7 @@ import java.util.Map; * class files. */ public class AndroidResourceClassWriter implements Flushable, AndroidResourceSymbolSink { - + /** Create a new class writer. */ public static AndroidResourceClassWriter createWith( Path androidJar, Path out, String javaPackage) { @@ -46,7 +46,7 @@ public class AndroidResourceClassWriter implements Flushable, AndroidResourceSym return new AndroidResourceClassWriter( PlaceholderIdFieldInitializerBuilder.from(androidIdProvider), outputBasePath, packageName); } - + private final Path outputBasePath; private final String packageName; private boolean includeClassFile = true; diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java index 2013617964..1257def88a 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java @@ -204,8 +204,8 @@ public class AndroidResourceMerger { } /** - * Merges all secondary compiled resources with the primary compiled resources, - * given that the primary resources have been separately compiled + * Merges all secondary compiled resources with the primary compiled resources, given that the + * primary resources have been separately compiled */ public static void mergeCompiledData( final SerializedAndroidData primary, @@ -245,5 +245,3 @@ public class AndroidResourceMerger { } } } - - diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java index 454f056f8b..ceda631537 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java @@ -184,12 +184,14 @@ public class AndroidResourceMergingAction { ) public Path dataBindingInfoOut; - @Option(name = "throwOnResourceConflict", - defaultValue = "false", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "If passed, resource merge conflicts will be treated as errors instead of warnings") + @Option( + name = "throwOnResourceConflict", + defaultValue = "false", + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "If passed, resource merge conflicts will be treated as errors instead of warnings" + ) public boolean throwOnResourceConflict; } @@ -328,8 +330,6 @@ public class AndroidResourceMergingAction { } @Override - public void end(int key) { - } - + public void end(int key) {} } } diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceOutputs.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceOutputs.java index 82001c6065..9b9cd2f317 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceOutputs.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceOutputs.java @@ -216,7 +216,6 @@ public class AndroidResourceOutputs { paths.add(dir); return FileVisitResult.CONTINUE; } - } /** A FileVisitor that will add all files to be stored in a zip archive. */ diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceParsingAction.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceParsingAction.java index 9b72728ad0..e2a98e4f13 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceParsingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceParsingAction.java @@ -39,9 +39,7 @@ public class AndroidResourceParsingAction { private static final Logger logger = Logger.getLogger(AndroidResourceParsingAction.class.getName()); - /** - * Flag specifications for this action. - */ + /** Flag specifications for this action. */ public static final class Options extends OptionsBase { @Option( @@ -83,15 +81,13 @@ public class AndroidResourceParsingAction { final Stopwatch timer = Stopwatch.createStarted(); ParsedAndroidData parsedPrimary = ParsedAndroidData.from(options.primaryData); logger.fine(String.format("Walked XML tree at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); - UnwrittenMergedAndroidData unwrittenData = UnwrittenMergedAndroidData.of( - null, - parsedPrimary, - ParsedAndroidData.from(ImmutableList.<DependencyAndroidData>of())); + UnwrittenMergedAndroidData unwrittenData = + UnwrittenMergedAndroidData.of( + null, parsedPrimary, ParsedAndroidData.from(ImmutableList.<DependencyAndroidData>of())); AndroidDataSerializer serializer = AndroidDataSerializer.create(); unwrittenData.serializeTo(serializer); serializer.flushTo(options.output); - logger.fine(String.format( - "Finished parse + serialize in %dms", timer.elapsed(TimeUnit.MILLISECONDS))); + logger.fine( + String.format("Finished parse + serialize in %dms", timer.elapsed(TimeUnit.MILLISECONDS))); } - } diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessingAction.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessingAction.java index 13b1c9aa46..86e5ec4d82 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessingAction.java @@ -364,8 +364,8 @@ public class AndroidResourceProcessingAction { public static void main(String[] args) throws Exception { final Stopwatch timer = Stopwatch.createStarted(); - OptionsParser optionsParser = OptionsParser.newOptionsParser( - Options.class, AaptConfigOptions.class); + OptionsParser optionsParser = + OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class); optionsParser.enableParamsFileSupport( new ShellQuotedParamsFilePreProcessor(FileSystems.getDefault())); optionsParser.parseAndExitUponError(args); @@ -384,9 +384,7 @@ public class AndroidResourceProcessingAction { final Path dummyManifest = tmp.resolve("manifest-aapt-dummy/AndroidManifest.xml"); Path generatedSources = null; - if (options.srcJarOutput != null - || options.rOutput != null - || options.symbolsOut != null) { + if (options.srcJarOutput != null || options.rOutput != null || options.symbolsOut != null) { generatedSources = tmp.resolve("generated_resources"); } @@ -419,9 +417,7 @@ public class AndroidResourceProcessingAction { ? options.densities : Collections.<String>emptyList(); final List<String> densitiesForManifest = - densitiesToFilter.isEmpty() - ? options.densitiesForManifest - : densitiesToFilter; + densitiesToFilter.isEmpty() ? options.densitiesForManifest : densitiesToFilter; final DensityFilteredAndroidData filteredData = mergedData.filter( @@ -457,14 +453,13 @@ public class AndroidResourceProcessingAction { } if (hasConflictWithPackageUnderTest( - options.packageUnderTest, - processedData.getManifest(), - timer)) { + options.packageUnderTest, processedData.getManifest(), timer)) { logger.log( Level.SEVERE, "Android resources cannot be provided if the instrumentation package is the same as " + "the package under test, but the instrumentation package (in the manifest) and " - + "the package under test both had the same package: " + options.packageUnderTest); + + "the package under test both had the same package: " + + options.packageUnderTest); System.exit(1); } @@ -531,26 +526,23 @@ public class AndroidResourceProcessingAction { /** * Checks if there is a conflict between the package under test and the package being built. * - * When testing Android code, the test can be run in the same or a different process as the code - * being tested. If it's in the same process, we do not allow Android resources to be used by the - * test, as they could overwrite the resources used by the code being tested. If this APK won't - * be testing another APK, the test and code under test are in different processes, or no + * <p>When testing Android code, the test can be run in the same or a different process as the + * code being tested. If it's in the same process, we do not allow Android resources to be used by + * the test, as they could overwrite the resources used by the code being tested. If this APK + * won't be testing another APK, the test and code under test are in different processes, or no * resources are being used, this isn't a concern. * - * To determine whether the test and code under test are run in the same process, we check the + * <p>To determine whether the test and code under test are run in the same process, we check the * package of the code under test, passed into this function, against the target packages of any * <code>instrumentation</code> tags in this APK's manifest. * * @param packageUnderTest the package of the code under test, or null if no code is under test * @param processedManifest the processed manifest for this APK - * * @return true if there is a conflict, false otherwise */ @VisibleForTesting static boolean hasConflictWithPackageUnderTest( - @Nullable String packageUnderTest, - Path processedManifest, - Stopwatch timer) + @Nullable String packageUnderTest, Path processedManifest, Stopwatch timer) throws SAXException, StreamException, ParserConfigurationException, IOException { if (packageUnderTest == null) { return false; diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessor.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessor.java index 6c8b86b3e1..25e9f39c73 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessor.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceProcessor.java @@ -68,15 +68,11 @@ import java.util.concurrent.Executors; import java.util.logging.Logger; import javax.xml.xpath.XPathExpressionException; -/** - * Provides a wrapper around the AOSP build tools for resource processing. - */ +/** Provides a wrapper around the AOSP build tools for resource processing. */ public class AndroidResourceProcessor { static final Logger logger = Logger.getLogger(AndroidResourceProcessor.class.getName()); - /** - * Options class containing flags for Aapt setup. - */ + /** Options class containing flags for Aapt setup. */ public static final class AaptConfigOptions extends OptionsBase { @Option( name = "buildToolsVersion", @@ -204,7 +200,7 @@ public class AndroidResourceProcessor { private static final String ANDROID_SPLIT_DOCUMENTATION_URL = "https://developer.android.com/guide/topics/resources/providing-resources.html" - + "#QualifierRules"; + + "#QualifierRules"; @Option( name = "split", @@ -229,9 +225,7 @@ public class AndroidResourceProcessor { public List<String> splits; } - /** - * {@link AaptOptions} backed by an {@link AaptConfigOptions}. - */ + /** {@link AaptOptions} backed by an {@link AaptConfigOptions}. */ public static final class FlagAaptOptions implements AaptOptions { private final AaptConfigOptions options; @@ -264,16 +258,15 @@ public class AndroidResourceProcessor { public List<String> getAdditionalParameters() { List<String> params = new java.util.ArrayList<String>(); if (options.featureOf != null) { - params.add("--feature-of"); - params.add(options.featureOf.toString()); + params.add("--feature-of"); + params.add(options.featureOf.toString()); } if (options.featureAfter != null) { - params.add("--feature-after"); - params.add(options.featureAfter.toString()); + params.add("--feature-after"); + params.add(options.featureAfter.toString()); } return ImmutableList.copyOf(params); } - } private final StdLogger stdLogger; @@ -580,8 +573,8 @@ public class AndroidResourceProcessor { // (on a shared system). On the other hand, a lot of the work is I/O, so it's not completely // CPU bound. As a compromise, divide by 2 the reported availableProcessors. int numThreads = Math.max(1, Runtime.getRuntime().availableProcessors() / 2); - ListeningExecutorService executorService = MoreExecutors.listeningDecorator( - Executors.newFixedThreadPool(numThreads)); + ListeningExecutorService executorService = + MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numThreads)); try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) { for (Entry<String, ListenableFuture<ResourceSymbols>> entry : ResourceSymbols.loadFrom(libraries, executorService, appPackageName).entries()) { @@ -600,7 +593,8 @@ public class AndroidResourceProcessor { List<DependencyAndroidData> dependencyData, String customPackageForR, Path androidManifest, - Path sourceOut) throws IOException { + Path sourceOut) + throws IOException { List<SymbolFileProvider> libraries = new ArrayList<>(); for (DependencyAndroidData dataDep : dependencyData) { SymbolFileProvider library = dataDep.asSymbolFileProvider(); @@ -691,9 +685,7 @@ public class AndroidResourceProcessor { AndroidManifestProcessor.writeDummyManifestForAapt(dummyManifest, packageForR); } - /** - * Shutdown AOSP utilized thread-pool. - */ + /** Shutdown AOSP utilized thread-pool. */ public void shutdown() { FullyQualifiedName.logCacheUsage(logger); // AOSP code never shuts down its singleton executor and leaves the process hanging. diff --git a/src/tools/android/java/com/google/devtools/build/android/Converters.java b/src/tools/android/java/com/google/devtools/build/android/Converters.java index 26d918b278..e58dd2d29b 100644 --- a/src/tools/android/java/com/google/devtools/build/android/Converters.java +++ b/src/tools/android/java/com/google/devtools/build/android/Converters.java @@ -321,8 +321,10 @@ public final class Converters { public static <T> List<T> concatLists( @Nullable List<? extends T> a, @Nullable List<? extends T> b) { - @SuppressWarnings("unchecked") List<T> la = (List<T>) a; - @SuppressWarnings("unchecked") List<T> lb = (List<T>) b; + @SuppressWarnings("unchecked") + List<T> la = (List<T>) a; + @SuppressWarnings("unchecked") + List<T> lb = (List<T>) b; if (la == null || la.isEmpty()) { return (lb == null || lb.isEmpty()) ? ImmutableList.of() : lb; } diff --git a/src/tools/android/java/com/google/devtools/build/android/DataAsset.java b/src/tools/android/java/com/google/devtools/build/android/DataAsset.java index b78b07fd30..c4ffbfe3b4 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataAsset.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataAsset.java @@ -15,16 +15,12 @@ package com.google.devtools.build.android; import java.io.IOException; -/** - * Represents an Asset created from a binary file. - */ +/** Represents an Asset created from a binary file. */ public interface DataAsset extends DataValue { - /** - * Write the asset value to mergedDataWriter. - */ + /** Write the asset value to mergedDataWriter. */ void writeAsset(RelativeAssetPath key, AndroidDataWritingVisitor mergedDataWriter) throws IOException; - + /** Overwrite another {@link DataAsset}. */ DataAsset overwrite(DataAsset other); } diff --git a/src/tools/android/java/com/google/devtools/build/android/DataKey.java b/src/tools/android/java/com/google/devtools/build/android/DataKey.java index 0fbbd1f9ed..02f193c0f7 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataKey.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataKey.java @@ -19,12 +19,12 @@ import java.io.OutputStream; /** * A general interface for resource and asset keys. * - * Resource and Assets are merged on the basis of a key value: + * <p>Resource and Assets are merged on the basis of a key value: * - * For Resources, this is the fully qualified name, consisting of the resource package, name, type, - * and qualifiers. + * <p>For Resources, this is the fully qualified name, consisting of the resource package, name, + * type, and qualifiers. * - * For Assets, it is the asset path from the assets directory. + * <p>For Assets, it is the asset path from the assets directory. */ public interface DataKey extends Comparable<DataKey> { @@ -33,18 +33,14 @@ public interface DataKey extends Comparable<DataKey> { * * @param output The destination stream to serialize the key. * @param valueSize The size, in bytes, of the serialized output for this key. The value size can - * be used for calculating offsets of the value in the stream. + * be used for calculating offsets of the value in the stream. */ void serializeTo(OutputStream output, int valueSize) throws IOException; - /** - * Returns a human readable string representation of the key. - */ + /** Returns a human readable string representation of the key. */ String toPrettyString(); - /** - * Defines a total ordering on the different key types to assist in compareTo operations. - */ + /** Defines a total ordering on the different key types to assist in compareTo operations. */ enum KeyType { ASSET_PATH, FULL_QUALIFIED_NAME diff --git a/src/tools/android/java/com/google/devtools/build/android/DataResource.java b/src/tools/android/java/com/google/devtools/build/android/DataResource.java index 1295f60192..16053923e1 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataResource.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataResource.java @@ -15,9 +15,7 @@ package com.google.devtools.build.android; import com.google.devtools.build.android.AndroidResourceMerger.MergingException; -/** - * Represents an Android Resource parsed from an xml or binary file. - */ +/** Represents an Android Resource parsed from an xml or binary file. */ public interface DataResource extends DataValue { /** Write as a resource using the supplied {@link AndroidDataWritingVisitor}. */ void writeResource(FullyQualifiedName key, AndroidDataWritingVisitor writer) @@ -25,7 +23,7 @@ public interface DataResource extends DataValue { /** * Combines these resource together and returns a single resource. - * + * * @param resource Another resource to be combined with this one. * @return A union of the values of these two resources. * @throws IllegalArgumentException if either resource cannot combine with the other. @@ -34,7 +32,7 @@ public interface DataResource extends DataValue { /** Queue up writing the resource to the given {@link AndroidResourceSymbolSink}. */ void writeResourceToClass(FullyQualifiedName key, AndroidResourceSymbolSink sink); - + /** Overwrite another {@link DataResource}. */ DataResource overwrite(DataResource other); } diff --git a/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java b/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java index 145725f941..e26a7a87bd 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java @@ -58,9 +58,8 @@ import javax.xml.stream.events.StartElement; /** * Represents an Android Resource defined in the xml and value folder. * - * <p> - * Basically, if the resource is defined inside a <resources> tag, this class will handle it. - * Layouts are treated separately as they don't declare anything besides ids. + * <p>Basically, if the resource is defined inside a <resources> tag, this class will handle + * it. Layouts are treated separately as they don't declare anything besides ids. */ public class DataResourceXml implements DataResource { @@ -88,8 +87,7 @@ public class DataResourceXml implements DataResource { throws XMLStreamException, FactoryConfigurationError, IOException { XMLEventReader eventReader = xmlInputFactory.createXMLEventReader( - new BufferedInputStream(Files.newInputStream(path)), - StandardCharsets.UTF_8.toString()); + new BufferedInputStream(Files.newInputStream(path)), StandardCharsets.UTF_8.toString()); try { // TODO(corysmith): Make the xml parsing more readable. for (StartElement resources = XmlResourceValues.moveToResources(eventReader); @@ -104,15 +102,12 @@ public class DataResourceXml implements DataResource { attribute.getName().getNamespaceURI().isEmpty() ? attribute.getName().getLocalPart() : attribute.getName().getPrefix() + ":" + attribute.getName().getLocalPart(); - FullyQualifiedName fqn = fqnFactory.create( - VirtualType.RESOURCES_ATTRIBUTE, - attribute.getName().toString()); + FullyQualifiedName fqn = + fqnFactory.create(VirtualType.RESOURCES_ATTRIBUTE, attribute.getName().toString()); ResourcesAttribute resourceAttribute = ResourcesAttribute.of(fqn, attributeName, attribute.getValue()); - DataResourceXml resource = DataResourceXml.createWithNamespaces( - path, - resourceAttribute, - namespaces); + DataResourceXml resource = + DataResourceXml.createWithNamespaces(path, resourceAttribute, namespaces); if (resourceAttribute.isCombining()) { combiningConsumer.accept(fqn, resource); } else { @@ -172,9 +167,7 @@ public class DataResourceXml implements DataResource { throws InvalidProtocolBufferException { DataValueXml xmlValue = protoValue.getXmlValue(); return createWithNamespaces( - source, - valueFromProto(xmlValue), - Namespaces.from(xmlValue.getNamespace())); + source, valueFromProto(xmlValue), Namespaces.from(xmlValue.getNamespace())); } private static XmlResourceValue valueFromProto(SerializeFormat.DataValueXml proto) @@ -210,10 +203,11 @@ public class DataResourceXml implements DataResource { ResourceType resourceType, Map<String, Entry<FullyQualifiedName, Boolean>> fullyQualifiedNames) throws InvalidProtocolBufferException { - DataResourceXml dataResourceXml = createWithNamespaces( - source, - valueFromProto(protoValue, resourceType, fullyQualifiedNames), - Namespaces.empty()); + DataResourceXml dataResourceXml = + createWithNamespaces( + source, + valueFromProto(protoValue, resourceType, fullyQualifiedNames), + Namespaces.empty()); return dataResourceXml; } @@ -335,12 +329,11 @@ public class DataResourceXml implements DataResource { Path sourcePath, XmlResourceValue xml, ImmutableMap<String, String> prefixToUri) { return createWithNamespaces(sourcePath, xml, Namespaces.from(prefixToUri)); } - + public static DataResourceXml createWithNoNamespace(DataSource source, XmlResourceValue xml) { return new DataResourceXml(source, xml, Namespaces.empty()); } - public static DataResourceXml createWithNamespaces( DataSource source, XmlResourceValue xml, Namespaces namespaces) { return new DataResourceXml(source, xml, namespaces); @@ -418,7 +411,7 @@ public class DataResourceXml implements DataResource { } return createWithNamespaces(source.overwrite(resource.source()), xml, namespaces); } - + @Override public DataValue update(DataSource source) { return createWithNamespaces(source, xml, namespaces); diff --git a/src/tools/android/java/com/google/devtools/build/android/DataValue.java b/src/tools/android/java/com/google/devtools/build/android/DataValue.java index b399b106ae..ce86664a09 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataValue.java @@ -19,7 +19,7 @@ import java.io.OutputStream; /** * Represents the value associated with DataKey interface for resource and asset values. * - * A DataValue is either an android resource or asset derived from a Path. + * <p>A DataValue is either an android resource or asset derived from a Path. */ public interface DataValue { @@ -28,12 +28,9 @@ public interface DataValue { */ DataSource source(); - /** - * Serializes to a supplied stream and returns the number of bytes written. - */ - int serializeTo( - DataKey key, DataSourceTable sourceTable, OutputStream output) throws IOException; - + /** Serializes to a supplied stream and returns the number of bytes written. */ + int serializeTo(DataKey key, DataSourceTable sourceTable, OutputStream output) throws IOException; + DataValue update(DataSource source); /** Provides a representation of the value suitable for a conflict message. */ 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 61c569c217..e45545f97a 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 @@ -25,7 +25,7 @@ import java.util.Objects; /** * Represents a file based android resource or asset. * - * These include all resource types except those found in values, as well as all assets. + * <p>These include all resource types except those found in values, as well as all assets. */ public class DataValueFile implements DataResource, DataAsset { diff --git a/src/tools/android/java/com/google/devtools/build/android/DensityFilteredAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/DensityFilteredAndroidData.java index ae2db68eca..ff39e921d6 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensityFilteredAndroidData.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensityFilteredAndroidData.java @@ -15,9 +15,7 @@ package com.google.devtools.build.android; import java.nio.file.Path; -/** - * Represents a MergedData that has been filtered for density content. - */ +/** Represents a MergedData that has been filtered for density content. */ public class DensityFilteredAndroidData extends MergedAndroidData { public DensityFilteredAndroidData(Path resources, Path assets, Path manifest) { diff --git a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java index 8a08978f94..a5c5632505 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java @@ -38,46 +38,52 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -/** - * Modifies a {@link MergedAndroidData} manifest for the specified densities. - */ +/** Modifies a {@link MergedAndroidData} manifest for the specified densities. */ public class DensitySpecificManifestProcessor { - static final ImmutableList<String> SCREEN_SIZES = ImmutableList.of( - "small", "normal", "large", "xlarge"); + static final ImmutableList<String> SCREEN_SIZES = + ImmutableList.of("small", "normal", "large", "xlarge"); static final ImmutableBiMap<String, String> PLAY_STORE_SUPPORTED_DENSITIES = ImmutableBiMap.<String, String>builder() - .put("ldpi", "ldpi") - .put("mdpi", "mdpi") - .put("tvdpi", "213") - .put("hdpi", "hdpi") - .put("280dpi", "280") - .put("xhdpi", "xhdpi") - .put("400dpi", "400") - .put("420dpi", "420") - .put("xxhdpi", "480") - .put("560dpi", "560") - .put("xxxhdpi", "640").build(); - - private static final ImmutableMap<String, Boolean> SECURE_XML_FEATURES = ImmutableMap.of( - XMLConstants.FEATURE_SECURE_PROCESSING, true, - "http://xml.org/sax/features/external-general-entities", false, - "http://xml.org/sax/features/external-parameter-entities", false, - "http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + .put("ldpi", "ldpi") + .put("mdpi", "mdpi") + .put("tvdpi", "213") + .put("hdpi", "hdpi") + .put("280dpi", "280") + .put("xhdpi", "xhdpi") + .put("400dpi", "400") + .put("420dpi", "420") + .put("xxhdpi", "480") + .put("560dpi", "560") + .put("xxxhdpi", "640") + .build(); + + private static final ImmutableMap<String, Boolean> SECURE_XML_FEATURES = + ImmutableMap.of( + XMLConstants.FEATURE_SECURE_PROCESSING, + true, + "http://xml.org/sax/features/external-general-entities", + false, + "http://xml.org/sax/features/external-parameter-entities", + false, + "http://apache.org/xml/features/nonvalidating/load-external-dtd", + false); private static DocumentBuilder getSecureDocumentBuilder() throws ParserConfigurationException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance( - "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null); + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance( + "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null); factory.setValidating(false); factory.setXIncludeAware(false); for (Map.Entry<String, Boolean> featureAndValue : SECURE_XML_FEATURES.entrySet()) { - try { - factory.setFeature(featureAndValue.getKey(), featureAndValue.getValue()); - } catch (ParserConfigurationException e) { - throw new FactoryConfigurationError(e, - "Xerces DocumentBuilderFactory doesn't support the required security features: " - + e.getMessage()); - } + try { + factory.setFeature(featureAndValue.getKey(), featureAndValue.getValue()); + } catch (ParserConfigurationException e) { + throw new FactoryConfigurationError( + e, + "Xerces DocumentBuilderFactory doesn't support the required security features: " + + e.getMessage()); + } } return factory.newDocumentBuilder(); } @@ -122,8 +128,10 @@ public class DensitySpecificManifestProcessor { NodeList screenElements = doc.getElementsByTagName("screen"); for (int i = 0; i < screenElements.getLength(); i++) { Node screen = screenElements.item(i); - existingDensities.add(PLAY_STORE_SUPPORTED_DENSITIES.inverse().get( - screen.getAttributes().getNamedItem("android:screenDensity").getNodeValue())); + existingDensities.add( + PLAY_STORE_SUPPORTED_DENSITIES + .inverse() + .get(screen.getAttributes().getNamedItem("android:screenDensity").getNodeValue())); } if (existingDensities.containsAll(densities)) { return manifest; @@ -157,8 +165,8 @@ public class DensitySpecificManifestProcessor { for (String screenSize : SCREEN_SIZES) { Element screen = doc.createElement("screen"); screen.setAttribute("android:screenSize", screenSize); - screen.setAttribute("android:screenDensity", - PLAY_STORE_SUPPORTED_DENSITIES.get(density)); + screen.setAttribute( + "android:screenDensity", PLAY_STORE_SUPPORTED_DENSITIES.get(density)); compatibleScreens.appendChild(screen); } } @@ -166,8 +174,9 @@ public class DensitySpecificManifestProcessor { Files.createDirectories(out.getParent()); TransformerFactory transformerFactory = TransformerFactory.newInstance(); - transformerFactory.newTransformer().transform( - new DOMSource(doc), new StreamResult(Files.newOutputStream(out))); + transformerFactory + .newTransformer() + .transform(new DOMSource(doc), new StreamResult(Files.newOutputStream(out))); return out; } catch (ParserConfigurationException | SAXException | IOException | TransformerException e) { diff --git a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java index 70180c1ccd..431169d2c2 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java @@ -42,20 +42,19 @@ import java.util.EnumSet; import java.util.List; import javax.annotation.Nullable; -/** - * Filters a {@link MergedAndroidData} resource drawables to the specified densities. - */ +/** Filters a {@link MergedAndroidData} resource drawables to the specified densities. */ public class DensitySpecificResourceFilter { private static class ResourceInfo { /** Path to an actual file resource, instead of a directory. */ private Path resource; + private String restype; private String qualifiers; private String density; private String resid; - public ResourceInfo(Path resource, String restype, String qualifiers, String density, - String resid) { + public ResourceInfo( + Path resource, String restype, String qualifiers, String density, String resid) { this.resource = resource; this.restype = restype; this.qualifiers = qualifiers; @@ -184,38 +183,43 @@ public class DensitySpecificResourceFilter { @VisibleForTesting List<Path> getResourceToRemove(List<Path> resourcePaths) { - Predicate<ResourceInfo> requestedDensityFilter = new Predicate<ResourceInfo>() { - @Override - public boolean apply(@Nullable ResourceInfo info) { - return !densities.contains(info.getDensity()); - } - }; + Predicate<ResourceInfo> requestedDensityFilter = + new Predicate<ResourceInfo>() { + @Override + public boolean apply(@Nullable ResourceInfo info) { + return !densities.contains(info.getDensity()); + } + }; List<ResourceInfo> resourceInfos = getResourceInfos(resourcePaths); List<ResourceInfo> densityResourceInfos = filterDensityResourceInfos(resourceInfos); List<ResourceInfo> resourceInfoToRemove = new ArrayList<>(); - Multimap<String, ResourceInfo> fileGroups = groupResourceInfos(densityResourceInfos, - GET_RESOURCE_ID); + Multimap<String, ResourceInfo> fileGroups = + groupResourceInfos(densityResourceInfos, GET_RESOURCE_ID); for (String key : fileGroups.keySet()) { - Multimap<String, ResourceInfo> qualifierGroups = groupResourceInfos(fileGroups.get(key), - GET_RESOURCE_QUALIFIERS); + Multimap<String, ResourceInfo> qualifierGroups = + groupResourceInfos(fileGroups.get(key), GET_RESOURCE_QUALIFIERS); for (String qualifiers : qualifierGroups.keySet()) { Collection<ResourceInfo> qualifierResourceInfos = qualifierGroups.get(qualifiers); if (qualifierResourceInfos.size() != 1) { - List<ResourceInfo> sortedResourceInfos = Ordering.natural().onResultOf( - new Function<ResourceInfo, Double>() { - @Override - public Double apply(ResourceInfo info) { - return matchScore(info, densities); - } - }).immutableSortedCopy(qualifierResourceInfos); - resourceInfoToRemove.addAll(Collections2.filter( - sortedResourceInfos.subList(1, sortedResourceInfos.size()), - requestedDensityFilter)); + List<ResourceInfo> sortedResourceInfos = + Ordering.natural() + .onResultOf( + new Function<ResourceInfo, Double>() { + @Override + public Double apply(ResourceInfo info) { + return matchScore(info, densities); + } + }) + .immutableSortedCopy(qualifierResourceInfos); + resourceInfoToRemove.addAll( + Collections2.filter( + sortedResourceInfos.subList(1, sortedResourceInfos.size()), + requestedDensityFilter)); } } } @@ -256,10 +260,13 @@ public class DensitySpecificResourceFilter { String[] qualifierArray = qualifiers.split("-"); String restype = qualifierArray[0]; - qualifiers = (qualifierArray.length) > 0 ? Joiner.on("-").join(Arrays.copyOfRange( - qualifierArray, 1, qualifierArray.length)) : ""; - resourceInfos.add(new ResourceInfo(resourcePath, restype, qualifiers, density, - resourcePath.getFileName().toString())); + qualifiers = + (qualifierArray.length) > 0 + ? Joiner.on("-").join(Arrays.copyOfRange(qualifierArray, 1, qualifierArray.length)) + : ""; + resourceInfos.add( + new ResourceInfo( + resourcePath, restype, qualifiers, density, resourcePath.getFileName().toString())); } return ImmutableList.copyOf(resourceInfos); @@ -270,8 +277,10 @@ public class DensitySpecificResourceFilter { List<ResourceInfo> densityResourceInfos = new ArrayList<>(); for (ResourceInfo info : resourceInfos) { - if (info.getRestype().equals("drawable") && !info.getDensity().equals("") - && !info.getDensity().equals("nodpi") && !info.getResid().endsWith(".xml")) { + if (info.getRestype().equals("drawable") + && !info.getDensity().equals("") + && !info.getDensity().equals("nodpi") + && !info.getResid().endsWith(".xml")) { densityResourceInfos.add(info); } } @@ -312,13 +321,15 @@ public class DensitySpecificResourceFilter { if (densities.isEmpty()) { return unFilteredResourceDir; } - final Path filteredResourceDir = - out.resolve(working.relativize(unFilteredResourceDir)); + final Path filteredResourceDir = out.resolve(working.relativize(unFilteredResourceDir)); RecursiveFileCopier fileVisitor = new RecursiveFileCopier(filteredResourceDir, unFilteredResourceDir); try { - Files.walkFileTree(unFilteredResourceDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), - Integer.MAX_VALUE, fileVisitor); + Files.walkFileTree( + unFilteredResourceDir, + EnumSet.of(FileVisitOption.FOLLOW_LINKS), + Integer.MAX_VALUE, + fileVisitor); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java index f59267d23e..b4d4b99b3f 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java +++ b/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java @@ -62,12 +62,11 @@ class DependencyAndroidData extends SerializedAndroidData { compiledSymbols = CompiledResources.from(exists(fileSystem.getPath(parts[4]))); symbolsBin = exists(fileSystem.getPath(parts[5])); } else if (parts.length == 5) { - //This is either symbols bin or compiled symbols depending on "useCompiledResourcesForMerge" + // This is either symbols bin or compiled symbols depending on "useCompiledResourcesForMerge" compiledSymbols = CompiledResources.from(exists(fileSystem.getPath(parts[4]))); symbolsBin = exists(fileSystem.getPath(parts[4])); } - return new DependencyAndroidData( splitPaths(parts[0], fileSystem), assetDirs, diff --git a/src/tools/android/java/com/google/devtools/build/android/DependencySymbolFileProvider.java b/src/tools/android/java/com/google/devtools/build/android/DependencySymbolFileProvider.java index b6f86bd636..f5f1977d81 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DependencySymbolFileProvider.java +++ b/src/tools/android/java/com/google/devtools/build/android/DependencySymbolFileProvider.java @@ -21,9 +21,7 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -/** - * Represents the R.txt symbol file and AndroidManifest (provides Java package) of libraries. - */ +/** Represents the R.txt symbol file and AndroidManifest (provides Java package) of libraries. */ class DependencySymbolFileProvider implements SymbolFileProvider { private final File symbolFile; @@ -91,5 +89,4 @@ class DependencySymbolFileProvider implements SymbolFileProvider { public String toString() { return String.format("%s, %s", symbolFile, manifest); } - } diff --git a/src/tools/android/java/com/google/devtools/build/android/FailedFutureAggregator.java b/src/tools/android/java/com/google/devtools/build/android/FailedFutureAggregator.java index 06f49036e2..b95684d0f3 100644 --- a/src/tools/android/java/com/google/devtools/build/android/FailedFutureAggregator.java +++ b/src/tools/android/java/com/google/devtools/build/android/FailedFutureAggregator.java @@ -19,9 +19,7 @@ import java.io.IOException; import java.util.List; import java.util.concurrent.ExecutionException; -/** - * Aggregates a list of failed {@link ListenableFuture} and throws it as an exception. - */ +/** Aggregates a list of failed {@link ListenableFuture} and throws it as an exception. */ class FailedFutureAggregator<T extends Throwable> { private ExceptionFactory<T> exceptionFactory; diff --git a/src/tools/android/java/com/google/devtools/build/android/GenerateRobolectricResourceSymbolsAction.java b/src/tools/android/java/com/google/devtools/build/android/GenerateRobolectricResourceSymbolsAction.java index fa71b5f3e1..d6010bf0e9 100644 --- a/src/tools/android/java/com/google/devtools/build/android/GenerateRobolectricResourceSymbolsAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/GenerateRobolectricResourceSymbolsAction.java @@ -46,9 +46,7 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -/** - * This action generates consistent ids R.class files for use in robolectric tests. - */ +/** This action generates consistent ids R.class files for use in robolectric tests. */ public class GenerateRobolectricResourceSymbolsAction { private static final Logger logger = diff --git a/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java b/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java index 63b0a3a036..d3733a33ac 100644 --- a/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java +++ b/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java @@ -18,7 +18,8 @@ import com.google.devtools.build.android.ParsedAndroidData.KeyValueConsumer; /** * A group of {@link KeyValueConsumer}s for each DataValue type. * - * This class acts as a parameter object for organizing the common grouping of consumer instances. + * <p>This class acts as a parameter object for organizing the common grouping of consumer + * instances. */ class KeyValueConsumers { static KeyValueConsumers of( diff --git a/src/tools/android/java/com/google/devtools/build/android/ManifestMergerAction.java b/src/tools/android/java/com/google/devtools/build/android/ManifestMergerAction.java index e7a3ac6d55..a7301f1030 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ManifestMergerAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/ManifestMergerAction.java @@ -178,9 +178,9 @@ public class ManifestMergerAction { // Write resulting manifest to the output directory, maintaining full path to prevent collisions Path output = outputDir.resolve(manifest.toString().replaceFirst("^/", "")); Files.createDirectories(output.getParent()); - TransformerFactory.newInstance().newTransformer().transform( - new DOMSource(doc), - new StreamResult(output.toFile())); + TransformerFactory.newInstance() + .newTransformer() + .transform(new DOMSource(doc), new StreamResult(output.toFile())); return output; } @@ -201,8 +201,7 @@ public class ManifestMergerAction { ImmutableMap.Builder<Path, String> mergeeManifests = ImmutableMap.builder(); for (Entry<Path, String> mergeeManifest : options.mergeeManifests.entrySet()) { mergeeManifests.put( - removePermissions(mergeeManifest.getKey(), tmp), - mergeeManifest.getValue()); + removePermissions(mergeeManifest.getKey(), tmp), mergeeManifest.getValue()); } mergedManifest = @@ -229,4 +228,3 @@ public class ManifestMergerAction { } } } - diff --git a/src/tools/android/java/com/google/devtools/build/android/ManifestProcessingException.java b/src/tools/android/java/com/google/devtools/build/android/ManifestProcessingException.java index 24e16c206c..1530959068 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ManifestProcessingException.java +++ b/src/tools/android/java/com/google/devtools/build/android/ManifestProcessingException.java @@ -13,9 +13,7 @@ // limitations under the License. package com.google.devtools.build.android; -/** - * Indicates an error parsing or modifying an AndroidManifest.xml. - */ +/** Indicates an error parsing or modifying an AndroidManifest.xml. */ public class ManifestProcessingException extends Exception { public ManifestProcessingException() { diff --git a/src/tools/android/java/com/google/devtools/build/android/MergeConflict.java b/src/tools/android/java/com/google/devtools/build/android/MergeConflict.java index 958c1e8456..5a98086bbb 100644 --- a/src/tools/android/java/com/google/devtools/build/android/MergeConflict.java +++ b/src/tools/android/java/com/google/devtools/build/android/MergeConflict.java @@ -24,11 +24,12 @@ import java.util.Objects; /** * Represents a conflict of two DataResources or DataAssets. * - * For resources, the dataKey is the FullyQualifiedName; Assets use the RelativeAssetPath. + * <p>For resources, the dataKey is the FullyQualifiedName; Assets use the RelativeAssetPath. */ @Immutable public class MergeConflict { - private static final String CONFLICT_MESSAGE = "\n\u001B[31mCONFLICT:\u001B[0m" + private static final String CONFLICT_MESSAGE = + "\n\u001B[31mCONFLICT:\u001B[0m" + " %s is provided with ambiguous priority from:\n\t%s\n\t%s"; private final DataKey dataKey; diff --git a/src/tools/android/java/com/google/devtools/build/android/MergedAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/MergedAndroidData.java index 431d205e12..8483e8dcd3 100644 --- a/src/tools/android/java/com/google/devtools/build/android/MergedAndroidData.java +++ b/src/tools/android/java/com/google/devtools/build/android/MergedAndroidData.java @@ -53,8 +53,8 @@ class MergedAndroidData implements ManifestContainer { public DensityFilteredAndroidData filter( DensitySpecificResourceFilter resourceFilter, DensitySpecificManifestProcessor manifestProcessor) - throws ManifestProcessingException { - return new DensityFilteredAndroidData(resourceFilter.filter(resourceDir), - assetDir, manifestProcessor.process(manifest)); + throws ManifestProcessingException { + return new DensityFilteredAndroidData( + resourceFilter.filter(resourceDir), assetDir, manifestProcessor.process(manifest)); } } diff --git a/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java b/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java index 99fcbcb86d..d497b0d2d6 100644 --- a/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java +++ b/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java @@ -22,9 +22,7 @@ import com.google.common.io.Files; import java.io.File; import java.io.IOException; -/** - * A wrapper around a PNG cruncher that only processes nine-patch PNGs. - */ +/** A wrapper around a PNG cruncher that only processes nine-patch PNGs. */ public class NinePatchOnlyCruncher extends AaptCruncher { public NinePatchOnlyCruncher( diff --git a/src/tools/android/java/com/google/devtools/build/android/RClassGeneratorAction.java b/src/tools/android/java/com/google/devtools/build/android/RClassGeneratorAction.java index 3cf3a9d9f0..bcfdb5fdb3 100644 --- a/src/tools/android/java/com/google/devtools/build/android/RClassGeneratorAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/RClassGeneratorAction.java @@ -56,14 +56,11 @@ import java.util.logging.Logger; */ public class RClassGeneratorAction { - private static final StdLogger STD_LOGGER = - new StdLogger(StdLogger.Level.WARNING); + private static final StdLogger STD_LOGGER = new StdLogger(StdLogger.Level.WARNING); private static final Logger logger = Logger.getLogger(RClassGeneratorAction.class.getName()); - /** - * Flag specifications for this action. - */ + /** Flag specifications for this action. */ public static final class Options extends OptionsBase { @Option( @@ -164,8 +161,8 @@ public class RClassGeneratorAction { if (options.primaryRTxt != null) { String appPackageName = options.packageForR; if (appPackageName == null) { - appPackageName = VariantConfiguration - .getManifestPackage(options.primaryManifest.toFile()); + appPackageName = + VariantConfiguration.getManifestPackage(options.primaryManifest.toFile()); } Multimap<String, ResourceSymbols> libSymbolMap = ArrayListMultimap.create(); ResourceSymbols fullSymbolValues = diff --git a/src/tools/android/java/com/google/devtools/build/android/RelativeAssetPath.java b/src/tools/android/java/com/google/devtools/build/android/RelativeAssetPath.java index 9940d13d27..1801026c96 100644 --- a/src/tools/android/java/com/google/devtools/build/android/RelativeAssetPath.java +++ b/src/tools/android/java/com/google/devtools/build/android/RelativeAssetPath.java @@ -25,16 +25,14 @@ import java.util.Objects; /** * Represents a DataKey for assets. * - * Assets are added to a single directory inside an apk by aapt. Therefore, to determine overwritten - * and conflicting assets we take the relative from the asset directory and turn it into a DataKey. - * This serves as the unique identifier for each apk stored asset. + * <p>Assets are added to a single directory inside an apk by aapt. Therefore, to determine + * overwritten and conflicting assets we take the relative from the asset directory and turn it into + * a DataKey. This serves as the unique identifier for each apk stored asset. * - * Note: Assets have no qualifiers or packages. + * <p>Note: Assets have no qualifiers or packages. */ public class RelativeAssetPath implements DataKey { - /** - * A Factory that creates RelativeAssetsPath objects whose paths are relative to a given path. - */ + /** A Factory that creates RelativeAssetsPath objects whose paths are relative to a given path. */ public static class Factory { private final Path assetRoot; @@ -42,9 +40,7 @@ public class RelativeAssetPath implements DataKey { this.assetRoot = assetRoot; } - /** - * Creates a new factory with the asset directory that contains assets. - */ + /** Creates a new factory with the asset directory that contains assets. */ public static Factory of(Path assetRoot) { return new Factory(Preconditions.checkNotNull(assetRoot)); } @@ -58,9 +54,7 @@ public class RelativeAssetPath implements DataKey { } } - /** - * Reconstitutes the relative asset path from a protocol buffer and {@link FileSystem}. - */ + /** Reconstitutes the relative asset path from a protocol buffer and {@link FileSystem}. */ static RelativeAssetPath fromProto(SerializeFormat.DataKey serialized, FileSystem fileSystem) { return of(fileSystem.getPath(serialized.getKeyValue())); } diff --git a/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java b/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java index ff38cac35f..7d9f59fb0d 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java @@ -239,7 +239,7 @@ public class ResourceShrinkerAction { } private static Set<String> getManifestPackages(Path primaryManifest, List<Path> otherManifests) - throws SAXException, IOException, StreamException, ParserConfigurationException { + throws SAXException, IOException, StreamException, ParserConfigurationException { Set<String> manifestPackages = new HashSet<>(); manifestPackages.add(getManifestPackage(primaryManifest)); for (Path manifest : otherManifests) { @@ -251,8 +251,8 @@ public class ResourceShrinkerAction { public static void main(String[] args) throws Exception { final Stopwatch timer = Stopwatch.createStarted(); // Parse arguments. - OptionsParser optionsParser = OptionsParser.newOptionsParser( - Options.class, AaptConfigOptions.class); + OptionsParser optionsParser = + OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class); optionsParser.enableParamsFileSupport( new ShellQuotedParamsFilePreProcessor(FileSystems.getDefault())); optionsParser.parseAndExitUponError(args); @@ -271,13 +271,13 @@ public class ResourceShrinkerAction { final Path shrunkResources = working.resolve("shrunk_resources"); // Gather package list from manifests. - Set<String> resourcePackages = getManifestPackages( - options.primaryManifest, options.dependencyManifests); + Set<String> resourcePackages = + getManifestPackages(options.primaryManifest, options.dependencyManifests); resourcePackages.addAll(options.resourcePackages); // Expand resource files zip into working directory. - try (ZipInputStream zin = new ZipInputStream( - new FileInputStream(options.resourcesZip.toFile()))) { + try (ZipInputStream zin = + new ZipInputStream(new FileInputStream(options.resourcesZip.toFile()))) { ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { if (!entry.isDirectory()) { @@ -291,18 +291,20 @@ public class ResourceShrinkerAction { } // Shrink resources. - ResourceUsageAnalyzer resourceShrinker = new ResourceUsageAnalyzer( - resourcePackages, - options.rTxt, - options.shrunkJar, - options.primaryManifest, - options.proguardMapping, - resourceFiles.resolve("res"), - options.log); + ResourceUsageAnalyzer resourceShrinker = + new ResourceUsageAnalyzer( + resourcePackages, + options.rTxt, + options.shrunkJar, + options.primaryManifest, + options.proguardMapping, + resourceFiles.resolve("res"), + options.log); resourceShrinker.shrink(shrunkResources); - logger.fine(String.format("Shrinking resources finished at %sms", - timer.elapsed(TimeUnit.MILLISECONDS))); + logger.fine( + String.format( + "Shrinking resources finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); Path generatedSources = null; if (options.rTxtOutput != null) { @@ -338,8 +340,9 @@ public class ResourceShrinkerAction { AndroidResourceOutputs.copyRToOutput( generatedSources, options.rTxtOutput, options.packageType == VariantType.LIBRARY); } - logger.fine(String.format("Packing resources finished at %sms", - timer.elapsed(TimeUnit.MILLISECONDS))); + logger.fine( + String.format( + "Packing resources finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); } catch (Exception e) { logger.log(Level.SEVERE, "Error shrinking resources", e); throw e; diff --git a/src/tools/android/java/com/google/devtools/build/android/SplitConfigurationFilter.java b/src/tools/android/java/com/google/devtools/build/android/SplitConfigurationFilter.java index c1454e4d76..4103b800a2 100644 --- a/src/tools/android/java/com/google/devtools/build/android/SplitConfigurationFilter.java +++ b/src/tools/android/java/com/google/devtools/build/android/SplitConfigurationFilter.java @@ -40,10 +40,10 @@ import java.util.regex.Pattern; * API version, if any, then by other specifiers (case-insensitive), with ties broken by the * filename or split flag originally used to create the instance (case-sensitive). * - * <p>This has the following useful property:<br/> - * Given two sets of {@link SplitConfigurationFilter}s, one from the input split flags, and - * one from aapt's outputs... Each member of the output set can be matched to the greatest member - * of the input set for which {@code input.matchesFilterFromFilename(output)} is true. + * <p>This has the following useful property:<br> + * Given two sets of {@link SplitConfigurationFilter}s, one from the input split flags, and one from + * aapt's outputs... Each member of the output set can be matched to the greatest member of the + * input set for which {@code input.matchesFilterFromFilename(output)} is true. */ final class SplitConfigurationFilter implements Comparable<SplitConfigurationFilter> { @@ -181,10 +181,10 @@ final class SplitConfigurationFilter implements Comparable<SplitConfigurationFil * <p>Order of whole configurations doesn't matter, as aapt will reorder the configurations * according to complicated internal logic (yes, logic even more complicated than this!). * - * <p>Care is needed with API version specifiers because aapt may add or change minimum - * API version specifiers to configurations according to whether they had specifiers which are - * only supported in certain versions of Android. It will only ever increase the minimum version - * or leave it the same. + * <p>Care is needed with API version specifiers because aapt may add or change minimum API + * version specifiers to configurations according to whether they had specifiers which are only + * supported in certain versions of Android. It will only ever increase the minimum version or + * leave it the same. * * <p>The other (non-wildcard) specifiers should be case-insensitive identical, including order; * aapt will not allow parts of a single configuration to be parsed out of order. @@ -262,10 +262,10 @@ final class SplitConfigurationFilter implements Comparable<SplitConfigurationFil * <p>The natural ordering of this class sorts by required API version, if any, then by other * specifiers. * - * <p>This has the following useful property:<br/> - * Given two sets of {@link ResourceConfiguration}s, one from an input split flag, and - * one from aapt's output... Each member of the output set can be matched to the greatest member - * of the input set for which {@code input.matchesConfigurationFromFilename(output)} is true. + * <p>This has the following useful property:<br> + * Given two sets of {@link ResourceConfiguration}s, one from an input split flag, and one from + * aapt's output... Each member of the output set can be matched to the greatest member of the + * input set for which {@code input.matchesConfigurationFromFilename(output)} is true. */ static final class ResourceConfiguration implements Comparable<ResourceConfiguration> { /** diff --git a/src/tools/android/java/com/google/devtools/build/android/UnvalidatedAndroidDirectories.java b/src/tools/android/java/com/google/devtools/build/android/UnvalidatedAndroidDirectories.java index 8be10be0fb..49fdb18296 100644 --- a/src/tools/android/java/com/google/devtools/build/android/UnvalidatedAndroidDirectories.java +++ b/src/tools/android/java/com/google/devtools/build/android/UnvalidatedAndroidDirectories.java @@ -23,9 +23,7 @@ import java.nio.file.Path; import java.util.Objects; import java.util.regex.Pattern; -/** - * Android resource and asset directories that can be parsed. - */ +/** Android resource and asset directories that can be parsed. */ public class UnvalidatedAndroidDirectories { private static final Pattern VALID_REGEX = Pattern.compile(".*:.*"); @@ -39,8 +37,7 @@ public class UnvalidatedAndroidDirectories { @VisibleForTesting static UnvalidatedAndroidDirectories valueOf(String text, FileSystem fileSystem) { if (!VALID_REGEX.matcher(text).find()) { - throw new IllegalArgumentException( - text + " is not in the format '" + EXPECTED_FORMAT + "'"); + throw new IllegalArgumentException(text + " is not in the format '" + EXPECTED_FORMAT + "'"); } String[] parts = text.split(":"); return new UnvalidatedAndroidDirectories( diff --git a/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java index 1f0fe68355..4668887a40 100644 --- a/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java +++ b/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java @@ -21,9 +21,7 @@ import java.nio.file.Path; import java.util.Map.Entry; import java.util.Objects; -/** - * Merged Android Data that has yet to written into a {@link MergedAndroidData}. - */ +/** Merged Android Data that has yet to written into a {@link MergedAndroidData}. */ public class UnwrittenMergedAndroidData { private final Path manifest; diff --git a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValue.java index 0c0edd92a5..f24d6b271a 100644 --- a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValue.java @@ -17,9 +17,7 @@ import com.google.devtools.build.android.xml.Namespaces; import java.io.IOException; import java.io.OutputStream; -/** - * An {@link XmlResourceValue} is extracted from xml files in the resource 'values' directory. - */ +/** An {@link XmlResourceValue} is extracted from xml files in the resource 'values' directory. */ public interface XmlResourceValue { /** * Each XmlValue is expected to write a valid representation in xml to the writer. @@ -35,7 +33,7 @@ public interface XmlResourceValue { /** * Combines these xml values together and returns a single value. - * + * * @param value Another resource to be combined with this one. * @return A union of the values of these two values. * @throws IllegalArgumentException if either value cannot combine with the other. diff --git a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java index 432cfc7495..1ea38826bf 100644 --- a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java +++ b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java @@ -80,6 +80,7 @@ public class XmlResourceValues { private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance(); private static XMLInputFactory inputFactoryInstance = null; + public static XMLInputFactory getXmlInputFactory() { if (inputFactoryInstance == null) { inputFactoryInstance = XMLInputFactory.newInstance(); @@ -130,8 +131,7 @@ public class XmlResourceValues { // <Parent> // And, in the resource name <parent>.<resource name> // Here, we take a garbage in, garbage out approach and just read the xml value raw. - return StyleXmlResourceValue.of(getElementAttributeByName(start, ATTR_PARENT), - values); + return StyleXmlResourceValue.of(getElementAttributeByName(start, ATTR_PARENT), values); } static void parseDeclareStyleable( @@ -281,7 +281,7 @@ public class XmlResourceValues { } // TODO(corysmith): Replace this with real escaping system, preferably a performant high level xml - //writing library. See AndroidDataWritingVisitor TODO. + // writing library. See AndroidDataWritingVisitor TODO. private static String escapeXmlValues(String data) { return data.replace("&", "&").replace("<", "<").replace(">", ">"); } diff --git a/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java b/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java index e8aae6bad0..c774ec22f6 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java @@ -53,9 +53,12 @@ import java.util.regex.Pattern; * extension of '.*' was specified. * * <p>Assuming each Zip as a set of entries, the result is: + * * <pre> outputZip = inputZip - union[x intersect filterTypes for x in filterZips]</pre> * - * <p><pre> + * <p> + * + * <pre> * Example Usage: * java/com/google/build/android/ZipFilterAction\ * --inputZip path/to/inputZip diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/Aapt2ConfigOptions.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/Aapt2ConfigOptions.java index 6d8d614116..1b402eaf90 100644 --- a/src/tools/android/java/com/google/devtools/build/android/aapt2/Aapt2ConfigOptions.java +++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/Aapt2ConfigOptions.java @@ -63,29 +63,28 @@ public class Aapt2ConfigOptions extends OptionsBase { public Path androidJar; @Option( - name = "annotationJar", - defaultValue = "null", - converter = ExistingPathConverter.class, - category = "tool", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "Path to the android jar for resource packaging and building apks." + name = "annotationJar", + defaultValue = "null", + converter = ExistingPathConverter.class, + category = "tool", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Path to the android jar for resource packaging and building apks." ) public Path annotationJar; - @Option( - name = "useAaptCruncher", - defaultValue = "auto", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = - "Use the legacy aapt cruncher, defaults to true for non-LIBRARY packageTypes. " - + " LIBRARY packages do not benefit from the additional processing as the resources" - + " will need to be reprocessed during the generation of the final apk. See" - + " https://code.google.com/p/android/issues/detail?id=67525 for a discussion of the" - + " different png crunching methods." + name = "useAaptCruncher", + defaultValue = "auto", + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = + "Use the legacy aapt cruncher, defaults to true for non-LIBRARY packageTypes. " + + " LIBRARY packages do not benefit from the additional processing as the resources" + + " will need to be reprocessed during the generation of the final apk. See" + + " https://code.google.com/p/android/issues/detail?id=67525 for a discussion of the" + + " different png crunching methods." ) public TriState useAaptCruncher; @@ -100,45 +99,45 @@ public class Aapt2ConfigOptions extends OptionsBase { public TriState conditionalKeepRules; @Option( - name = "uncompressedExtensions", - defaultValue = "", - converter = CommaSeparatedOptionListConverter.class, - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "A list of file extensions not to compress." + name = "uncompressedExtensions", + defaultValue = "", + converter = CommaSeparatedOptionListConverter.class, + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "A list of file extensions not to compress." ) public List<String> uncompressedExtensions; @Option( - name = "assetsToIgnore", - defaultValue = "", - converter = CommaSeparatedOptionListConverter.class, - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "A list of assets extensions to ignore." + name = "assetsToIgnore", + defaultValue = "", + converter = CommaSeparatedOptionListConverter.class, + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "A list of assets extensions to ignore." ) public List<String> assetsToIgnore; @Option( - name = "debug", - defaultValue = "false", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "Indicates if it is a debug build." + name = "debug", + defaultValue = "false", + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Indicates if it is a debug build." ) public boolean debug; @Option( - name = "resourceConfigs", - defaultValue = "", - converter = CommaSeparatedOptionListConverter.class, - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "A list of resource config filters to pass to aapt." + name = "resourceConfigs", + defaultValue = "", + converter = CommaSeparatedOptionListConverter.class, + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "A list of resource config filters to pass to aapt." ) public List<String> resourceConfigs; @@ -147,34 +146,34 @@ public class Aapt2ConfigOptions extends OptionsBase { + "#QualifierRules"; @Option( - name = "split", - defaultValue = "required but ignored due to allowMultiple", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - allowMultiple = true, - help = - "An individual split configuration to pass to aapt." - + " Each split is a list of configuration filters separated by commas." - + " Configuration filters are lists of configuration qualifiers separated by dashes," - + " as used in resource directory names and described on the Android developer site: " - + ANDROID_SPLIT_DOCUMENTATION_URL - + " For example, a split might be 'en-television,en-xxhdpi', containing English" - + " assets which either are for TV screens or are extra extra high resolution." - + " Multiple splits can be specified by passing this flag multiple times." - + " Each split flag will produce an additional output file, named by replacing the" - + " commas in the split specification with underscores, and appending the result to" - + " the output package name following an underscore." + name = "split", + defaultValue = "required but ignored due to allowMultiple", + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + allowMultiple = true, + help = + "An individual split configuration to pass to aapt." + + " Each split is a list of configuration filters separated by commas." + + " Configuration filters are lists of configuration qualifiers separated by dashes," + + " as used in resource directory names and described on the Android developer site: " + + ANDROID_SPLIT_DOCUMENTATION_URL + + " For example, a split might be 'en-television,en-xxhdpi', containing English" + + " assets which either are for TV screens or are extra extra high resolution." + + " Multiple splits can be specified by passing this flag multiple times." + + " Each split flag will produce an additional output file, named by replacing the" + + " commas in the split specification with underscores, and appending the result to" + + " the output package name following an underscore." ) public List<String> splits; @Option( - name = "useCompiledResourcesForMerge", - defaultValue = "false", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "Use compiled resources for merging rather than parsed symbols binary." + name = "useCompiledResourcesForMerge", + defaultValue = "false", + category = "config", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Use compiled resources for merging rather than parsed symbols binary." ) public boolean useCompiledResourcesForMerge; } diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/CompiledResources.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/CompiledResources.java index 2e96319a81..65200f6b52 100644 --- a/src/tools/android/java/com/google/devtools/build/android/aapt2/CompiledResources.java +++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/CompiledResources.java @@ -65,9 +65,7 @@ public class CompiledResources implements ManifestContainer { resources, manifest, assetDirs != null ? assetDirs : ImmutableList.of(), Optional.empty()); } - /** - * This zip file contains resource flat files that are the result of aapt2 compile - */ + /** This zip file contains resource flat files that are the result of aapt2 compile */ public Path getZip() { return resources; } diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/StaticLibrary.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/StaticLibrary.java index 142d7fefb1..a8b27e9e8c 100644 --- a/src/tools/android/java/com/google/devtools/build/android/aapt2/StaticLibrary.java +++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/StaticLibrary.java @@ -57,13 +57,8 @@ public class StaticLibrary { return new StaticLibrary(library, rTxt, assets, sourceJar); } - public static StaticLibrary from( - Path library, Path rTxt, ImmutableList<Path> assetDirs) { - return of( - library, - Optional.ofNullable(rTxt), - Optional.ofNullable(assetDirs), - Optional.empty()); + public static StaticLibrary from(Path library, Path rTxt, ImmutableList<Path> assetDirs) { + return of(library, Optional.ofNullable(rTxt), Optional.ofNullable(assetDirs), Optional.empty()); } public static StaticLibrary from( diff --git a/src/tools/android/java/com/google/devtools/build/android/desugar/BitFlags.java b/src/tools/android/java/com/google/devtools/build/android/desugar/BitFlags.java index bb32c452e2..8be228801d 100644 --- a/src/tools/android/java/com/google/devtools/build/android/desugar/BitFlags.java +++ b/src/tools/android/java/com/google/devtools/build/android/desugar/BitFlags.java @@ -15,14 +15,12 @@ package com.google.devtools.build.android.desugar; import org.objectweb.asm.Opcodes; -/** - * Convenience method for working with {@code int} bitwise flags. - */ +/** Convenience method for working with {@code int} bitwise flags. */ class BitFlags { /** - * Returns {@code true} iff <b>all</b> bits in {@code bitmask} are set in {@code flags}. - * Trivially returns {@code true} if {@code bitmask} is 0. + * Returns {@code true} iff <b>all</b> bits in {@code bitmask} are set in {@code flags}. Trivially + * returns {@code true} if {@code bitmask} is 0. */ public static boolean isSet(int flags, int bitmask) { return (flags & bitmask) == bitmask; |