Skip to content

Commit 54ad290

Browse files
authored
Merge pull request #87 from utPLSQL/feature/version_info
Version info and info command in cli Reporters-list command in cli
2 parents e8251c7 + d402718 commit 54ad290

23 files changed

+779
-259
lines changed

README.md

Lines changed: 132 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,87 +39,89 @@ export LC_ALL=en_US.utf-8
3939
The charset-part of LC_ALL is ignored.
4040

4141
## Usage
42+
Currently, utPLSQL-cli supports the following commands:
43+
- run
44+
- info
45+
- reporters
4246

43-
`utplsql run <ConnectionURL> [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]`
47+
#### \<ConnectionURL>
4448

45-
```
46-
<ConnectionURL> - accepted formats:
47-
<user>/<password>@//<host>[:<port>]/<service>
48-
<user>/<password>@<host>:<port>:<SID>
49-
<user>/<password>@<TNSName>
50-
To connect using TNS, you need to have the ORACLE_HOME environment variable set.
51-
The file tnsnames.ora must exist in path %ORACLE_HOME%/network/admin
52-
The file tnsnames.ora must contain valid TNS entries.
49+
This is used in all commands as first parameter (though it's optional for `info`).
50+
51+
Accepted formats:
52+
53+
- `<user>/<password>@//<host>[:<port>]/<service>`
54+
- `<user>/<password>@<host>:<port>:<SID>`
55+
- `<user>/<password>@<TNSName>`
56+
57+
To connect using TNS, you need to have the ORACLE_HOME environment variable set.
58+
The file tnsnames.ora must exist in path %ORACLE_HOME%/network/admin
59+
The file tnsnames.ora must contain valid TNS entries.
60+
61+
### run
62+
`utplsql run <ConnectionURL> [<options>]`
63+
64+
65+
#### Options
66+
```
5367
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
5468
The path(s) can be in one of the following formats:
5569
schema[.package[.procedure]]
5670
schema:suite[.suite[.suite][...]][.procedure]
5771
Both formats can be mixed in the list.
5872
If only schema is provided, then all suites owner by that schema are executed.
5973
If -p is omitted, the current schema is used.
74+
6075
-f=format - A reporter to be used for reporting.
6176
If no -f option is provided, the default ut_documentation_reporter is used.
62-
Available options:
63-
-f=ut_documentation_reporter
64-
A textual pretty-print of unit test results (usually use for console output)
65-
-f=ut_teamcity_reporter
66-
For reporting live progress of test execution with Teamcity CI.
67-
-f=ut_xunit_reporter
68-
Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity.
69-
-f=ut_coverage_html_reporter
70-
Generates a HTML coverage report with summary and line by line information on code coverage.
71-
Based on open-source simplecov-html coverage reporter for Ruby.
72-
Includes source code in the report.
73-
-f=ut_coveralls_reporter
74-
Generates a JSON coverage report providing information on code coverage with line numbers.
75-
Designed for [Coveralls](https://coveralls.io/).
76-
-f=ut_coverage_sonar_reporter
77-
Generates a JSON coverage report providing information on code coverage with line numbers.
78-
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
79-
-f=ut_sonar_test_reporter
80-
Generates a JSON report providing detailed information on test execution.
81-
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
82-
83-
-o=output - Defines file name to save the output from the specified reporter.
77+
See reporters command for possible values
78+
-o=output - Defines file name to save the output from the specified reporter.
8479
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
8580
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
8681
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
87-
-s - Forces putting output to to screen for a given -f parameter.
82+
-s - Forces putting output to to screen for a given -f parameter.
83+
8884
-source_path=source - path to project source files, use the following options to enable custom type mappings:
89-
-owner="app"
90-
-regex_expression="pattern"
91-
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
92-
-owner_subexpression=subexpression_number
93-
-type_subexpression=subexpression_number
94-
-name_subexpression=subexpression_number
85+
-owner="app"
86+
-regex_expression="pattern"
87+
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
88+
-owner_subexpression=subexpression_number
89+
-type_subexpression=subexpression_number
90+
-name_subexpression=subexpression_number
91+
9592
-test_path=test - path to project test files, use the following options to enable custom type mappings:
96-
-owner="app"
97-
-regex_expression="pattern"
98-
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
99-
-owner_subexpression=subexpression_number
100-
-type_subexpression=subexpression_number
101-
-name_subexpression=subexpression_number
93+
-owner="app"
94+
-regex_expression="pattern"
95+
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
96+
-owner_subexpression=subexpression_number
97+
-type_subexpression=subexpression_number
98+
-name_subexpression=subexpression_number
99+
102100
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
103101
Works only on reporeters that support colors (ut_documentation_reporter).
102+
104103
--failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.
104+
105105
-scc - If specified, skips the compatibility-check with the version of the database framework.
106106
If you skip compatibility-check, CLI will expect the most actual framework version
107-
-include=package_list - Comma-separated object list to include in the coverage report.
108-
Format: [schema.]package[,[schema.]package ...].
109-
See coverage reporting options in framework documentation.
110-
-exclude=package_list - Comma-separated object list to exclude from the coverage report.
111-
Format: [schema.]package[,[schema.]package ...].
112-
See coverage reporting options in framework documentation.
107+
108+
-include=pckg_list - Comma-separated object list to include in the coverage report.
109+
Format: [schema.]package[,[schema.]package ...].
110+
See coverage reporting options in framework documentation.
111+
112+
-exclude=pckg_list - Comma-separated object list to exclude from the coverage report.
113+
Format: [schema.]package[,[schema.]package ...].
114+
See coverage reporting options in framework documentation.
113115
```
114116

