|
1 | | -import aQute.bnd.gradle.BundleTaskConvention |
2 | | -import aQute.bnd.gradle.FileSetRepositoryConvention |
3 | | -import aQute.bnd.gradle.Resolve |
4 | | - |
5 | 1 | plugins { |
6 | 2 | `java-library` |
7 | 3 | eclipse |
@@ -83,6 +79,7 @@ tasks.checkstyleMain { |
83 | 79 | if (project in mavenizedProjects) { |
84 | 80 |
|
85 | 81 | apply(plugin = "publishing-conventions") |
| 82 | + apply(plugin = "osgi-conventions") |
86 | 83 |
|
87 | 84 | java { |
88 | 85 | withJavadocJar() |
@@ -157,105 +154,6 @@ if (project in mavenizedProjects) { |
157 | 154 | } |
158 | 155 | } |
159 | 156 |
|
160 | | - // This task enances `jar` and `shadowJar` tasks with the bnd |
161 | | - // `BundleTaskConvention` convention which allows for generating OSGi |
162 | | - // metadata into the jar |
163 | | - tasks.withType<Jar>().matching { |
164 | | - task: Jar -> task.name == "jar" || task.name == "shadowJar" |
165 | | - }.configureEach { |
166 | | - val btc = BundleTaskConvention(this) |
167 | | - |
168 | | - // These are bnd instructions necessary for generating OSGi metadata. |
169 | | - // We've generalized these so that they are widely applicable limiting |
170 | | - // module configurations to special cases. |
171 | | - btc.setBnd(""" |
172 | | - # These are the general rules for package imports. |
173 | | - Import-Package: \ |
174 | | - !org.apiguardian.api,\ |
175 | | - org.junit.platform.commons.logging;status=INTERNAL,\ |
176 | | - kotlin.*;resolution:="optional",\ |
177 | | - * |
178 | | -
|
179 | | - # This tells bnd not to complain if a module doesn't actually import |
180 | | - # the kotlin packages, but enough modules do to make it a default. |
181 | | - -fixupmessages.kotlin.import: "Unused Import-Package instructions: \\[kotlin.*\\]";is:=ignore |
182 | | -
|
183 | | - # This tells bnd to ignore classes it files in `META-INF/versions/` |
184 | | - # because bnd doesn't yet support multi-release jars. |
185 | | - -fixupmessages.wrong.dir: "Classes found in the wrong directory: \\{META-INF/versions/...";is:=ignore |
186 | | -
|
187 | | - # Don't scan for Class.forName package imports. |
188 | | - # See https://bnd.bndtools.org/instructions/noclassforname.html |
189 | | - -noclassforname: true |
190 | | -
|
191 | | - # Don't add all the extra headers bnd normally adds. |
192 | | - # See https://bnd.bndtools.org/instructions/noextraheaders.html |
193 | | - -noextraheaders: true |
194 | | -
|
195 | | - # Don't add the Private-Package header. |
196 | | - # See https://bnd.bndtools.org/instructions/removeheaders.html |
197 | | - -removeheaders: Private-Package |
198 | | -
|
199 | | - # Add the custom buildSrc/src/main/kotlin/APIGuardianAnnotations.kt |
200 | | - # plugin to bnd |
201 | | - -plugin.apiguardian.annotations: ${APIGuardianAnnotations::class.qualifiedName} |
202 | | -
|
203 | | - # Instruct the APIGuardianAnnotations how to operate. |
204 | | - # See https://bnd.bndtools.org/instructions/export-apiguardian.html |
205 | | - -export-apiguardian: *;version=${project.version} |
206 | | - """) |
207 | | - |
208 | | - // Add the convention to the jar task |
209 | | - convention.plugins.put("bundle", btc) |
210 | | - |
211 | | - doLast { |
212 | | - // Do the actual work putting OSGi stuff in the jar. |
213 | | - btc.buildBundle() |
214 | | - } |
215 | | - |
216 | | - finalizedBy("verifyOSGi") |
217 | | - } |
218 | | - |
219 | | - // Bnd's Resolve task uses a properties file for it's configuration. This |
220 | | - // task writes out the properties necessary for it to verify the OSGi |
221 | | - // metadata. |
222 | | - tasks.register<WriteProperties>("verifyOSGiProperties") { |
223 | | - setOutputFile("${buildDir}/verifyOSGiProperties.bndrun") |
224 | | - property("-standalone", "true") |
225 | | - property("-runee", "JavaSE-${Versions.jvmTarget}") |
226 | | - property("-runrequires", "osgi.identity;filter:='(osgi.identity=${project.name})'") |
227 | | - property("-runsystempackages", "jdk.internal.misc,sun.misc") |
228 | | - } |
229 | | - |
230 | | - // Bnd's Resolve task is what verifies that a jar can be used in OSGi and |
231 | | - // that it's metadata is valid. If the metadata is invalid this task will |
232 | | - // fail. |
233 | | - tasks.register<Resolve>("verifyOSGi") { |
234 | | - dependsOn("verifyOSGiProperties") |
235 | | - setBndrun("${buildDir}/verifyOSGiProperties.bndrun") |
236 | | - setReportOptional(false) |
237 | | - withConvention(FileSetRepositoryConvention::class) { |
238 | | - |
239 | | - // By default bnd will use jars found in: |
240 | | - // 1. project.sourceSets.main.runtimeClasspath |
241 | | - // 2. project.configurations.archives.artifacts.files |
242 | | - // to validate the metadata. |
243 | | - // This adds jars defined in `testRuntimeClasses` also so that bnd |
244 | | - // can use them to validate the metadata without causing those to |
245 | | - // end up in the dependencies of those projects. |
246 | | - bundles(sourceSets["test"].runtimeClasspath) |
247 | | - } |
248 | | - } |
249 | | - |
250 | | - // The ${project.description}, for some odd reason, is only available |
251 | | - // afterEvaluate. |
252 | | - afterEvaluate { |
253 | | - tasks.withType<Jar>().configureEach { |
254 | | - convention.findPlugin(BundleTaskConvention::class.java) |
255 | | - ?.bnd("Bundle-Name: ${project.description}") |
256 | | - } |
257 | | - } |
258 | | - |
259 | 157 | } else { |
260 | 158 | tasks { |
261 | 159 | jar { |
|
0 commit comments