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

OSGi compatibility #270

Merged
merged 2 commits into from
Nov 22, 2022
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
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pluginManagement {
fun String.v() = extra["$this.version"].toString()
fun PluginDependenciesSpec.idv(id: String, key: String = id) = id(id) version key.v()

id("biz.aQute.bnd.builder") version "6.3.1"
id("com.github.spotbugs") version "5.0.+"
id("com.diffplug.spotless") version "6.11.+"
id("com.github.vlsi.gradle-extensions") version "1.+"
Expand Down
20 changes: 20 additions & 0 deletions wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
checkstyle
java
jacoco
id("biz.aQute.bnd.builder")
id("com.diffplug.spotless")
id("com.github.spotbugs")
id("com.github.vlsi.gradle-extensions")
Expand All @@ -30,6 +31,7 @@ dependencies {
compileOnly("com.zaxxer:HikariCP:4.0.3") // Version 4.+ is compatible with Java 8
compileOnly("software.amazon.awssdk:secretsmanager:2.17.285")
compileOnly("com.fasterxml.jackson.core:jackson-databind:2.13.4")
compileOnly("org.osgi:org.osgi.core:4.3.0")

testImplementation("org.junit.platform:junit-platform-commons:1.9.0")
testImplementation("org.junit.platform:junit-platform-engine:1.9.0")
Expand Down Expand Up @@ -174,6 +176,24 @@ tasks.jar {
into("META-INF/services/")
}

bundle {
bnd(
"""
-exportcontents: software.*
-removeheaders: Created-By
Bundle-Description: Amazon Web Services (AWS) Advanced JDBC Wrapper Driver
Bundle-DocURL: https://github.com/awslabs/aws-advanced-jdbc-wrapper
Bundle-Vendor: Amazon Web Services (AWS)
Import-Package: javax.sql, javax.transaction.xa, javax.naming, javax.security.sasl;resolution:=optional, *;resolution:=optional
Bundle-Activator: software.amazon.jdbc.osgi.WrapperBundleActivator
Bundle-SymbolicName: software.aws.rds
Bundle-Name: Amazon Web Services (AWS) Advanced JDBC Wrapper Driver
Bundle-Copyright: Copyright Amazon.com Inc. or affiliates.
Require-Capability: osgi.ee;filter:="(&(|(osgi.ee=J2SE)(osgi.ee=JavaSE))(version>=1.8))"
"""
)
}

doFirst {
mkdir("${buildDir}/META-INF/services/")
val driverFile = File("${buildDir}/META-INF/services/java.sql.Driver")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*/

package software.amazon.jdbc.osgi;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class WrapperBundleActivator implements BundleActivator {

public void start(BundleContext context) throws Exception {
if (!software.amazon.jdbc.Driver.isRegistered()) {
software.amazon.jdbc.Driver.register();
}
}

public void stop(BundleContext context) throws Exception {
if (software.amazon.jdbc.Driver.isRegistered()) {
software.amazon.jdbc.Driver.deregister();
}
}
}