39
39
* This class expose the {@link TestRunner} interface to Maven.
40
40
*
41
41
* @author Alberto Hernández
42
+ * @author Simon Martinelli
42
43
*/
43
44
@ Mojo (name = "test" , defaultPhase = LifecyclePhase .TEST )
44
45
public class UtPLSQLMojo extends AbstractMojo {
@@ -115,7 +116,7 @@ public class UtPLSQLMojo extends AbstractMojo {
115
116
private List <CustomTypeMapping > testsCustomTypeMapping ;
116
117
117
118
@ Parameter
118
- private Set <String > tags = new LinkedHashSet <>();
119
+ private final Set <String > tags = new LinkedHashSet <>();
119
120
120
121
@ Parameter
121
122
private boolean randomTestOrder ;
@@ -129,22 +130,22 @@ public class UtPLSQLMojo extends AbstractMojo {
129
130
@ Parameter (defaultValue = "${maven.test.failure.ignore}" )
130
131
protected boolean ignoreFailure ;
131
132
132
- @ Parameter (defaultValue = "${skiptUtplsqlTests }" )
133
- protected boolean skiptUtplsqlTests ;
133
+ @ Parameter (defaultValue = "${skipUtplsqlTests }" )
134
+ protected boolean skipUtplsqlTests ;
134
135
135
136
// Color in the console, bases on Maven logging configuration.
136
- private boolean colorConsole = MessageUtils .isColorEnabled ();
137
+ private final boolean colorConsole = MessageUtils .isColorEnabled ();
137
138
138
139
private ReporterWriter reporterWriter ;
139
140
140
- private DatabaseInformation databaseInformation = new DefaultDatabaseInformation ();
141
+ private final DatabaseInformation databaseInformation = new DefaultDatabaseInformation ();
141
142
142
143
/**
143
144
* Executes the plugin.
144
145
*/
145
146
@ Override
146
147
public void execute () throws MojoExecutionException {
147
- if (skiptUtplsqlTests ) {
148
+ if (skipUtplsqlTests ) {
148
149
getLog ().debug ("utPLSQLTests are skipped." );
149
150
} else {
150
151
getLog ().debug ("Java Api Version = " + JavaApiVersionInfo .getVersion ());
@@ -211,11 +212,9 @@ private void loadConfFromEnvironment() {
211
212
if (StringUtils .isEmpty (url )) {
212
213
url = System .getProperty ("dbUrl" );
213
214
}
214
-
215
215
if (StringUtils .isEmpty (user )) {
216
216
user = System .getProperty ("dbUser" );
217
217
}
218
-
219
218
if (StringUtils .isEmpty (password )) {
220
219
password = System .getProperty ("dbPass" );
221
220
}
@@ -234,37 +233,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
234
233
235
234
List <String > scripts = SQLScannerHelper .findSQLs (project .getBasedir (), sources ,
236
235
PluginDefault .SOURCE_DIRECTORY , PluginDefault .SOURCE_FILE_PATTERN );
237
- FileMapperOptions fileMapperOptions = new FileMapperOptions (scripts );
238
-
239
- if (StringUtils .isNotEmpty (sourcesOwner )) {
240
- fileMapperOptions .setObjectOwner (sourcesOwner );
241
- }
242
-
243
- if (StringUtils .isNotEmpty (sourcesRegexExpression )) {
244
- fileMapperOptions .setRegexPattern (sourcesRegexExpression );
245
- }
246
-
247
- if (sourcesOwnerSubexpression != null ) {
248
- fileMapperOptions .setOwnerSubExpression (sourcesOwnerSubexpression );
249
- }
250
-
251
- if (sourcesNameSubexpression != null ) {
252
- fileMapperOptions .setNameSubExpression (sourcesNameSubexpression );
253
- }
254
-
255
- if (sourcesTypeSubexpression != null ) {
256
- fileMapperOptions .setTypeSubExpression (sourcesTypeSubexpression );
257
- }
258
-
259
- if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping .isEmpty ()) {
260
- fileMapperOptions .setTypeMappings (new ArrayList <>());
261
- for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping ) {
262
- fileMapperOptions .getTypeMappings ()
263
- .add (new KeyValuePair (typeMapping .getCustomMapping (), typeMapping .getType ()));
264
- }
265
- }
266
-
267
- return fileMapperOptions ;
236
+ return createFileMapperOptions (scripts );
268
237
269
238
} catch (Exception e ) {
270
239
throw new MojoExecutionException ("Invalid <SOURCES> in your pom.xml" , e );
@@ -285,42 +254,46 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
285
254
286
255
List <String > scripts = SQLScannerHelper .findSQLs (project .getBasedir (), tests , PluginDefault .TEST_DIRECTORY ,
287
256
PluginDefault .TEST_FILE_PATTERN );
288
- FileMapperOptions fileMapperOptions = new FileMapperOptions (scripts );
257
+ return createFileMapperOptions (scripts );
289
258
290
- if ( StringUtils . isNotEmpty ( testsOwner ) ) {
291
- fileMapperOptions . setObjectOwner ( testsOwner );
292
- }
259
+ } catch ( Exception e ) {
260
+ throw new MojoExecutionException ( "Invalid <TESTS> in your pom.xml: " + e . getMessage () );
261
+ }
293
262
294
- if (StringUtils .isNotEmpty (testsRegexExpression )) {
295
- fileMapperOptions .setRegexPattern (testsRegexExpression );
296
- }
263
+ }
297
264
298
- if (testsOwnerSubexpression != null ) {
299
- fileMapperOptions .setOwnerSubExpression (testsOwnerSubexpression );
300
- }
265
+ private FileMapperOptions createFileMapperOptions (List <String > scripts ) {
266
+ FileMapperOptions fileMapperOptions = new FileMapperOptions (scripts );
301
267
302
- if (testsNameSubexpression != null ) {
303
- fileMapperOptions .setNameSubExpression ( testsNameSubexpression );
304
- }
268
+ if (StringUtils . isNotEmpty ( sourcesOwner ) ) {
269
+ fileMapperOptions .setObjectOwner ( sourcesOwner );
270
+ }
305
271
306
- if (testsTypeSubexpression != null ) {
307
- fileMapperOptions .setTypeSubExpression ( testsTypeSubexpression );
308
- }
272
+ if (StringUtils . isNotEmpty ( sourcesRegexExpression ) ) {
273
+ fileMapperOptions .setRegexPattern ( sourcesRegexExpression );
274
+ }
309
275
310
- if (testsCustomTypeMapping != null && !testsCustomTypeMapping .isEmpty ()) {
311
- fileMapperOptions .setTypeMappings (new ArrayList <>());
312
- for (CustomTypeMapping typeMapping : testsCustomTypeMapping ) {
313
- fileMapperOptions .getTypeMappings ()
314
- .add (new KeyValuePair (typeMapping .getCustomMapping (), typeMapping .getType ()));
315
- }
316
- }
276
+ if (sourcesOwnerSubexpression != null ) {
277
+ fileMapperOptions .setOwnerSubExpression (sourcesOwnerSubexpression );
278
+ }
317
279
318
- return fileMapperOptions ;
280
+ if (sourcesNameSubexpression != null ) {
281
+ fileMapperOptions .setNameSubExpression (sourcesNameSubexpression );
282
+ }
319
283
320
- } catch ( Exception e ) {
321
- throw new MojoExecutionException ( "Invalid <TESTS> in your pom.xml: " + e . getMessage () );
284
+ if ( sourcesTypeSubexpression != null ) {
285
+ fileMapperOptions . setTypeSubExpression ( sourcesTypeSubexpression );
322
286
}
323
287
288
+ if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping .isEmpty ()) {
289
+ fileMapperOptions .setTypeMappings (new ArrayList <>());
290
+ for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping ) {
291
+ fileMapperOptions .getTypeMappings ()
292
+ .add (new KeyValuePair (typeMapping .getCustomMapping (), typeMapping .getType ()));
293
+ }
294
+ }
295
+
296
+ return fileMapperOptions ;
324
297
}
325
298
326
299
private List <Reporter > initReporters (Connection connection , Version utlVersion , ReporterFactory reporterFactory )
@@ -341,8 +314,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
341
314
reporter .init (connection );
342
315
reporterList .add (reporter );
343
316
344
- // Turns the console output on by default if both file and console output are
345
- // empty.
317
+ // Turns the console output on by default if both file and console output are empty.
346
318
if (!reporterParameter .isFileOutput () && null == reporterParameter .getConsoleOutput ()) {
347
319
reporterParameter .setConsoleOutput (true );
348
320
}
@@ -366,10 +338,13 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt
366
338
}
367
339
368
340
log .debug ("Invoking TestRunner with: " );
341
+
369
342
log .debug ("reporters=" );
370
343
reporterList .forEach ((Reporter r ) -> log .debug (r .getTypeName ()));
344
+
371
345
log .debug ("sources=" );
372
346
sourceMappingOptions .getFilePaths ().forEach (log ::debug );
347
+
373
348
log .debug ("tests=" );
374
349
testMappingOptions .getFilePaths ().forEach (log ::debug );
375
350
}
0 commit comments