aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/buildjar
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2018-06-28 18:00:44 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-28 18:01:55 -0700
commit52c6adadeebd58a811bcf4c22d6d3f3ccde812d8 (patch)
treee90c96a9fabbb8d2727d300e8ae3df7e19f43956 /src/java_tools/buildjar
parent0541f95e4a03d99bd17d5e56f57cc38f41121e5a (diff)
Update turbine's experimental dep fixing suggestions
PiperOrigin-RevId: 202577988
Diffstat (limited to 'src/java_tools/buildjar')
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/Turbine.java32
-rw-r--r--src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/TurbineTest.java6
2 files changed, 25 insertions, 13 deletions
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/Turbine.java b/src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/Turbine.java
index ddf5887de3..0e70408d24 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/Turbine.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/Turbine.java
@@ -39,19 +39,28 @@ public class Turbine {
public static void main(String[] args) throws Exception {
System.exit(
- new Turbine("An exception has occurred in turbine.", "", "")
+ new Turbine(
+ /* bugMessage= */ "An exception has occurred in turbine.",
+ /* unhelpfulMessage= */ "",
+ /* fixImportCommand= */ null)
.compile(TurbineOptionsParser.parse(ImmutableList.copyOf(args))));
}
+ /** Formats a suggested fix for missing import errors. */
+ @FunctionalInterface
+ public interface FixImportCommand {
+ String formatCommand(String type, String target);
+ }
+
private final String bugMessage;
private final String unhelpfulMessage;
- // path to jadep binary, see: https://github.com/bazelbuild/tools_jvm_autodeps
- private final @Nullable String jadepPath;
+ private final @Nullable FixImportCommand fixImportCommand;
- public Turbine(String bugMessage, String unhelpfulMessage, @Nullable String jadepPath) {
+ public Turbine(
+ String bugMessage, String unhelpfulMessage, @Nullable FixImportCommand fixImportCommand) {
this.bugMessage = bugMessage;
this.unhelpfulMessage = unhelpfulMessage;
- this.jadepPath = jadepPath;
+ this.fixImportCommand = fixImportCommand;
}
public int compile(TurbineOptions options) throws IOException {
@@ -86,15 +95,14 @@ public class Turbine {
out.println(turbineError.getMessage());
switch (turbineError.kind()) {
case SYMBOL_NOT_FOUND:
- if (jadepPath != null && options.targetLabel().isPresent()) {
+ if (fixImportCommand != null && options.targetLabel().isPresent()) {
out.println();
Object arg = getOnlyElement(turbineError.args());
- out.printf(
- "\033[35m\033[1m** Command to add missing dependencies:\033[0m"
- + "\n%s -classnames=%s %s",
- jadepPath,
- CharMatcher.anyOf("$/").replaceFrom(arg.toString(), '.'),
- options.targetLabel().get());
+ out.println("\033[35m\033[1m** Command to add missing dependencies:\033[0m\n");
+ out.println(
+ fixImportCommand.formatCommand(
+ CharMatcher.anyOf("$/").replaceFrom(arg.toString(), '.'),
+ options.targetLabel().get()));
out.println();
}
break;
diff --git a/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/TurbineTest.java b/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/TurbineTest.java
index 465cdcfed7..3a73e7b7f3 100644
--- a/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/TurbineTest.java
+++ b/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/TurbineTest.java
@@ -64,7 +64,10 @@ public final class TurbineTest {
StringWriter errOutput = new StringWriter();
int result =
- new Turbine("An exception has occurred in turbine.", "", "jadep")
+ new Turbine(
+ "An exception has occurred in turbine.",
+ "",
+ (type, target) -> String.format("jadep -classnames=%s %s", type, target))
.compile(optionsBuilder.build(), new PrintWriter(errOutput, true));
assertThat(errOutput.toString())
.contains(
@@ -73,6 +76,7 @@ public final class TurbineTest {
+ " ^\n"
+ "\n"
+ "\033[35m\033[1m** Command to add missing dependencies:\033[0m\n"
+ + "\n"
+ "jadep -classnames=p.Lib //test");
assertThat(result).isEqualTo(1);
}