Skip to content

Commit b158774

Browse files
committed
Using Maven log in ReporterWriter. Enable skipUtPlsqlTests with system property. Updated README.md
1 parent 8f3b059 commit b158774

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=org.utplsql%3Autplsql-maven-plugin&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.utplsql%3Autplsql-maven-plugin)
33

44
# utPLSQL-maven-plugin
5-
* A maven plugin for running Unit Tests with utPLSQL v3+.
5+
A maven plugin for running Unit Tests with utPLSQL v3+.
66

77
## Compatibility
8-
* This plugin is compatible with utPLSQL 3.1.0+.
8+
This plugin is compatible with utPLSQL 3.1.0+.
99

1010
## Prerequisites
1111
* Java SE Runtime Environment 8
1212
* Maven Version 3.5+
13-
14-
The plugin requires Oracle JDBC driver (ojdbc8) as a Maven dependency.
13+
* Oracle JDBC driver
1514

1615
```xml
1716
<dependency>
@@ -49,11 +48,11 @@ If you want to skip tests by default but want the ability to re-enable tests fro
4948

5049
This will allow you to run with all tests disabled by default and to run them with this command:
5150

52-
mvn install -DskipTests=false
51+
mvn install -DskipUtplsqlTests=false
5352

54-
### Usage Example
53+
### Configuration
5554

56-
Please refer to the following usage example for the parameters descriptions.
55+
Please refer to the following usage example for the parameters descriptions:
5756

5857
```xml
5958
<project xmlns="http://maven.apache.org/POM/4.0.0"
@@ -90,7 +89,6 @@ Please refer to the following usage example for the parameters descriptions.
9089
<goal>test</goal>
9190
</goals>
9291
<configuration>
93-
9492
<!-- REQUIRED PARAMETERS -->
9593

9694
<!-- A list of tests suite paths. -->
@@ -142,6 +140,10 @@ Please refer to the following usage example for the parameters descriptions.
142140
<!-- Defaults to: false -->
143141
<skipUtplsqlTests>false</skipUtplsqlTests>
144142

