Skip to content

Commit 97dc84f

Browse files
authored
OSGi compatibility (#270)
### Summary RDS-1092 ### Description - Added dependencies - Added bundle activator class - Added headers for OSGi compatibility ### Additional Reviewers <!-- Any additional reviewers -->
1 parent cba6bc9 commit 97dc84f

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pluginManagement {
3434
fun String.v() = extra["$this.version"].toString()
3535
fun PluginDependenciesSpec.idv(id: String, key: String = id) = id(id) version key.v()
3636

37+
id("biz.aQute.bnd.builder") version "6.3.1"
3738
id("com.github.spotbugs") version "5.0.+"
3839
id("com.diffplug.spotless") version "6.11.+"
3940
id("com.github.vlsi.gradle-extensions") version "1.+"

wrapper/build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ plugins {
1818
checkstyle
1919
java
2020
jacoco
21+
id("biz.aQute.bnd.builder")
2122
id("com.diffplug.spotless")
2223
id("com.github.spotbugs")
2324
id("com.github.vlsi.gradle-extensions")
@@ -30,6 +31,7 @@ dependencies {
3031
compileOnly("com.zaxxer:HikariCP:4.0.3") // Version 4.+ is compatible with Java 8
3132
compileOnly("software.amazon.awssdk:secretsmanager:2.17.285")
3233
compileOnly("com.fasterxml.jackson.core:jackson-databind:2.13.4")
34+
compileOnly("org.osgi:org.osgi.core:4.3.0")
3335

3436
testImplementation("org.junit.platform:junit-platform-commons:1.9.0")
3537
testImplementation("org.junit.platform:junit-platform-engine:1.9.0")
@@ -174,6 +176,24 @@ tasks.jar {
174176
into("META-INF/services/")
175177
}
176178

179+
bundle {
180+
bnd(
181+
"""
182+
-exportcontents: software.*
183+
-removeheaders: Created-By
184+
Bundle-Description: Amazon Web Services (AWS) Advanced JDBC Wrapper Driver
185+
Bundle-DocURL: https://github.com/awslabs/aws-advanced-jdbc-wrapper
186+
Bundle-Vendor: Amazon Web Services (AWS)
187+
Import-Package: javax.sql, javax.transaction.xa, javax.naming, javax.security.sasl;resolution:=optional, *;resolution:=optional
188+
Bundle-Activator: software.amazon.jdbc.osgi.WrapperBundleActivator
189+
Bundle-SymbolicName: software.aws.rds
190+
Bundle-Name: Amazon Web Services (AWS) Advanced JDBC Wrapper Driver
191+
Bundle-Copyright: Copyright Amazon.com Inc. or affiliates.
192+
Require-Capability: osgi.ee;filter:="(&(|(osgi.ee=J2SE)(osgi.ee=JavaSE))(version>=1.8))"
193+
"""
194+
)
195+
}
196+
177197
doFirst {
178198
mkdir("${buildDir}/META-INF/services/")
179199
val driverFile = File("${buildDir}/META-INF/services/java.sql.Driver")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package software.amazon.jdbc.osgi;
18+
19+
import org.osgi.framework.BundleActivator;
20+
import org.osgi.framework.BundleContext;
21+
22+
public class WrapperBundleActivator implements BundleActivator {
23+
24+
public void start(BundleContext context) throws Exception {
25+
if (!software.amazon.jdbc.Driver.isRegistered()) {
26+
software.amazon.jdbc.Driver.register();
27+
}
28+
}
29+
30+
public void stop(BundleContext context) throws Exception {
31+
if (software.amazon.jdbc.Driver.isRegistered()) {
32+
software.amazon.jdbc.Driver.deregister();
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)