Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OSGi metadata via build in a non intrusive way #777

Merged
merged 5 commits into from
Sep 27, 2020

Conversation

swimmesberger
Copy link
Contributor

Implementation of the build discussed in the issue #776

Fixes #776

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already declared in the root build.gradle as gradlePluginPortal().

}
}
dependencies {
classpath deps.bnd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this to the root build.gradle. The buildscript classpath is global and it's much easier to deal with when there is only a single place where dependencies are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason gradle does not allow to access buildscript classes directly in a gradle file that is externally applied. Therefore as a workaround I have added the class as a property to the root project to make it accessible from the jvm.gradle file.

Copy link
Contributor Author

@swimmesberger swimmesberger Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying plugins in applied scripts works as intended but I don't want to apply the bnd plugin because on default the bnd plugin overwrites the jar task to provide the updated MANIFEST.MF and that could be counted as "intrusive" again.

@swankjesse
Copy link
Collaborator

Manifest-Version: 1.0
Automatic-Module-Name: okio
Bnd-LastModified: 1601068645975
Bundle-ManifestVersion: 2
Bundle-Name: com.squareup.okio
Bundle-SymbolicName: com.squareup.okio
Bundle-Version: 2.9.0.SNAPSHOT
Created-By: 11.0.7 (AdoptOpenJDK)
Export-Package: okio;uses:="kotlin,kotlin.collections,kotlin.jvm,kotli
 n.jvm.functions,kotlin.jvm.internal";version="2.9.0"
Import-Package: javax.crypto,javax.crypto.spec,kotlin,kotlin.collectio
 ns,kotlin.jvm,kotlin.jvm.functions,kotlin.jvm.internal,kotlin.text
Private-Package: okio.internal
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Tool: Bnd-5.1.2.202007211702

Copy link
Collaborator

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Thanks for doing this.

'''
}

// extract only the MANIFEST.MF file from the OSGi compatible JAR file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this part do anything meaningful, or is it just because with the old plugin things went sideways here? If this is just ceremony to make me feel better, I think we should remove it.

Copy link
Contributor Author

@swimmesberger swimmesberger Sep 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swankjesse to be honest it's just ceremony to make you feel better. I wanted to reduce the surface area the bnd plugins is working on (if you do not trust what the plugin does) therefore my idea was to let the plugin generate the jar file and simply use only the META-INF/MANIFEST.MF file for the jar file generated by the jvmJar task. In practice for the bnd instructions used at the moment the resulting jar file of the bnd plugin will be exactly the same as the resulting jar from the jvmJar task except that the MANIFEST.MF contains the proper OSGi metadata.

@swimmesberger
Copy link
Contributor Author

@swankjesse I have changed the code to be simpler but potentially more intrusive.

Copy link
Collaborator

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're gonna support OSGi, I'd like to do it in the least creative, least invasive way possible.


// configure the kotlin JVM jar task
tasks['jvmJar'].configure { t ->
// the bnd task conention modifies this jar task accordingly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not: conention

manifest {
attributes('Automatic-Module-Name': 'okio')

// configure the kotlin JVM jar task
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not: delete comment

Bundle-SymbolicName: com.squareup.okio
'''
// call the convention when the task has finished to modify the jar to contain OSGi metadata
t.doLast {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question: what's different between this approach and typical use of bnd? The way this stuff is hooked up seems pretty atypical! doLast and bndBundleTaskConventionClass both seem awkward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically you would apply the plugin itself which will overwrite the jar task and read a file in the projects directory called bnd.bnd where the multiline string should be in. With the build of okio this is not possible because the jar task itself doesn't really do anything the real "jar" task is the "jvmJar" therefore I applied the stuff the plugin does normally to the jar task to the jvmJar task instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation

@swankjesse swankjesse merged commit c1427b8 into square:master Sep 27, 2020
15characterlimi pushed a commit to 15characterlimi/okio that referenced this pull request Nov 9, 2020
* Added OSGi metadata via build in a non intrusive way

* Add bnd to root buildscript

* Added bnd class to root project only

* Simplified bnd usage

* Fixed comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include OSGi metadata
3 participants