Skip to content

Commit 610010d

Browse files
author
Samuel Nitsche
committed
Merge branch 'bugfix/exclude_jdbc_jars' into feature/compatibility_and_ora_libs
2 parents 14401b5 + f76f9a7 commit 610010d

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

.travis/create_release.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ VERSION=`date +%Y%m%d%H%M`
55

66
mkdir dist
77
mv target/appassembler utPLSQL-cli
8+
# Remove Oracle libraries du to licensing problems
9+
rm utPLSQL-cli/lib/ojdbc8*
10+
rm utPLSQL-cli/lib/orai18n*
11+
812
zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli
913
zip -r -q utPLSQL-cli.zip utPLSQL-cli
1014

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa
1515
## Requirements
1616
* [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
1717
* When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory.
18+
* Due to Oracle license we can't ship the necessary oracle libraries directly with utPLSQL-cli. <b>Please download the libraries directly from oracle website and put the jars into the "lib" folder of your utPLSQL-cli installation</b>
19+
* Oracle JDBC driver: http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html
20+
* 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
1821

1922
## Compatibility
2023
The latest CLI is always compatible with all database frameworks of the same major version.

src/main/java/org/utplsql/cli/ConnectionInfo.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
import java.io.File;
88
import java.sql.Connection;
9+
import java.sql.PreparedStatement;
10+
import java.sql.ResultSet;
911
import java.sql.SQLException;
1012

1113
public class ConnectionInfo {
1214

15+
private String databaseVersion;
16+
1317
static {
1418
String oracleHome = System.getenv("ORACLE_HOME");
1519
if (oracleHome != null) {
@@ -42,4 +46,40 @@ public ConnectionInfo convert(String s) {
4246
}
4347
}
4448

49+
public String getOracleDatabaseVersion() throws SQLException
50+
{
51+
try ( Connection conn = getConnection() ) {
52+
return getOracleDatabaseVersion(conn);
53+
}
54+
}
55+
56+
public String getOracleDatabaseVersion( Connection conn ) throws SQLException
57+
{
58+
if ( databaseVersion == null ) {
59+
databaseVersion = getOracleDatabaseVersionFromConnection( conn );
60+
}
61+
62+
return databaseVersion;
63+
}
64+
65+
/** TODO: Outsource this to Java-API
66+
*
67+
* @param conn
68+
* @return
69+
* @throws SQLException
70+
*/
71+
public static String getOracleDatabaseVersionFromConnection( Connection conn ) throws SQLException {
72+
assert conn != null;
73+
String result = null;
74+
try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'"))
75+
{
76+
ResultSet rs = stmt.executeQuery();
77+
78+
if ( rs.next() )
79+
result = rs.getString(1);
80+
}
81+
82+
return result;
83+
}
84+
4585
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.utplsql.cli;
2+
3+
/** Simple class to check whether needed Oracle libraries are on classpath or not
4+
*
5+
* @author pesse
6+
*/
7+
class OracleLibraryChecker {
8+
9+
private static boolean classExists( String classFullName ){
10+
try
11+
{
12+
Class.forName(classFullName);
13+
14+
return true;
15+
}
16+
catch ( ClassNotFoundException e )
17+
{
18+
return false;
19+
}
20+
}
21+
22+
/** Checks if OJDBC library is on the classpath by searching for oracle.jdbc.OracleDriver class
23+
*
24+
* @return true or false
25+
*/
26+
public static boolean checkOjdbcExists() {
27+
return classExists("oracle.jdbc.OracleDriver");
28+
}
29+
30+
/** Checks if Orai18n library is on the classpath by searching for oracle.i18n.text.OraCharset
31+
*
32+
* @return true or false
33+
*/
34+
public static boolean checkOrai18nExists() {
35+
return classExists("oracle.i18n.text.OraCharset");
36+
}
37+
38+
39+
}

src/main/java/org/utplsql/cli/RunCommand.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public List<String> getTestPaths() {
8989
}
9090

9191
public int run() throws Exception {
92+
93+
checkOracleJDBCExists();
94+
9295
final ConnectionInfo ci = getConnectionInfo();
9396

9497
final List<Reporter> reporterList;
@@ -107,6 +110,9 @@ public int run() throws Exception {
107110
// Do the reporters initialization, so we can use the id to run and gather results.
108111
try (Connection conn = ci.getConnection()) {
109112

113+
// Check if orai18n exists if database version is 11g
114+
checkOracleI18nExists(ci.getOracleDatabaseVersion(conn));
115+
110116
// First of all do a compatibility check and fail-fast
111117
checkFrameworkCompatibility(conn);
112118

@@ -320,4 +326,33 @@ public FileMapperOptions getMapperOptions(List<String> mappingParams, List<Strin
320326
return mapperOptions;
321327
}
322328

329+
330+
/** Checks that ojdbc library exists
331+
*
332+
*/
333+
private void checkOracleJDBCExists()
334+
{
335+
if ( !OracleLibraryChecker.checkOjdbcExists() )
336+
{
337+
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
338+
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
339+
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");
340+
341+
throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
342+
}
343+
}
344+
345+
/** Checks that orai18n library exists if database is an oracle 11
346+
*
347+
*/
348+
private void checkOracleI18nExists(String oracleDatabaseVersion )
349+
{
350+
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
351+
{
352+
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
353+
"utPLSQL-cli might not run properly. It is recommended you download " +
354+
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
355+
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
356+
}
357+
}
323358
}

0 commit comments

Comments
 (0)