Skip to content

Commit

Permalink
#338: Colored console report (#349)
Browse files Browse the repository at this point in the history
* #338: Colored console report

* #338: Fixed small issues.

* #338: Fixed tests and warnings.

* #338: Fixed tests and warnings.

* #338: Fixed tests and warnings.

* #338: Fixed self-trace.

* #338: Fixed Java 18 JavaDoc warnings.

* #338: Fixed UTF-8 encoding int test.

* #338: Updated user guide.

* #338: Fixed review findings. Improved user guide.

* Deactivate scacap/action-surefire-report on macos

This fails because of ScaCap/action-surefire-report#95 / ScaCap/action-surefire-report#85

* Deactivate surefire report

Caused by ScaCap/action-surefire-report#95

Co-authored-by: kaklakariada <kaklakariada@users.noreply.github.com>
  • Loading branch information
redcatbear and kaklakariada committed Nov 22, 2022
1 parent 83a8063 commit 801ff93
Show file tree
Hide file tree
Showing 28 changed files with 786 additions and 216 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
MAVEN_OPTS: "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"

- name: Publish Test Report for Java ${{ matrix.java }} on ${{ matrix.os }}
uses: scacap/action-surefire-report@v1
if: ${{ always() && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
with:
report_paths: '**/target/surefire-reports/TEST-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Archive oft binary
uses: actions/upload-artifact@v3
if: ${{ env.DEFAULT_OS == matrix.os && env.DEFAULT_JAVA == matrix.java }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.itsallcode.openfasttrace.api;

/**
* Color schemes
*/
public enum ColorScheme {
/** Black and white */
BLACK_AND_WHITE,
/** Monochrome (e.g for printers) */
MONOCHROME,
/** COLOR */
COLOR
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.itsallcode.openfasttrace.api.report.ReportConstants;
import org.itsallcode.openfasttrace.api.report.ReportVerbosity;

import java.util.Objects;

/**
* This class implements a parameter object to control the settings of OFT's
* report mode.
Expand All @@ -14,13 +16,15 @@ public class ReportSettings
private final boolean showOrigin;
private final String outputFormat;
private final Newline newline;
private final ColorScheme colorScheme;

private ReportSettings(final Builder builder)
{
this.verbosity = builder.verbosity;
this.showOrigin = builder.showOrigin;
this.outputFormat = builder.outputFormat;
this.newline = builder.newline;
this.colorScheme = Objects.requireNonNull(builder.colorScheme);
}

/**
Expand Down Expand Up @@ -63,6 +67,15 @@ public Newline getNewline()
return this.newline;
}

/**
* Get the color scheme
*
* @return color scheme
*/
public ColorScheme getColorScheme() {
return this.colorScheme;
}

/**
* Create default report settings
*
Expand Down Expand Up @@ -92,6 +105,7 @@ public static class Builder
private String outputFormat = ReportConstants.DEFAULT_REPORT_FORMAT;
private boolean showOrigin = false;
private ReportVerbosity verbosity = ReportVerbosity.FAILURE_DETAILS;
private ColorScheme colorScheme = ColorScheme.BLACK_AND_WHITE;

private Builder()
{
Expand Down Expand Up @@ -160,5 +174,16 @@ public Builder newline(final Newline newline)
this.newline = newline;
return this;
}

/**
* Set the desired color scheme
*
* @param colorScheme color scheme to use
* @return <code>this</code> for fluent programming
*/
public Builder colorScheme(final ColorScheme colorScheme) {
this.colorScheme = Objects.requireNonNull(colorScheme);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private boolean validate()
{
final Optional<String> command = this.arguments.getCommand();
boolean ok = false;
if (!command.isPresent())
if (command.isEmpty())
{
this.error = "Missing command";
this.suggestion = "Add one of " + listCommands();
Expand Down Expand Up @@ -72,7 +72,7 @@ private boolean validateTraceCommand()
if (this.arguments.getReportVerbosity() == ReportVerbosity.QUIET
&& this.arguments.getOutputPath() != null)
{
this.error = "combining stream verbosity 'quiet' and ouput to file is not supported.";
this.error = "combining stream verbosity 'quiet' and output to file is not supported.";
this.suggestion = "remove output file parameter.";
}
else
Expand Down Expand Up @@ -132,5 +132,4 @@ public String getSuggestion()
{
return this.suggestion;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.itsallcode.openfasttrace.core.cli;

import static java.util.Arrays.asList;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

import org.itsallcode.openfasttrace.api.ColorScheme;
import org.itsallcode.openfasttrace.api.cli.DirectoryService;
import org.itsallcode.openfasttrace.api.core.Newline;
import org.itsallcode.openfasttrace.api.report.ReportConstants;
Expand Down Expand Up @@ -37,6 +36,7 @@ public class CliArguments
// [impl->dsn~reporting.html.linked-specification-item-origin~1]
private boolean showOrigin;
private final DirectoryService directoryService;
private ColorScheme colorScheme;

/**
* Create new {@link CliArguments}.
Expand Down Expand Up @@ -111,7 +111,7 @@ public List<String> getInputs()
{
if (this.unnamedValues == null || this.unnamedValues.size() <= 1)
{
return asList(this.directoryService.getCurrent());
return List.of(this.directoryService.getCurrent());
}
return this.unnamedValues.subList(1, this.unnamedValues.size());
}
Expand Down Expand Up @@ -293,6 +293,25 @@ public Set<String> getWantedTags()
return this.wantedTags;
}

/**
* Get the color scheme.
* <p>
* Defaults to {@link ColorScheme#COLOR}. The switch <code>-f</code> overrides this setting, so that the color
* scheme is always {@link ColorScheme#BLACK_AND_WHITE}.
* </p>
*
* @return the color scheme
*/
public ColorScheme getColorScheme()
{
if (this.getOutputPath() == null) {
return (this.colorScheme == null) ? ColorScheme.COLOR : this.colorScheme;
}
else {
return ColorScheme.BLACK_AND_WHITE;
}
}

/**
* Set a list of tags to be applied as filter during import
*
Expand Down Expand Up @@ -349,4 +368,24 @@ public void setS(final boolean showOrigin)
{
setShowOrigin(showOrigin);
}

/**
* Choose the color scheme.
*
* @param colorScheme color scheme to use for console output
*/
public void setColorScheme(final ColorScheme colorScheme)
{
this.colorScheme = colorScheme;
}

/**
* Choose the color scheme.
*
* @param colorScheme color scheme to use for console output
*/
public void setC(final ColorScheme colorScheme)
{
this.setColorScheme(colorScheme);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private ReportSettings convertCommandLineArgumentsToReportSettings()
.verbosity(this.arguments.getReportVerbosity()) //
.newline(this.arguments.getNewline()) //
.showOrigin(this.arguments.getShowOrigin()) //
.colorScheme(this.arguments.getColorScheme()) //
.build();
}
}
8 changes: 6 additions & 2 deletions core/src/main/resources/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ Converting options:
(e.g. file and line number)

Common options:
-f, --file path The output file. Defaults to STDOUT.
-n, --newline format Newline format one of "unix", "windows", "oldmac"
-a, --wanted-artifact-types Import only specification items contained in the
comma-separated list
-c, --color-scheme scheme Color scheme for output. One of "black-and-white",
"monochrome", "color". Defaults to "color".
Note that this option is ignored when -f is also
set.
-f, --file path The output file. Defaults to STDOUT.
-n, --newline format Newline format. One of "unix", "windows", "oldmac"
-t, --wanted-tags Import only specification items that have at
least one tag contained in the comma-separated
list. Add a single underscore as first item in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void testTraceCommandQuietAndOutputFileGivenIsNotValid()
cliArgs.setV(ReportVerbosity.QUIET);
cliArgs.setOutputFile("outputFile");
assertValidatorResult(
"combining stream verbosity 'quiet' and ouput to file is not supported.",
"combining stream verbosity 'quiet' and output to file is not supported.",
"remove output file parameter.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.itsallcode.openfasttrace.core.cli;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

import java.nio.file.Paths;
import java.util.List;

import org.itsallcode.openfasttrace.api.ColorScheme;
import org.itsallcode.openfasttrace.api.core.Newline;
import org.itsallcode.openfasttrace.api.report.ReportConstants;
import org.itsallcode.openfasttrace.api.report.ReportVerbosity;
Expand Down Expand Up @@ -54,7 +55,7 @@ void testSetOutputFormat()
@Test
void getStandardOutputFormatForExport()
{
this.arguments.setUnnamedValues(asList(ConvertCommand.COMMAND_NAME));
this.arguments.setUnnamedValues(List.of(ConvertCommand.COMMAND_NAME));
assertThat(this.arguments.getOutputFormat(),
equalTo(ExporterConstants.DEFAULT_OUTPUT_FORMAT));
}
Expand All @@ -63,7 +64,7 @@ void getStandardOutputFormatForExport()
@Test
void getStandardOutputFormatForReport()
{
this.arguments.setUnnamedValues(asList(TraceCommand.COMMAND_NAME));
this.arguments.setUnnamedValues(List.of(TraceCommand.COMMAND_NAME));
assertThat(this.arguments.getOutputFormat(),
equalTo(ReportConstants.DEFAULT_REPORT_FORMAT));
}
Expand Down Expand Up @@ -146,7 +147,7 @@ void testWantedArtifactTypesEmptyByDefault()

// [utest->dsn~filtering-by-artifact-types-during-import~1]
@Test
void testSetIngnoreArtifactTypes()
void testSetIgnoreArtifactTypes()
{
final String value = "impl,utest";
this.arguments.setWantedArtifactTypes(value);
Expand Down Expand Up @@ -183,7 +184,7 @@ void testSetWantedTags()

// [utest->dsn~filtering-by-tags-during-import~1]
@Test
void testSetd()
void testSetD()
{
final String value = "client,server";
this.arguments.setT(value);
Expand Down Expand Up @@ -232,4 +233,37 @@ void testSetS()
this.arguments.setS(true);
assertThat(this.arguments.getShowOrigin(), is(true));
}

// [dsn~reporting.plain-text.ansi-color~1]
// [dsn~reporting.plain-text.ansi-font-style~1]
@Test
void testSetColorScheme()
{
this.arguments.setColorScheme(ColorScheme.MONOCHROME);
assertThat(this.arguments.getColorScheme(), is(ColorScheme.MONOCHROME));
}

// [dsn~reporting.plain-text.ansi-color~1]
// [dsn~reporting.plain-text.ansi-font-style~1]
@Test
void testSetC()
{
this.arguments.setC(ColorScheme.MONOCHROME);
assertThat(this.arguments.getColorScheme(), is(ColorScheme.MONOCHROME));
}


@Test
void testColorSchemeDefaultsToColor()
{
assertThat(this.arguments.getColorScheme(), is(ColorScheme.COLOR));
}

@Test
void testSetOutputFileOverridesColorSchemeSetting()
{
this.arguments.setColorScheme(ColorScheme.MONOCHROME);
this.arguments.setOutputFile("something");
assertThat(this.arguments.getColorScheme(), is(ColorScheme.BLACK_AND_WHITE));
}
}
23 changes: 23 additions & 0 deletions doc/spec/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,29 @@ Covers:

Needs: impl, utest

### Plain Text Report ANSI Color
`dsn~reporting.plain-text.ansi-color~1`

The plain text report uses ANSI escape sequences to color the output.

Covers:

* `req~colored-plain-text-report~1`

Needs: impl, utest

### Plain Text Report ANSI Font Style
`dsn~reporting.plain-text.ansi-font-style~1`

The plain text report uses ANSI escape sequences to modify the font style of the output.

Covers:

* `req~colored-plain-text-report~1`
* `req~monochrome-plain-text-report-with-font-style~1`

Needs: impl, utest

### HTML Report

#### HTML Report Inlines CSS
Expand Down
Loading

0 comments on commit 801ff93

Please sign in to comment.