From e345a3565597b76ee5bf6bfbf2c84ce9271be079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20Koz=C3=A1k?= Date: Fri, 31 Oct 2014 16:01:51 +0100 Subject: Command line option for disabling warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new command line option to dx: --no-warning. If the caller appends this to the arguments, dx won't print warnings to System.err. This can be useful if the user dexes external jars with old class format, so dx would print lot of warning about those. Bug: https://code.google.com/p/android/issues/detail?id=78285 Signed-off-by: Csaba Kozák (cherry picked from commit ef1de423e70704c478ee77956f44b0a040d8bede) Change-Id: I6d09c684b5eb97aa28e0b12e3ef44b46293c7dec --- dx/src/com/android/dx/command/DxConsole.java | 13 +++++++++++++ dx/src/com/android/dx/command/Main.java | 2 +- dx/src/com/android/dx/command/dexer/Main.java | 12 +++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/dx/src/com/android/dx/command/DxConsole.java b/dx/src/com/android/dx/command/DxConsole.java index 9ce9836ef..919de8c80 100644 --- a/dx/src/com/android/dx/command/DxConsole.java +++ b/dx/src/com/android/dx/command/DxConsole.java @@ -16,6 +16,8 @@ package com.android.dx.command; +import java.io.IOException; +import java.io.OutputStream; import java.io.PrintStream; /** @@ -34,4 +36,15 @@ public class DxConsole { * Error output stream. Links to {@code System.err} by default. */ public static PrintStream err = System.err; + + /** + * Output stream which prints to nowhere. + */ + public static final PrintStream noop = new PrintStream(new OutputStream() { + + @Override + public void write(int b) throws IOException { + // noop + } + }); } diff --git a/dx/src/com/android/dx/command/Main.java b/dx/src/com/android/dx/command/Main.java index 9834987e5..a0be5bd51 100644 --- a/dx/src/com/android/dx/command/Main.java +++ b/dx/src/com/android/dx/command/Main.java @@ -33,7 +33,7 @@ public class Main { "[--dump-width=]\n" + " [--dump-method=[*]] [--verbose-dump] [--no-files] " + "[--core-library]\n" + - " [--num-threads=] [--incremental] [--force-jumbo]\n" + + " [--num-threads=] [--incremental] [--force-jumbo] [--no-warning]\n" + " [--multi-dex [--main-dex-list= [--minimal-main-dex]]\n" + " [--input-list=]\n" + " [.class | .{zip,jar,apk} | ] ...\n" + diff --git a/dx/src/com/android/dx/command/dexer/Main.java b/dx/src/com/android/dx/command/dexer/Main.java index 4a3d1952f..563a93c39 100644 --- a/dx/src/com/android/dx/command/dexer/Main.java +++ b/dx/src/com/android/dx/command/dexer/Main.java @@ -1199,6 +1199,9 @@ public class Main { /** whether to run in debug mode */ public boolean debug = false; + /** whether to emit warning messages */ + public boolean warnings = true; + /** whether to emit high-level verbose human-oriented output */ public boolean verbose = false; @@ -1409,6 +1412,8 @@ public class Main { while(parser.getNext()) { if (parser.isArg("--debug")) { debug = true; + } else if (parser.isArg("--no-warning")) { + warnings = false; } else if (parser.isArg("--verbose")) { verbose = true; } else if (parser.isArg("--verbose-dump")) { @@ -1580,7 +1585,12 @@ public class Main { cfOptions.optimizeListFile = optimizeListFile; cfOptions.dontOptimizeListFile = dontOptimizeListFile; cfOptions.statistics = statistics; - cfOptions.warn = DxConsole.err; + + if (warnings) { + cfOptions.warn = DxConsole.err; + } else { + cfOptions.warn = DxConsole.noop; + } dexOptions = new DexOptions(); dexOptions.forceJumbo = forceJumbo; -- cgit v1.2.3