Skip to content

Commit 639b834

Browse files
committed
Merge branch 'feature/55_skipUtplsqlTests' into develop
2 parents 83bc463 + 3acad4b commit 639b834

File tree

11 files changed

+292
-189
lines changed

11 files changed

+292
-189
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ install:
3434

3535
script:
3636
- echo "Run Verify with Coverage"
37-
- mvn org.jacoco:jacoco-maven-plugin:prepare-agent verify -Pintegration -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}"
37+
- mvn org.jacoco:jacoco-maven-plugin:prepare-agent verify -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}"
3838

3939
before_deploy:
4040
- echo $GPG_SECRET_KEYS | base64 --decode | ${GPG_EXECUTABLE} --import

README.md

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,54 @@
44
# utPLSQL-maven-plugin
55
* A maven plugin for running Unit Tests with utPLSQL v3+.
66

7-
### Compatibility
7+
## Compatibility
88
* This plugin is compatible with utPLSQL 3.1.0+.
99

10-
### Prerequisites
10+
## Prerequisites
1111
* Java SE Runtime Environment 8
1212
* Maven Version 3.5+
1313

14-
The plugin requires Oracle JDBC driver (ojdbc8) as a maven dependency.
15-
In order to download the required driver, you need to configure access to Oracle's Maven Repository in your `settings.xml` file.
14+
The plugin requires Oracle JDBC driver (ojdbc8) as a Maven dependency.
1615

17-
http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010
16+
```xml
17+
<dependency>
18+
<groupId>com.oracle.database.jdbc</groupId>
19+
<artifactId>ojdbc8</artifactId>
20+
<version>21.3.0.0</version>
21+
</dependency>
22+
```
23+
24+
## Usage
25+
26+
### Skipping Tests
27+
28+
To skip running the tests for a particular project, set the **skipUtplsqlTests** property to true.
29+
30+
```xml
31+
<configuration>
32+
<skipUtplsqlTests>true</skipUtplsqlTests>
33+
</configuration>
34+
```
35+
36+
You can also skip the tests via the command line by executing the following command:
1837

19-
Sections 6.1 and 6.5 are the more important ones, and the only ones you need if you're using the latest Maven version.
38+
mvn install -DskipTests
2039

21-
Below is an example of changes needed to your `settings.xml` file.
40+
#### Skipping by Default
41+
42+
If you want to skip tests by default but want the ability to re-enable tests from the command line, you need to go via a properties section in the pom:
2243

2344
```xml
24-
<settings>
25-
<servers>
26-
<server>
27-
<id>maven.oracle.com</id>
28-
<username>oracle_tech_net_user_name</username>
29-
<password>oracle_tech_net_password</password>
30-
<configuration>
31-
<basicAuthScope>
32-
<host>ANY</host>
33-
<port>ANY</port>
34-
<realm>OAM 11g</realm>
35-
</basicAuthScope>
36-
<httpConfiguration>
37-
<all>
38-
<params>
39-
<property>
40-
<name>http.protocol.allow-circular-redirects</name>
41-
<value>%b,true</value>
42-
</property>
43-
</params>
44-
</all>
45-
</httpConfiguration>
46-
</configuration>
47-
</server>
48-
</servers>
49-
</settings>
45+
<configuration>
46+
<skipUtplsqlTests>true</skipUtplsqlTests>
47+
</configuration>
5048
```
5149

52-
### Usage
50+
This will allow you to run with all tests disabled by default and to run them with this command:
51+
52+
mvn install -DskipTests=false
53+
54+
### Usage Example
5355

5456
Please refer to the following usage example for the parameters descriptions.
5557

@@ -81,7 +83,7 @@ Please refer to the following usage example for the parameters descriptions.
8183
<plugin>
8284
<groupId>org.utplsql</groupId>
8385
<artifactId>utplsql-maven-plugin</artifactId>
84-
<version>3.1.0</version>
86+
<version>3.1.5</version>
8587
<executions>
8688
<execution>
8789
<goals>
@@ -136,6 +138,10 @@ Please refer to the following usage example for the parameters descriptions.
136138
<!-- Defaults to: false -->
137139
<skipCompatibilityCheck>false</skipCompatibilityCheck>
138140

