summaryrefslogtreecommitdiff
path: root/java/com/google/devtools/build
diff options
context:
space:
mode:
authorccalvarin <ccalvarin@google.com>2017-08-18 16:21:32 +0200
committerColin Cross <ccross@android.com>2017-08-25 10:57:21 -0700
commit6c8eff0f04f07ed7a9cf75558d4c5af3a2a2778a (patch)
tree37e50ccb8c2b3c39169d55eb0e581845ee6724b5 /java/com/google/devtools/build
parent118f625c3d1f372a63283f405046f3e51cb654e9 (diff)
downloaddesugar-6c8eff0f04f07ed7a9cf75558d4c5af3a2a2778a.tar.gz
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 GitOrigin-RevId: 74a8c3e529f0c3ec9ab02db684e9d0ec4f71bf64 Change-Id: I944ff475980a1bad39e3cce6d7ebf674a3806a09
Diffstat (limited to 'java/com/google/devtools/build')
-rw-r--r--java/com/google/devtools/build/android/desugar/Desugar.java23
1 files changed, 10 insertions, 13 deletions
diff --git a/java/com/google/devtools/build/android/desugar/Desugar.java b/java/com/google/devtools/build/android/desugar/Desugar.java
index 5ba7699..63ca5e7 100644
--- a/java/com/google/devtools/build/android/desugar/Desugar.java
+++ b/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();