115117
Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.
116118

117119
Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path.
118120

119-
Examples:
121+
#### Examples
120122

121123
```
122-
utplsql run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_coverage_html_reporter -o=coverage.html -source_path=source
124+
> utplsql run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_coverage_html_reporter -o=coverage.html -source_path=source
123125
```
124126

125127
Invokes all Unit tests from schema/package "hr_test" with two reporters:
@@ -128,12 +130,87 @@ Invokes all Unit tests from schema/package "hr_test" with two reporters:
128130
* ut_coverage_html_reporter - will report only on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html"
129131

130132
```
131-
utplsql run hr/hr@xe
133+
> utplsql run hr/hr@xe
132134
```
133135

134136
Invokes all unit test suites from schema "hr". Results are displayed to screen using default ut_documentation_reporter.
135137

136-
#### Enabling Color Outputs on Windows
138+
### info
139+
`utplsql info [<ConnectionURL>]`
140+
141+
142+
#### Examples
143+
144+
```
145+
> utplsql info
146+
147+
cli 3.1.1-SNAPSHOT.local
148+
utPLSQL-java-api 3.1.1-SNAPSHOT.123
149+
```
150+
```
151+
> utplsql info app/app@localhost:1521/ORCLPDB1
152+
153+
cli 3.1.1-SNAPSHOT.local
154+
utPLSQL-java-api 3.1.1-SNAPSHOT.123
155+
utPLSQL 3.1.2.1913
156+
```
157+
158+
### reporters
159+
`utplsql reporters <ConnectionURL>`
160+
161+
#### Examples
162+
```
163+
> utplsql reporters app/app@localhost:1521/ORCLPDB1
164+
165+
UT_COVERAGE_COBERTURA_REPORTER:
166+
Generates a Cobertura coverage report providing information on code coverage with line numbers.
167+
Designed for Jenkins and TFS to report coverage.
168+
Cobertura Document Type Definition can be found: http://cobertura.sourceforge.net/xml/coverage-04.dtd.
169+
Sample file: https://github.com/leobalter/testing-examples/blob/master/solutions/3/report/cobertura-coverage.xml.
170+
171+
UT_COVERAGE_HTML_REPORTER:
172+
Generates a HTML coverage report with summary and line by line information on code coverage.
173+
Based on open-source simplecov-html coverage reporter for Ruby.
174+
Includes source code in the report.
175+
Will copy all necessary assets to a folder named after the Output-File
176+
177+
UT_COVERAGE_SONAR_REPORTER:
178+
Generates a JSON coverage report providing information on code coverage with line numbers.
179+
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
180+
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
181+
182+
UT_COVERALLS_REPORTER:
183+
Generates a JSON coverage report providing information on code coverage with line numbers.
184+
Designed for [Coveralls](https://coveralls.io/).
185+
JSON format conforms with specification: https://docs.coveralls.io/api-introduction
186+
187+
UT_DOCUMENTATION_REPORTER:
188+
A textual pretty-print of unit test results (usually use for console output)
189+
Provides additional properties lvl and failed
190+
191+
UT_JUNIT_REPORTER:
192+
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
193+
194+
UT_SONAR_TEST_REPORTER:
195+
Generates a JSON report providing detailed information on test execution.
196+
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
197+
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
198+
199+
UT_TEAMCITY_REPORTER:
200+
Provides the TeamCity (a CI server by jetbrains) reporting-format that allows tracking of progress of a CI step/task as it executes.
201+
https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity
202+
203+
UT_TFS_JUNIT_REPORTER:
204+
Provides outcomes in a format conforming with JUnit version for TFS / VSTS.
205+
As defined by specs :https://docs.microsoft.com/en-us/vsts/build-release/tasks/test/publish-test-results?view=vsts
206+
Version is based on windy road junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd.
207+
208+
UT_XUNIT_REPORTER:
209+
Depracated reporter. Please use Junit.
210+
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
211+
```
212+
213+
## Enabling Color Outputs on Windows
137214

