Skip to content

Commit

Permalink
Auto generate OSGi require bundle header
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmudd committed Oct 1, 2024
1 parent e85d030 commit a5eac30
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion jhdf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jar {
'Bundle-Vendor': 'James Mudd',
'Bundle-Version': project.version,
'Export-Package': 'io.jhdf,io.jhdf.*,io.jhdf.api,io.jhdf.api.*',
'Require-Bundle': 'slf4j.api;bundle-version="1.7.36",org.apache.commons.lang3;bundle-version="3.17.0",com.ning.compress-lzf;bundle-version="1.1.2",lz4-java;bundle-version="1.8.0"',
'Require-Bundle': buildRequireBundleHeader(),
// Build data
'Build-JDK': System.getProperty('java.vendor') + ' ' + System.getProperty('java.version'),
'Build-OS': System.getProperty('os.name') + ' ' + System.getProperty('os.version'),
Expand Down Expand Up @@ -198,6 +198,9 @@ signing {

import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort

import java.util.stream.Collectors

spotbugs {
ignoreFailures = true // Allow build to continue with errors
effort = Effort.valueOf('MAX')
Expand All @@ -222,3 +225,28 @@ sonarqube {
property "sonar.java.checkstyle.reportPaths", "build/reports/checkstyle/main.xml,build/reports/checkstyle/test.xml"
}
}

String buildRequireBundleHeader() {
def runtimeDependencies = configurations.runtimeClasspath.getAllDependencies()
def bundleToModule = [
"slf4j.api": "org.slf4j:slf4j-api",
"org.apache.commons.lang3": "org.apache.commons:commons-lang3",
"com.ning.compress-lzf": "com.ning:compress-lzf",
"lz4-java": "org.lz4:lz4-java"
]

def moduleToVersion = runtimeDependencies.collectEntries {
[it.module.toString(), it.version]
}

// Check here to catch when dependencies are added/removed
if(!bundleToModule.values().containsAll(moduleToVersion.keySet())) {
throw new IllegalStateException("Runtime dependencies not mapped for OSGi")
}

def header = bundleToModule.entrySet().stream()
.map {"${it.key};bundle-version=\"${moduleToVersion.get(it.value)}\"" }
.collect(Collectors.joining(","))

return header
}

0 comments on commit a5eac30

Please sign in to comment.