Skip to content

Commit 57209f6

Browse files
committed
Code cleanup
1 parent 4cc8421 commit 57209f6

File tree

7 files changed

+97
-131
lines changed

7 files changed

+97
-131
lines changed

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

Lines changed: 42 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
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)
4445
public 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
}

src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.utplsql.maven.plugin.helper;
22

3-
import java.util.Arrays;
4-
53
import org.apache.maven.model.Resource;
64

5+
import java.util.Collections;
6+
77
/**
88
* This class provides methods to retrieve the list of resources in the default
99
* {@literal <source> and <test>} directories.
@@ -57,7 +57,7 @@ public static Resource buildDefaultTest() {
5757
private static Resource buildDirectory(String directory, String includes) {
5858
Resource resource = new Resource();
5959
resource.setDirectory(directory);
60-
resource.setIncludes(Arrays.asList(includes));
60+
resource.setIncludes(Collections.singletonList(includes));
6161
return resource;
6262
}
6363
}

src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* This class is an enumeration of all the known reporter in {@code utPLSQL}.
7-
* It further more defines the default output file for each {@link Reporter}.
7+
* Furthermore, it defines the default output file for each {@link Reporter}.
88
* In case the output file is set to {@code -}, it will mean the stdout of the
99
* process.
1010
*
@@ -20,9 +20,9 @@ public enum ReporterDefault {
2020
UT_COVERAGE_SONAR_REPORTER("utplsql/coverage-sonar-reporter.xml"),
2121
UT_SONAR_TEST_REPORTER("utplsql/sonar-test-reporter.xml");
2222

23-
private String outputFile;
23+
private final String outputFile;
2424

25-
private ReporterDefault(String outputFile) {
25+
ReporterDefault(String outputFile) {
2626
this.outputFile = outputFile;
2727
}
2828

src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package org.utplsql.maven.plugin.helper;
22

3-
import static java.lang.String.format;
3+
import org.apache.maven.model.Resource;
4+
import org.codehaus.plexus.util.DirectoryScanner;
45

56
import java.io.File;
67
import java.util.ArrayList;
7-
import java.util.Arrays;
8+
import java.util.Collections;
89
import java.util.List;
910

10-
import org.apache.maven.model.Resource;
11-
import org.codehaus.plexus.util.DirectoryScanner;
11+
import static java.lang.String.format;
1212

1313
/**
1414
* Utility to scan all resources
15-
*
15+
*
1616
* @author Alberto Hernández
1717
*/
1818
public class SQLScannerHelper {
@@ -23,17 +23,15 @@ private SQLScannerHelper() {
2323

2424
/**
2525
* Scans a directory looking for the matching patterns.
26-
*
26+
*
2727
* @param baseDir the base directory
2828
* @param resources a list of resources
2929
* @param defaultDirectory the default search directory
3030
* @param defaultFilePattern the default file pattern
3131
* @return a list of the files found
3232
*/
33-
public static List<String> findSQLs(File baseDir, List<Resource> resources, String defaultDirectory,
34-
String defaultFilePattern) {
35-
36-
List<String> founds = new ArrayList<String>();
33+
public static List<String> findSQLs(File baseDir, List<Resource> resources, String defaultDirectory, String defaultFilePattern) {
34+
List<String> founds = new ArrayList<>();
3735

3836
for (Resource resource : resources) {
3937

@@ -52,7 +50,7 @@ public static List<String> findSQLs(File baseDir, List<Resource> resources, Stri
5250
founds.add(baseDir.toURI().relativize(new File(scanner.getBasedir(), basename).toURI()).getPath());
5351
}
5452

55-
founds.addAll(Arrays.asList());
53+
founds.addAll(Collections.emptyList());
5654
}
5755

5856
return founds;

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
package org.utplsql.maven.plugin.reporter;
22

3-
import static java.lang.String.format;
4-
5-
import java.io.File;
6-
import java.io.FileOutputStream;
7-
import java.io.IOException;
8-
import java.io.PrintStream;
9-
import java.sql.Connection;
10-
import java.util.ArrayList;
11-
import java.util.List;
12-
133
import org.apache.commons.lang3.tuple.Pair;
144
import org.apache.maven.plugin.MojoExecutionException;
155
import org.apache.maven.plugin.logging.Log;
@@ -20,15 +10,25 @@
2010
import org.utplsql.api.reporter.Reporter;
2111
import org.utplsql.maven.plugin.model.ReporterParameter;
2212

13+
import java.io.File;
14+
import java.io.FileOutputStream;
15+
import java.io.IOException;
16+
import java.io.PrintStream;
17+
import java.sql.Connection;
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
import static java.lang.String.format;
22+
2323
public class ReporterWriter {
2424

2525
private static final Log LOG = new SystemStreamLog();
2626

27-
private List<Pair<Reporter, ReporterParameter>> listReporters;
27+
private final List<Pair<Reporter, ReporterParameter>> listReporters;
2828

29-
private String outputDirectory;
29+
private final String outputDirectory;
3030

31-
private Version databaseVersion;
31+
private final Version databaseVersion;
3232

3333
/**
3434
* Constructor of the reporter writer.
@@ -109,6 +109,5 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
109109
}
110110
}
111111
}
112-
113112
}
114113
}

0 commit comments

Comments
 (0)