This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
100 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 59 additions & 10 deletions
69
src/main/java/com/atomist/rug/cli/output/PassThroughProgressReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters