Skip to content

Commit 7157a4b

Browse files
committed
Code clean up
1 parent 12e57f9 commit 7157a4b

4 files changed

Lines changed: 44 additions & 70 deletions

File tree

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
<plugin>
248248
<groupId>org.apache.maven.plugins</groupId>
249249
<artifactId>maven-javadoc-plugin</artifactId>
250-
<version>3.1.1</version>
250+
<version>3.3.1</version>
251251
<executions>
252252
<execution>
253253
<id>attach-javadocs</id>
@@ -274,7 +274,7 @@
274274
<plugin>
275275
<groupId>org.apache.maven.plugins</groupId>
276276
<artifactId>maven-gpg-plugin</artifactId>
277-
<version>1.6</version>
277+
<version>3.0.1</version>
278278
<executions>
279279
<execution>
280280
<id>sign-artifacts</id>

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

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public class UtPLSQLMojo extends AbstractMojo {
6767
protected boolean skipCompatibilityCheck;
6868

6969
@Parameter
70-
protected List<ReporterParameter> reporters = new ArrayList<>();
70+
protected final List<ReporterParameter> reporters = new ArrayList<>();
7171

7272
@Parameter
73-
protected List<String> paths = new ArrayList<>();
73+
protected final List<String> paths = new ArrayList<>();
7474

7575
// Sources Configuration
7676
@Parameter
77-
protected List<Resource> sources = new ArrayList<>();
77+
protected final List<Resource> sources = new ArrayList<>();
7878

7979
@Parameter
8080
private String sourcesOwner;
@@ -96,7 +96,7 @@ public class UtPLSQLMojo extends AbstractMojo {
9696

9797
// Tests Configuration
9898
@Parameter
99-
protected List<Resource> tests = new ArrayList<>();
99+
protected final List<Resource> tests = new ArrayList<>();
100100

101101
@Parameter
102102
private String testsOwner;
@@ -244,37 +244,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
244244

245245
List<String> scripts = SQLScannerHelper.findSQLs(project.getBasedir(), sources,
246246
PluginDefault.SOURCE_DIRECTORY, PluginDefault.SOURCE_FILE_PATTERN);
247-
FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts);
248-
249-
if (StringUtils.isNotEmpty(sourcesOwner)) {
250-
fileMapperOptions.setObjectOwner(sourcesOwner);
251-
}
252-
253-
if (StringUtils.isNotEmpty(sourcesRegexExpression)) {
254-
fileMapperOptions.setRegexPattern(sourcesRegexExpression);
255-
}
256-
257-
if (sourcesOwnerSubexpression != null) {
258-
fileMapperOptions.setOwnerSubExpression(sourcesOwnerSubexpression);
259-
}
260-
261-
if (sourcesNameSubexpression != null) {
262-
fileMapperOptions.setNameSubExpression(sourcesNameSubexpression);
263-
}
264-
265-
if (sourcesTypeSubexpression != null) {
266-
fileMapperOptions.setTypeSubExpression(sourcesTypeSubexpression);
267-
}
268-
269-
if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping.isEmpty()) {
270-
fileMapperOptions.setTypeMappings(new ArrayList<>());
271-
for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) {
272-
fileMapperOptions.getTypeMappings()
273-
.add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType()));
274-
}
275-
}
276-
277-
return fileMapperOptions;
247+
return createFileMapperOptions(scripts, sourcesOwner, sourcesRegexExpression, sourcesOwnerSubexpression, sourcesNameSubexpression, sourcesTypeSubexpression, sourcesCustomTypeMapping);
278248

279249
} catch (Exception e) {
280250
throw new MojoExecutionException("Invalid <SOURCES> in your pom.xml", e);
@@ -295,42 +265,49 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
295265

296266
List<String> scripts = SQLScannerHelper.findSQLs(project.getBasedir(), tests, PluginDefault.TEST_DIRECTORY,
297267
PluginDefault.TEST_FILE_PATTERN);
298-
FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts);
268+
return createFileMapperOptions(scripts, testsOwner, testsRegexExpression, testsOwnerSubexpression,
269+
testsNameSubexpression, testsTypeSubexpression, testsCustomTypeMapping);
299270

300-
if (StringUtils.isNotEmpty(testsOwner)) {
301-
fileMapperOptions.setObjectOwner(testsOwner);
302-
}
271+
} catch (Exception e) {
272+
throw new MojoExecutionException("Invalid <TESTS> in your pom.xml: " + e.getMessage());
273+
}
303274

304-
if (StringUtils.isNotEmpty(testsRegexExpression)) {
305-
fileMapperOptions.setRegexPattern(testsRegexExpression);
306-
}
275+
}
307276

308-
if (testsOwnerSubexpression != null) {
309-
fileMapperOptions.setOwnerSubExpression(testsOwnerSubexpression);
310-
}
277+
private FileMapperOptions createFileMapperOptions(List<String> scripts, String objectOwner, String regexPattern,
278+
Integer ownerSubExpression, Integer nameSubExpression,
279+
Integer typeSubExpression, List<CustomTypeMapping> typeMappings) {
280+
FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts);
311281

