Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis/create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
zip -r -q utPLSQL-cli.zip utPLSQL-cli

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <b>Please download the libraries directly from oracle website and put the jars into the "lib" folder of your utPLSQL-cli installation</b>
* 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.
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/org/utplsql/cli/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

}
39 changes: 39 additions & 0 deletions src/main/java/org/utplsql/cli/OracleLibraryChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.utplsql.cli;

/** Simple class to check whether needed Oracle libraries are on classpath or not
*
* @author pesse
*/
class OracleLibraryChecker {

private static boolean classExists( String classFullName ){
try
{
Class.forName(classFullName);

return true;
}
catch ( ClassNotFoundException e )
{
return false;
}
}

/** Checks if OJDBC library is on the classpath by searching for oracle.jdbc.OracleDriver class
*
* @return true or false
*/
public static boolean checkOjdbcExists() {
return classExists("oracle.jdbc.OracleDriver");
}

/** Checks if Orai18n library is on the classpath by searching for oracle.i18n.text.OraCharset
*
* @return true or false
*/
public static boolean checkOrai18nExists() {
return classExists("oracle.i18n.text.OraCharset");
}


}
35 changes: 35 additions & 0 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public List<String> getTestPaths() {
}

public int run() throws Exception {

checkOracleJDBCExists();

final ConnectionInfo ci = getConnectionInfo();

final List<Reporter> reporterList;
Expand All @@ -107,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);

Expand Down Expand Up @@ -320,4 +326,33 @@ public FileMapperOptions getMapperOptions(List<String> mappingParams, List<Strin
return mapperOptions;
}


/** Checks that ojdbc library exists
*
*/
private void checkOracleJDBCExists()
{
if ( !OracleLibraryChecker.checkOjdbcExists() )
{
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");

throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
}
}

/** Checks that orai18n library exists if database is an oracle 11
*
*/
private void checkOracleI18nExists(String oracleDatabaseVersion )
{
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
{
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
"utPLSQL-cli might not run properly. It is recommended you download " +
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
}
}
}