From 5401f35cc3c70a8cf2f21e5fe25f42751a46c449 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 10 Nov 2017 16:52:15 +0100 Subject: [PATCH 1/6] Removed Oracle libaries from release Included check for specific classes. Needs some refactoring for we only want to check for orai18n when database is 11g --- .travis/create_release.sh | 4 ++ .../org/utplsql/cli/OracleLibraryChecker.java | 39 +++++++++++++++++++ src/main/java/org/utplsql/cli/RunCommand.java | 26 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/main/java/org/utplsql/cli/OracleLibraryChecker.java diff --git a/.travis/create_release.sh b/.travis/create_release.sh index 8daebe9..78c9788 100644 --- a/.travis/create_release.sh +++ b/.travis/create_release.sh @@ -5,6 +5,10 @@ VERSION=`date +%Y%m%d%H%M` mkdir dist mv target/appassembler utPLSQL-cli +# Remove Oracle libraries du to licensing problems +rm utPLSQL-cli/lib/ojdbc8* +rm utPLSQL-cli/lib/orai18n* + zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli cat > bintray.json < getTestPaths() { } public int run() throws Exception { + + checkOracleLibrariesExist(); + final ConnectionInfo ci = getConnectionInfo(); final List reporterOptionsList = getReporterOptionsList(); @@ -246,4 +249,27 @@ public FileMapperOptions getMapperOptions(List mappingParams, List Date: Sun, 12 Nov 2017 14:44:34 +0100 Subject: [PATCH 2/6] Only check for orai18n when we are on a 11g database the library is not needed for 12c --- .../java/org/utplsql/cli/ConnectionInfo.java | 40 +++++++++++++++++++ src/main/java/org/utplsql/cli/RunCommand.java | 21 +++++++--- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/utplsql/cli/ConnectionInfo.java b/src/main/java/org/utplsql/cli/ConnectionInfo.java index 287f989..4f76f81 100644 --- a/src/main/java/org/utplsql/cli/ConnectionInfo.java +++ b/src/main/java/org/utplsql/cli/ConnectionInfo.java @@ -6,10 +6,14 @@ import java.io.File; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; public class ConnectionInfo { + private String databaseVersion; + static { String oracleHome = System.getenv("ORACLE_HOME"); if (oracleHome != null) { @@ -42,4 +46,40 @@ public ConnectionInfo convert(String s) { } } + public String getOracleDatabaseVersion() throws SQLException + { + try ( Connection conn = getConnection() ) { + return getOracleDatabaseVersion(conn); + } + } + + public String getOracleDatabaseVersion( Connection conn ) throws SQLException + { + if ( databaseVersion == null ) { + databaseVersion = getOracleDatabaseVersionFromConnection( conn ); + } + + return databaseVersion; + } + + /** TODO: Outsource this to Java-API + * + * @param conn + * @return + * @throws SQLException + */ + public static String getOracleDatabaseVersionFromConnection( Connection conn ) throws SQLException { + assert conn != null; + String result = null; + try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'")) + { + ResultSet rs = stmt.executeQuery(); + + if ( rs.next() ) + result = rs.getString(1); + } + + return result; + } + } diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 6cc18ee..b81e189 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -90,7 +90,7 @@ public List getTestPaths() { public int run() throws Exception { - checkOracleLibrariesExist(); + checkOracleJDBCExists(); final ConnectionInfo ci = getConnectionInfo(); @@ -110,6 +110,9 @@ public int run() throws Exception { // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { + // Check if orai18n exists if database version is 11g + checkOracleI18nExists(ci.getOracleDatabaseVersion(conn)); + // First of all do a compatibility check and fail-fast checkFrameworkCompatibility(conn); @@ -324,10 +327,10 @@ public FileMapperOptions getMapperOptions(List mappingParams, List Date: Sun, 12 Nov 2017 14:48:20 +0100 Subject: [PATCH 3/6] Updated documentation --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a98c171..973b531 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa ## Requirements * [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) * When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory. +* Due to Oracle license we can't ship the necessary oracle libraries directly with utPLSQL-cli. Please download the libraries directly from oracle website and put the jars into the "lib" folder of your utPLSQL-cli installation + * Oracle JDBC driver: http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html + * If you are on a 11g database you might need the orai18n library, too: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html ## Compatibility The latest CLI is always compatible with all database frameworks of the same major version. From b972be1cc7fe56b602fc9fa77f445292956b49f8 Mon Sep 17 00:00:00 2001 From: pesse Date: Thu, 16 Nov 2017 15:27:57 +0100 Subject: [PATCH 4/6] Using new API Compatibility check Let CLI exit gracefully when versions not compatible --- src/main/java/org/utplsql/cli/Cli.java | 3 +++ src/main/java/org/utplsql/cli/RunCommand.java | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java index 4ea8652..c173ae3 100644 --- a/src/main/java/org/utplsql/cli/Cli.java +++ b/src/main/java/org/utplsql/cli/Cli.java @@ -3,6 +3,7 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; +import org.utplsql.api.exception.DatabaseNotCompatibleException; public class Cli { @@ -34,6 +35,8 @@ public static void main(String[] args) { } else { jc.usage(); } + } catch ( DatabaseNotCompatibleException e ) { + System.out.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index b81e189..3d7dd50 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import org.utplsql.api.*; +import org.utplsql.api.compatibility.CompatibilityProxy; import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; @@ -264,14 +265,10 @@ public List getReporterOptionsList() { */ private void checkFrameworkCompatibility(Connection conn) throws SQLException { - if ( !skipCompatibilityCheck ) { - try { - DBHelper.failOnVersionCompatibilityCheckFailed(conn); - } catch (DatabaseNotCompatibleException e) { - System.out.println(e.getMessage()); + CompatibilityProxy proxy = new CompatibilityProxy(conn, skipCompatibilityCheck); - throw e; - } + if ( !skipCompatibilityCheck ) { + proxy.failOnNotCompatible(); } else { System.out.println("Skipping Compatibility check with framework version, expecting the latest version " + From c140c5e58e02b90689a91734d926df16586f0dc6 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 17 Nov 2017 10:32:32 +0100 Subject: [PATCH 5/6] Shutdown cli gracefully when known exceptions occur Fixes #44 --- src/main/java/org/utplsql/cli/Cli.java | 4 +++- src/main/java/org/utplsql/cli/RunCommand.java | 9 +++++++-- .../cli/exception/DatabaseConnectionFailed.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java diff --git a/src/main/java/org/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java index c173ae3..bdfbac3 100644 --- a/src/main/java/org/utplsql/cli/Cli.java +++ b/src/main/java/org/utplsql/cli/Cli.java @@ -4,6 +4,8 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; import org.utplsql.api.exception.DatabaseNotCompatibleException; +import org.utplsql.api.exception.UtPLSQLNotInstalledException; +import org.utplsql.cli.exception.DatabaseConnectionFailed; public class Cli { @@ -35,7 +37,7 @@ public static void main(String[] args) { } else { jc.usage(); } - } catch ( DatabaseNotCompatibleException e ) { + } catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) { System.out.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 3d7dd50..a03045c 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -8,6 +8,7 @@ import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; +import org.utplsql.cli.exception.DatabaseConnectionFailed; import java.io.File; import java.io.FileNotFoundException; @@ -120,8 +121,12 @@ public int run() throws Exception { reporterList = initReporters(conn, reporterOptionsList); } catch (SQLException e) { - System.out.println(e.getMessage()); - return Cli.DEFAULT_ERROR_CODE; + if ( e.getErrorCode() == 1017 || e.getErrorCode() == 12514 ) { + throw new DatabaseConnectionFailed(e); + } + else { + throw e; + } } ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size()); diff --git a/src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java b/src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java new file mode 100644 index 0000000..01b03db --- /dev/null +++ b/src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java @@ -0,0 +1,10 @@ +package org.utplsql.cli.exception; + +import java.sql.SQLException; + +public class DatabaseConnectionFailed extends SQLException { + + public DatabaseConnectionFailed(SQLException cause ) { + super( "Could not establish connection to database. Reason: " + cause.getMessage(), cause); + } +} From dd0dcdf2d67d6e61d920ab3e21d9e58632ba609b Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 17 Nov 2017 11:00:22 +0100 Subject: [PATCH 6/6] Output warning when --failureExitCode is set and framework is not compatible with that option also refactored some things and made run_Default-test work with framework versions < 3.0.3, too --- src/main/java/org/utplsql/cli/RunCommand.java | 50 ++++++++--------- .../org/utplsql/cli/RunCommandChecker.java | 54 +++++++++++++++++++ .../java/org/utplsql/cli/RunCommandTest.java | 8 ++- .../utplsql/cli/TestRunCommandChecker.java | 19 +++++++ 4 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/utplsql/cli/RunCommandChecker.java create mode 100644 src/test/java/org/utplsql/cli/TestRunCommandChecker.java diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index a03045c..690a453 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -4,6 +4,7 @@ import com.beust.jcommander.Parameters; import org.utplsql.api.*; import org.utplsql.api.compatibility.CompatibilityProxy; +import org.utplsql.api.compatibility.OptionalFeatures; import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; @@ -82,6 +83,8 @@ public class RunCommand { "most actual. Use this if you use CLI with a development version of utPLSQL-framework") private boolean skipCompatibilityCheck = false; + private CompatibilityProxy compatibilityProxy; + public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); } @@ -92,7 +95,7 @@ public List getTestPaths() { public int run() throws Exception { - checkOracleJDBCExists(); + RunCommandChecker.checkOracleJDBCExists(); final ConnectionInfo ci = getConnectionInfo(); @@ -113,10 +116,10 @@ public int run() throws Exception { try (Connection conn = ci.getConnection()) { // Check if orai18n exists if database version is 11g - checkOracleI18nExists(ci.getOracleDatabaseVersion(conn)); + RunCommandChecker.checkOracleI18nExists(ci.getOracleDatabaseVersion(conn)); // First of all do a compatibility check and fail-fast - checkFrameworkCompatibility(conn); + compatibilityProxy = checkFrameworkCompatibility(conn); reporterList = initReporters(conn, reporterOptionsList); @@ -129,6 +132,12 @@ public int run() throws Exception { } } + // Output a message if --failureExitCode is set but database framework is not capable of + String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getDatabaseVersion()); + if ( msg != null ) { + System.out.println(msg); + } + ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size()); // Run tests. @@ -268,7 +277,7 @@ public List getReporterOptionsList() { * @param conn Active Connection * @throws SQLException */ - private void checkFrameworkCompatibility(Connection conn) throws SQLException { + private CompatibilityProxy checkFrameworkCompatibility(Connection conn) throws SQLException { CompatibilityProxy proxy = new CompatibilityProxy(conn, skipCompatibilityCheck); @@ -279,6 +288,8 @@ private void checkFrameworkCompatibility(Connection conn) throws SQLException { System.out.println("Skipping Compatibility check with framework version, expecting the latest version " + "to be installed in database"); } + + return proxy; } public FileMapperOptions getMapperOptions(List mappingParams, List filePaths) { @@ -328,33 +339,14 @@ public FileMapperOptions getMapperOptions(List mappingParams, List