Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Refactoring of ReportersCommand
Also much nicer formatting
  • Loading branch information
pesse committed Jun 12, 2018
commit 554c71bbd3a02b6967f0910c3088ee9faddfb69f
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,42 +162,42 @@ utPLSQL 3.1.2.1913
```
> utplsql reporters app/app@localhost:1521/ORCLPDB1

UT_COVERAGE_COBERTURA_REPORTER (SQL): Generates a Cobertura coverage report providing information on code coverage with line numbers.
Designed for Jenkins and TFS to report coverage.
Cobertura Document Type Definition can be found: http://cobertura.sourceforge.net/xml/coverage-04.dtd.
Sample file: https://github.com/leobalter/testing-examples/blob/master/solutions/3/report/cobertura-coverage.xml.
UT_COVERAGE_COBERTURA_REPORTER Generates a Cobertura coverage report providing information on code coverage with line numbers.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my pedantic hat on - wouldn't it be better to have it formatted with indentation of 4 spaces?

UT_COVERAGE_COBERTURA_REPORTER:
    Generates a Cobertura coverage report providing information on code coverage with line numbers.
    Designed for Jenkins and TFS to report coverage.

Indenting by up to 31 chars seems excessive

Designed for Jenkins and TFS to report coverage.
Cobertura Document Type Definition can be found: http://cobertura.sourceforge.net/xml/coverage-04.dtd.
Sample file: https://github.com/leobalter/testing-examples/blob/master/solutions/3/report/cobertura-coverage.xml.

UT_COVERAGE_HTML_REPORTER (SQL_WITH_JAVA): Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
Will copy all necessary assets to a folder named after the Output-File
UT_COVERAGE_HTML_REPORTER Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
Will copy all necessary assets to a folder named after the Output-File

UT_COVERAGE_SONAR_REPORTER (SQL): Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
UT_COVERAGE_SONAR_REPORTER Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data

UT_COVERALLS_REPORTER (SQL): Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
JSON format conforms with specification: https://docs.coveralls.io/api-introduction
UT_COVERALLS_REPORTER Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
JSON format conforms with specification: https://docs.coveralls.io/api-introduction

UT_DOCUMENTATION_REPORTER (SQL_WITH_JAVA): A textual pretty-print of unit test results (usually use for console output)
Provides additional properties lvl and failed
UT_DOCUMENTATION_REPORTER A textual pretty-print of unit test results (usually use for console output)
Provides additional properties lvl and failed

UT_JUNIT_REPORTER (SQL): Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
UT_JUNIT_REPORTER Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578

UT_SONAR_TEST_REPORTER (SQL): Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
UT_SONAR_TEST_REPORTER Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data

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.
https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity
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.
https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity

UT_TFS_JUNIT_REPORTER (SQL): Provides outcomes in a format conforming with JUnit version for TFS / VSTS.
As defined by specs :https://docs.microsoft.com/en-us/vsts/build-release/tasks/test/publish-test-results?view=vsts
Version is based on windy road junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd.
UT_TFS_JUNIT_REPORTER Provides outcomes in a format conforming with JUnit version for TFS / VSTS.
As defined by specs :https://docs.microsoft.com/en-us/vsts/build-release/tasks/test/publish-test-results?view=vsts
Version is based on windy road junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd.

UT_XUNIT_REPORTER (SQL): Depracated reporter. Please use Junit.
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
UT_XUNIT_REPORTER Depracated reporter. Please use Junit.
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
```

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

```
utplsql run hr/hr@xe -p=hr_test -f=my_custom_reporter -o=run.log -s
```
```
56 changes: 46 additions & 10 deletions src/main/java/org/utplsql/cli/ReportersCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.api.reporter.inspect.ReporterInfo;
import org.utplsql.api.reporter.inspect.ReporterInspector;

import javax.sql.DataSource;
import java.io.PrintStream;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.*;

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

ReporterFactory reporterFactory = ReporterFactoryProvider.createReporterFactory(con);

ReporterInspector.create(reporterFactory, con).getReporterInfos().stream()
.sorted(Comparator.comparing(ReporterInfo::getName))
.forEach(r -> {
System.out.println(r.getName() + " (" + r.getType().name() + "): " + r.getDescription());
System.out.println();
});
writeReporters(ReporterInspector.create(reporterFactory, con).getReporterInfos(), System.out);
}
catch ( Exception e ) {
e.printStackTrace();
Expand All @@ -56,4 +49,47 @@ public int run() {
public String getCommand() {
return "reporters";
}

private int getMaxNameLength(List<ReporterInfo> reporterInfos) {
return reporterInfos.stream()
.mapToInt(info -> info.getName().length())
.max()
.orElse(0);
}

private void writeReporters(List<ReporterInfo> reporterInfos, PrintStream out) {
int padding = getMaxNameLength(reporterInfos)+1;
reporterInfos.stream()
.sorted(Comparator.comparing(ReporterInfo::getName))
.forEach(info -> writeReporter(info, padding, out));
}

private void writeReporter(ReporterInfo info, int padding, PrintStream out) {

writeReporterName(info, padding, out);
writeReporterDescription(info, padding, out);

out.println();
}

private void writeReporterName( ReporterInfo info, int paddingRight, PrintStream out ) {
out.print(String.format("%1$-" + paddingRight + "s", info.getName()));
}

private void writeReporterDescription( ReporterInfo info, int paddingLeft, PrintStream out ) {
String[] lines = info.getDescription().split("\n");

boolean firstLine = true;
for ( String line : lines ) {

line = line.trim();

if ( !firstLine )
out.print(String.format("%1$" + paddingLeft + "s", ""));

out.println(line);
firstLine = false;
}

}
}