3939 * This class expose the {@link TestRunner} interface to Maven.
4040 *
4141 * @author Alberto Hernández
42+ * @author Simon Martinelli
4243 */
4344@ Mojo (name = "test" , defaultPhase = LifecyclePhase .TEST )
4445public class UtPLSQLMojo extends AbstractMojo {
@@ -115,7 +116,7 @@ public class UtPLSQLMojo extends AbstractMojo {
115116 private List <CustomTypeMapping > testsCustomTypeMapping ;
116117
117118 @ Parameter
118- private Set <String > tags = new LinkedHashSet <>();
119+ private final Set <String > tags = new LinkedHashSet <>();
119120
120121 @ Parameter
121122 private boolean randomTestOrder ;
@@ -129,22 +130,22 @@ public class UtPLSQLMojo extends AbstractMojo {
129130 @ Parameter (defaultValue = "${maven.test.failure.ignore}" )
130131 protected boolean ignoreFailure ;
131132
132- @ Parameter (defaultValue = "${skiptUtplsqlTests }" )
133- protected boolean skiptUtplsqlTests ;
133+ @ Parameter (defaultValue = "${skipUtplsqlTests }" )
134+ protected boolean skipUtplsqlTests ;
134135
135136 // Color in the console, bases on Maven logging configuration.
136- private boolean colorConsole = MessageUtils .isColorEnabled ();
137+ private final boolean colorConsole = MessageUtils .isColorEnabled ();
137138
138139 private ReporterWriter reporterWriter ;
139140
140- private DatabaseInformation databaseInformation = new DefaultDatabaseInformation ();
141+ private final DatabaseInformation databaseInformation = new DefaultDatabaseInformation ();
141142
142143 /**
143144 * Executes the plugin.
144145 */
145146 @ Override
146147 public void execute () throws MojoExecutionException {
147- if (skiptUtplsqlTests ) {
148+ if (skipUtplsqlTests ) {
148149 getLog ().debug ("utPLSQLTests are skipped." );
149150 } else {
150151 getLog ().debug ("Java Api Version = " + JavaApiVersionInfo .getVersion ());
@@ -211,11 +212,9 @@ private void loadConfFromEnvironment() {
211212 if (StringUtils .isEmpty (url )) {
212213 url = System .getProperty ("dbUrl" );
213214 }
214-
215215 if (StringUtils .isEmpty (user )) {
216216 user = System .getProperty ("dbUser" );
217217 }
218-
219218 if (StringUtils .isEmpty (password )) {
220219 password = System .getProperty ("dbPass" );
221220 }
@@ -234,37 +233,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
234233
235234 List <String > scripts = SQLScannerHelper .findSQLs (project .getBasedir (), sources ,
236235 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 );
268237
269238 } catch (Exception e ) {
270239 throw new MojoExecutionException ("Invalid <SOURCES> in your pom.xml" , e );
@@ -285,42 +254,46 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
285254
286255 List <String > scripts = SQLScannerHelper .findSQLs (project .getBasedir (), tests , PluginDefault .TEST_DIRECTORY ,
287256 PluginDefault .TEST_FILE_PATTERN );
288- FileMapperOptions fileMapperOptions = new FileMapperOptions (scripts );
257+ return createFileMapperOptions (scripts );
289258
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+ }
293262
294- if (StringUtils .isNotEmpty (testsRegexExpression )) {
295- fileMapperOptions .setRegexPattern (testsRegexExpression );
296- }
263+ }
297264
298- if (testsOwnerSubexpression != null ) {
299- fileMapperOptions .setOwnerSubExpression (testsOwnerSubexpression );
300- }
265+ private FileMapperOptions createFileMapperOptions (List <String > scripts ) {
266+ FileMapperOptions fileMapperOptions = new FileMapperOptions (scripts );
301267
302- if (testsNameSubexpression != null ) {
303- fileMapperOptions .setNameSubExpression ( testsNameSubexpression );
304- }
268+ if (StringUtils . isNotEmpty ( sourcesOwner ) ) {
269+ fileMapperOptions .setObjectOwner ( sourcesOwner );
270+ }
305271
306- if (testsTypeSubexpression != null ) {
307- fileMapperOptions .setTypeSubExpression ( testsTypeSubexpression );
308- }
272+ if (StringUtils . isNotEmpty ( sourcesRegexExpression ) ) {
273+ fileMapperOptions .setRegexPattern ( sourcesRegexExpression );
274+ }
309275
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+ }
317279
318- return fileMapperOptions ;
280+ if (sourcesNameSubexpression != null ) {
281+ fileMapperOptions .setNameSubExpression (sourcesNameSubexpression );
282+ }
319283
320- } catch ( Exception e ) {
321- throw new MojoExecutionException ( "Invalid <TESTS> in your pom.xml: " + e . getMessage () );
284+ if ( sourcesTypeSubexpression != null ) {
285+ fileMapperOptions . setTypeSubExpression ( sourcesTypeSubexpression );
322286 }
323287
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 ;
324297 }
325298
326299 private List <Reporter > initReporters (Connection connection , Version utlVersion , ReporterFactory reporterFactory )
@@ -341,8 +314,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
341314 reporter .init (connection );
342315 reporterList .add (reporter );
343316
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.
346318 if (!reporterParameter .isFileOutput () && null == reporterParameter .getConsoleOutput ()) {
347319 reporterParameter .setConsoleOutput (true );
348320 }
@@ -366,10 +338,13 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt
366338 }
367339
368340 log .debug ("Invoking TestRunner with: " );
341+
369342 log .debug ("reporters=" );
370343 reporterList .forEach ((Reporter r ) -> log .debug (r .getTypeName ()));
344+
371345 log .debug ("sources=" );
372346 sourceMappingOptions .getFilePaths ().forEach (log ::debug );
347+
373348 log .debug ("tests=" );
374349 testMappingOptions .getFilePaths ().forEach (log ::debug );
375350 }
0 commit comments