diff --git a/src/main/java/io/github/utplsql/api/TestRunner.java b/src/main/java/io/github/utplsql/api/TestRunner.java index 7bdc4e0..c904093 100644 --- a/src/main/java/io/github/utplsql/api/TestRunner.java +++ b/src/main/java/io/github/utplsql/api/TestRunner.java @@ -28,7 +28,7 @@ public TestRunner addPath(String path) { } public TestRunner addPathList(List paths) { - this.pathList.addAll(paths); + if (pathList != null) this.pathList.addAll(paths); return this; } @@ -43,7 +43,7 @@ public TestRunner colorConsole(boolean colorConsole) { } public TestRunner addReporterList(List reporterList) { - this.reporterList.addAll(reporterList); + if (reporterList != null) this.reporterList.addAll(reporterList); return this; } @@ -53,12 +53,12 @@ public TestRunner addCoverageScheme(String coverageScheme) { } public TestRunner withSourceFiles(List sourceFiles) { - this.sourceFiles.addAll(sourceFiles); + if (sourceFiles != null) this.sourceFiles.addAll(sourceFiles); return this; } public TestRunner withTestFiles(List testFiles) { - this.testFiles.addAll(testFiles); + if (testFiles != null) this.testFiles.addAll(testFiles); return this; } @@ -84,34 +84,63 @@ public void run(Connection conn) throws SQLException { this.reporterList.add(new DocumentationReporter().init(conn)); } - OracleConnection oraConn = conn.unwrap(OracleConnection.class); - Array pathArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.pathList.toArray()); - Array reporterArray = oraConn.createARRAY(CustomTypes.UT_REPORTERS, this.reporterList.toArray()); - Array coverageSchemesArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.coverageSchemes.toArray()); - Array sourceFilesArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.sourceFiles.toArray()); - Array testFilesArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.testFiles.toArray()); - Array includeObjectsArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.includeObjects.toArray()); - Array excludeObjectsArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.excludeObjects.toArray()); - // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. String colorConsoleStr = Boolean.toString(this.colorConsole); + OracleConnection oraConn = conn.unwrap(OracleConnection.class); CallableStatement callableStatement = null; try { callableStatement = conn.prepareCall( "BEGIN " + - "ut_runner.run(" + + "ut_runner.run(" + "a_paths => ?, a_reporters => ?, a_color_console => " + colorConsoleStr + ", " + "a_coverage_schemes => ?, a_source_files => ?, a_test_files => ?, " + "a_include_objects => ?, a_exclude_objects => ?); " + - "END;"); - callableStatement.setArray(1, pathArray); - callableStatement.setArray(2, reporterArray); - callableStatement.setArray(3, coverageSchemesArray); - callableStatement.setArray(4, sourceFilesArray); - callableStatement.setArray(5, testFilesArray); - callableStatement.setArray(6, includeObjectsArray); - callableStatement.setArray(7, excludeObjectsArray); + "END;"); + + int paramIdx = 0; + + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.pathList.toArray())); + + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_REPORTERS, this.reporterList.toArray())); + + if (this.coverageSchemes.isEmpty()) { + callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); + } else { + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.coverageSchemes.toArray())); + } + + if (this.sourceFiles.isEmpty()) { + callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); + } else { + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.sourceFiles.toArray())); + } + + if (this.testFiles.isEmpty()) { + callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); + } else { + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.testFiles.toArray())); + } + + if (this.includeObjects.isEmpty()) { + callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); + } else { + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.includeObjects.toArray())); + } + + if (this.excludeObjects.isEmpty()) { + callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); + } else { + callableStatement.setArray( + ++paramIdx, oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.excludeObjects.toArray())); + } + callableStatement.execute(); } finally { if (callableStatement != null) diff --git a/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java b/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java index b0a61be..b6f180e 100644 --- a/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java +++ b/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java @@ -8,11 +8,15 @@ public class CoverageHTMLReporter extends Reporter { + // Could override Reporter.init and call ut_coverage_report_html_helper.get_default_html_assets_path from database, + // but had permissions issues. + public static final String DEFAULT_ASSETS_PATH = "https://utplsql.github.io/utPLSQL-coverage-html/assets/"; + private String projectName; private String assetsPath; public CoverageHTMLReporter() { - + this(null, DEFAULT_ASSETS_PATH); } public CoverageHTMLReporter(String projectName, String assetsPath) {