Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Introduce -n
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Apr 24, 2017
1 parent 7b8b46f commit afddb7b
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]: https://github.com/atomist/rug-cli/compare/0.33.3...HEAD

### Added

- New flag `-n` to get more progress updates. Now `-V` can be used to
dump the contents of `ArtifactSource` and the compiled JavaScript code
if needed

## [0.33.3] - 2017-04-23

[0.33.3]: https://github.com/atomist/rug-cli/compare/0.33.2...0.33.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final Options globalOptions() {
options.addOption(Option.builder("s").longOpt("settings").argName("FILE").hasArg(true)
.required(false).desc("Use settings file FILE").build());
options.addOption("q", "quiet", false, "Do not display progress messages");
options.addOption("n", "noisy", false, "Display more progress messages");
options.addOption("o", "offline", false, "Use only downloaded archives");
options.addOption("t", "timer", false, "Print timing information");
options.addOption("r", "resolver-report", false, "Print dependency tree");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.atomist.project.archive.Dependency;
import com.atomist.project.archive.ResolvedDependency;
import com.atomist.project.archive.RugResolver;
import com.atomist.rug.cli.Constants;
import com.atomist.rug.cli.Log;
import com.atomist.rug.cli.command.utils.ArtifactSourceUtils;
import com.atomist.rug.cli.output.ConsoleLogger;
Expand Down Expand Up @@ -163,7 +162,7 @@ private static class ReportingCompilerListener implements CompilerListener {

@Override
public void compileFailed(String path) {
log.info(" Compiled " + path + " " + Style.red("failed"));
log.info("Compiled " + path + " " + Style.red("failed"));
}

@Override
Expand All @@ -178,16 +177,15 @@ public void compileStarted(String path) {
@Override
public void compileSucceeded(String path, String content) {
ProgressReporterUtils.detail(null);
if (CommandLineOptions.hasOption("X") && content != null) {
log.info(" Compiled " + Style.yellow(path) + " " + Style.green("succeeded"));
if (CommandLineOptions.hasOption("V") && content != null) {
log.info("Compiled " + Style.yellow(path) + " " + Style.green("succeeded"));
if (!path.endsWith(".js.map")) {
log.info(" " + content.replace("\n", "\n "));
log.info(content);
}
}
else if (CommandLineOptions.hasOption("V")) {
log.info(" Compiled " + path + " " + Style.green("succeeded"));
else if (CommandLineOptions.hasOption("n") && content != null) {
log.info("Compiled " + path + " " + Style.green("succeeded"));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public BoxedUnit apply(ScriptEngine engine) {
}

public static AbstractFunction1<ScriptEngine, BoxedUnit> consoleLogger() {
return consoleLogger(Constants.LEFT_PADDING);
return consoleLogger("");
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,80 @@
package com.atomist.rug.cli.output;

import com.atomist.rug.cli.Log;
import java.io.PrintStream;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class PassThroughProgressReporter implements ProgressReporter {

private Log log = new Log(PassThroughProgressReporter.class);
public class PassThroughProgressReporter extends Thread implements ProgressReporter {

private Queue<String> additionalMessages = new ConcurrentLinkedQueue<>();
private boolean showProgress = true;
private String message;
private boolean success;
private float duration;
private PrintStream stream;

public PassThroughProgressReporter(String message) {
public PassThroughProgressReporter(String message, PrintStream stream) {
this.message = message;
this.stream = stream;
report(message);
start();
}

@Override
public void finish(boolean success, float duration) {
log.info(message + Style.green(" completed")
+ (duration > -1 ? " in " + String.format("%.2f", duration) + "s" : ""));
public void report(String message) {
String[] messages = message.split("\n");
for (String msg : messages) {
String content = msg.trim();
if (!content.equals("") && !content.equals("$")) {
additionalMessages.offer(msg);
}
}
}

@Override
public void report(String message) {
log.info(message.replace("\t", " "));
public void finish(boolean success, float duration) {
this.success = success;
this.duration = duration;
while (!additionalMessages.isEmpty()) {
sleep(10);
}
this.showProgress = false;
try {
this.join();
}
catch (InterruptedException e) {
}
}

@Override
public void detail(String detail) {
// no op
}

public void run() {
while (showProgress) {
while (!additionalMessages.isEmpty()) {
String newMsg = additionalMessages.poll();
newMsg = newMsg.replace("\t", " ");
stream.println(newMsg);
}
sleep(50);
}
if (success) {
stream.println(message + " " + Style.green("completed")
+ (duration > -1 ? " in " + String.format("%.2f", duration) + "s" : ""));
}
else {
stream.println(message + " " + Style.red("failed")
+ (duration > -1 ? " in " + String.format("%.2f", duration) + "s" : ""));
}
}

private void sleep(int timeout) {
try {
Thread.sleep(timeout);
}
catch (Exception e) {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.atomist.rug.cli.output;

import java.io.PrintStream;

import com.atomist.rug.cli.RunnerException;
import com.atomist.rug.cli.utils.CommandLineOptions;
import com.atomist.rug.cli.utils.Timing;
Expand Down Expand Up @@ -39,14 +41,15 @@ public T run(ProgressReportingOperation<T> operation) throws RunnerException {

private ProgressReporter createProgressReporter() {
ProgressReporter indicator = null;
PrintStream stream = (CommandLineOptions.hasOption("output") ? System.err : System.out);
if (CommandLineOptions.hasOption("output") || CommandLineOptions.hasOption("q")
|| (msg.length()) >= ConsoleUtils.width()) {
indicator = new PassThroughProgressReporter(msg);
indicator = new PassThroughProgressReporter(msg, stream);
}
else {
indicator = new SpinningProgressReporter(msg);
ProgressReporterUtils.setActiveProgressReporter(indicator);
indicator = new SpinningProgressReporter(msg, stream);
}
ProgressReporterUtils.setActiveProgressReporter(indicator);
return indicator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ public ProgressReportingTransferListener(Map<String, RemoteRepository> repositor

@Override
public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
if (CommandLineOptions.hasOption("V")) {
if (CommandLineOptions.hasOption("n")) {
report(event);
}
}

@Override
public void transferFailed(TransferEvent event) {
if (CommandLineOptions.hasOption("V")) {
if (CommandLineOptions.hasOption("n")) {
report(event);
}
}

@Override
public void transferSucceeded(TransferEvent event) {
if (CommandLineOptions.hasOption("V") || CommandLineOptions.hasOption("q")) {
if (CommandLineOptions.hasOption("n") || CommandLineOptions.hasOption("q")) {
report(event);
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.atomist.rug.cli.output;

import java.io.PrintStream;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

Expand All @@ -20,9 +21,11 @@ public class SpinningProgressReporter extends Thread implements ProgressReporter
private String message = null;
private boolean showProgress = true;
private boolean success = true;
private PrintStream stream;

public SpinningProgressReporter(String msg) {
public SpinningProgressReporter(String msg, PrintStream stream) {
this.message = msg;
this.stream = stream;
if (isWindows) {
anim = animWin32;
}
Expand Down Expand Up @@ -67,34 +70,34 @@ public void run() {
int x = 0;
while (showProgress) {
if (additionalMessages.isEmpty()) {
System.out.print("\r");
System.out.print(Ansi.eraseLine());
System.out.print(formatDetail(
stream.print("\r");
stream.print(Ansi.eraseLine());
stream.print(formatDetail(
message + " " + Style.yellow("" + anim.charAt(x++ % anim.length())) + " "));
}
else {
System.out.print("\r");
System.out.print(Ansi.eraseLine());
stream.print("\r");
stream.print(Ansi.eraseLine());
while (!additionalMessages.isEmpty()) {
String newMsg = additionalMessages.poll();
newMsg = newMsg.replace("\t", " ");
System.out.println(newMsg);
stream.println(newMsg);
}
System.out.print("\r");
System.out.print(Ansi.eraseLine());
System.out.print(formatDetail(
stream.print("\r");
stream.print(Ansi.eraseLine());
stream.print(formatDetail(
message + " " + Style.yellow("" + anim.charAt(x++ % anim.length())) + " "));
}
sleep(50);
}
System.out.print("\r");
System.out.print(Ansi.eraseLine());
stream.print("\r");
stream.print(Ansi.eraseLine());
if (success) {
System.out.println(message + " " + Style.green("completed")
stream.println(message + " " + Style.green("completed")
+ (duration > -1 ? " in " + String.format("%.2f", duration) + "s" : ""));
}
else {
System.out.println(message + " " + Style.red("failed")
stream.println(message + " " + Style.red("failed")
+ (duration > -1 ? " in " + String.format("%.2f", duration) + "s" : ""));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void starting(String group, String artifact, String version) {
@Override
public void succeeded(String group, String artifact, String version) {
sb.append(Style.green("succeeded"));
if (CommandLineOptions.hasOption("V")) {
if (CommandLineOptions.hasOption("n")) {
log.info(sb.toString());
}
else {
Expand Down

0 comments on commit afddb7b

Please sign in to comment.