141+
<!-- Skip the tests -->
142+
<!-- Defaults to: false -->
143+
<skipUtplsqlTests>false</skipUtplsqlTests>
144+
139145
<!-- A list of tags to run. -->
140146
<tags>
141147
<tag>test_tag</tag>
@@ -229,7 +235,7 @@ More project samples are available in the src/test/resources directory:
229235
* **type-mapping-project:** this project shows how to use regex and custom type parameters together.
230236
* **owner-param-project:** this project demonstrates how to use sourcesOwner and testsOwner parameters.
231237

232-
### Comparaison with the CLI
238+
## Comparaison with the CLI
233239

234240
| CLI short parameter | CLI long parameter | maven XML path |
235241
| --- | --- | --- |

pom.xml

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

66
<groupId>org.utplsql</groupId>
77
<artifactId>utplsql-maven-plugin</artifactId>
8-
<version>3.2.0-SNAPSHOT</version>
8+
<version>3.1.5-SNAPSHOT</version>
99
<packaging>maven-plugin</packaging>
1010

1111
<name>utPLSQL Maven Plugin</name>

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

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package org.utplsql.maven.plugin;
22

3-
import java.io.File;
4-
import java.sql.Connection;
5-
import java.sql.SQLException;
6-
import java.util.ArrayList;
7-
import java.util.LinkedHashSet;
8-
import java.util.List;
9-
import java.util.Set;
10-
3+
import oracle.jdbc.pool.OracleDataSource;
114
import org.apache.commons.lang3.StringUtils;
125
import org.apache.maven.model.Resource;
136
import org.apache.maven.plugin.AbstractMojo;
@@ -34,12 +27,19 @@
3427
import org.utplsql.maven.plugin.model.ReporterParameter;
3528
import org.utplsql.maven.plugin.reporter.ReporterWriter;
3629

37-
import oracle.jdbc.pool.OracleDataSource;
30+
import java.io.File;
31+
import java.sql.Connection;
32+
import java.sql.SQLException;
33+
import java.util.ArrayList;
34+
import java.util.LinkedHashSet;
35+
import java.util.List;
36+
import java.util.Set;
3837

