aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-08-18 16:21:32 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-21 14:15:42 +0200
commit74a8c3e529f0c3ec9ab02db684e9d0ec4f71bf64 (patch)
tree0d9061d2b81e04724c55f22e74d2826c15d7a4df /src/tools/android
parente6d2077cab9eef14afc25e54ab6b0e583e0b3bf0 (diff)
Switch android tools' use of options parser to a more concise form for the single options-base case.
This is to prepare the options parser from making options parser creation exceptions a caught exception. Since all of these classes already have a single options class and used parseAndExitUponError, this allows us to keep behavior consistent between the malformed options-base errors and the incorrect user-input errors. All the other uses of the options parser in //src/tools already throw sufficiently broad exceptions to not need this. RELNOTES: None PiperOrigin-RevId: 165702786
Diffstat (limited to 'src/tools/android')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java12
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java23
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/idlclass/IdlClass.java27
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/ziputils/BUILD1
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/ziputils/DexMapper.java14
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/ziputils/DexReducer.java14
6 files changed, 43 insertions, 48 deletions
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 f074a0cd16..62ad8fe166 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
@@ -27,8 +27,8 @@ import com.google.devtools.build.android.Converters.UnvalidatedAndroidDataConver
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsBase;
-import com.google.devtools.common.options.OptionsParser;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
@@ -67,7 +67,7 @@ public class AarGeneratorAction {
private static final Logger logger = Logger.getLogger(AarGeneratorAction.class.getName());
/** Flag specifications for this action. */
- public static final class Options extends OptionsBase {
+ public static final class AarGeneratorOptions extends OptionsBase {
@Option(
name = "mainData",
defaultValue = "null",
@@ -137,9 +137,9 @@ public class AarGeneratorAction {
public static void main(String[] args) {
Stopwatch timer = Stopwatch.createStarted();
- OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
- optionsParser.parseAndExitUponError(args);
- Options options = optionsParser.getOptions(Options.class);
+ AarGeneratorOptions options =
+ Options.parseAndExitUponError(AarGeneratorOptions.class, /*allowResidue=*/ true, args)
+ .getOptions();
checkFlags(options);
@@ -181,7 +181,7 @@ public class AarGeneratorAction {
}
@VisibleForTesting
- static void checkFlags(Options options) throws IllegalArgumentException {
+ static void checkFlags(AarGeneratorOptions options) {
List<String> nullFlags = new LinkedList<>();
if (options.manifest == null) {
nullFlags.add("manifest");
diff --git a/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java b/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java
index 5ba76999ba..63ca5e7a6b 100644
--- a/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java
+++ b/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java
@@ -33,8 +33,8 @@ import com.google.devtools.build.android.desugar.CoreLibraryRewriter.Unprefixing
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsBase;
-import com.google.devtools.common.options.OptionsParser;
import com.google.errorprone.annotations.MustBeClosed;
import java.io.IOError;
import java.io.IOException;
@@ -65,7 +65,7 @@ import org.objectweb.asm.tree.ClassNode;
class Desugar {
/** Commandline options for {@link Desugar}. */
- public static class Options extends OptionsBase {
+ public static class DesugarOptions extends OptionsBase {
@Option(
name = "input",
allowMultiple = true,
@@ -231,7 +231,7 @@ class Desugar {
public boolean coreLibrary;
}
- private final Options options;
+ private final DesugarOptions options;
private final CoreLibraryRewriter rewriter;
private final LambdaClassMaker lambdas;
private final GeneratedClassStore store;
@@ -247,7 +247,7 @@ class Desugar {
/** An instance of Desugar is expected to be used ONLY ONCE */
private boolean used;
- private Desugar(Options options, Path dumpDirectory) {
+ private Desugar(DesugarOptions options, Path dumpDirectory) {
this.options = options;
this.rewriter = new CoreLibraryRewriter(options.coreLibrary ? "__desugar__/" : "");
this.lambdas = new LambdaClassMaker(dumpDirectory);
@@ -590,7 +590,7 @@ class Desugar {
Path dumpDirectory = createAndRegisterLambdaDumpDirectory();
verifyLambdaDumpDirectoryRegistered(dumpDirectory);
- Options options = parseCommandLineOptions(args);
+ DesugarOptions options = parseCommandLineOptions(args);
if (options.verbose) {
System.out.printf("Lambda classes will be written under %s%n", dumpDirectory);
}
@@ -646,16 +646,13 @@ class Desugar {
return dumpDirectory;
}
- private static Options parseCommandLineOptions(String[] args) throws IOException {
+ private static DesugarOptions parseCommandLineOptions(String[] args) throws IOException {
if (args.length == 1 && args[0].startsWith("@")) {
args = Files.readAllLines(Paths.get(args[0].substring(1)), ISO_8859_1).toArray(new String[0]);
}
-
- OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
- optionsParser.setAllowResidue(false);
- optionsParser.parseAndExitUponError(args);
-
- Options options = optionsParser.getOptions(Options.class);
+ DesugarOptions options =
+ Options.parseAndExitUponError(DesugarOptions.class, /*allowResidue=*/ false, args)
+ .getOptions();
checkArgument(!options.inputJars.isEmpty(), "--input is required");
checkArgument(
@@ -672,7 +669,7 @@ class Desugar {
return options;
}
- private static ImmutableList<InputOutputPair> toInputOutputPairs(Options options) {
+ private static ImmutableList<InputOutputPair> toInputOutputPairs(DesugarOptions options) {
final ImmutableList.Builder<InputOutputPair> ioPairListbuilder = ImmutableList.builder();
for (Iterator<Path> inputIt = options.inputJars.iterator(),
outputIt = options.outputJars.iterator();
diff --git a/src/tools/android/java/com/google/devtools/build/android/idlclass/IdlClass.java b/src/tools/android/java/com/google/devtools/build/android/idlclass/IdlClass.java
index fabf09a2d3..3bce5c1509 100644
--- a/src/tools/android/java/com/google/devtools/build/android/idlclass/IdlClass.java
+++ b/src/tools/android/java/com/google/devtools/build/android/idlclass/IdlClass.java
@@ -22,7 +22,7 @@ import com.google.common.collect.Sets;
import com.google.devtools.build.buildjar.jarhelper.JarCreator;
import com.google.devtools.build.buildjar.proto.JavaCompilation.CompilationUnit;
import com.google.devtools.build.buildjar.proto.JavaCompilation.Manifest;
-import com.google.devtools.common.options.OptionsParser;
+import com.google.devtools.common.options.Options;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -42,23 +42,24 @@ import java.util.jar.JarFile;
public class IdlClass {
public static void main(String[] args) throws IOException {
- OptionsParser optionsParser = OptionsParser.newOptionsParser(IdlClassOptions.class);
- optionsParser.parseAndExitUponError(args);
- IdlClassOptions options = optionsParser.getOptions(IdlClassOptions.class);
- Preconditions.checkNotNull(options.manifestProto);
- Preconditions.checkNotNull(options.classJar);
- Preconditions.checkNotNull(options.outputClassJar);
- Preconditions.checkNotNull(options.outputSourceJar);
- Preconditions.checkNotNull(options.tempDir);
+ Options<IdlClassOptions> options =
+ Options.parseAndExitUponError(IdlClassOptions.class, /*allowResidue=*/ true, args);
+
+ IdlClassOptions idlClassOptions = options.getOptions();
+ Preconditions.checkNotNull(idlClassOptions.manifestProto);
+ Preconditions.checkNotNull(idlClassOptions.classJar);
+ Preconditions.checkNotNull(idlClassOptions.outputClassJar);
+ Preconditions.checkNotNull(idlClassOptions.outputSourceJar);
+ Preconditions.checkNotNull(idlClassOptions.tempDir);
List<Path> idlSources = Lists.newArrayList();
- for (String idlSource : optionsParser.getResidue()) {
+ for (String idlSource : options.getRemainingArgs()) {
idlSources.add(Paths.get(idlSource));
}
- Manifest manifest = readManifest(options.manifestProto);
- writeClassJar(options, idlSources, manifest);
- writeSourceJar(options, idlSources, manifest);
+ Manifest manifest = readManifest(idlClassOptions.manifestProto);
+ writeClassJar(idlClassOptions, idlSources, manifest);
+ writeSourceJar(idlClassOptions, idlSources, manifest);
}
private static void writeClassJar(IdlClassOptions options,
diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/BUILD b/src/tools/android/java/com/google/devtools/build/android/ziputils/BUILD
index 4f88bf774e..81fc56cd2e 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ziputils/BUILD
+++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/BUILD
@@ -75,6 +75,7 @@ java_binary(
deps = [
":ziputils_lib",
"//src/main/java/com/google/devtools/common/options",
+ "//third_party:guava",
],
)
diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/DexMapper.java b/src/tools/android/java/com/google/devtools/build/android/ziputils/DexMapper.java
index e26db4fe31..931879159a 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ziputils/DexMapper.java
+++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/DexMapper.java
@@ -19,8 +19,8 @@ import com.google.common.base.Predicates;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsBase;
-import com.google.devtools.common.options.OptionsParser;
import java.util.List;
/**
@@ -36,9 +36,9 @@ public class DexMapper {
* @param args the command line arguments
*/
public static void main(String[] args) {
- OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
- optionsParser.parseAndExitUponError(args);
- Options options = optionsParser.getOptions(Options.class);
+ DexMapperOptions options =
+ Options.parseAndExitUponError(DexMapperOptions.class, /*allowResidue=*/ true, args)
+ .getOptions();
List<String> inputs = options.inputJars;
List<String> outputs = options.outputJars;
String filterFile = options.mainDexFilter;
@@ -67,10 +67,8 @@ public class DexMapper {
}
}
- /**
- * Commandline options.
- */
- public static class Options extends OptionsBase {
+ /** Commandline options. */
+ public static class DexMapperOptions extends OptionsBase {
@Option(
name = "input_jar",
defaultValue = "null",
diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/DexReducer.java b/src/tools/android/java/com/google/devtools/build/android/ziputils/DexReducer.java
index 2ba1d9d854..91f1a56eab 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ziputils/DexReducer.java
+++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/DexReducer.java
@@ -27,8 +27,8 @@ import static com.google.devtools.build.android.ziputils.LocalFileHeader.LOCTIM;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsBase;
-import com.google.devtools.common.options.OptionsParser;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -73,9 +73,9 @@ public class DexReducer implements EntryHandler {
}
private void parseArguments(String[] args) {
- OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
- optionsParser.parseAndExitUponError(args);
- Options options = optionsParser.getOptions(Options.class);
+ DexReducerOptions options =
+ Options.parseAndExitUponError(DexReducerOptions.class, /*allowResidue=*/ true, args)
+ .getOptions();
paths = options.inputZips;
outFile = options.outputZip;
}
@@ -112,10 +112,8 @@ public class DexReducer implements EntryHandler {
}
}
- /**
- * Commandline options.
- */
- public static class Options extends OptionsBase {
+ /** Commandline options. */
+ public static class DexReducerOptions extends OptionsBase {
@Option(
name = "input_zip",
defaultValue = "null",