From d4324a86e1e139271eb8c0a083581f326b7d3ef5 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 13:01:50 -0800 Subject: [PATCH 01/16] [AD-492] Working JNI GitHub workflow https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/linux-build.yml | 10 +++ .github/workflows/mac-build.yml | 5 ++ .github/workflows/mac-debug-build.yml | 5 ++ .github/workflows/release-workflow.yml | 15 +++++ .github/workflows/win-build.yml | 10 +++ .github/workflows/win-debug-build.yml | 10 +++ src/odbcdriver/CMakeLists.txt | 15 +++++ src/odbcdriver/jni/Connection.cpp | 68 ++++++++++++++++++++ src/odbcdriver/jni/Connection.h | 30 +++++++++ src/odbcdriver/jni/ConnectionProperties.cpp | 71 +++++++++++++++++++++ src/odbcdriver/jni/ConnectionProperties.h | 28 ++++++++ src/odbcdriver/jni/JniEnv.cpp | 45 +++++++++++++ src/odbcdriver/jni/JniEnv.h | 25 ++++++++ 13 files changed, 337 insertions(+) create mode 100644 src/odbcdriver/jni/Connection.cpp create mode 100644 src/odbcdriver/jni/Connection.h create mode 100644 src/odbcdriver/jni/ConnectionProperties.cpp create mode 100644 src/odbcdriver/jni/ConnectionProperties.h create mode 100644 src/odbcdriver/jni/JniEnv.cpp create mode 100644 src/odbcdriver/jni/JniEnv.h diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index 29d7a0450..f8cf4c5c0 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -23,6 +23,11 @@ jobs: build-linux64: runs-on: ubuntu-latest steps: + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.11 with: @@ -101,6 +106,11 @@ jobs: build-linux32: runs-on: ubuntu-latest steps: + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x86 - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.11 with: diff --git a/.github/workflows/mac-build.yml b/.github/workflows/mac-build.yml index 73a1926a7..a81f28f2b 100644 --- a/.github/workflows/mac-build.yml +++ b/.github/workflows/mac-build.yml @@ -23,6 +23,11 @@ jobs: build-mac: runs-on: macos-latest steps: + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.9 with: diff --git a/.github/workflows/mac-debug-build.yml b/.github/workflows/mac-debug-build.yml index d145295b6..1cb8b39fb 100644 --- a/.github/workflows/mac-debug-build.yml +++ b/.github/workflows/mac-debug-build.yml @@ -19,6 +19,11 @@ jobs: NOT_CONNETECD: 1 FAKE_CONNECTION: 1 steps: + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.11 with: diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml index a43764b51..f23542ea2 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/release-workflow.yml @@ -16,6 +16,11 @@ jobs: build-mac: runs-on: macos-latest steps: + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.11 with: @@ -72,6 +77,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x32 - name: Get specific version CMake, v3.18.3 uses: lukka/get-cmake@v3.18.3 - name: add-msbuild-to-path @@ -103,6 +113,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Get specific version CMake, v3.18.3 uses: lukka/get-cmake@v3.18.3 - name: add-msbuild-to-path diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 58703ed69..3b8cbb204 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -24,6 +24,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x86 - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path @@ -75,6 +80,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path diff --git a/.github/workflows/win-debug-build.yml b/.github/workflows/win-debug-build.yml index d35852160..0bbfc951e 100644 --- a/.github/workflows/win-debug-build.yml +++ b/.github/workflows/win-debug-build.yml @@ -17,6 +17,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x32 - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path @@ -61,6 +66,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: joschi/setup-jdk@v2 + with: + java-version: '17' + architecture: x64 - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path diff --git a/src/odbcdriver/CMakeLists.txt b/src/odbcdriver/CMakeLists.txt index 46c198fe7..ae9a10508 100644 --- a/src/odbcdriver/CMakeLists.txt +++ b/src/odbcdriver/CMakeLists.txt @@ -15,6 +15,12 @@ project(odbcdriver) +# JNI requirements +find_package(Java REQUIRED) +find_package(JNI REQUIRED) +include(UseJava) +include_directories(${JNI_INCLUDE_DIRS} ${JAVA_INCLUDE_PATH2} ${JAVA_INCLUDE_PATH}) + # Source files for odbcdriver set(C_SOURCE_FILES bind.c columninfoclass.c @@ -72,6 +78,12 @@ set(CPP_SOURCE_FILES communication.cpp Row.cpp ScalarType.cpp Type.cpp + jni/JniEnv.cpp + jni/Connection.cpp + jni/ConnectionProperties.cpp + jni/JniEnv.h + jni/Connection.h + jni/ConnectionProperties.h ) if(WIN32) @@ -151,13 +163,16 @@ if(WIN32) target_link_libraries(odbcdriver wsock32 ws2_32 winmm user32 gdi32 legacy_stdio_definitions aws-cpp-sdk-core aws-cpp-sdk-sts kernel32 advapi32 secur32 XOleHlp Wldap32 crypt32 Normaliz odbccp32 odbc32) target_link_libraries(odbcdriver debug msvcrtd) target_link_libraries(odbcdriver optimized msvcrt) + target_link_libraries(odbcdriver ${JNI_LIBRARIES}) elseif(APPLE) # Apple specific target_link_libraries(odbcdriver iodbc iodbcinst aws-cpp-sdk-core aws-cpp-sdk-sts ) + target_link_libraries(odbcdriver ${JNI_LIBRARIES}) elseif(UNIX) # Unix specific include_directories(/usr/src/linux-headers-5.0.0-27/include) target_link_libraries(odbcdriver aws-cpp-sdk-core aws-cpp-sdk-sts odbc odbcinst) + target_link_libraries(odbcdriver ${JNI_LIBRARIES}) if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) if (Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) diff --git a/src/odbcdriver/jni/Connection.cpp b/src/odbcdriver/jni/Connection.cpp new file mode 100644 index 000000000..2cbe87b37 --- /dev/null +++ b/src/odbcdriver/jni/Connection.cpp @@ -0,0 +1,68 @@ + +#include +#include "Connection.h" +#include +using namespace std; + +namespace jni { + +void Connection::Connect() { + if (connection_ != nullptr) { + return; + } + + jni_env_->CreateJavaVM(); + JNIEnv* const env = jni_env_->GetJniEnv(); + static jclass cls_documentdb_connection = env->FindClass( + "software/amazon/documentdb/jdbc/" + "DocumentDbConnection"); // try to find the class + if (cls_documentdb_connection == nullptr) { + cerr << "ERROR: class not found !" << endl; + throw runtime_error("Class not found."); + } + cout << "DocumentDbConnection class found." << endl; + + static jmethodID m_dcoumentdb_constructor = env->GetMethodID( + cls_documentdb_connection, "", + "(Lsoftware/amazon/documentdb/jdbc/DocumentDbConnectionProperties;)V"); + if (m_dcoumentdb_constructor == nullptr) { + throw runtime_error( + "ERROR: constructor DocumentDbConnection(connectionProperties) not " + "found!"); + } + cout << "DocumentDbConnection constructor found." << endl; + + connection_ = + env->NewObject(cls_documentdb_connection, m_dcoumentdb_constructor, + connection_properties_.GetHandle()); + if (connection_ == nullptr) { + throw runtime_error("Unable to construct DocumentDbConnection"); + } + cout << "Constructor created." << endl; +} + +Connection::~Connection() { + if (jni_env_ != nullptr && connection_ != nullptr) { + JNIEnv* const env = jni_env_->GetJniEnv(); + static jclass cls_documentdb_connection = env->FindClass( + "software/amazon/documentdb/jdbc/" + "DocumentDbConnection"); // try to find the class + if (cls_documentdb_connection == nullptr) { + cerr << "ERROR: class DocumentDbConnection not found !" << endl; + return; + } + cout << "DocumentDbConnection class found." << endl; + + static jmethodID m_dcoumentdb_close = + env->GetMethodID(cls_documentdb_connection, "doClose", "()V"); + if (m_dcoumentdb_close == nullptr) { + cerr << "ERROR: method DocumentDbConnection.doClose not found !" + << endl; + return; + } + env->CallVoidMethod(connection_, m_dcoumentdb_close); + connection_ = nullptr; + } +} + +} // namespace jni \ No newline at end of file diff --git a/src/odbcdriver/jni/Connection.h b/src/odbcdriver/jni/Connection.h new file mode 100644 index 000000000..0b73855ef --- /dev/null +++ b/src/odbcdriver/jni/Connection.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include "JniEnv.h" +#include "ConnectionProperties.h" + +namespace jni { +class Connection { + private: + JniEnv* const jni_env_; + ConnectionProperties connection_properties_; + jobject connection_; + + public: + inline Connection(JniEnv* const jni_env, + ConnectionProperties connection_properties) + : jni_env_{jni_env}, + connection_properties_{connection_properties}, + connection_{nullptr} { + jni_env_->CreateJavaVM(); + } + + void Connect(); + inline jobject GetHandle() { + return connection_; + } + ~Connection(); +}; +} // namespace jni \ No newline at end of file diff --git a/src/odbcdriver/jni/ConnectionProperties.cpp b/src/odbcdriver/jni/ConnectionProperties.cpp new file mode 100644 index 000000000..ecb9011ef --- /dev/null +++ b/src/odbcdriver/jni/ConnectionProperties.cpp @@ -0,0 +1,71 @@ + +#include +#include +#include "ConnectionProperties.h" +using namespace std; + +namespace jni { + +ConnectionProperties* ConnectionProperties::GetPropertiesFromConnectionString( + JniEnv* const jni_env_, const std::string connectionString) { + jni_env_->CreateJavaVM(); + JNIEnv* const env = jni_env_->GetJniEnv(); + static jclass cls_exception = env->FindClass("java/lang/Exception"); + static jmethodID m_exception_get_message = + env->GetMethodID(cls_exception, "getMessage", "()Ljava/lang/String;"); + + static jclass clsConnectionProperties = env->FindClass( + "software/amazon/documentdb/jdbc/" + "DocumentDbConnectionProperties"); // try to find the class + if (clsConnectionProperties == nullptr) { + cerr << "ERROR: class not found !" << endl; + throw runtime_error("Class not found."); + } + // if class found, continue + cout << "Class DocumentDbConnectionProperties found" << endl; + + jmethodID mGetPropertiesFromConnectionString = + GetMethodGetPropertiesFromConnectionString(env, + clsConnectionProperties); + if (mGetPropertiesFromConnectionString == nullptr) { + cerr << "ERROR: method void mymain() not found !" << endl; + throw runtime_error("Method not found."); + } + + jstring jstr = env->NewStringUTF(connectionString.c_str()); + jobject connection_properties = env->CallStaticObjectMethod( + clsConnectionProperties, mGetPropertiesFromConnectionString, + jstr); // call method + if (env->ExceptionCheck()) { + jstring o_message = (jstring)env->CallObjectMethod( + env->ExceptionOccurred(), m_exception_get_message); + jboolean isCopy; + const char* message = env->GetStringUTFChars(o_message, &isCopy); + env->ReleaseStringUTFChars(o_message, message); + throw runtime_error(message); + return nullptr; + } + + return new ConnectionProperties(connection_properties); +} + +jmethodID ConnectionProperties::GetMethodGetPropertiesFromConnectionString( + JNIEnv* const env, const jclass clsConnectionProperties) { + // find method + static jmethodID mGetPropertiesFromConnectionString = + env->GetStaticMethodID(clsConnectionProperties, + "getPropertiesFromConnectionString", + "(Ljava/lang/String;)" + "Lsoftware/amazon/documentdb/jdbc/" + "DocumentDbConnectionProperties;"); + if (mGetPropertiesFromConnectionString == nullptr) { + cerr << "ERROR: method void getPropertiesFromConnectionString() not " + "found !" + << endl; + return nullptr; + } else { + return mGetPropertiesFromConnectionString; + } +} + +} // namespace jni \ No newline at end of file diff --git a/src/odbcdriver/jni/ConnectionProperties.h b/src/odbcdriver/jni/ConnectionProperties.h new file mode 100644 index 000000000..4858f402a --- /dev/null +++ b/src/odbcdriver/jni/ConnectionProperties.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include "JniEnv.h" + +namespace jni { +class ConnectionProperties { + private: + jobject connection_properties_; + + inline ConnectionProperties(jobject connection_properties) + : connection_properties_{connection_properties} { + } + + static jmethodID GetMethodGetPropertiesFromConnectionString( + JNIEnv* const env, const jclass connection_properties); + + public: + static ConnectionProperties* GetPropertiesFromConnectionString( + JniEnv* const jni_env, const std::string connectionString); + + inline jobject GetHandle() { + return connection_properties_; + }; +}; + +} // namespace jni \ No newline at end of file diff --git a/src/odbcdriver/jni/JniEnv.cpp b/src/odbcdriver/jni/JniEnv.cpp new file mode 100644 index 000000000..f41e38a66 --- /dev/null +++ b/src/odbcdriver/jni/JniEnv.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +#include "JniEnv.h" + +using namespace std; +using namespace chrono; + +namespace jni { +JniEnv::JniEnv() { +} +void JniEnv::CreateJavaVM() { + if (jvm_ != nullptr && env_ != nullptr) { + return; + } + + int numOfOptions = 1; + JavaVMInitArgs vm_args = JavaVMInitArgs(); // Initialization arguments + JavaVMOption *options = + new JavaVMOption[numOfOptions]; // JVM invocation options + + options[0].optionString = + (char *)"-Djava.class.path=./documentdb-jdbc-1.0.0-all.jar"; // where to find + // java .class + options[0].extraInfo = nullptr; + vm_args.version = JNI_VERSION_1_8; // minimum Java version + vm_args.nOptions = numOfOptions; // number of options + vm_args.options = options; + vm_args.ignoreUnrecognized = + false; // invalid options make the JVM init fail + + //=============== load and initialize + // Java VM and JNI interface ============= + jint rc = JNI_CreateJavaVM(&jvm_, (void **)&env_, &vm_args); // YES !! + delete[] options; // we then no longer need the initialisation options. + if (rc != JNI_OK) { + // TO DO: error processing... + throw std::runtime_error("Unable to create Java VM."); + } +} + +} // namespace jni \ No newline at end of file diff --git a/src/odbcdriver/jni/JniEnv.h b/src/odbcdriver/jni/JniEnv.h new file mode 100644 index 000000000..f9bef4965 --- /dev/null +++ b/src/odbcdriver/jni/JniEnv.h @@ -0,0 +1,25 @@ +#pragma once + +namespace jni { +#include + +class JniEnv { + private: + JavaVM *jvm_ = nullptr; + JNIEnv *env_ = nullptr; + + public: + JniEnv(); + void CreateJavaVM(); + inline JNIEnv* GetJniEnv() { + return env_; + }; + inline ~JniEnv() { + if (jvm_ != nullptr) { + jvm_->DestroyJavaVM(); + jvm_ = nullptr; + } + } +}; + +} // namespace jni From baceba5a8ed3fd3e29f7953e1b7dbe41c8d43d36 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 13:19:21 -0800 Subject: [PATCH 02/16] [AD-492] Use different action. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/linux-build.yml | 6 ++++-- .github/workflows/mac-build.yml | 3 ++- .github/workflows/mac-debug-build.yml | 3 ++- .github/workflows/release-workflow.yml | 9 ++++++--- .github/workflows/win-build.yml | 6 ++++-- .github/workflows/win-debug-build.yml | 6 ++++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index f8cf4c5c0..c2182e489 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -24,8 +24,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Setup cmake @@ -107,8 +108,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x86 - name: Setup cmake diff --git a/.github/workflows/mac-build.yml b/.github/workflows/mac-build.yml index a81f28f2b..c28370d08 100644 --- a/.github/workflows/mac-build.yml +++ b/.github/workflows/mac-build.yml @@ -24,8 +24,9 @@ jobs: runs-on: macos-latest steps: - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Setup cmake diff --git a/.github/workflows/mac-debug-build.yml b/.github/workflows/mac-debug-build.yml index 1cb8b39fb..583fc32ef 100644 --- a/.github/workflows/mac-debug-build.yml +++ b/.github/workflows/mac-debug-build.yml @@ -20,8 +20,9 @@ jobs: FAKE_CONNECTION: 1 steps: - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Setup cmake diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml index f23542ea2..db1c2be67 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/release-workflow.yml @@ -17,8 +17,9 @@ jobs: runs-on: macos-latest steps: - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Setup cmake @@ -78,8 +79,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x32 - name: Get specific version CMake, v3.18.3 @@ -114,8 +116,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Get specific version CMake, v3.18.3 diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 3b8cbb204..32714194d 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -25,8 +25,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x86 - name: Get specific version CMake, v3.20.1 @@ -81,8 +82,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Get specific version CMake, v3.20.1 diff --git a/.github/workflows/win-debug-build.yml b/.github/workflows/win-debug-build.yml index 0bbfc951e..fae3ca7c4 100644 --- a/.github/workflows/win-debug-build.yml +++ b/.github/workflows/win-debug-build.yml @@ -18,8 +18,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x32 - name: Get specific version CMake, v3.20.1 @@ -67,8 +68,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Get Java distribution - uses: joschi/setup-jdk@v2 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '17' architecture: x64 - name: Get specific version CMake, v3.20.1 From d0ce218a7f7eaad32f6437513f0d3db3626ef0c9 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 13:36:35 -0800 Subject: [PATCH 03/16] [AD-492] Disable Linux 32-bit build. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/linux-build.yml | 174 +++++++++++++++--------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index c2182e489..558cd8ad9 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -104,90 +104,90 @@ jobs: with: name: linux64-deb-installer path: deb-installer - build-linux32: - runs-on: ubuntu-latest - steps: - - name: Get Java distribution - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - architecture: x86 - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.11 - with: - cmake-version: '3.21.4' - - uses: actions/checkout@v2 - - name: run-cppcheck - run: | - sudo apt install cppcheck - sh run_cppcheck.sh - - name: upload-cppcheck-results - if: failure() - uses: actions/upload-artifact@v2 - with: - name: cppcheck-results - path: cppcheck-results.log - - name: get-dependencies - if: success() - run: | - # Need to install i386 versions - sudo dpkg --add-architecture i386 - sudo apt update - sudo apt install unixodbc:i386 unixodbc-dev:i386 odbcinst1debian2:i386 libodbc1:i386 libcurl4-openssl-dev:i386 libssl-dev:i386 uuid-dev:i386 cpp:i386 cpp-9:i386 gcc:i386 g++:i386 zlib1g-dev:i386 linux-headers-$(uname -r) gcc-multilib:i386 g++-multilib:i386 g++-9:i386 gcc-9:i386 gcc-9-multilib:i386 g++-9-multilib:i386 binutils:i386 make:i386 - - name: prepare-dsn - if: success() - run: | - sudo cp ./src/Tests/Tests/odbc-linux32.ini /etc/odbc.ini - sudo cp ./src/Tests/Tests/odbcinst-linux32.ini /etc/odbcinst.ini - mkdir -p ${{ github.workspace }}/odbc-logs - export ODBCSYSINI=/etc/ - export ODBCINSTINI=odbcinst.ini - export ODBCINI=/etc/odbc.ini - - name: configure-and-build-driver - if: success() - run: | - ./build_linux_release32_deb.sh - - name: run-tests - if: success() - run: | - ./build/odbc/bin/tests --gtest_output="xml:report.xml" - - name: prepare-test-results - if: always() - run: | - cp ${{ github.workspace }}/report.xml ${{ github.workspace }}/odbc-logs/ - - name: upload-test-report - if: failure() - uses: actions/upload-artifact@v2 - with: - name: test-results-linux32 - path: ${{ github.workspace }}/report.xml - - name: build-deb-installer - if: success() - run: | - cd cmake-build32 - cmake ../src - make -j4 - cpack . - cd .. - - name: create-output - if: success() - run: | - mkdir deb-installer - mkdir build-output - mkdir test-output - cp -v ./build/odbc/lib/*.a build-output/ - cp -v ./build/odbc/lib/*.so build-output/ - cp -v ./cmake-build32/*.deb deb-installer/ - - name: upload-build - if: success() - uses: actions/upload-artifact@v2 - with: - name: linux32-build - path: build-output - - name: upload-linux32-deb-installer - if: success() - uses: actions/upload-artifact@v2 - with: - name: linux32-deb-installer - path: deb-installer + #build-linux32: + # runs-on: ubuntu-latest + # steps: + # - name: Get Java distribution + # uses: actions/setup-java@v2 + # with: + # distribution: 'temurin' + # java-version: '17' + # architecture: x86 + # - name: Setup cmake + # uses: jwlawson/actions-setup-cmake@v1.11 + # with: + # cmake-version: '3.21.4' + # - uses: actions/checkout@v2 + # - name: run-cppcheck + # run: | + # sudo apt install cppcheck + # sh run_cppcheck.sh + # - name: upload-cppcheck-results + # if: failure() + # uses: actions/upload-artifact@v2 + # with: + # name: cppcheck-results + # path: cppcheck-results.log + # - name: get-dependencies + # if: success() + # run: | + # # Need to install i386 versions + # sudo dpkg --add-architecture i386 + # sudo apt update + # sudo apt install unixodbc:i386 unixodbc-dev:i386 odbcinst1debian2:i386 libodbc1:i386 libcurl4-openssl-dev:i386 libssl-dev:i386 uuid-dev:i386 cpp:i386 cpp-9:i386 gcc:i386 g++:i386 zlib1g-dev:i386 linux-headers-$(uname -r) gcc-multilib:i386 g++-multilib:i386 g++-9:i386 gcc-9:i386 gcc-9-multilib:i386 g++-9-multilib:i386 binutils:i386 make:i386 + # - name: prepare-dsn + # if: success() + # run: | + # sudo cp ./src/Tests/Tests/odbc-linux32.ini /etc/odbc.ini + # sudo cp ./src/Tests/Tests/odbcinst-linux32.ini /etc/odbcinst.ini + # mkdir -p ${{ github.workspace }}/odbc-logs + # export ODBCSYSINI=/etc/ + # export ODBCINSTINI=odbcinst.ini + # export ODBCINI=/etc/odbc.ini + # - name: configure-and-build-driver + # if: success() + # run: | + # ./build_linux_release32_deb.sh + # - name: run-tests + # if: success() + # run: | + # ./build/odbc/bin/tests --gtest_output="xml:report.xml" + # - name: prepare-test-results + # if: always() + # run: | + # cp ${{ github.workspace }}/report.xml ${{ github.workspace }}/odbc-logs/ + # - name: upload-test-report + # if: failure() + # uses: actions/upload-artifact@v2 + # with: + # name: test-results-linux32 + # path: ${{ github.workspace }}/report.xml + # - name: build-deb-installer + # if: success() + # run: | + # cd cmake-build32 + # cmake ../src + # make -j4 + # cpack . + # cd .. + # - name: create-output + # if: success() + # run: | + # mkdir deb-installer + # mkdir build-output + # mkdir test-output + # cp -v ./build/odbc/lib/*.a build-output/ + # cp -v ./build/odbc/lib/*.so build-output/ + # cp -v ./cmake-build32/*.deb deb-installer/ + # - name: upload-build + # if: success() + # uses: actions/upload-artifact@v2 + # with: + # name: linux32-build + # path: build-output + # - name: upload-linux32-deb-installer + # if: success() + # uses: actions/upload-artifact@v2 + # with: + # name: linux32-deb-installer + # path: deb-installer From 21c4dddb0fa6604f13d9d590c09a06d99eb4f5fe Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 13:48:58 -0800 Subject: [PATCH 04/16] [AD-492] Disable Windows 32-bit build. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/win-build.yml | 120 +++++++++++++++++--------------- 1 file changed, 63 insertions(+), 57 deletions(-) diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 32714194d..4ff29be24 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -20,63 +20,63 @@ env: FAKE_CONNECTION: 1 jobs: - build-windows32: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - name: Get Java distribution - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - architecture: x86 - - name: Get specific version CMake, v3.20.1 - uses: lukka/get-cmake@v3.20.1 - - name: add-msbuild-to-path - uses: microsoft/setup-msbuild@v1.0.2 - - name: configure-and-build-driver - run: | - .\build_win_release32.ps1 - - name: import-registry - run: | - reg import .\src\Tests\Tests\AWSProfileRegistry_Win32.reg - reg import .\src\Tests\Tests\IAMRegistry_Win32.reg - mkdir ${{ github.workspace }}\odbc-logs - - name: run-tests - run: | - .\build\odbc\bin\Release\tests.exe --gtest_output="xml:report.xml" - - name: upload-test-report - if: failure() - uses: actions/upload-artifact@v2 - with: - name: test-logs-win32 - path: ${{ github.workspace }}\report.xml - - name: build-installer - if: success() - run: | - .\scripts\build_installer.ps1 Release Win32 .\src $Env:ODBC_BUILD_PATH $Env:AWS_SDK_INSTALL_PATH - - name: prepare-output - if: success() - run: | - .\scripts\prepare_ci_output.ps1 $Env:ODBC_BIN_PATH $Env:ODBC_LIB_PATH $Env:ODBC_BUILD_PATH - - name: upload-build - if: always() - uses: actions/upload-artifact@v2 - with: - name: windows32-build - path: ci-output/build - - name: upload-installer - if: success() - uses: actions/upload-artifact@v2 - with: - name: windows32-installer - path: ci-output/installer - - name: upload-test-results - if: always() - uses: actions/upload-artifact@v2 - with: - name: windows-test-results - path: $CI_OUTPUT_PATH/test + #build-windows32: + # runs-on: windows-latest + # steps: + # - uses: actions/checkout@v2 + # - name: Get Java distribution + # uses: actions/setup-java@v2 + # with: + # distribution: 'temurin' + # java-version: '17' + # architecture: x86 + # - name: Get specific version CMake, v3.20.1 + # uses: lukka/get-cmake@v3.20.1 + # - name: add-msbuild-to-path + # uses: microsoft/setup-msbuild@v1.0.2 + # - name: configure-and-build-driver + # run: | + # .\build_win_release32.ps1 + # - name: import-registry + # run: | + # reg import .\src\Tests\Tests\AWSProfileRegistry_Win32.reg + # reg import .\src\Tests\Tests\IAMRegistry_Win32.reg + # mkdir ${{ github.workspace }}\odbc-logs + # - name: run-tests + # run: | + # .\build\odbc\bin\Release\tests.exe --gtest_output="xml:report.xml" + # - name: upload-test-report + # if: failure() + # uses: actions/upload-artifact@v2 + # with: + # name: test-logs-win32 + # path: ${{ github.workspace }}\report.xml + # - name: build-installer + # if: success() + # run: | + # .\scripts\build_installer.ps1 Release Win32 .\src $Env:ODBC_BUILD_PATH $Env:AWS_SDK_INSTALL_PATH + # - name: prepare-output + # if: success() + # run: | + # .\scripts\prepare_ci_output.ps1 $Env:ODBC_BIN_PATH $Env:ODBC_LIB_PATH $Env:ODBC_BUILD_PATH + # - name: upload-build + # if: always() + # uses: actions/upload-artifact@v2 + # with: + # name: windows32-build + # path: ci-output/build + # - name: upload-installer + # if: success() + # uses: actions/upload-artifact@v2 + # with: + # name: windows32-installer + # path: ci-output/installer + # - name: upload-test-results + # if: always() + # uses: actions/upload-artifact@v2 + # with: + # name: windows-test-results + # path: $CI_OUTPUT_PATH/test build-windows64: runs-on: windows-latest steps: @@ -132,6 +132,12 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 + - name: Get Java distribution + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + architecture: x64 - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path From 2772a2f7cff88f6693d9f17a20e5484ed52f79ac Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 14:36:28 -0800 Subject: [PATCH 05/16] [AD-492] Debugging test_main.cpp. https:/bitquill.atlassian.net/browse/AD-492 --- src/Tests/Tests/test_main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Tests/Tests/test_main.cpp b/src/Tests/Tests/test_main.cpp index beb9c417d..224531dd4 100644 --- a/src/Tests/Tests/test_main.cpp +++ b/src/Tests/Tests/test_main.cpp @@ -27,26 +27,39 @@ // clang-format on int main(int argc, char** argv) { + std::cout << "Start: Line 30" << std::endl; #ifdef WIN32 + std::cout << "Line 32" << std::endl; // Enable CRT for detecting memory leaks _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); + std::cout << "Line 35" << std::endl; _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + std::cout << "Line 37" << std::endl; _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); + std::cout << "Line 39" << std::endl; #endif #ifdef __APPLE__ // Enable malloc logging for detecting memory leaks. system("export MallocStackLogging=1"); #endif + std::cout << "Line 45" << std::endl; testing::internal::CaptureStdout(); + std::cout << "Line 47" << std::endl; ::testing::InitGoogleTest(&argc, argv); + std::cout << "Line 50" << std::endl; int failures = RUN_ALL_TESTS(); + std::cout << "Line 53" << std::endl; std::string output = testing::internal::GetCapturedStdout(); + std::cout << "Line 55" << std::endl; std::cout << output << std::endl; + std::cout << "Line 56" << std::endl; std::cout << (failures ? "Not all tests passed." : "All tests passed") << std::endl; + std::cout << "Line 60" << std::endl; WriteFileIfSpecified(argv, argv + argc, "-fout", output); + std::cout << "Line 62" << std::endl; #ifdef __APPLE__ // Disable malloc logging and report memory leaks From da6534cd7de38eb4074bbf01eacfa2c6ab8649ac Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 14:49:32 -0800 Subject: [PATCH 06/16] [AD-492] Debugging test_main.cpp. https:/bitquill.atlassian.net/browse/AD-492 --- src/Tests/Tests/test_main.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Tests/Tests/test_main.cpp b/src/Tests/Tests/test_main.cpp index 224531dd4..6ff137fe5 100644 --- a/src/Tests/Tests/test_main.cpp +++ b/src/Tests/Tests/test_main.cpp @@ -27,39 +27,39 @@ // clang-format on int main(int argc, char** argv) { - std::cout << "Start: Line 30" << std::endl; + std::cerr << "Start: Line 30" << std::endl; #ifdef WIN32 - std::cout << "Line 32" << std::endl; + std::cerr << "Line 32" << std::endl; // Enable CRT for detecting memory leaks _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); - std::cout << "Line 35" << std::endl; + std::cerr << "Line 35" << std::endl; _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - std::cout << "Line 37" << std::endl; + std::cerr << "Line 37" << std::endl; _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - std::cout << "Line 39" << std::endl; + std::cerr << "Line 39" << std::endl; #endif #ifdef __APPLE__ // Enable malloc logging for detecting memory leaks. system("export MallocStackLogging=1"); #endif - std::cout << "Line 45" << std::endl; + std::cerr << "Line 45" << std::endl; testing::internal::CaptureStdout(); - std::cout << "Line 47" << std::endl; + std::cerr << "Line 47" << std::endl; ::testing::InitGoogleTest(&argc, argv); - std::cout << "Line 50" << std::endl; + std::cerr << "Line 50" << std::endl; int failures = RUN_ALL_TESTS(); - std::cout << "Line 53" << std::endl; + std::cerr << "Line 53" << std::endl; std::string output = testing::internal::GetCapturedStdout(); - std::cout << "Line 55" << std::endl; + std::cerr << "Line 55" << std::endl; std::cout << output << std::endl; - std::cout << "Line 56" << std::endl; + std::cerr << "Line 56" << std::endl; std::cout << (failures ? "Not all tests passed." : "All tests passed") << std::endl; - std::cout << "Line 60" << std::endl; + std::cerr << "Line 60" << std::endl; WriteFileIfSpecified(argv, argv + argc, "-fout", output); - std::cout << "Line 62" << std::endl; + std::cerr << "Line 62" << std::endl; #ifdef __APPLE__ // Disable malloc logging and report memory leaks From 59b1d2ddd51dd2434c4d8dd1494e90b1da6fb912 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 15:15:39 -0800 Subject: [PATCH 07/16] [AD-492] Update path for Java. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/win-build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 4ff29be24..67ed83a39 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -87,6 +87,10 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x64 + + - name: "Update path for Java" + run: | + echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path @@ -138,6 +142,9 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x64 + - name: "Update path for Java" + run: | + echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path From 4da278638c634ac90e95f9763ac90d2a2d7e6cf0 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 15:18:20 -0800 Subject: [PATCH 08/16] [AD-492] Update path for Java. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/win-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 67ed83a39..5f470f2f4 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -90,7 +90,7 @@ jobs: - name: "Update path for Java" run: | - echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path @@ -144,7 +144,7 @@ jobs: architecture: x64 - name: "Update path for Java" run: | - echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path From c960ba1a5fe9278485c0c4b4f4869af41dc7999e Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 15:34:03 -0800 Subject: [PATCH 09/16] [AD-492] Update path for Java. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/win-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 5f470f2f4..60ed629d0 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -90,7 +90,7 @@ jobs: - name: "Update path for Java" run: | - echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path @@ -144,7 +144,7 @@ jobs: architecture: x64 - name: "Update path for Java" run: | - echo "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.1-12\x64\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path From 30e2143c53a464c69030e0826af537dcf6439b9f Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 15:48:02 -0800 Subject: [PATCH 10/16] [AD-492] Re-enable Windows 32-bit. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/win-build.yml | 118 ++++++++++++++++---------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/.github/workflows/win-build.yml b/.github/workflows/win-build.yml index 60ed629d0..1622747b9 100644 --- a/.github/workflows/win-build.yml +++ b/.github/workflows/win-build.yml @@ -20,63 +20,66 @@ env: FAKE_CONNECTION: 1 jobs: - #build-windows32: - # runs-on: windows-latest - # steps: - # - uses: actions/checkout@v2 - # - name: Get Java distribution - # uses: actions/setup-java@v2 - # with: - # distribution: 'temurin' - # java-version: '17' - # architecture: x86 - # - name: Get specific version CMake, v3.20.1 - # uses: lukka/get-cmake@v3.20.1 - # - name: add-msbuild-to-path - # uses: microsoft/setup-msbuild@v1.0.2 - # - name: configure-and-build-driver - # run: | - # .\build_win_release32.ps1 - # - name: import-registry - # run: | - # reg import .\src\Tests\Tests\AWSProfileRegistry_Win32.reg - # reg import .\src\Tests\Tests\IAMRegistry_Win32.reg - # mkdir ${{ github.workspace }}\odbc-logs - # - name: run-tests - # run: | - # .\build\odbc\bin\Release\tests.exe --gtest_output="xml:report.xml" - # - name: upload-test-report - # if: failure() - # uses: actions/upload-artifact@v2 - # with: - # name: test-logs-win32 - # path: ${{ github.workspace }}\report.xml - # - name: build-installer - # if: success() - # run: | - # .\scripts\build_installer.ps1 Release Win32 .\src $Env:ODBC_BUILD_PATH $Env:AWS_SDK_INSTALL_PATH - # - name: prepare-output - # if: success() - # run: | - # .\scripts\prepare_ci_output.ps1 $Env:ODBC_BIN_PATH $Env:ODBC_LIB_PATH $Env:ODBC_BUILD_PATH - # - name: upload-build - # if: always() - # uses: actions/upload-artifact@v2 - # with: - # name: windows32-build - # path: ci-output/build - # - name: upload-installer - # if: success() - # uses: actions/upload-artifact@v2 - # with: - # name: windows32-installer - # path: ci-output/installer - # - name: upload-test-results - # if: always() - # uses: actions/upload-artifact@v2 - # with: - # name: windows-test-results - # path: $CI_OUTPUT_PATH/test + build-windows32: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Get Java distribution + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + architecture: x86 + - name: "Update path for Java" + run: | + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: Get specific version CMake, v3.20.1 + uses: lukka/get-cmake@v3.20.1 + - name: add-msbuild-to-path + uses: microsoft/setup-msbuild@v1.0.2 + - name: configure-and-build-driver + run: | + .\build_win_release32.ps1 + - name: import-registry + run: | + reg import .\src\Tests\Tests\AWSProfileRegistry_Win32.reg + reg import .\src\Tests\Tests\IAMRegistry_Win32.reg + mkdir ${{ github.workspace }}\odbc-logs + - name: run-tests + run: | + .\build\odbc\bin\Release\tests.exe --gtest_output="xml:report.xml" + - name: upload-test-report + if: failure() + uses: actions/upload-artifact@v2 + with: + name: test-logs-win32 + path: ${{ github.workspace }}\report.xml + - name: build-installer + if: success() + run: | + .\scripts\build_installer.ps1 Release Win32 .\src $Env:ODBC_BUILD_PATH $Env:AWS_SDK_INSTALL_PATH + - name: prepare-output + if: success() + run: | + .\scripts\prepare_ci_output.ps1 $Env:ODBC_BIN_PATH $Env:ODBC_LIB_PATH $Env:ODBC_BUILD_PATH + - name: upload-build + if: always() + uses: actions/upload-artifact@v2 + with: + name: windows32-build + path: ci-output/build + - name: upload-installer + if: success() + uses: actions/upload-artifact@v2 + with: + name: windows32-installer + path: ci-output/installer + - name: upload-test-results + if: always() + uses: actions/upload-artifact@v2 + with: + name: windows-test-results + path: $CI_OUTPUT_PATH/test build-windows64: runs-on: windows-latest steps: @@ -87,7 +90,6 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x64 - - name: "Update path for Java" run: | echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append From b68b3b024c90f5447c355bd84b780b40e5711674 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Tue, 7 Dec 2021 16:35:43 -0800 Subject: [PATCH 11/16] [AD-492] Solidify placement and ensure all platforms/workflows are covered. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/linux-build.yml | 20 ++++++++++---------- .github/workflows/mac-build.yml | 10 +++++----- .github/workflows/mac-debug-build.yml | 10 +++++----- .github/workflows/release-workflow.yml | 17 +++++++++++------ .github/workflows/win-debug-build.yml | 6 ++++++ 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index 558cd8ad9..e26e9d9cb 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -23,17 +23,17 @@ jobs: build-linux64: runs-on: ubuntu-latest steps: + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.11 + with: + cmake-version: '3.21.4' + - uses: actions/checkout@v2 - name: Get Java distribution uses: actions/setup-java@v2 with: distribution: 'temurin' java-version: '17' architecture: x64 - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.11 - with: - cmake-version: '3.21.4' - - uses: actions/checkout@v2 - name: run-cppcheck run: | sudo apt install cppcheck @@ -107,17 +107,17 @@ jobs: #build-linux32: # runs-on: ubuntu-latest # steps: + # - name: Setup cmake + # uses: jwlawson/actions-setup-cmake@v1.11 + # with: + # cmake-version: '3.21.4' + # - uses: actions/checkout@v2 # - name: Get Java distribution # uses: actions/setup-java@v2 # with: # distribution: 'temurin' # java-version: '17' # architecture: x86 - # - name: Setup cmake - # uses: jwlawson/actions-setup-cmake@v1.11 - # with: - # cmake-version: '3.21.4' - # - uses: actions/checkout@v2 # - name: run-cppcheck # run: | # sudo apt install cppcheck diff --git a/.github/workflows/mac-build.yml b/.github/workflows/mac-build.yml index c28370d08..a73fa8cbe 100644 --- a/.github/workflows/mac-build.yml +++ b/.github/workflows/mac-build.yml @@ -23,17 +23,17 @@ jobs: build-mac: runs-on: macos-latest steps: + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.9 + with: + cmake-version: '3.21.4' + - uses: actions/checkout@v2 - name: Get Java distribution uses: actions/setup-java@v2 with: distribution: 'temurin' java-version: '17' architecture: x64 - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.9 - with: - cmake-version: '3.21.4' - - uses: actions/checkout@v2 - name: run-cppcheck run: | brew install cppcheck diff --git a/.github/workflows/mac-debug-build.yml b/.github/workflows/mac-debug-build.yml index 583fc32ef..2f585aa95 100644 --- a/.github/workflows/mac-debug-build.yml +++ b/.github/workflows/mac-debug-build.yml @@ -19,17 +19,17 @@ jobs: NOT_CONNETECD: 1 FAKE_CONNECTION: 1 steps: + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.11 + with: + cmake-version: '3.21.4' + - uses: actions/checkout@v2 - name: Get Java distribution uses: actions/setup-java@v2 with: distribution: 'temurin' java-version: '17' architecture: x64 - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.11 - with: - cmake-version: '3.21.4' - - uses: actions/checkout@v2 - name: run-cppcheck run: | brew install cppcheck diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml index db1c2be67..941de7768 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/release-workflow.yml @@ -16,17 +16,17 @@ jobs: build-mac: runs-on: macos-latest steps: + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.11 + with: + cmake-version: '3.21.4' + - uses: actions/checkout@v2 - name: Get Java distribution uses: actions/setup-java@v2 with: distribution: 'temurin' java-version: '17' architecture: x64 - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.11 - with: - cmake-version: '3.21.4' - - uses: actions/checkout@v2 - name: run-cppcheck run: | brew install cppcheck @@ -84,6 +84,9 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x32 + - name: "Update path for Java" + run: | + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.18.3 - name: Get specific version CMake, v3.18.3 uses: lukka/get-cmake@v3.18.3 - name: add-msbuild-to-path @@ -121,7 +124,9 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x64 - - name: Get specific version CMake, v3.18.3 + - name: "Update path for Java" + run: | + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.18.3 uses: lukka/get-cmake@v3.18.3 - name: add-msbuild-to-path uses: microsoft/setup-msbuild@v1.0.2 diff --git a/.github/workflows/win-debug-build.yml b/.github/workflows/win-debug-build.yml index fae3ca7c4..a9ee6df98 100644 --- a/.github/workflows/win-debug-build.yml +++ b/.github/workflows/win-debug-build.yml @@ -23,6 +23,9 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x32 + - name: "Update path for Java" + run: | + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path @@ -73,6 +76,9 @@ jobs: distribution: 'temurin' java-version: '17' architecture: x64 + - name: "Update path for Java" + run: | + echo "${{ env.JAVA_HOME }}\bin\server" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Get specific version CMake, v3.20.1 uses: lukka/get-cmake@v3.20.1 - name: add-msbuild-to-path From e575d9a4b48e953c79e487e70eed8429be0142dc Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Wed, 8 Dec 2021 10:56:12 -0800 Subject: [PATCH 12/16] [AD-492] Remove debugging test_main.cpp. https:/bitquill.atlassian.net/browse/AD-492 --- src/Tests/Tests/test_main.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Tests/Tests/test_main.cpp b/src/Tests/Tests/test_main.cpp index 6ff137fe5..beb9c417d 100644 --- a/src/Tests/Tests/test_main.cpp +++ b/src/Tests/Tests/test_main.cpp @@ -27,39 +27,26 @@ // clang-format on int main(int argc, char** argv) { - std::cerr << "Start: Line 30" << std::endl; #ifdef WIN32 - std::cerr << "Line 32" << std::endl; // Enable CRT for detecting memory leaks _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); - std::cerr << "Line 35" << std::endl; _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - std::cerr << "Line 37" << std::endl; _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - std::cerr << "Line 39" << std::endl; #endif #ifdef __APPLE__ // Enable malloc logging for detecting memory leaks. system("export MallocStackLogging=1"); #endif - std::cerr << "Line 45" << std::endl; testing::internal::CaptureStdout(); - std::cerr << "Line 47" << std::endl; ::testing::InitGoogleTest(&argc, argv); - std::cerr << "Line 50" << std::endl; int failures = RUN_ALL_TESTS(); - std::cerr << "Line 53" << std::endl; std::string output = testing::internal::GetCapturedStdout(); - std::cerr << "Line 55" << std::endl; std::cout << output << std::endl; - std::cerr << "Line 56" << std::endl; std::cout << (failures ? "Not all tests passed." : "All tests passed") << std::endl; - std::cerr << "Line 60" << std::endl; WriteFileIfSpecified(argv, argv + argc, "-fout", output); - std::cerr << "Line 62" << std::endl; #ifdef __APPLE__ // Disable malloc logging and report memory leaks From f10442ec54679145fdfe328d913eaf31f56c7fcd Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Wed, 8 Dec 2021 11:32:51 -0800 Subject: [PATCH 13/16] [AD-492] Remove build steps for 32-bit Linux. https:/bitquill.atlassian.net/browse/AD-492 --- .github/workflows/linux-build.yml | 87 ------------------------------- 1 file changed, 87 deletions(-) diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index e26e9d9cb..c096b6b27 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -104,90 +104,3 @@ jobs: with: name: linux64-deb-installer path: deb-installer - #build-linux32: - # runs-on: ubuntu-latest - # steps: - # - name: Setup cmake - # uses: jwlawson/actions-setup-cmake@v1.11 - # with: - # cmake-version: '3.21.4' - # - uses: actions/checkout@v2 - # - name: Get Java distribution - # uses: actions/setup-java@v2 - # with: - # distribution: 'temurin' - # java-version: '17' - # architecture: x86 - # - name: run-cppcheck - # run: | - # sudo apt install cppcheck - # sh run_cppcheck.sh - # - name: upload-cppcheck-results - # if: failure() - # uses: actions/upload-artifact@v2 - # with: - # name: cppcheck-results - # path: cppcheck-results.log - # - name: get-dependencies - # if: success() - # run: | - # # Need to install i386 versions - # sudo dpkg --add-architecture i386 - # sudo apt update - # sudo apt install unixodbc:i386 unixodbc-dev:i386 odbcinst1debian2:i386 libodbc1:i386 libcurl4-openssl-dev:i386 libssl-dev:i386 uuid-dev:i386 cpp:i386 cpp-9:i386 gcc:i386 g++:i386 zlib1g-dev:i386 linux-headers-$(uname -r) gcc-multilib:i386 g++-multilib:i386 g++-9:i386 gcc-9:i386 gcc-9-multilib:i386 g++-9-multilib:i386 binutils:i386 make:i386 - # - name: prepare-dsn - # if: success() - # run: | - # sudo cp ./src/Tests/Tests/odbc-linux32.ini /etc/odbc.ini - # sudo cp ./src/Tests/Tests/odbcinst-linux32.ini /etc/odbcinst.ini - # mkdir -p ${{ github.workspace }}/odbc-logs - # export ODBCSYSINI=/etc/ - # export ODBCINSTINI=odbcinst.ini - # export ODBCINI=/etc/odbc.ini - # - name: configure-and-build-driver - # if: success() - # run: | - # ./build_linux_release32_deb.sh - # - name: run-tests - # if: success() - # run: | - # ./build/odbc/bin/tests --gtest_output="xml:report.xml" - # - name: prepare-test-results - # if: always() - # run: | - # cp ${{ github.workspace }}/report.xml ${{ github.workspace }}/odbc-logs/ - # - name: upload-test-report - # if: failure() - # uses: actions/upload-artifact@v2 - # with: - # name: test-results-linux32 - # path: ${{ github.workspace }}/report.xml - # - name: build-deb-installer - # if: success() - # run: | - # cd cmake-build32 - # cmake ../src - # make -j4 - # cpack . - # cd .. - # - name: create-output - # if: success() - # run: | - # mkdir deb-installer - # mkdir build-output - # mkdir test-output - # cp -v ./build/odbc/lib/*.a build-output/ - # cp -v ./build/odbc/lib/*.so build-output/ - # cp -v ./cmake-build32/*.deb deb-installer/ - # - name: upload-build - # if: success() - # uses: actions/upload-artifact@v2 - # with: - # name: linux32-build - # path: build-output - # - name: upload-linux32-deb-installer - # if: success() - # uses: actions/upload-artifact@v2 - # with: - # name: linux32-deb-installer - # path: deb-installer From e0a38f57515644d3236a0b356f752336ba2fa91b Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Wed, 8 Dec 2021 11:37:54 -0800 Subject: [PATCH 14/16] [AD-492] Add license headers. https:/bitquill.atlassian.net/browse/AD-492 --- src/odbcdriver/jni/Connection.cpp | 17 ++++++++++++++++- src/odbcdriver/jni/Connection.h | 18 +++++++++++++++++- src/odbcdriver/jni/ConnectionProperties.cpp | 17 ++++++++++++++++- src/odbcdriver/jni/ConnectionProperties.h | 18 +++++++++++++++++- src/odbcdriver/jni/JniEnv.cpp | 18 +++++++++++++++++- src/odbcdriver/jni/JniEnv.h | 16 ++++++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/odbcdriver/jni/Connection.cpp b/src/odbcdriver/jni/Connection.cpp index 2cbe87b37..ee4da05f4 100644 --- a/src/odbcdriver/jni/Connection.cpp +++ b/src/odbcdriver/jni/Connection.cpp @@ -1,3 +1,18 @@ +/* + * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ #include #include "Connection.h" @@ -65,4 +80,4 @@ Connection::~Connection() { } } -} // namespace jni \ No newline at end of file +} // namespace jni diff --git a/src/odbcdriver/jni/Connection.h b/src/odbcdriver/jni/Connection.h index 0b73855ef..072c3c1d9 100644 --- a/src/odbcdriver/jni/Connection.h +++ b/src/odbcdriver/jni/Connection.h @@ -1,3 +1,19 @@ +/* + * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ + #pragma once #include @@ -27,4 +43,4 @@ class Connection { } ~Connection(); }; -} // namespace jni \ No newline at end of file +} // namespace jni diff --git a/src/odbcdriver/jni/ConnectionProperties.cpp b/src/odbcdriver/jni/ConnectionProperties.cpp index ecb9011ef..dc40318ae 100644 --- a/src/odbcdriver/jni/ConnectionProperties.cpp +++ b/src/odbcdriver/jni/ConnectionProperties.cpp @@ -1,3 +1,18 @@ +/* + * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ #include #include @@ -68,4 +83,4 @@ jmethodID ConnectionProperties::GetMethodGetPropertiesFromConnectionString( } } -} // namespace jni \ No newline at end of file +} // namespace jni diff --git a/src/odbcdriver/jni/ConnectionProperties.h b/src/odbcdriver/jni/ConnectionProperties.h index 4858f402a..ba6b60856 100644 --- a/src/odbcdriver/jni/ConnectionProperties.h +++ b/src/odbcdriver/jni/ConnectionProperties.h @@ -1,3 +1,19 @@ +/* + * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ + #pragma once #include @@ -25,4 +41,4 @@ class ConnectionProperties { }; }; -} // namespace jni \ No newline at end of file +} // namespace jni diff --git a/src/odbcdriver/jni/JniEnv.cpp b/src/odbcdriver/jni/JniEnv.cpp index f41e38a66..1c834ae2f 100644 --- a/src/odbcdriver/jni/JniEnv.cpp +++ b/src/odbcdriver/jni/JniEnv.cpp @@ -1,3 +1,19 @@ +/* + * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ + #include #include #include @@ -42,4 +58,4 @@ void JniEnv::CreateJavaVM() { } } -} // namespace jni \ No newline at end of file +} // namespace jni diff --git a/src/odbcdriver/jni/JniEnv.h b/src/odbcdriver/jni/JniEnv.h index f9bef4965..5f98a5b79 100644 --- a/src/odbcdriver/jni/JniEnv.h +++ b/src/odbcdriver/jni/JniEnv.h @@ -1,3 +1,19 @@ +/* + * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ + #pragma once namespace jni { From 35508b64280c5dbc89968921a68d8d86198a939b Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Wed, 15 Dec 2021 14:55:16 -0800 Subject: [PATCH 15/16] [AD-492] Review improvements some use of smart pointers. https:/bitquill.atlassian.net/browse/AD-492 --- src/odbcdriver/jni/Connection.cpp | 8 +++++--- src/odbcdriver/jni/Connection.h | 2 +- src/odbcdriver/jni/ConnectionProperties.cpp | 7 ++++--- src/odbcdriver/jni/ConnectionProperties.h | 10 +++++----- src/odbcdriver/jni/JniEnv.cpp | 14 ++++++++------ src/odbcdriver/jni/JniEnv.h | 3 ++- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/odbcdriver/jni/Connection.cpp b/src/odbcdriver/jni/Connection.cpp index ee4da05f4..1d11c758e 100644 --- a/src/odbcdriver/jni/Connection.cpp +++ b/src/odbcdriver/jni/Connection.cpp @@ -37,10 +37,10 @@ void Connection::Connect() { } cout << "DocumentDbConnection class found." << endl; - static jmethodID m_dcoumentdb_constructor = env->GetMethodID( + static jmethodID m_documentdb_constructor = env->GetMethodID( cls_documentdb_connection, "", "(Lsoftware/amazon/documentdb/jdbc/DocumentDbConnectionProperties;)V"); - if (m_dcoumentdb_constructor == nullptr) { + if (m_documentdb_constructor == nullptr) { throw runtime_error( "ERROR: constructor DocumentDbConnection(connectionProperties) not " "found!"); @@ -48,7 +48,7 @@ void Connection::Connect() { cout << "DocumentDbConnection constructor found." << endl; connection_ = - env->NewObject(cls_documentdb_connection, m_dcoumentdb_constructor, + env->NewObject(cls_documentdb_connection, m_documentdb_constructor, connection_properties_.GetHandle()); if (connection_ == nullptr) { throw runtime_error("Unable to construct DocumentDbConnection"); @@ -76,7 +76,9 @@ Connection::~Connection() { return; } env->CallVoidMethod(connection_, m_dcoumentdb_close); + // Ensure all member Java object are set to null. connection_ = nullptr; + jni_env_ = nullptr; } } diff --git a/src/odbcdriver/jni/Connection.h b/src/odbcdriver/jni/Connection.h index 072c3c1d9..7e8ba9411 100644 --- a/src/odbcdriver/jni/Connection.h +++ b/src/odbcdriver/jni/Connection.h @@ -24,7 +24,7 @@ namespace jni { class Connection { private: - JniEnv* const jni_env_; + JniEnv* jni_env_; ConnectionProperties connection_properties_; jobject connection_; diff --git a/src/odbcdriver/jni/ConnectionProperties.cpp b/src/odbcdriver/jni/ConnectionProperties.cpp index dc40318ae..86491ab30 100644 --- a/src/odbcdriver/jni/ConnectionProperties.cpp +++ b/src/odbcdriver/jni/ConnectionProperties.cpp @@ -16,12 +16,14 @@ #include #include +#include #include "ConnectionProperties.h" + using namespace std; namespace jni { -ConnectionProperties* ConnectionProperties::GetPropertiesFromConnectionString( +std::shared_ptr< ConnectionProperties > ConnectionProperties::GetPropertiesFromConnectionString( JniEnv* const jni_env_, const std::string connectionString) { jni_env_->CreateJavaVM(); JNIEnv* const env = jni_env_->GetJniEnv(); @@ -58,10 +60,9 @@ ConnectionProperties* ConnectionProperties::GetPropertiesFromConnectionString( const char* message = env->GetStringUTFChars(o_message, &isCopy); env->ReleaseStringUTFChars(o_message, message); throw runtime_error(message); - return nullptr; } - return new ConnectionProperties(connection_properties); + return std::make_shared(connection_properties); } jmethodID ConnectionProperties::GetMethodGetPropertiesFromConnectionString( diff --git a/src/odbcdriver/jni/ConnectionProperties.h b/src/odbcdriver/jni/ConnectionProperties.h index ba6b60856..4b4780b8e 100644 --- a/src/odbcdriver/jni/ConnectionProperties.h +++ b/src/odbcdriver/jni/ConnectionProperties.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include "JniEnv.h" @@ -25,17 +26,16 @@ class ConnectionProperties { private: jobject connection_properties_; - inline ConnectionProperties(jobject connection_properties) - : connection_properties_{connection_properties} { - } - static jmethodID GetMethodGetPropertiesFromConnectionString( JNIEnv* const env, const jclass connection_properties); public: - static ConnectionProperties* GetPropertiesFromConnectionString( + static std::shared_ptr< ConnectionProperties > GetPropertiesFromConnectionString( JniEnv* const jni_env, const std::string connectionString); + inline ConnectionProperties(jobject connection_properties) + : connection_properties_{connection_properties} {}; + inline jobject GetHandle() { return connection_properties_; }; diff --git a/src/odbcdriver/jni/JniEnv.cpp b/src/odbcdriver/jni/JniEnv.cpp index 1c834ae2f..b6f8c2ab3 100644 --- a/src/odbcdriver/jni/JniEnv.cpp +++ b/src/odbcdriver/jni/JniEnv.cpp @@ -38,15 +38,17 @@ void JniEnv::CreateJavaVM() { JavaVMOption *options = new JavaVMOption[numOfOptions]; // JVM invocation options + // where to find java .class options[0].optionString = - (char *)"-Djava.class.path=./documentdb-jdbc-1.0.0-all.jar"; // where to find - // java .class + (char *)"-Djava.class.path=./documentdb-jdbc-1.0.0-all.jar"; options[0].extraInfo = nullptr; - vm_args.version = JNI_VERSION_1_8; // minimum Java version - vm_args.nOptions = numOfOptions; // number of options + // minimum Java version + vm_args.version = JNI_VERSION_1_8; + // number of options + vm_args.nOptions = numOfOptions; vm_args.options = options; - vm_args.ignoreUnrecognized = - false; // invalid options make the JVM init fail + // invalid options make the JVM init fail + vm_args.ignoreUnrecognized = false; //=============== load and initialize // Java VM and JNI interface ============= diff --git a/src/odbcdriver/jni/JniEnv.h b/src/odbcdriver/jni/JniEnv.h index 5f98a5b79..4d6987422 100644 --- a/src/odbcdriver/jni/JniEnv.h +++ b/src/odbcdriver/jni/JniEnv.h @@ -27,13 +27,14 @@ class JniEnv { public: JniEnv(); void CreateJavaVM(); - inline JNIEnv* GetJniEnv() { + inline JNIEnv* const GetJniEnv() { return env_; }; inline ~JniEnv() { if (jvm_ != nullptr) { jvm_->DestroyJavaVM(); jvm_ = nullptr; + env_ = nullptr; } } }; From 57865da5a49364e1b7be48152e0b41dd34737ec1 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Wed, 15 Dec 2021 15:10:27 -0800 Subject: [PATCH 16/16] [AD-492] Resolve warning (for MacOS/Linux). https:/bitquill.atlassian.net/browse/AD-492 --- src/odbcdriver/jni/JniEnv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/odbcdriver/jni/JniEnv.h b/src/odbcdriver/jni/JniEnv.h index 4d6987422..a038bcc1b 100644 --- a/src/odbcdriver/jni/JniEnv.h +++ b/src/odbcdriver/jni/JniEnv.h @@ -27,7 +27,7 @@ class JniEnv { public: JniEnv(); void CreateJavaVM(); - inline JNIEnv* const GetJniEnv() { + inline JNIEnv* GetJniEnv() { return env_; }; inline ~JniEnv() {