Don't print empty add dep commands
package com.google.devtools.build.buildjar.javac.plugins.dependency;
import static com.google.common.collect.ImmutableList.toImmutableList;
-import static java.util.stream.Collectors.joining;
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
@@ -343,15 +344,18 @@ public final class DependencyModule {
private static class DefaultFixMessage implements FixMessage {
@Override
public String get(Iterable<JarOwner> missing, String recipient, DependencyModule depModule) {
- String missingTargetsStr =
+ ImmutableSet<String> missingTargets =
Streams.stream(missing)
.flatMap(owner -> owner.label().map(Stream::of).orElse(Stream.empty()))
- .collect(joining(" "));
+ .collect(toImmutableSet());
+ if (missingTargets.isEmpty()) {
+ return "";
+ }
return String.format(
"%1$s ** Please add the following dependencies:%2$s \n %3$s to %4$s \n"
+ "%1$s ** You can use the following buildozer command:%2$s "
+ "\nbuildozer 'add deps %3$s' %4$s \n\n",
- "\033[35m\033[1m", "\033[0m", missingTargetsStr.toString(), recipient);
+ "\033[35m\033[1m", "\033[0m", Joiner.on(" ").join(missingTargets), recipient);
}
}