3938
/**
4039
* This class expose the {@link TestRunner} interface to Maven.
41-
*
40+
*
4241
* @author Alberto Hernández
42+
* @author Simon Martinelli
4343
*/
4444
@Mojo(name = "test", defaultPhase = LifecyclePhase.TEST)
4545
public class UtPLSQLMojo extends AbstractMojo {
@@ -116,7 +116,7 @@ public class UtPLSQLMojo extends AbstractMojo {
116116
private List<CustomTypeMapping> testsCustomTypeMapping;
117117

118118
@Parameter
119-
private Set<String> tags = new LinkedHashSet<>();
119+
private final Set<String> tags = new LinkedHashSet<>();
120120

121121
@Parameter
122122
private boolean randomTestOrder;
@@ -130,74 +130,80 @@ public class UtPLSQLMojo extends AbstractMojo {
130130
@Parameter(defaultValue = "${maven.test.failure.ignore}")
131131
protected boolean ignoreFailure;
132132

133+
@Parameter(defaultValue = "${skipUtplsqlTests}")
134+
protected boolean skipUtplsqlTests;
135+
133136
// Color in the console, bases on Maven logging configuration.
134-
private boolean colorConsole = MessageUtils.isColorEnabled();
137+
private final boolean colorConsole = MessageUtils.isColorEnabled();
135138

136139
private ReporterWriter reporterWriter;
137140

138-
private DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
141+
private final DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
139142

140143
/**
141144
* Executes the plugin.
142145
*/
143146
@Override
144147
public void execute() throws MojoExecutionException {
148+
if (skipUtplsqlTests) {
149+
getLog().debug("utPLSQLTests are skipped.");
150+
} else {
151+
getLog().debug("Java Api Version = " + JavaApiVersionInfo.getVersion());
152+
loadConfFromEnvironment();
145153

146-
getLog().debug("Java Api Version = " + JavaApiVersionInfo.getVersion());
147-
loadConfFromEnvironment();
148-
149-
Connection connection = null;
150-
try {
151-
FileMapperOptions sourceMappingOptions = buildSourcesOptions();
152-
FileMapperOptions testMappingOptions = buildTestsOptions();
153-
OracleDataSource ds = new OracleDataSource();
154-
ds.setURL(url);
155-
ds.setUser(user);
156-
ds.setPassword(password);
157-
connection = ds.getConnection();
158-
159-
Version utlVersion = this.databaseInformation.getUtPlsqlFrameworkVersion(connection);
160-
getLog().info("utPLSQL Version = " + utlVersion);
161-
162-
List<Reporter> reporterList = initReporters(connection, utlVersion, ReporterFactory.createEmpty());
163-
164-
logParameters(sourceMappingOptions, testMappingOptions, reporterList);
165-
166-
TestRunner runner = new TestRunner()
167-
.addPathList(paths)
168-
.addReporterList(reporterList)
169-
.sourceMappingOptions(sourceMappingOptions)
170-
.testMappingOptions(testMappingOptions)
171-
.skipCompatibilityCheck(skipCompatibilityCheck)
172-
.colorConsole(colorConsole)
173-
.addTags(tags)
174-
.randomTestOrder(randomTestOrder)
175-
.randomTestOrderSeed(randomTestOrderSeed)
176-
.failOnErrors(!ignoreFailure);
177-
178-
if (StringUtils.isNotBlank(excludeObject)) {
179-
runner.excludeObject(excludeObject);
180-
}
181-
if (StringUtils.isNotBlank(includeObject)) {
182-
runner.includeObject(includeObject);
183-
}
154+
Connection connection = null;
155+
try {
156+
FileMapperOptions sourceMappingOptions = buildSourcesOptions();
157+
FileMapperOptions testMappingOptions = buildTestsOptions();
158+
OracleDataSource ds = new OracleDataSource();
159+
ds.setURL(url);
160+
ds.setUser(user);
161+
ds.setPassword(password);
162+
connection = ds.getConnection();
163+
164+
Version utlVersion = this.databaseInformation.getUtPlsqlFrameworkVersion(connection);
165+
getLog().info("utPLSQL Version = " + utlVersion);
166+
167+
List<Reporter> reporterList = initReporters(connection, utlVersion, ReporterFactory.createEmpty());
168+
169+
logParameters(sourceMappingOptions, testMappingOptions, reporterList);
170+
171+
TestRunner runner = new TestRunner()
172+
.addPathList(paths)
173+
.addReporterList(reporterList)
174+
.sourceMappingOptions(sourceMappingOptions)
175+
.testMappingOptions(testMappingOptions)
176+
.skipCompatibilityCheck(skipCompatibilityCheck)
177+
.colorConsole(colorConsole)
178+
.addTags(tags)
179+
.randomTestOrder(randomTestOrder)
180+
.randomTestOrderSeed(randomTestOrderSeed)
181+
.failOnErrors(!ignoreFailure);
182+
183+
if (StringUtils.isNotBlank(excludeObject)) {
184+
runner.excludeObject(excludeObject);
185+
}
186+
if (StringUtils.isNotBlank(includeObject)) {
187+
runner.includeObject(includeObject);
188+
}
184189

185-
runner.run(connection);
190+
runner.run(connection);
186191

187-
} catch (SomeTestsFailedException e) {
188-
if (!this.ignoreFailure) {
192+
} catch (SomeTestsFailedException e) {
193+
if (!this.ignoreFailure) {
194+
throw new MojoExecutionException(e.getMessage(), e);
195+
}
196+
} catch (SQLException e) {
189197
throw new MojoExecutionException(e.getMessage(), e);
190-
}
191-
} catch (SQLException e) {
192-
throw new MojoExecutionException(e.getMessage(), e);
193-
} finally {
194-
try {
195-
if (null != connection) {
196-
reporterWriter.writeReporters(connection);
197-
connection.close();
198+
} finally {
199+
try {
200+
if (null != connection) {
201+
reporterWriter.writeReporters(connection);
202+
connection.close();
203+
}
204+
} catch (Exception e) {
205+
getLog().error(e.getMessage(), e);
198206
}
199-
} catch (Exception e) {
200-
getLog().error(e.getMessage(), e);
201207
}
202208
}
203209
}
@@ -206,11 +212,9 @@ private void loadConfFromEnvironment() {
206212
if (StringUtils.isEmpty(url)) {
207213
url = System.getProperty("dbUrl");
208214
}
209-
210215
if (StringUtils.isEmpty(user)) {
211216
user = System.getProperty("dbUser");
212217
}
213-
214218
if (StringUtils.isEmpty(password)) {
215219
password = System.getProperty("dbPass");
216220
}
@@ -223,7 +227,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
223227
if (defaultSourceDirectory.exists()) {
224228
sources.add(PluginDefault.buildDefaultSource());
225229
} else {
226-
return new FileMapperOptions(new ArrayList<String>());
230+
return new FileMapperOptions(new ArrayList<>());
227231
}
228232
}
229233

@@ -252,7 +256,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
252256
}
253257

254258
if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping.isEmpty()) {
255-
fileMapperOptions.setTypeMappings(new ArrayList<KeyValuePair>());
259+
fileMapperOptions.setTypeMappings(new ArrayList<>());
256260
for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) {
257261
fileMapperOptions.getTypeMappings()
258262
.add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType()));
@@ -274,7 +278,7 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
274278
if (defaultTestDirectory.exists()) {
275279
tests.add(PluginDefault.buildDefaultTest());
276280
} else {
277-
return new FileMapperOptions(new ArrayList<String>());
281+
return new FileMapperOptions(new ArrayList<>());
278282
}
279283
}
280284

@@ -303,7 +307,7 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
303307
}
304308

305309
if (testsCustomTypeMapping != null && !testsCustomTypeMapping.isEmpty()) {
306-
fileMapperOptions.setTypeMappings(new ArrayList<KeyValuePair>());
310+
fileMapperOptions.setTypeMappings(new ArrayList<>());
307311
for (CustomTypeMapping typeMapping : testsCustomTypeMapping) {
308312
fileMapperOptions.getTypeMappings()
309313
.add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType()));
@@ -336,8 +340,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
336340
reporter.init(connection);
337341
reporterList.add(reporter);
338342

339-
// Turns the console output on by default if both file and console output are
340-
// empty.
343+
// Turns the console output on by default if both file and console output are empty.
341344
if (!reporterParameter.isFileOutput() && null == reporterParameter.getConsoleOutput()) {
342345
reporterParameter.setConsoleOutput(true);
343346
}
@@ -352,7 +355,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
352355
}
353356

354357
private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions,
355-
List<Reporter> reporterList) {
358+
List<Reporter> reporterList) {
356359
Log log = getLog();
357360
log.info("Invoking TestRunner with: " + targetDir);
358361

@@ -361,11 +364,14 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt
361364
}
362365

363366
log.debug("Invoking TestRunner with: ");
367+
364368
log.debug("reporters=");
365369
reporterList.forEach((Reporter r) -> log.debug(r.getTypeName()));
370+
366371
log.debug("sources=");
367372
sourceMappingOptions.getFilePaths().forEach(log::debug);
373+
368374
log.debug("tests=");
369375
testMappingOptions.getFilePaths().forEach(log::debug);
370376
}
371-
}
377+
}

0 commit comments

Comments
 (0)