Skip to content

Commit

Permalink
chore: Hide progress if no console available
Browse files Browse the repository at this point in the history
fix: Don't show progress messages if no console available, to avoid progress messages from being included in redirected/piped command output
  • Loading branch information
rsenden committed Feb 8, 2024
1 parent 2c966f8 commit 2af26ce
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
public enum ProgressWriterType {
auto(ProgressWriterType::auto),
none(NoProgressWriter::new),
simple(SimpleProgressWriter::new),
simple(SimpleProgressWriter::new),
stderr(SimpleStdErrProgressWriter::new),
single_line(SingleLineProgressWriter::new),
ansi(AnsiProgressWriter::new);

Expand All @@ -38,7 +39,7 @@ private static final IProgressWriter auto() {
var hasAnsiConsole = Ansi.AUTO.enabled() && hasConsole;
if ( hasAnsiConsole ) { return new AnsiProgressWriter(); }
else if ( hasConsole ) { return new SingleLineProgressWriter(); }
else { return new SimpleProgressWriter(); }
else { return new NoProgressWriter(); }
}

private static abstract class AbstractProgressWriter implements IProgressWriter {
Expand Down Expand Up @@ -89,6 +90,26 @@ public void writeProgress(String message, Object... args) {
public void clearProgress() {}
}

private static final class SimpleStdErrProgressWriter extends AbstractProgressWriter {
@Override
public boolean isMultiLineSupported() {
return true;
}

@Override
public void writeProgress(String message, Object... args) {
String formattedMessage = String.format(message, args);
if ( formattedMessage.indexOf('\n') > 0 ) {
// Add extra newline to separate multi-line blocks
formattedMessage += "\n";
}
System.err.println(formattedMessage);
}

@Override
public void clearProgress() {}
}

private static final class SingleLineProgressWriter extends AbstractProgressWriter {
private static final String LINE_START = "\r";
private int lastNumberOfChars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ToolBugTrackerUtilitySpec extends FcliBaseSpec {
@Shared Path globalBinScript = Path.of(baseDir).resolve("bin/FortifyBugTrackerUtility.bat");
@Shared Path binScript = Path.of(baseDir).resolve("bugtracker-utility/${version}/bin/FortifyBugTrackerUtility.bat");
def "install"() {
def args = "tool bugtracker-utility install -y -v=${version} --progress=none -b ${baseDir}"
def args = "tool bugtracker-utility install -y -v=${version} -b ${baseDir}"
when:
def result = Fcli.run(args, {it.expectZeroExitCode()})
then:
Expand All @@ -56,7 +56,7 @@ class ToolBugTrackerUtilitySpec extends FcliBaseSpec {
}

def "uninstall"() {
def args = "tool bugtracker-utility uninstall -y --progress=none -v=${version}"
def args = "tool bugtracker-utility uninstall -y -v=${version}"
when:
def result = Fcli.run(args)
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToolDebrickedSpec extends FcliBaseSpec {
@Shared Path binScript = Path.of(baseDir).resolve("debricked-cli/${version}/bin/debricked.exe");

def "install"() {
def args = "tool debricked-cli install -y -v=${version} --progress=none -b ${baseDir} --platform windows/x64"
def args = "tool debricked-cli install -y -v=${version} -b ${baseDir} --platform windows/x64"
when:
def result = Fcli.run(args, {it.expectZeroExitCode()})
then:
Expand All @@ -57,7 +57,7 @@ class ToolDebrickedSpec extends FcliBaseSpec {
}

def "uninstall"() {
def args = "tool debricked-cli uninstall -y --progress=none -v=${version}"
def args = "tool debricked-cli uninstall -y -v=${version}"
when:
def result = Fcli.run(args)
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToolFcliSpec extends FcliBaseSpec {
@Shared Path binScript = Path.of(baseDir).resolve("fcli/${version}/bin/fcli.exe");

def "install"() {
def args = "tool fcli install -y -v=${version} --progress=none -b ${baseDir} --platform windows/x64"
def args = "tool fcli install -y -v=${version} -b ${baseDir} --platform windows/x64"
when:
def result = Fcli.run(args, {it.expectZeroExitCode()})
then:
Expand All @@ -57,7 +57,7 @@ class ToolFcliSpec extends FcliBaseSpec {
}

def "uninstall"() {
def args = "tool fcli uninstall -y --progress=none -v=${version}"
def args = "tool fcli uninstall -y -v=${version}"
when:
def result = Fcli.run(args)
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToolFoDUploaderSpec extends FcliBaseSpec {
@Shared Path binScript = Path.of(baseDir).resolve("fod-uploader/${version}/bin/FoDUpload.bat");

def "installLatest"() {
def args = "tool fod-uploader install -y -v=${version} --progress=none -b ${baseDir}"
def args = "tool fod-uploader install -y -v=${version} -b ${baseDir}"
when:
def result = Fcli.run(args, {it.expectZeroExitCode()})
then:
Expand All @@ -57,7 +57,7 @@ class ToolFoDUploaderSpec extends FcliBaseSpec {
}

def "uninstall"() {
def args = "tool fod-uploader uninstall -y --progress=none -v=${version}"
def args = "tool fod-uploader uninstall -y -v=${version}"
when:
def result = Fcli.run(args)
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToolScClientSpec extends FcliBaseSpec {
@Shared Path binScript = Path.of(baseDir).resolve("sc-client/${version}/bin/scancentral.bat")

def "install"() {
def args = "tool sc-client install -y -v=${version} --progress=none -b ${baseDir}"
def args = "tool sc-client install -y -v=${version} -b ${baseDir}"
when:
def result = Fcli.run(args, {it.expectZeroExitCode()})
then:
Expand All @@ -57,7 +57,7 @@ class ToolScClientSpec extends FcliBaseSpec {
}

def "uninstall"() {
def args = "tool sc-client uninstall -y --progress=none -v=${version}"
def args = "tool sc-client uninstall -y -v=${version}"
when:
def result = Fcli.run(args)
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToolVulnExporterSpec extends FcliBaseSpec {
@Shared Path binScript = Path.of(baseDir).resolve("vuln-exporter/${version}/bin/FortifyVulnerabilityExporter.bat");

def "install"() {
def args = "tool vuln-exporter install -y -v=${version} --progress=none -b ${baseDir}"
def args = "tool vuln-exporter install -y -v=${version} -b ${baseDir}"
when:
def result = Fcli.run(args, {it.expectZeroExitCode()})
then:
Expand All @@ -57,7 +57,7 @@ class ToolVulnExporterSpec extends FcliBaseSpec {
}

def "uninstall"() {
def args = "tool vuln-exporter uninstall -y --progress=none -v=${version}"
def args = "tool vuln-exporter uninstall -y -v=${version}"
when:
def result = Fcli.run(args)
then:
Expand Down

0 comments on commit 2af26ce

Please sign in to comment.