143+
<!-- Enables DBMS_OUTPUT -->
144+
<!-- Defaults to: false -->
145+
<dbmsOutput>false</dbmsOutput>
146+
145147
<!-- A list of tags to run. -->
146148
<tags>
147149
<tag>test_tag</tag>
@@ -230,14 +232,14 @@ Please refer to the following usage example for the parameters descriptions.
230232
```
231233

232234
More project samples are available in the src/test/resources directory:
233-
* **simple-project:** minimalist test project with standard project directory structure.
234-
* **regex-project:** overrides project directory structure and use additional parameters (sourcesRegexExpression, testsRegexExpression, ...), to tell utPLSQL how project files should be mapped into database objects.
235-
* **type-mapping-project:** this project shows how to use regex and custom type parameters together.
236-
* **owner-param-project:** this project demonstrates how to use sourcesOwner and testsOwner parameters.
235+
* **simple-project:** Minimalist test project with standard project directory structure.
236+
* **regex-project:** Overrides project directory structure and use additional parameters (sourcesRegexExpression, testsRegexExpression, ...), to tell utPLSQL how project files should be mapped into database objects.
237+
* **type-mapping-project:** Example how to use regex and custom type parameters together.
238+
* **owner-param-project:** Demonstrates how to use sourcesOwner and testsOwner parameters.
237239

238-
## Comparaison with the CLI
240+
## Comparison with utPLSQL CLI
239241

240-
| CLI short parameter | CLI long parameter | maven XML path |
242+
| CLI short parameter | CLI long parameter | Maven XML path |
241243
| --- | --- | --- |
242244
| -c | --color | |
243245
| | --failure-exit-code | |
@@ -248,6 +250,7 @@ More project samples are available in the src/test/resources directory:
248250
| | | ignoreFailure |
249251
| -scc | --skip-compatibility-check | skipCompatibilityCheck |
250252
| | --tags | tags.tag |
253+
| -D | --dbms_output | dbmsOutput |
251254
| -r | --random-test-order | randomTestOrder |
252255
| -seed | --random-test-order-seed | randomTestOrderSeed |
253256
| -exclude | | excludeObject |

src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.maven.plugins.annotations.Parameter;
1212
import org.apache.maven.project.MavenProject;
1313
import org.apache.maven.shared.utils.logging.MessageUtils;
14+
import org.utplsql.api.DBHelper;
1415
import org.utplsql.api.FileMapperOptions;
1516
import org.utplsql.api.JavaApiVersionInfo;
1617
import org.utplsql.api.KeyValuePair;
@@ -130,9 +131,12 @@ public class UtPLSQLMojo extends AbstractMojo {
130131
@Parameter(defaultValue = "${maven.test.failure.ignore}")
131132
protected boolean ignoreFailure;
132133

133-
@Parameter(defaultValue = "${skipUtplsqlTests}")
134+
@Parameter(property = "skipUtplsqlTests", defaultValue = "false")
134135
protected boolean skipUtplsqlTests;
135136

137+
@Parameter
138+
protected boolean dbmsOutput;
139+
136140
// Color in the console, bases on Maven logging configuration.
137141
private final boolean colorConsole = MessageUtils.isColorEnabled();
138142

@@ -146,7 +150,7 @@ public class UtPLSQLMojo extends AbstractMojo {
146150
@Override
147151
public void execute() throws MojoExecutionException {
148152
if (skipUtplsqlTests) {
149-
getLog().debug("utPLSQLTests are skipped.");
153+
getLog().info("utPLSQLTests are skipped.");
150154
} else {
151155
getLog().debug("Java Api Version = " + JavaApiVersionInfo.getVersion());
152156
loadConfFromEnvironment();
@@ -168,6 +172,11 @@ public void execute() throws MojoExecutionException {
168172

169173
logParameters(sourceMappingOptions, testMappingOptions, reporterList);
170174

175+
if (dbmsOutput) {
176+
DBHelper.enableDBMSOutput(connection);
177+
getLog().info("Enabled dbms_output.");
178+
}
179+
171180
TestRunner runner = new TestRunner()
172181
.addPathList(paths)
173182
.addReporterList(reporterList)
@@ -199,6 +208,8 @@ public void execute() throws MojoExecutionException {
199208
try {
200209
if (null != connection) {
201210
reporterWriter.writeReporters(connection);
211+
212+
DBHelper.disableDBMSOutput(connection);
202213
connection.close();
203214
}
204215
} catch (Exception e) {
@@ -326,7 +337,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
326337
throws SQLException {
327338

328339
List<Reporter> reporterList = new ArrayList<>();
329-
reporterWriter = new ReporterWriter(targetDir, utlVersion);
340+
reporterWriter = new ReporterWriter(targetDir, utlVersion, getLog());
330341

331342
if (reporters.isEmpty()) {
332343
ReporterParameter reporterParameter = new ReporterParameter();

src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,31 @@
2222

2323
public class ReporterWriter {
2424

25-
private static final Log LOG = new SystemStreamLog();
26-
2725
private final List<Pair<Reporter, ReporterParameter>> listReporters;
2826

2927
private final String outputDirectory;
3028

3129
private final Version databaseVersion;
3230

31+
private final Log log;
32+
3333
/**
3434
* Constructor of the reporter writer.
35-
*
35+
*
3636
* @param outputDirectory the reporter output directory
3737
* @param databaseVersion the utPLSQL framework version
38+
* @param log the Maven log
3839
*/
39-
public ReporterWriter(String outputDirectory, Version databaseVersion) {
40+
public ReporterWriter(String outputDirectory, Version databaseVersion, Log log) {
4041
this.listReporters = new ArrayList<>();
4142
this.outputDirectory = outputDirectory;
4243
this.databaseVersion = databaseVersion;
43-
44+
this.log = log;
4445
}
4546

4647
/**
4748
* Adds a new reporter to the writter.
48-
*
49+
*
4950
* @param parameter the reporter parameter
5051
* @param reporter the reporter Object
5152
*/
@@ -55,7 +56,7 @@ public void addReporter(ReporterParameter parameter, Reporter reporter) {
5556

5657
/**
5758
* Writes the reporters to the output.
58-
*
59+
*
5960
* @param connection the database connection
6061
* @throws MojoExecutionException if any exception happens
6162
*/
@@ -82,19 +83,19 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
8283
}
8384

8485
if (!file.getParentFile().exists()) {
85-
LOG.debug("Creating directory for reporter file " + file.getAbsolutePath());
86+
log.debug("Creating directory for reporter file " + file.getAbsolutePath());
8687
file.getParentFile().mkdirs();
8788
}
8889

8990
fout = new FileOutputStream(file);
90-
LOG.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath()));
91+
log.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath()));
9192

9293
// Added to the Report
9394
printStreams.add(new PrintStream(fout));
9495
}
9596

9697
if (reporterParameter.isConsoleOutput()) {
97-
LOG.info(format("Writing report %s to Console", reporter.getTypeName()));
98+
log.info(format("Writing report %s to Console", reporter.getTypeName()));
9899
printStreams.add(System.out);
99100
}
100101
buffer.printAvailable(connection, printStreams);
@@ -105,7 +106,7 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
105106
try {
106107
fout.close();
107108
} catch (IOException e) {
108-
LOG.info(format("Failed to closing the reporting %s", reporterParameter.getClass()));
109+
log.info(format("Failed to closing the reporting %s", reporterParameter.getClass()));
109110
}
110111
}
111112
}

0 commit comments

Comments
 (0)