diff options
Diffstat (limited to 'src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/Main.java')
-rw-r--r-- | src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/Main.java | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/Main.java b/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/Main.java index 5df2eaa04d..3726caed30 100644 --- a/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/Main.java +++ b/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/Main.java @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.view.proto.Deps.Dependencies; import com.google.devtools.common.options.Converter; +import com.google.devtools.common.options.EnumConverter; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.OptionDocumentationCategory; import com.google.devtools.common.options.OptionEffectTag; @@ -116,14 +117,26 @@ public class Main { help = "The rule label of the current target under analysis.") public String ruleLabel; + // TODO (cnsun): remove this flag. @Option( name = "fail_on_errors", - defaultValue = "true", + defaultValue = "false", documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.UNKNOWN}, + deprecationWarning = "This will be replaced with --checking_mode.", help = "Fail on incomplete dependencies, otherwise emit warnings." ) public boolean failOnErrors; + + @Option( + name = "checking_mode", + defaultValue = "null", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.UNKNOWN}, + converter = CheckingModeConverter.class, + help = "Controls the behavior of the checker." + ) + public CheckingMode checkingMode; } /** A randomly picked large exit code to avoid collision with other common exit codes. */ @@ -147,10 +160,10 @@ public class Main { ImmutableList.copyOf(options.bootclasspath), ImmutableList.copyOf(options.classpath), ImmutableList.copyOf(options.inputJars))) { - if (!checker.check()) { + if (!checker.check() && options.checkingMode != CheckingMode.SILENCE) { String result = checker.computeResultOutput(); checkState(!result.isEmpty(), "The result should NOT be empty."); - exitCode = options.failOnErrors ? DEPS_ERROR_EXIT_CODE : 0; + exitCode = options.checkingMode == CheckingMode.ERROR ? DEPS_ERROR_EXIT_CODE : 0; printErrorMessage(result, options); asCharSink(options.output, StandardCharsets.UTF_8).write(result); } @@ -166,7 +179,9 @@ public class Main { } private static void printErrorMessage(String detailedErrorMessage, Options options) { - System.err.print(options.failOnErrors ? "ERROR" : "WARNING"); + checkArgument( + options.checkingMode == CheckingMode.ERROR || options.checkingMode == CheckingMode.WARNING); + System.err.print(options.checkingMode == CheckingMode.ERROR ? "ERROR" : "WARNING"); System.err.printf( ": The dependencies for the following %d jar(s) are not complete.\n", options.inputJars.size()); @@ -194,6 +209,11 @@ public class Main { options.jdepsOutput == null || !Files.isDirectory(options.jdepsOutput), "Invalid value of --jdeps_output: '%s'", options.jdepsOutput); + if (options.checkingMode == null) { + // Convert --fail_on_errors to --checking_mode + options.checkingMode = options.failOnErrors ? CheckingMode.ERROR : CheckingMode.WARNING; + } + return options; } @@ -239,4 +259,26 @@ public class Main { super(true); } } + + /** Converter for {@link CheckingMode} */ + public static class CheckingModeConverter extends EnumConverter<CheckingMode> { + public CheckingModeConverter() { + super(CheckingMode.class, "The checking mode for the dependency checker."); + } + } + + /** + * The checking mode of the dependency checker. + */ + public enum CheckingMode { + /** Emit 'errors' on missing or incomplete dependencies. */ + ERROR, + /** Emit 'warnings' on missing or incomplete dependencies. */ + WARNING, + /** + * Emit 'nothing' on missing or incomplete dependencies. This is mainly used to dump jdeps + * protos. + */ + SILENCE + } } |