@@ -10,60 +10,65 @@ val importAPIGuardian = "org.apiguardian.*;resolution:=\"optional\""
10
10
// This task enhances `jar` and `shadowJar` tasks with the bnd
11
11
// `BundleTaskExtension` extension which allows for generating OSGi
12
12
// metadata into the jar
13
- tasks.withType<Jar >().matching {
14
- task: Jar -> task .name == " jar" || task.name == " shadowJar"
13
+ tasks.withType<Jar >().matching { task : Jar ->
14
+ task.name == " jar" || task.name == " shadowJar"
15
15
}.configureEach {
16
- val bte = extensions.create<BundleTaskExtension >(BundleTaskExtension .NAME , this )
17
-
18
16
extra[" importAPIGuardian" ] = importAPIGuardian
19
17
20
- // These are bnd instructions necessary for generating OSGi metadata.
21
- // We've generalized these so that they are widely applicable limiting
22
- // module configurations to special cases.
23
- bte.setBnd("""
24
- # Set the Bundle-SymbolicName to the archiveBaseName.
25
- # We don't use the archiveClassifier which Bnd will use
26
- # in the default Bundle-SymbolicName value.
27
- Bundle-SymbolicName: ${' $' } {task.archiveBaseName}
28
-
29
- # Set the Bundle-Name from the project description
30
- Bundle-Name: ${' $' } {project.description}
31
-
32
- # These are the general rules for package imports.
33
- Import-Package: \
34
- ${importAPIGuardian} ,\
35
- org.junit.platform.commons.logging;status=INTERNAL,\
36
- kotlin.*;resolution:="optional",\
37
- *
38
-
39
- # This tells bnd not to complain if a module doesn't actually import
40
- # the kotlin and apiguardian packages, but enough modules do to make it a default.
41
- -fixupmessages.kotlin.import: "Unused Import-Package instructions: \\[kotlin.*\\]";is:=ignore
42
- -fixupmessages.apiguardian.import: "Unused Import-Package instructions: \\[org.apiguardian.*\\]";is:=ignore
43
-
44
- # This tells bnd to ignore classes it finds in `META-INF/versions/`
45
- # because bnd doesn't yet support multi-release jars.
46
- -fixupmessages.wrong.dir: "Classes found in the wrong directory: \\{META-INF/versions/...";is:=ignore
47
-
48
- # Don't scan for Class.forName package imports.
49
- # See https://bnd.bndtools.org/instructions/noclassforname.html
50
- -noclassforname: true
51
-
52
- # Don't add all the extra headers bnd normally adds.
53
- # See https://bnd.bndtools.org/instructions/noextraheaders.html
54
- -noextraheaders: true
55
-
56
- # Don't add the Private-Package header.
57
- # See https://bnd.bndtools.org/instructions/removeheaders.html
58
- -removeheaders: Private-Package
59
-
60
- # Instruct the APIGuardianAnnotations how to operate.
61
- # See https://bnd.bndtools.org/instructions/export-apiguardian.html
62
- -export-apiguardian: *;version=${' $' } {versionmask;===;${' $' } {version_cleanup;${' $' } {task.archiveVersion}}}
63
- """ )
64
-
65
- // Do the actual work putting OSGi stuff in the jar.
66
- doLast(bte.buildAction())
18
+ extensions.create<BundleTaskExtension >(BundleTaskExtension .NAME , this ).apply {
19
+ properties.set(provider {
20
+ mapOf (" project.description" to project.description)
21
+ })
22
+ // These are bnd instructions necessary for generating OSGi metadata.
23
+ // We've generalized these so that they are widely applicable limiting
24
+ // module configurations to special cases.
25
+ setBnd(
26
+ """
27
+ # Set the Bundle-SymbolicName to the archiveBaseName.
28
+ # We don't use the archiveClassifier which Bnd will use
29
+ # in the default Bundle-SymbolicName value.
30
+ Bundle-SymbolicName: ${' $' } {task.archiveBaseName}
31
+
32
+ # Set the Bundle-Name from the project description
33
+ Bundle-Name: ${' $' } {project.description}
34
+
35
+ # These are the general rules for package imports.
36
+ Import-Package: \
37
+ ${importAPIGuardian} ,\
38
+ org.junit.platform.commons.logging;status=INTERNAL,\
39
+ kotlin.*;resolution:="optional",\
40
+ *
41
+
42
+ # This tells bnd not to complain if a module doesn't actually import
43
+ # the kotlin and apiguardian packages, but enough modules do to make it a default.
44
+ -fixupmessages.kotlin.import: "Unused Import-Package instructions: \\[kotlin.*\\]";is:=ignore
45
+ -fixupmessages.apiguardian.import: "Unused Import-Package instructions: \\[org.apiguardian.*\\]";is:=ignore
46
+
47
+ # This tells bnd to ignore classes it finds in `META-INF/versions/`
48
+ # because bnd doesn't yet support multi-release jars.
49
+ -fixupmessages.wrong.dir: "Classes found in the wrong directory: \\{META-INF/versions/...";is:=ignore
50
+
51
+ # Don't scan for Class.forName package imports.
52
+ # See https://bnd.bndtools.org/instructions/noclassforname.html
53
+ -noclassforname: true
54
+
55
+ # Don't add all the extra headers bnd normally adds.
56
+ # See https://bnd.bndtools.org/instructions/noextraheaders.html
57
+ -noextraheaders: true
58
+
59
+ # Don't add the Private-Package header.
60
+ # See https://bnd.bndtools.org/instructions/removeheaders.html
61
+ -removeheaders: Private-Package
62
+
63
+ # Instruct the APIGuardianAnnotations how to operate.
64
+ # See https://bnd.bndtools.org/instructions/export-apiguardian.html
65
+ -export-apiguardian: *;version=${' $' } {versionmask;===;${' $' } {version_cleanup;${' $' } {task.archiveVersion}}}
66
+ """
67
+ )
68
+
69
+ // Do the actual work putting OSGi stuff in the jar.
70
+ doLast(buildAction())
71
+ }
67
72
}
68
73
69
74
// Bnd's Resolve task uses a properties file for its configuration. This
@@ -90,7 +95,7 @@ val osgiVerification by configurations.creating {
90
95
// that its metadata is valid. If the metadata is invalid this task will
91
96
// fail.
92
97
val verifyOSGi by tasks.registering(Resolve ::class ) {
93
- bndrun.fileProvider(osgiProperties.map{ it.outputFile })
98
+ bndrun.fileProvider(osgiProperties.map { it.outputFile })
94
99
outputBndrun.set(layout.buildDirectory.file(" resolvedOSGiProperties.bndrun" ))
95
100
isReportOptional = false
96
101
// By default bnd will use jars found in:
0 commit comments