diff options
3 files changed, 41 insertions, 8 deletions
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java index 95e4bb7c33..c243948fc0 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java @@ -93,9 +93,23 @@ public final class JavaLibraryBuildRequest { */ public JavaLibraryBuildRequest(List<String> args, List<BlazeJavaCompilerPlugin> extraPlugins) throws InvalidCommandLineException, IOException { + this(args, extraPlugins, new DependencyModule.Builder()); + } + + /** + * Constructs a build from a list of command args. Sets the same JavacRunner + * for both compilation and annotation processing. + * + * @param args the list of command line args + * @param extraPlugins extraneous plugins to use in addition to the strict dependency module. + * @param builder a preconstructed dependency module builder. + * @throws InvalidCommandLineException on any command line error + */ + public JavaLibraryBuildRequest(List<String> args, List<BlazeJavaCompilerPlugin> extraPlugins, + DependencyModule.Builder builder) + throws InvalidCommandLineException, IOException { OptionsParser optionsParser = new OptionsParser(args); - DependencyModule.Builder builder = new DependencyModule.Builder(); builder.addDirectMappings(optionsParser.getDirectMappings()); builder.addIndirectMappings(optionsParser.getIndirectMappings()); if (optionsParser.getStrictJavaDeps() != null) { diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java index e08eba324b..ab2e87138e 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java @@ -78,6 +78,7 @@ public final class DependencyModule { private final Map<String, Deps.Dependency> explicitDependenciesMap; private final Map<String, Deps.Dependency> implicitDependenciesMap; Set<String> requiredClasspath; + private final String fixMessage; DependencyModule(StrictJavaDeps strictJavaDeps, Map<String, String> directJarsToTargets, @@ -87,7 +88,8 @@ public final class DependencyModule { String ruleKind, String targetLabel, String outputDepsFile, - String outputDepsProtoFile) { + String outputDepsProtoFile, + String fixMessage) { this.strictJavaDeps = strictJavaDeps; this.directJarsToTargets = directJarsToTargets; this.indirectJarsToTargets = indirectJarsToTargets; @@ -100,6 +102,7 @@ public final class DependencyModule { this.explicitDependenciesMap = new HashMap<>(); this.implicitDependenciesMap = new HashMap<>(); this.usedClasspath = new HashSet<>(); + this.fixMessage = fixMessage; } /** @@ -237,6 +240,13 @@ public final class DependencyModule { } /** + * Returns a message to suggest fix when a missing indirect dependency is found. + */ + public String getFixMessage() { + return fixMessage; + } + + /** * Returns whether classpath reduction is enabled for this invocation. */ public boolean reduceClasspath() { @@ -323,6 +333,8 @@ public final class DependencyModule { private String outputDepsFile; private String outputDepsProtoFile; private boolean strictClasspathMode = false; + private String fixMessage = "%s** Please add the following dependencies:%s\n" + + " %s to %s\n\n"; /** * Constructs the DependencyModule, guaranteeing that the maps are @@ -334,7 +346,7 @@ public final class DependencyModule { public DependencyModule build() { return new DependencyModule(strictJavaDeps, directJarsToTargets, indirectJarsToTargets, strictClasspathMode, depsArtifacts, ruleKind, targetLabel, outputDepsFile, - outputDepsProtoFile); + outputDepsProtoFile, fixMessage); } /** @@ -461,5 +473,16 @@ public final class DependencyModule { this.strictClasspathMode = true; return this; } + + /** + * Set the message to display when a missing indirect dependency is found. + * + * @param fixMessage the fix message + * @return this Builder instance + */ + public Builder setFixMessage(String fixMessage) { + this.fixMessage = fixMessage; + return this; + } } } diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java index f309556810..7b7d9e9d92 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java @@ -66,10 +66,6 @@ public final class StrictJavaDepsPlugin extends BlazeJavaCompilerPlugin { static String targetMapping = "com/google/devtools/build/buildjar/javac/resources/target.properties"; - private static final String FIX_MESSAGE = - "%s** Command to add missing strict dependencies:%s\n" - + " add_dep %s%s\n\n"; - private static final boolean USE_COLOR = true; private ImplicitDependencyExtractor implicitDependencyExtractor; private CheckingTreeScanner checkingTreeScanner; @@ -171,7 +167,7 @@ public final class StrictJavaDepsPlugin extends BlazeJavaCompilerPlugin { missingTargetsStr.append(target); missingTargetsStr.append(" "); } - errWriter.print(String.format(FIX_MESSAGE, + errWriter.print(String.format(dependencyModule.getFixMessage(), USE_COLOR ? "\033[35m\033[1m" : "", USE_COLOR ? "\033[0m" : "", missingTargetsStr.toString(), |