Skip to content

Commit da9e28a

Browse files
author
ahernandez
committed
Refactor code to package org.utplsql.maven.plugin
Fix for #6, in order to pass the DB credentials from command line
1 parent 0072f47 commit da9e28a

File tree

9 files changed

+57
-33
lines changed

9 files changed

+57
-33
lines changed

utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java renamed to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql;
1+
package org.utplsql.maven.plugin;
22

33
import static java.lang.String.format;
44

@@ -23,10 +23,10 @@
2323
import org.utplsql.api.exception.SomeTestsFailedException;
2424
import org.utplsql.api.reporter.Reporter;
2525
import org.utplsql.api.reporter.ReporterFactory;
26-
import org.utplsql.helper.PluginDefault;
27-
import org.utplsql.helper.SQLScannerHelper;
28-
import org.utplsql.model.ReporterParameter;
29-
import org.utplsql.reporter.ReporterWriter;
26+
import org.utplsql.maven.plugin.helper.PluginDefault;
27+
import org.utplsql.maven.plugin.helper.SQLScannerHelper;
28+
import org.utplsql.maven.plugin.model.ReporterParameter;
29+
import org.utplsql.maven.plugin.reporter.ReporterWriter;
3030

3131
/**
3232
* This class expose the {@link TestRunner} interface to Maven.
@@ -37,41 +37,42 @@
3737
@Mojo(name = "test", defaultPhase = LifecyclePhase.TEST)
3838
public class UtPLSQLMojo extends AbstractMojo
3939
{
40-
@Parameter(defaultValue = "${dbUrl}")
41-
private String url;
40+
@Parameter(property = "dbUrl")
41+
protected String url;
4242

43-
@Parameter(defaultValue = "${dbUser}")
44-
private String user;
43+
@Parameter(property = "dbUser")
44+
protected String user;
4545

46-
@Parameter(defaultValue = "${dbPass}")
47-
private String password;
46+
@Parameter(property = "dbPass")
47+
protected String password;
4848

4949
@Parameter
50-
private String includeObject;
50+
protected String includeObject;
5151

5252
@Parameter
53-
private String excludeObject;
53+
protected String excludeObject;
5454

5555
@Parameter(defaultValue = "false")
56-
private boolean skipCompatibilityCheck;
56+
protected boolean skipCompatibilityCheck;
5757

5858
@Parameter
59-
private List<ReporterParameter> reporters;
59+
protected List<ReporterParameter> reporters;
6060

6161
@Parameter(defaultValue = "")
62-
private List<String> paths;
62+
protected List<String> paths;
6363

6464
@Parameter
65-
private List<Resource> sources = new ArrayList<>();
65+
protected List<Resource> sources = new ArrayList<>();
6666

6767
@Parameter
68-
private List<Resource> tests = new ArrayList<>();
68+
protected List<Resource> tests = new ArrayList<>();
6969

7070
@Parameter(defaultValue = "${project.build.directory}", readonly = true)
71-
private String targetDir;
71+
protected String targetDir;
7272

7373
@Parameter(defaultValue = "${maven.test.failure.ignore}")
74-
private boolean ignoreFailure;
74+
protected boolean ignoreFailure;
75+
7576

7677
// Color in the console, loaded by environment variables
7778
private boolean colorConsole = PluginDefault.resolveColor();
@@ -87,6 +88,8 @@ public class UtPLSQLMojo extends AbstractMojo
8788
@Override
8889
public void execute() throws MojoExecutionException
8990
{
91+
loadDefaultCredentials();
92+
9093
Connection connection = null;
9194
try
9295
{
@@ -137,14 +140,32 @@ public void execute() throws MojoExecutionException
137140
try
138141
{
139142
// Write Reporters
140-
reporterWriter.writeReporters(connection);
143+
if (connection != null)
144+
reporterWriter.writeReporters(connection);
141145
}
142146
catch (Exception e)
143147
{
144148
getLog().error(e.getMessage(), e);
145149
}
146150
}
147151
}
152+
153+
/**
154+
* Load
155+
*
156+
*/
157+
private void loadDefaultCredentials ()
158+
{
159+
if (StringUtils.isEmpty(user))
160+
{
161+
user = System.getProperty("dbUser");
162+
}
163+
164+
if (StringUtils.isEmpty(password))
165+
{
166+
password = System.getProperty("dbPass");
167+
}
168+
}
148169

149170
/**
150171
*

utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java renamed to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql.helper;
1+
package org.utplsql.maven.plugin.helper;
22

33
import java.util.Arrays;
44
import java.util.Map;

utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java renamed to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql.helper;
1+
package org.utplsql.maven.plugin.helper;
22

33
import org.utplsql.api.reporter.Reporter;
44

utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java renamed to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql.helper;
1+
package org.utplsql.maven.plugin.helper;
22

33
import static java.lang.String.format;
44

utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java renamed to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql.model;
1+
package org.utplsql.maven.plugin.model;
22

33
import org.codehaus.plexus.util.StringUtils;
44

utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java renamed to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql.reporter;
1+
package org.utplsql.maven.plugin.reporter;
22

33
import static java.lang.String.format;
44

@@ -18,7 +18,7 @@
1818
import org.utplsql.api.outputBuffer.OutputBuffer;
1919
import org.utplsql.api.outputBuffer.OutputBufferProvider;
2020
import org.utplsql.api.reporter.Reporter;
21-
import org.utplsql.model.ReporterParameter;
21+
import org.utplsql.maven.plugin.model.ReporterParameter;
2222

2323
public class ReporterWriter
2424
{

utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java renamed to utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package org.utpsql.test;
1+
package org.utpsql.maven.plugin.test;
22

33
import java.io.File;
44

55
import org.apache.maven.plugin.testing.MojoRule;
66
import org.junit.Assert;
77
import org.junit.Rule;
88
import org.junit.Test;
9-
import org.utplsql.UtPLSQLMojo;
9+
import org.utplsql.maven.plugin.UtPLSQLMojo;
1010

1111
public class UtPLSQLMojoTest
1212
{

utplsql-maven-plugin/src/test/resources/pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
<properties>
1414
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
15-
<dbUser>ut3</dbUser>
15+
16+
<!--
17+
<dbUser>ut3</dbUser>
1618
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
17-
</properties>
19+
-->
20+
</properties>
1821

1922
<build>
2023
<directory>../../../target/test-classes</directory>

utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS
2+
-- %suite(TEST_PKG_TEST_ME)
3+
-- %suitepath(plsql.examples)
24
--
35
-- This package shows all the possibilities to unit test
46
-- your PL/SQL package. NOTE that it is not limited to
@@ -10,8 +12,6 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS
1012
* This two parameters are used by the test framework in
1113
* order to identify the test suite to run
1214
*/
13-
-- %suite(plsql)
14-
-- %suitepath(plsql.examples)
1515

1616
/*
1717
* This method is invoked once before any other method.

0 commit comments

Comments
 (0)