Skip to content

Commit 554c71b

Browse files
committed
Refactoring of ReportersCommand
Also much nicer formatting
1 parent 808a2d6 commit 554c71b

File tree

2 files changed

+74
-38
lines changed

2 files changed

+74
-38
lines changed

README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,42 +162,42 @@ utPLSQL 3.1.2.1913
162162
```
163163
> utplsql reporters app/app@localhost:1521/ORCLPDB1
164164
165-
UT_COVERAGE_COBERTURA_REPORTER (SQL): Generates a Cobertura coverage report providing information on code coverage with line numbers.
166-
Designed for Jenkins and TFS to report coverage.
167-
Cobertura Document Type Definition can be found: http://cobertura.sourceforge.net/xml/coverage-04.dtd.
168-
Sample file: https://github.com/leobalter/testing-examples/blob/master/solutions/3/report/cobertura-coverage.xml.
165+
UT_COVERAGE_COBERTURA_REPORTER Generates a Cobertura coverage report providing information on code coverage with line numbers.
166+
Designed for Jenkins and TFS to report coverage.
167+
Cobertura Document Type Definition can be found: http://cobertura.sourceforge.net/xml/coverage-04.dtd.
168+
Sample file: https://github.com/leobalter/testing-examples/blob/master/solutions/3/report/cobertura-coverage.xml.
169169
170-
UT_COVERAGE_HTML_REPORTER (SQL_WITH_JAVA): Generates a HTML coverage report with summary and line by line information on code coverage.
171-
Based on open-source simplecov-html coverage reporter for Ruby.
172-
Includes source code in the report.
173-
Will copy all necessary assets to a folder named after the Output-File
170+
UT_COVERAGE_HTML_REPORTER Generates a HTML coverage report with summary and line by line information on code coverage.
171+
Based on open-source simplecov-html coverage reporter for Ruby.
172+
Includes source code in the report.
173+
Will copy all necessary assets to a folder named after the Output-File
174174
175-
UT_COVERAGE_SONAR_REPORTER (SQL): Generates a JSON coverage report providing information on code coverage with line numbers.
176-
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
177-
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
175+
UT_COVERAGE_SONAR_REPORTER Generates a JSON coverage report providing information on code coverage with line numbers.
176+
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
177+
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
178178
179-
UT_COVERALLS_REPORTER (SQL): Generates a JSON coverage report providing information on code coverage with line numbers.
180-
Designed for [Coveralls](https://coveralls.io/).
181-
JSON format conforms with specification: https://docs.coveralls.io/api-introduction
179+
UT_COVERALLS_REPORTER Generates a JSON coverage report providing information on code coverage with line numbers.
180+
Designed for [Coveralls](https://coveralls.io/).
181+
JSON format conforms with specification: https://docs.coveralls.io/api-introduction
182182
183-
UT_DOCUMENTATION_REPORTER (SQL_WITH_JAVA): A textual pretty-print of unit test results (usually use for console output)
184-
Provides additional properties lvl and failed
183+
UT_DOCUMENTATION_REPORTER A textual pretty-print of unit test results (usually use for console output)
184+
Provides additional properties lvl and failed
185185
186-
UT_JUNIT_REPORTER (SQL): Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
186+
UT_JUNIT_REPORTER Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
187187
188-
UT_SONAR_TEST_REPORTER (SQL): Generates a JSON report providing detailed information on test execution.
189-
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
190-
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
188+
UT_SONAR_TEST_REPORTER Generates a JSON report providing detailed information on test execution.
189+
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
190+
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
191191
192-
UT_TEAMCITY_REPORTER (SQL): Provides the TeamCity (a CI server by jetbrains) reporting-format that allows tracking of progress of a CI step/task as it executes.
193-
https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity
192+
UT_TEAMCITY_REPORTER Provides the TeamCity (a CI server by jetbrains) reporting-format that allows tracking of progress of a CI step/task as it executes.
193+
https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity
194194
195-
UT_TFS_JUNIT_REPORTER (SQL): Provides outcomes in a format conforming with JUnit version for TFS / VSTS.
196-
As defined by specs :https://docs.microsoft.com/en-us/vsts/build-release/tasks/test/publish-test-results?view=vsts
197-
Version is based on windy road junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd.
195+
UT_TFS_JUNIT_REPORTER Provides outcomes in a format conforming with JUnit version for TFS / VSTS.
196+
As defined by specs :https://docs.microsoft.com/en-us/vsts/build-release/tasks/test/publish-test-results?view=vsts
197+
Version is based on windy road junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd.
198198
199-
UT_XUNIT_REPORTER (SQL): Depracated reporter. Please use Junit.
200-
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
199+
UT_XUNIT_REPORTER Depracated reporter. Please use Junit.
200+
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
201201
```
202202

