Skip to content

Commit 47df5d5

Browse files
Upgrade the Maven Plugin to the API version 3.1.0
1 parent 8eef742 commit 47df5d5

6 files changed

Lines changed: 55 additions & 25 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ A maven plugin for running Unit Tests with utPLSQL v3+
33

44
### Compatibility
55

6-
This plugin is compatible with the Java-API 3.0.4.
6+
This plugin is compatible with the Java-API 3.1.0.
77

88
### Prerequisites
99
You have to be a fully utPLSQL environment available compatible with the Java API.
@@ -20,6 +20,9 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
2020
* `password`
2121
* Password of the connection to the database
2222
* Default: `${dbPass}`
23+
* `version`
24+
* Version of the utplsql
25+
* Default: `3.1.0`
2326
* `ignoreFailure`
2427
* Ignore or continue when a test fail
2528
* Default: `${maven.test.failure.ignore}`
@@ -62,6 +65,7 @@ The next snippet is a sample of declaration of the pom
6265
<url>url_of_connection</url>
6366
<user>user</user>
6467
<password>password</password>
68+
<version>3.1.0</version>
6569
<failOnErrors>false</failOnErrors>
6670
<reporters>
6771
<reporter>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.utplsql</groupId>
66
<artifactId>utplsql-maven-plugin-build</artifactId>
7-
<version>1.0-SNAPSHOT</version>
7+
<version>1.0.0-SNAPSHOT</version>
88
<packaging>pom</packaging>
99

1010
<name>utplsql-maven-plugin Maven Plugin Build</name>

utplsql-maven-plugin/pom.xml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
<java.version>1.8</java.version>
1919
</properties>
20-
2120
<dependencies>
2221

2322
<dependency>
2423
<groupId>org.utplsql</groupId>
2524
<artifactId>java-api</artifactId>
26-
<version>3.0.4</version>
25+
<version>3.1.0</version>
2726
</dependency>
2827

2928
<dependency>
@@ -118,9 +117,22 @@
118117
</goals>
119118
</execution>
120119
</executions>
121-
120+
122121
</plugin>
123122
</plugins>
124123
</build>
125124

125+
<repositories>
126+
<repository>
127+
<id>utplsql-java-api</id>
128+
<url>https://packagecloud.io/utplsql/utplsql-java-api/maven2</url>
129+
<releases>
130+
<enabled>true</enabled>
131+
</releases>
132+
<snapshots>
133+
<enabled>true</enabled>
134+
</snapshots>
135+
</repository>
136+
</repositories>
137+
126138
</project>

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.maven.plugins.annotations.Parameter;
1919
import org.utplsql.api.FileMapperOptions;
2020
import org.utplsql.api.TestRunner;
21+
import org.utplsql.api.Version;
2122
import org.utplsql.api.exception.SomeTestsFailedException;
2223
import org.utplsql.api.reporter.Reporter;
2324
import org.utplsql.api.reporter.ReporterFactory;
@@ -43,6 +44,9 @@ public class UtPLSQLMojo extends AbstractMojo
4344

4445
@Parameter(defaultValue = "${dbPass}")
4546
private String password;
47+
48+
@Parameter(defaultValue = "3.1.0")
49+
private String version;
4650

4751
@Parameter
4852
private String includeObject;
@@ -86,13 +90,14 @@ public class UtPLSQLMojo extends AbstractMojo
8690
public void execute() throws MojoExecutionException
8791
{
8892
Connection connection = null;
89-
try
93+
try
9094
{
9195
FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource(), "sources");
9296
FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest(), "test");
93-
97+
9498
// Create the Connection to the Database
9599
connection = DriverManager.getConnection(url, user, password);
100+
96101
List<Reporter> reporterList = initReporters(connection);
97102

98103
logParameters(sourceMappingOptions, testMappingOptions, reporterList);
@@ -117,7 +122,7 @@ public void execute() throws MojoExecutionException
117122
}
118123

