1
1
package org .utplsql .maven .plugin ;
2
2
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 ;
11
4
import org .apache .commons .lang3 .StringUtils ;
12
5
import org .apache .maven .model .Resource ;
13
6
import org .apache .maven .plugin .AbstractMojo ;
34
27
import org .utplsql .maven .plugin .model .ReporterParameter ;
35
28
import org .utplsql .maven .plugin .reporter .ReporterWriter ;
36
29
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 ;
38
37
39
38
/**
40
39
* This class expose the {@link TestRunner} interface to Maven.
41
- *
40
+ *
42
41
* @author Alberto Hernández
43
42
*/
44
43
@ Mojo (name = "test" , defaultPhase = LifecyclePhase .TEST )
@@ -130,6 +129,9 @@ public class UtPLSQLMojo extends AbstractMojo {
130
129
@ Parameter (defaultValue = "${maven.test.failure.ignore}" )
131
130
protected boolean ignoreFailure ;
132
131
132
+ @ Parameter (defaultValue = "${skiptUtplsqlTests}" )
133
+ protected boolean skiptUtplsqlTests ;
134
+
133
135
// Color in the console, bases on Maven logging configuration.
134
136
private boolean colorConsole = MessageUtils .isColorEnabled ();
135
137
@@ -142,62 +144,65 @@ public class UtPLSQLMojo extends AbstractMojo {
142
144
*/
143
145
@ Override
144
146
public void execute () throws MojoExecutionException {
147
+ if (skiptUtplsqlTests ) {
148
+ getLog ().debug ("utPLSQLTests are skipped." );
149
+ } else {
150
+ getLog ().debug ("Java Api Version = " + JavaApiVersionInfo .getVersion ());
151
+ loadConfFromEnvironment ();
145
152
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
- }
153
+ Connection connection = null ;
154
+ try {
155
+ FileMapperOptions sourceMappingOptions = buildSourcesOptions ();
156
+ FileMapperOptions testMappingOptions = buildTestsOptions ();
157
+ OracleDataSource ds = new OracleDataSource ();
158
+ ds .setURL (url );
159
+ ds .setUser (user );
160
+ ds .setPassword (password );
161
+ connection = ds .getConnection ();
162
+
163
+ Version utlVersion = this .databaseInformation .getUtPlsqlFrameworkVersion (connection );
164
+ getLog ().info ("utPLSQL Version = " + utlVersion );
165
+
166
+ List <Reporter > reporterList = initReporters (connection , utlVersion , ReporterFactory .createEmpty ());
167
+
168
+ logParameters (sourceMappingOptions , testMappingOptions , reporterList );
169
+
170
+ TestRunner runner = new TestRunner ()
171
+ .addPathList (paths )
172
+ .addReporterList (reporterList )
173
+ .sourceMappingOptions (sourceMappingOptions )
174
+ .testMappingOptions (testMappingOptions )
175
+ .skipCompatibilityCheck (skipCompatibilityCheck )
176
+ .colorConsole (colorConsole )
177
+ .addTags (tags )
178
+ .randomTestOrder (randomTestOrder )
179
+ .randomTestOrderSeed (randomTestOrderSeed )
180
+ .failOnErrors (!ignoreFailure );
181
+
182
+ if (StringUtils .isNotBlank (excludeObject )) {
183
+ runner .excludeObject (excludeObject );
184
+ }
185
+ if (StringUtils .isNotBlank (includeObject )) {
186
+ runner .includeObject (includeObject );
187
+ }
184
188
185
- runner .run (connection );
189
+ runner .run (connection );
186
190
187
- } catch (SomeTestsFailedException e ) {
188
- if (!this .ignoreFailure ) {
191
+ } catch (SomeTestsFailedException e ) {
192
+ if (!this .ignoreFailure ) {
193
+ throw new MojoExecutionException (e .getMessage (), e );
194
+ }
195
+ } catch (SQLException e ) {
189
196
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 ( );
197
+ } finally {
198
+ try {
199
+ if ( null != connection ) {
200
+ reporterWriter . writeReporters ( connection );
201
+ connection . close ();
202
+ }
203
+ } catch ( Exception e ) {
204
+ getLog (). error ( e . getMessage (), e );
198
205
}
199
- } catch (Exception e ) {
200
- getLog ().error (e .getMessage (), e );
201
206
}
202
207
}
203
208
}
@@ -223,7 +228,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
223
228
if (defaultSourceDirectory .exists ()) {
224
229
sources .add (PluginDefault .buildDefaultSource ());
225
230
} else {
226
- return new FileMapperOptions (new ArrayList <String >());
231
+ return new FileMapperOptions (new ArrayList <>());
227
232
}
228
233
}
229
234
@@ -252,7 +257,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
252
257
}
253
258
254
259
if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping .isEmpty ()) {
255
- fileMapperOptions .setTypeMappings (new ArrayList <KeyValuePair >());
260
+ fileMapperOptions .setTypeMappings (new ArrayList <>());
256
261
for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping ) {
257
262
fileMapperOptions .getTypeMappings ()
258
263
.add (new KeyValuePair (typeMapping .getCustomMapping (), typeMapping .getType ()));
@@ -274,7 +279,7 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
274
279
if (defaultTestDirectory .exists ()) {
275
280
tests .add (PluginDefault .buildDefaultTest ());
276
281
} else {
277
- return new FileMapperOptions (new ArrayList <String >());
282
+ return new FileMapperOptions (new ArrayList <>());
278
283
}
279
284
}
280
285
@@ -303,7 +308,7 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
303
308
}
304
309
305
310
if (testsCustomTypeMapping != null && !testsCustomTypeMapping .isEmpty ()) {
306
- fileMapperOptions .setTypeMappings (new ArrayList <KeyValuePair >());
311
+ fileMapperOptions .setTypeMappings (new ArrayList <>());
307
312
for (CustomTypeMapping typeMapping : testsCustomTypeMapping ) {
308
313
fileMapperOptions .getTypeMappings ()
309
314
.add (new KeyValuePair (typeMapping .getCustomMapping (), typeMapping .getType ()));
@@ -352,7 +357,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
352
357
}
353
358
354
359
private void logParameters (FileMapperOptions sourceMappingOptions , FileMapperOptions testMappingOptions ,
355
- List <Reporter > reporterList ) {
360
+ List <Reporter > reporterList ) {
356
361
Log log = getLog ();
357
362
log .info ("Invoking TestRunner with: " + targetDir );
358
363
@@ -368,4 +373,4 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt
368
373
log .debug ("tests=" );
369
374
testMappingOptions .getFilePaths ().forEach (log ::debug );
370
375
}
371
- }
376
+ }
0 commit comments