312-
if (testsNameSubexpression != null) {
313-
fileMapperOptions.setNameSubExpression(testsNameSubexpression);
314-
}
282+
if (StringUtils.isNotEmpty(objectOwner)) {
283+
fileMapperOptions.setObjectOwner(objectOwner);
284+
}
315285

316-
if (testsTypeSubexpression != null) {
317-
fileMapperOptions.setTypeSubExpression(testsTypeSubexpression);
318-
}
286+
if (StringUtils.isNotEmpty(regexPattern)) {
287+
fileMapperOptions.setRegexPattern(regexPattern);
288+
}
319289

320-
if (testsCustomTypeMapping != null && !testsCustomTypeMapping.isEmpty()) {
321-
fileMapperOptions.setTypeMappings(new ArrayList<>());
322-
for (CustomTypeMapping typeMapping : testsCustomTypeMapping) {
323-
fileMapperOptions.getTypeMappings()
324-
.add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType()));
325-
}
326-
}
290+
if (ownerSubExpression != null) {
291+
fileMapperOptions.setOwnerSubExpression(ownerSubExpression);
292+
}
327293

328-
return fileMapperOptions;
294+
if (nameSubExpression != null) {
295+
fileMapperOptions.setNameSubExpression(nameSubExpression);
296+
}
329297

330-
} catch (Exception e) {
331-
throw new MojoExecutionException("Invalid <TESTS> in your pom.xml: " + e.getMessage());
298+
if (typeSubExpression != null) {
299+
fileMapperOptions.setTypeSubExpression(typeSubExpression);
300+
}
301+
302+
if (typeMappings != null && !typeMappings.isEmpty()) {
303+
fileMapperOptions.setTypeMappings(new ArrayList<>());
304+
for (CustomTypeMapping typeMapping : typeMappings) {
305+
fileMapperOptions.getTypeMappings()
306+
.add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType()));
307+
}
332308
}
333309

310+
return fileMapperOptions;
334311
}
335312

336313
private List<Reporter> initReporters(Connection connection, Version utlVersion, ReporterFactory reporterFactory)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.apache.commons.lang3.tuple.Pair;
44
import org.apache.maven.plugin.MojoExecutionException;
55
import org.apache.maven.plugin.logging.Log;
6-
import org.apache.maven.plugin.logging.SystemStreamLog;
76
import org.utplsql.api.Version;
87
import org.utplsql.api.outputBuffer.OutputBuffer;
98
import org.utplsql.api.outputBuffer.OutputBufferProvider;

‎src/test/java/org/utplsql/maven/plugin/UtPLSQLMojoTest.java‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.junit.Before;
88
import org.junit.Rule;
99
import org.junit.Test;
10-
import org.junit.rules.ExpectedException;
1110
import org.junit.runner.RunWith;
1211
import org.mockito.Mock;
1312
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -18,7 +17,6 @@
1817
import org.utplsql.api.Version;
1918
import org.utplsql.api.reporter.Reporter;
2019
import org.utplsql.api.reporter.ReporterFactory;
21-
import org.utplsql.maven.plugin.UtPLSQLMojo;
2220
import org.utplsql.maven.plugin.model.ReporterParameter;
2321
import org.utplsql.maven.plugin.reporter.ReporterWriter;
2422

@@ -45,7 +43,7 @@
4543
public class UtPLSQLMojoTest {
4644

4745
@Rule
48-
public MojoRule rule = new MojoRule();
46+
public final MojoRule rule = new MojoRule();
4947

5048
@Mock
5149
public Connection mockConnection;
@@ -69,7 +67,7 @@ public void setUp() throws Exception {
6967
* testInvalidSourcesDirectory.
7068
* <p>
7169
* Given : a pom.xml with invalid sources' directory
72-
* When : pom is read andbuildSourcesOptions is run
70+
* When : pom is read and buildSourcesOptions is run
7371
* Then : it should throw a MojoExecutionException
7472
*/
7573
@Test
@@ -275,8 +273,8 @@ public void testDefaultConsoleBehaviour() throws Exception {
275273
}
276274

277275
// Assert that we added only the necessary reporters to the writer.
278-
ReporterWriter reporterWritter = Whitebox.getInternalState(utplsqlMojo, "reporterWriter");
279-
List<Pair<Reporter, ReporterParameter>> listReporters = Whitebox.getInternalState(reporterWritter, "listReporters");
276+
ReporterWriter reporterWriter = Whitebox.getInternalState(utplsqlMojo, "reporterWriter");
277+
List<Pair<Reporter, ReporterParameter>> listReporters = Whitebox.getInternalState(reporterWriter, "listReporters");
280278
assertEquals(3, listReporters.size());
281279

282280
ReporterParameter reporterParameter1 = listReporters.get(0).getRight();

0 commit comments

Comments
 (0)