119124
runner.run(connection);
120-
125+
121126
}
122127
catch (SomeTestsFailedException e)
123128
{
@@ -135,11 +140,6 @@ public void execute() throws MojoExecutionException
135140
{
136141
// Write Reporters
137142
reporterWriter.writeReporters(connection);
138-
139-
if (connection != null)
140-
{
141-
connection.close();
142-
}
143143
}
144144
catch (Exception e)
145145
{
@@ -184,13 +184,17 @@ private FileMapperOptions buildOptions(List<Resource> resources, Resource defaul
184184
private List<Reporter> initReporters(Connection connection) throws SQLException
185185
{
186186
List<Reporter> reporterList = new ArrayList<>();
187+
188+
Version utlVersion = new Version (version);
187189

188-
// Initializate Reporters
189-
reporterWriter = new ReporterWriter(targetDir);
190+
// Initialized Reporters
191+
reporterWriter = new ReporterWriter(targetDir, utlVersion);
192+
193+
ReporterFactory reporterFactory = ReporterFactory.createEmpty();
190194

191195
for (ReporterParameter reporterParameter : reporters)
192196
{
193-
Reporter reporter = ReporterFactory.createReporter(reporterParameter.getName());
197+
Reporter reporter = reporterFactory.createReporter(reporterParameter.getName());
194198
reporter.init(connection);
195199
reporterList.add(reporter);
196200

@@ -224,7 +228,7 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt
224228

225229
log.debug("Invoking TestRunner with: ");
226230
log.debug("reporters=");
227-
reporterList.forEach((Reporter r) -> log.debug(r.getSelfType()));
231+
reporterList.forEach((Reporter r) -> log.debug(r.getTypeName()));
228232
log.debug("sources=");
229233
sourceMappingOptions.getFilePaths().forEach(log::debug);
230234
log.debug("tests=");

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import org.apache.maven.plugin.MojoExecutionException;
1515
import org.apache.maven.plugin.logging.Log;
1616
import org.apache.maven.plugin.logging.SystemStreamLog;
17-
import org.utplsql.api.OutputBuffer;
17+
import org.utplsql.api.Version;
18+
import org.utplsql.api.outputBuffer.OutputBuffer;
19+
import org.utplsql.api.outputBuffer.OutputBufferProvider;
1820
import org.utplsql.api.reporter.Reporter;
1921
import org.utplsql.model.ReporterParameter;
2022

@@ -27,14 +29,22 @@ public class ReporterWriter
2729

2830
// Output Directory
2931
private String outputDirectory;
32+
33+
// Database Version
34+
private Version databaseVersion;
3035

36+
3137
/**
32-
*
38+
* Constructor of the reporter writer
39+
* @param outputDirectory
40+
* @param databaseVersion
3341
*/
34-
public ReporterWriter(String outputDirectory)
42+
public ReporterWriter(String outputDirectory, Version databaseVersion)
3543
{
36-
listReporters = new ArrayList<>();
44+
this.listReporters = new ArrayList<>();
3745
this.outputDirectory = outputDirectory;
46+
this.databaseVersion = databaseVersion;
47+
3848
}
3949

4050
/**
@@ -64,7 +74,7 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
6474
//
6575
try
6676
{
67-
OutputBuffer buffer = new OutputBuffer(reporter);
77+
OutputBuffer buffer = OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, connection);
6878

6979
if (reporterParameter.isFileOutput())
7080
{
@@ -82,15 +92,15 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
8292
}
8393

8494
fout = new FileOutputStream(file);
85-
LOG.info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath()));
95+
LOG.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath()));
8696

8797
// Added to the Report
8898
printStreams.add(new PrintStream(fout));
8999
}
90100

91101
if (reporterParameter.isConsoleOutput())
92102
{
93-
LOG.info(format("Writing report %s to Console", reporter.getSelfType()));
103+
LOG.info(format("Writing report %s to Console", reporter.getTypeName()));
94104
printStreams.add(System.out);
95105
}
96106
buffer.printAvailable(connection, printStreams);

utplsql-maven-plugin/src/test/resources/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
<properties>
14-
<dbUrl>jdbc:oracle:thin:@180.129.3.101:1521:xe</dbUrl>
14+
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
1515
<dbUser>ut3</dbUser>
1616
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
1717
</properties>

0 commit comments

Comments
 (0)