138215
To enable color outputs on Windows cmd you need to install an open-source utility called [ANSICON](http://adoxa.altervista.org/ansicon/).
139216

@@ -143,4 +220,4 @@ Since v3.1.0 you can call custom reporters (PL/SQL) via cli, too. Just call the
143220

144221
```
145222
utplsql run hr/hr@xe -p=hr_test -f=my_custom_reporter -o=run.log -s
146-
```
223+
```

pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<maven.compiler.target>1.8</maven.compiler.target>
1717
<junit.platform.version>1.0.3</junit.platform.version>
1818
<junit.jupiter.version>5.0.3</junit.jupiter.version>
19+
<travisBuildNumber>local</travisBuildNumber>
1920
</properties>
2021

2122
<dependencies>
@@ -88,6 +89,41 @@
8889
</programs>
8990
</configuration>
9091
</plugin>
92+
<plugin>
93+
<groupId>com.google.code.maven-replacer-plugin</groupId>
94+
<artifactId>replacer</artifactId>
95+
<version>1.5.3</version>
96+
<executions>
97+
<execution>
98+
<id>replace-version-number</id>
99+
<phase>generate-sources</phase>
100+
<goals>
101+
<goal>replace</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
<configuration>
106+
<basedir>${project.basedir}/src/main/java</basedir>
107+
<includes>
108+
<include>**/CliVersionInfo.java</include>
109+
</includes>
110+
<preserveDir>true</preserveDir>
111+
<replacements>
112+
<replacement>
113+
<token>MAVEN_PROJECT_NAME = ".*"</token>
114+
<value>MAVEN_PROJECT_NAME = "${project.name}"</value>
115+
</replacement>
116+
<replacement>
117+
<token>MAVEN_PROJECT_VERSION = ".*"</token>
118+
<value>MAVEN_PROJECT_VERSION = "${project.version}"</value>
119+
</replacement>
120+
<replacement>
121+
<token>BUILD_NO = ".*"</token>
122+
<value>BUILD_NO = "${travisBuildNumber}"</value>
123+
</replacement>
124+
</replacements>
125+
</configuration>
126+
</plugin>
91127
<plugin>
92128
<groupId>org.apache.maven.plugins</groupId>
93129
<artifactId>maven-surefire-plugin</artifactId>

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,43 @@ public class Cli {
1212
static final int DEFAULT_ERROR_CODE = 1;
1313

1414
static final String HELP_CMD = "-h";
15-
private static final String RUN_CMD = "run";
1615

1716
public static void main(String[] args) {
1817

18+
int exitCode = runWithExitCode(args);
19+
20+
System.exit(exitCode);
21+
}
22+
23+
static int runWithExitCode( String[] args ) {
1924
LocaleInitializer.initLocale();
2025

2126
JCommander jc = new JCommander();
2227
jc.setProgramName("utplsql");
23-
// jc.addCommand(HELP_CMD, new HelpCommand());
24-
RunCommand runCmd = new RunCommand();
25-
jc.addCommand(RUN_CMD, runCmd);
28+
29+
CommandProvider cmdProvider = new CommandProvider();
30+
31+
cmdProvider.commands().forEach(cmd -> jc.addCommand(cmd.getCommand(), cmd));
2632

2733
int exitCode = DEFAULT_ERROR_CODE;
2834

2935
try {
3036
jc.parse(args);
3137

32-
if (RUN_CMD.equals(jc.getParsedCommand())) {
33-
exitCode = runCmd.run();
34-
} else {
35-
throw new ParameterException("Command not specified.");
36-
}
38+
exitCode = cmdProvider.getCommand(jc.getParsedCommand()).run();
39+
3740
} catch (ParameterException e) {
3841
if (jc.getParsedCommand() != null) {
3942
System.err.println(e.getMessage());
4043
jc.usage(jc.getParsedCommand());
4144
} else {
4245
jc.usage();
4346
}
44-
} catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
45-
System.out.println(e.getMessage());
46-
} catch (Exception e) {
47+
} catch (Exception e) {
4748
e.printStackTrace();
4849
}
4950

50-
System.exit(exitCode);
51+
return exitCode;
5152
}
5253

5354
private static class HelpCommand {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.utplsql.cli;
2+
3+
/** This class is getting updated automatically by the build process.
4+
* Please do not update its constants manually cause they will be overwritten.
5+
*
6+
* @author pesse
7+
*/
8+
public class CliVersionInfo {
9+
10+
private static final String BUILD_NO = "local";
11+
private static final String MAVEN_PROJECT_NAME = "cli";
12+
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";
13+
14+
public static String getVersion() {
15+
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;
16+
}
17+
18+
public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); }
19+
20+
}

0 commit comments

Comments
 (0)