203203
## Enabling Color Outputs on Windows
@@ -210,4 +210,4 @@ Since v3.1.0 you can call custom reporters (PL/SQL) via cli, too. Just call the
210210

211211
```
212212
utplsql run hr/hr@xe -p=hr_test -f=my_custom_reporter -o=run.log -s
213-
```
213+
```

src/main/java/org/utplsql/cli/ReportersCommand.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import com.beust.jcommander.Parameter;
44
import com.beust.jcommander.Parameters;
5-
import org.utplsql.api.compatibility.CompatibilityProxy;
65
import org.utplsql.api.reporter.ReporterFactory;
76
import org.utplsql.api.reporter.inspect.ReporterInfo;
87
import org.utplsql.api.reporter.inspect.ReporterInspector;
98

109
import javax.sql.DataSource;
10+
import java.io.PrintStream;
1111
import java.sql.Connection;
12-
import java.util.ArrayList;
13-
import java.util.Comparator;
14-
import java.util.List;
12+
import java.util.*;
1513

1614
@Parameters(separators = "=", commandDescription = "prints a list of reporters available in the specified database")
1715
public class ReportersCommand implements ICommand {
@@ -37,12 +35,7 @@ public int run() {
3735

3836
ReporterFactory reporterFactory = ReporterFactoryProvider.createReporterFactory(con);
3937

40-
ReporterInspector.create(reporterFactory, con).getReporterInfos().stream()
41-
.sorted(Comparator.comparing(ReporterInfo::getName))
42-
.forEach(r -> {
43-
System.out.println(r.getName() + " (" + r.getType().name() + "): " + r.getDescription());
44-
System.out.println();
45-
});
38+
writeReporters(ReporterInspector.create(reporterFactory, con).getReporterInfos(), System.out);
4639
}
4740
catch ( Exception e ) {
4841
e.printStackTrace();
@@ -56,4 +49,47 @@ public int run() {
5649
public String getCommand() {
5750
return "reporters";
5851
}
52+
53+
private int getMaxNameLength(List<ReporterInfo> reporterInfos) {
54+
return reporterInfos.stream()
55+
.mapToInt(info -> info.getName().length())
56+
.max()
57+
.orElse(0);
58+
}
59+
60+
private void writeReporters(List<ReporterInfo> reporterInfos, PrintStream out) {
61+
int padding = getMaxNameLength(reporterInfos)+1;
62+
reporterInfos.stream()
63+
.sorted(Comparator.comparing(ReporterInfo::getName))
64+
.forEach(info -> writeReporter(info, padding, out));
65+
}
66+
67+
private void writeReporter(ReporterInfo info, int padding, PrintStream out) {
68+
69+
writeReporterName(info, padding, out);
70+
writeReporterDescription(info, padding, out);
71+
72+
out.println();
73+
}
74+
75+
private void writeReporterName( ReporterInfo info, int paddingRight, PrintStream out ) {
76+
out.print(String.format("%1$-" + paddingRight + "s", info.getName()));
77+
}
78+
79+
private void writeReporterDescription( ReporterInfo info, int paddingLeft, PrintStream out ) {
80+
String[] lines = info.getDescription().split("\n");
81+
82+
boolean firstLine = true;
83+
for ( String line : lines ) {
84+
85+
line = line.trim();
86+
87+
if ( !firstLine )
88+
out.print(String.format("%1$" + paddingLeft + "s", ""));
89+
90+
out.println(line);
91+
firstLine = false;
92+
}
93+
94+
}
5995
}

0 commit comments

Comments
 (0)