Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AD-492] Working JNI GitHub workflow #2

Merged
merged 16 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
87 changes: 6 additions & 81 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
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: run-cppcheck
run: |
sudo apt install cppcheck
Expand Down Expand Up @@ -98,84 +104,3 @@ jobs:
with:
name: linux64-deb-installer
path: deb-installer
build-linux32:
birschick-bq marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Setup cmake
uses: jwlawson/[email protected]
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
6 changes: 6 additions & 0 deletions .github/workflows/mac-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
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: run-cppcheck
run: |
brew install cppcheck
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/mac-debug-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ jobs:
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: run-cppcheck
run: |
brew install cppcheck
Expand Down
25 changes: 24 additions & 1 deletion .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
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: run-cppcheck
run: |
brew install cppcheck
Expand Down Expand Up @@ -72,6 +78,15 @@ 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: 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/[email protected]
- name: add-msbuild-to-path
Expand Down Expand Up @@ -103,7 +118,15 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Get specific version CMake, v3.18.3
- name: Get Java distribution
uses: actions/setup-java@v2
with:
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.18.3
uses: lukka/[email protected]
- name: add-msbuild-to-path
uses: microsoft/[email protected]
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/win-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ 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: 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/[email protected]
- name: add-msbuild-to-path
Expand Down Expand Up @@ -75,6 +84,15 @@ 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: "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/[email protected]
- name: add-msbuild-to-path
Expand Down Expand Up @@ -120,6 +138,15 @@ 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: "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/[email protected]
- name: add-msbuild-to-path
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/win-debug-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ 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: 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/[email protected]
- name: add-msbuild-to-path
Expand Down Expand Up @@ -61,6 +70,15 @@ 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: "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/[email protected]
- name: add-msbuild-to-path
Expand Down
15 changes: 15 additions & 0 deletions src/odbcdriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
85 changes: 85 additions & 0 deletions src/odbcdriver/jni/Connection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 <jni.h>
#include "Connection.h"
#include <iostream>
using namespace std;

namespace jni {

void Connection::Connect() {
if (connection_ != nullptr) {
return;
}

jni_env_->CreateJavaVM();
birschick-bq marked this conversation as resolved.
Show resolved Hide resolved
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_documentdb_constructor = env->GetMethodID(
cls_documentdb_connection, "<init>",
"(Lsoftware/amazon/documentdb/jdbc/DocumentDbConnectionProperties;)V");
if (m_documentdb_constructor == nullptr) {
throw runtime_error(
"ERROR: constructor DocumentDbConnection(connectionProperties) not "
"found!");
}
cout << "DocumentDbConnection constructor found." << endl;

connection_ =
env->NewObject(cls_documentdb_connection, m_documentdb_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) {
garya-bitquill marked this conversation as resolved.
Show resolved Hide resolved
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);
// Ensure all member Java object are set to null.
connection_ = nullptr;
jni_env_ = nullptr;
}
}

} // namespace jni
Loading