Skip to content

Commit

Permalink
CORE-15310: Use custom SLF4J bundle in OSGi tests (#6248)
Browse files Browse the repository at this point in the history
The main principle is that `net.corda.slf4jv1` bundle and `slf4j.api` should be mutually exclusive.

I.e. `slf4j.api` is used during production Workers run, including Combined Worker. Whereas `net.corda.slf4jv1` bundle is used for any OSGi testing.

But these bundles should never be used together as this causes OSGi conflicts like:
```
"Uses constraint violation. Unable to resolve resource micrometer-core [micrometer-core [37](R 37.0)] because it is exposed to package 'org.slf4j.spi' from resources net.corda.slf4jv1 [net.corda.slf4jv1 [142](R 142.0)] and slf4j.api [slf4j.api [209](R 209.0)] via two dependency chains.

Chain 1:
  micrometer-core [micrometer-core [37](R 37.0)]
  import: (&(osgi.wiring.package=org.slf4j.spi)(version>=1.7.0)(!(version>=2.0.0)))
  |
  export: osgi.wiring.package: org.slf4j.spi
  net.corda.slf4jv1 [net.corda.slf4jv1 [142](R 142.0)]

Chain 2:
  micrometer-core [micrometer-core [37](R 37.0)]
  import: (&(osgi.wiring.package=org.slf4j)(version>=1.7.0)(!(version>=2.0.0)))
  |
  export: osgi.wiring.package=org.slf4j; uses:=org.slf4j.spi
  slf4j.api [slf4j.api [209](R 209.0)]
  import: (&(osgi.wiring.package=org.slf4j.spi)(version>=2.0.13)(!(version>=3.0.0)))
  |
  export: osgi.wiring.package: org.slf4j.spi
  slf4j.api [slf4j.api [209](R 209.0)]"
```
  • Loading branch information
vkolomeyko authored Jul 2, 2024
1 parent 8800fcd commit 6183cb0
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions buildSrc/src/main/groovy/corda.osgi-test-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ Test-Cases: \${classes;HIERARCHY_INDIRECTLY_ANNOTATED;org.junit.platform.commons
}
}

def slf4j2Dependency = libs.slf4j.api.get()

def bundlesSet = files(sourceSets.integrationTest.runtimeClasspath.filter {
// Filter out SLF4J bundle as it will be conflicting with special bundle we provide for OSGi testing purposes: slf4jv1
!(it.path.contains("${slf4j2Dependency.name}-${slf4j2Dependency.version}"))
}, configurations.archives.artifacts.files)

def resolve = tasks.register('resolve', Resolve) {
dependsOn jar, testingBundle
bundles = files(sourceSets.integrationTest.runtimeClasspath, configurations.archives.artifacts.files)
bundles = bundlesSet
bndrun = file('test.bndrun')
outputBndrun = layout.buildDirectory.file('resolved-test.bndrun')
doFirst {
Expand All @@ -81,7 +88,7 @@ def testOSGi = tasks.register('testOSGi', TestOSGi) {
languageVersion = of(17)
}
resultsDirectory = file("$testResultsDir/integrationTest")
bundles = files(sourceSets.integrationTest.runtimeClasspath, configurations.archives.artifacts.files)
bundles = bundlesSet
bndrun = resolve.flatMap { it.outputBndrun }

// These properties are for Quasar's framework extension, should it be present.
Expand Down
2 changes: 1 addition & 1 deletion components/ledger/ledger-verification/test.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
bnd.identity;id='net.bytebuddy.byte-buddy',\
bnd.identity;id='junit-jupiter-engine',\
bnd.identity;id='junit-platform-launcher',\
bnd.identity;id='slf4j.api',\
bnd.identity;id='net.corda.slf4jv1',\
bnd.identity;id='slf4j.simple',\
bnd.identity;id='org.liquibase.core',\
bnd.identity;id='com.opencsv',\
Expand Down
2 changes: 1 addition & 1 deletion components/security-manager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
integrationTestImplementation "org.osgi:org.osgi.service.component:$osgiServiceComponentVersion"
integrationTestImplementation project(':testing:security-manager-utilities')
integrationTestImplementation "net.corda:corda-application"
integrationTestImplementation 'org.slf4j:slf4j-api'
integrationTestRuntimeOnly project(':testing:slf4jv1')
integrationTestRuntimeOnly("org.apache.felix:org.apache.felix.framework.security:$felixSecurityVersion") {
exclude group: 'org.osgi'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
bnd.identity;id='net.corda.test-impl-two',\
bnd.identity;id='junit-jupiter-engine',\
bnd.identity;id='junit-platform-launcher',\
bnd.identity;id='slf4j.api',\
bnd.identity;id='net.corda.slf4jv1',\
bnd.identity;id='slf4j.simple'

-runstartlevel: \
Expand Down
1 change: 1 addition & 0 deletions libs/configuration/configuration-validation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies {
because "Version bundled with current version of 'com.networknt:json-schema-validator' does not have OSGi manifest."
}
}
integrationTestRuntimeOnly project(':testing:slf4jv1')
}
2 changes: 1 addition & 1 deletion libs/kotlin-reflection/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ dependencies {
testRuntimeOnly "org.ow2.asm:asm:$asmVersion"

integrationTestImplementation project(':libs:kotlin-reflection:kotlin-reflection-test-example')
integrationTestImplementation 'org.slf4j:slf4j-api'
integrationTestImplementation "org.apache.felix:org.apache.felix.framework:$felixVersion"
integrationTestImplementation project(':testing:slf4jv1')
integrationTestImplementation libs.junit
integrationTestRuntimeOnly libs.junit.engine
integrationTestRuntimeOnly libs.junit.platform
Expand Down
1 change: 1 addition & 0 deletions libs/layered-property-map/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ dependencies {
testImplementation project(":testing:test-utilities")

integrationTestImplementation project(":libs:layered-property-map:layered-property-map-test-converter")
integrationTestRuntimeOnly project(':testing:slf4jv1')
}
2 changes: 1 addition & 1 deletion libs/sandbox-internal/test.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
bnd.identity;id='co.paralleluniverse.quasar-core',\
bnd.identity;id='junit-jupiter-engine',\
bnd.identity;id='junit-platform-launcher',\
bnd.identity;id='slf4j.api',\
bnd.identity;id='net.corda.slf4jv1',\
bnd.identity;id='slf4j.simple'

-runstartlevel: \
Expand Down
1 change: 1 addition & 0 deletions testing/p2p/inmemory-messaging-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ dependencies {

integrationTestApi project(":testing:test-utilities")
testImplementation project(":libs:lifecycle:lifecycle-impl")
integrationTestRuntimeOnly project(':testing:slf4jv1')
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SandboxSetupImpl @Activate constructor(
"org.apache.felix.scr",
"org.hibernate.orm.core",
"org.jetbrains.kotlin.osgi-bundle",
"slf4j.api"
"net.corda.slf4jv1"
))

private val REPLACEMENT_SERVICES = unmodifiableSet(setOf(
Expand Down
2 changes: 1 addition & 1 deletion testing/slf4jv1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tasks.named('jar', Jar) {
archiveBaseName = 'corda-slf4jv1'

ext {
bundleVersion = parseMavenString(antlrVersion).OSGiVersion
bundleVersion = parseMavenString(libs.slf4j.api.get().version).OSGiVersion
}

bundle {
Expand Down

0 comments on commit 6183cb0

Please sign in to comment.