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

OSGi Support #33

Closed
swimmesberger opened this issue Feb 12, 2020 · 13 comments
Closed

OSGi Support #33

swimmesberger opened this issue Feb 12, 2020 · 13 comments

Comments

@swimmesberger
Copy link

swimmesberger commented Feb 12, 2020

It would be nice when the jar would contain OSGi metadata so we could directly consume it via maven central without doing any wrapping.
I have seen this project uses ant to build. I'm not familiar with ant (only gradle/maven) so I can't provide a pull request for generating OSGi metdata but I can guide you into the right direction.
First I would recommend BND - BND is a tool which automatically generates a MANIFEST.MF containing all the necessary OSGi metdata based on the compiled *.class files. BND can be used with gradle, maven and ant to analyze the class files and generate the corresponding MANIFEST.MF based on them and a instructions file (e.g. bnd.bnd). This bnd.bnd file tells bnd what it should do.
In your case:
Bundle-SymbolicName: com.github.seancfoley.ipaddress
Export-Package: inet.ipaddr.*

would be probably enough.

Here I have also found a BND ant example: https://groups.google.com/forum/#!topic/bndtools-users/UgQ9bmoU4Eg

The final MANIFEST.MF should look roughly something like that:

Manifest-Version: 1.0
Automatic-Module-Name: com.github.seancfoley.ipaddress
Bnd-LastModified: 1581504821138
Bundle-ManifestVersion: 2
Bundle-Name: com.github.seancfoley.ipaddress
Bundle-SymbolicName: com.github.seancfoley.ipaddress
Bundle-Version: 5.2.1
Created-By: 1.8.0_202-ea (Oracle Corporation)
Export-Package: inet.ipaddr;uses:="inet.ipaddr.format,inet.ipaddr.form
 at.standard,inet.ipaddr.format.string,inet.ipaddr.format.util,inet.ip
 addr.format.util.sql,inet.ipaddr.format.validate,inet.ipaddr.ipv4,ine
 t.ipaddr.ipv6,inet.ipaddr.mac";version="5.2.1",inet.ipaddr.format;use
 s:="inet.ipaddr,inet.ipaddr.format.standard,inet.ipaddr.format.string
 ,inet.ipaddr.format.util";version="5.2.1",inet.ipaddr.format.large;us
 es:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.string,inet.ip
 addr.format.util";version="5.2.1",inet.ipaddr.format.standard;uses:="
 inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.string,inet.ipaddr.
 format.util,inet.ipaddr.format.validate";version="5.2.1",inet.ipaddr.
 format.string;uses:="inet.ipaddr,inet.ipaddr.format.util";version="5.
 2.1",inet.ipaddr.format.util;uses:="inet.ipaddr,inet.ipaddr.format,in
 et.ipaddr.format.standard,inet.ipaddr.format.string,inet.ipaddr.forma
 t.util.sql";version="5.2.1",inet.ipaddr.format.util.sql;uses:="inet.i
 paddr.format.string,inet.ipaddr.format.util";version="5.2.1",inet.ipa
 ddr.format.validate;uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr
 .format.standard,inet.ipaddr.mac";version="5.2.1",inet.ipaddr.ipv4;us
 es:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.standard,inet.
 ipaddr.format.string,inet.ipaddr.format.util,inet.ipaddr.ipv6";versio
 n="5.2.1",inet.ipaddr.ipv6;uses:="inet.ipaddr,inet.ipaddr.format,inet
 .ipaddr.format.standard,inet.ipaddr.format.string,inet.ipaddr.format.
 util,inet.ipaddr.ipv4,inet.ipaddr.mac";version="5.2.1",inet.ipaddr.ma
 c;uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.standard,i
 net.ipaddr.format.string,inet.ipaddr.format.util,inet.ipaddr.ipv6";ve
 rsion="5.2.1"
Import-Package: inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.larg
 e,inet.ipaddr.format.standard,inet.ipaddr.format.string,inet.ipaddr.f
 ormat.util,inet.ipaddr.format.util.sql,inet.ipaddr.format.validate,in
 et.ipaddr.ipv4,inet.ipaddr.ipv6,inet.ipaddr.mac
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-4.3.1.201911131708

It is possible to simply "hardcode" the manifest additions like that but that would mean that if packages are added you would have to manually maintain that hardcoded manifest too. Some stuff listed above is also optional and only produced because bnd produces "super correct" manifests.

@seancfoley
Copy link
Owner

OK, seems not too difficult, and off the top of my head I cannot think of any downside. Yes, I have been using ant, and have a bit of familiarity with maven, and not much with gradle, despite the fact that's the reverse order of popularity these days.

Thanks for the pointers.

Would not be able to alter any previous releases since the maven repositories forbid changing a release. But could make the changes to the jar manifests for the next release(s).

@swimmesberger
Copy link
Author

Would be nice if you could do a minor release which contains the OSGi metadata then you wouldn't have to overwrite any existing version and we could switch to the new version.
If you planned a release anyway in the foreseeable future you could include the build change in that version.

@seancfoley
Copy link
Owner

Yes, I expect to do a release sometime in the next 1-2 months, so I would include this with it.

@swimmesberger
Copy link
Author

Any progress or eta. for the release?

@seancfoley
Copy link
Owner

I'm getting close, I estimate a few more weeks.

@seancfoley
Copy link
Owner

seancfoley commented May 13, 2020

As you suggested I am using the bnd tool, and now I am remembering how complicated osgi can be. Anyway, here is what I am producing as a manifest from what appears to be the latest bnd jar:

Manifest-Version: 1.0
Bnd-LastModified: 1589338050342
Bundle-ManifestVersion: 2
Bundle-Name: com.github.seancfoley.ipaddress
Bundle-SymbolicName: com.github.seancfoley.ipaddress
Bundle-Version: 5.3.0
Created-By: 11.0.5 (Oracle Corporation)
DSTAMP: 20200512
Export-Package: inet.ipaddr;version="5.3.0";uses:="inet.ipaddr.format,in
et.ipaddr.format.standard,inet.ipaddr.format.string,inet.ipaddr.format.
util,inet.ipaddr.format.util.sql,inet.ipaddr.format.validate,inet.ipadd
r.ipv4,inet.ipaddr.ipv6,inet.ipaddr.mac",inet.ipaddr.format;version="5.
3.0";uses:="inet.ipaddr,inet.ipaddr.format.standard,inet.ipaddr.format.
string,inet.ipaddr.format.util",inet.ipaddr.format.large;version="5.3.0
";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.string,inet.
ipaddr.format.util",inet.ipaddr.format.standard;version="5.3.0";uses:="
inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.string,inet.ipaddr.fo
rmat.util,inet.ipaddr.format.validate",inet.ipaddr.format.string;versio
n="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format.util",inet.ipaddr.forma
t.util;version="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipadd
r.format.standard,inet.ipaddr.format.string,inet.ipaddr.format.util.sql
",inet.ipaddr.format.util.sql;version="5.3.0";uses:="inet.ipaddr.format
.util",inet.ipaddr.format.validate;version="5.3.0";uses:="inet.ipaddr,i
net.ipaddr.format,inet.ipaddr.format.standard,inet.ipaddr.mac",inet.ipa
ddr.ipv4;version="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipa
ddr.format.standard,inet.ipaddr.format.string,inet.ipaddr.format.util,i
net.ipaddr.ipv6",inet.ipaddr.ipv6;version="5.3.0";uses:="inet.ipaddr,in
et.ipaddr.format,inet.ipaddr.format.standard,inet.ipaddr.format.string,
inet.ipaddr.format.util,inet.ipaddr.ipv4,inet.ipaddr.mac",inet.ipaddr.m
ac;version="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.fo
rmat.standard,inet.ipaddr.format.string,inet.ipaddr.format.util,inet.ip
addr.ipv6"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
TODAY: May 12 2020
Tool: Bnd-2.4.0.201411031536
TSTAMP: 2247

I can see you use the bnd tools, which is different from the jar. In fact, there are so many different bnd deliveries it mirrors the complexity of osgi. Too complicated :-) I am not getting an Import-package section like your example, don't know why, but that's probably fine, ipaddress only needs core java 8, nothing fancy.

I assume that the above would work for you. If not, please advise. It will end up in the IPAddress jar files found in the releases, and also in the ipaddress-5.3.0.jar jar soon to be found on maven central (https://repo1.maven.org/maven2/com/github/seancfoley/ipaddress) and jfrog bintray (I assume it doesn't need to be in the maven source or javadoc jars). Since I don't know much about osgi, I really don't know.

@swimmesberger
Copy link
Author

Which bnd tool do you use? The ant plugin? It seems "2.4.0.201411031536" is quite old. BND changed the artifactid some time ago - so here you find updated binaries:
https://mvnrepository.com/artifact/biz.aQute.bnd/biz.aQute.bndlib/5.0.1

"aQute.bnd.plugin.ant.AntPlugin" is still available in the newest version.

@seancfoley
Copy link
Owner

seancfoley commented May 13, 2020

I used the ant task. I downloaded something called "bndtools.api-4.2.0.jar" which appeared to the latest of whatever it was, and there was no ant tasks inside. I did not want to go through all 41 chapters on the web site to figure out what to download, after trying a few pages I found nothing useful. The one page on ant is empty. I did a search on maven and it showed 45 things to choose from! Even Eclipse doesn't have 45 separate downloads. So I went looking for the one jar referenced in your link above, the bnd-version.jar, and I found it somewhere.

Thanks for pointing to this particular jar, because there is no way I would have ever found it otherwise.

@seancfoley
Copy link
Owner

That jar does not work. It does not have any defined ant tasks. Is there a jar that is recent that has taskdef.properties in it?

@seancfoley
Copy link
Owner

seancfoley commented May 13, 2020

The other option would be to run the thing using java from the command line, I could do that from ant. How do you run this jar the command line? The readme says nothing. The manual says nothing useful in that regard.

@seancfoley
Copy link
Owner

Ok, found a jar that works at https://search.maven.org/artifact/biz.aQute.bnd/biz.aQute.bnd/5.0.1/jar

Manifest-Version: 1.0
Bnd-LastModified: 1589410597025
Bundle-ManifestVersion: 2
Bundle-Name: com.github.seancfoley.ipaddress
Bundle-SymbolicName: com.github.seancfoley.ipaddress
Bundle-Version: 5.3.0
Created-By: 1.8.0_231 (Oracle Corporation)
DSTAMP: 20200513
Export-Package: inet.ipaddr;version="5.3.0";uses:="inet.ipaddr.format,
inet.ipaddr.format.standard,inet.ipaddr.format.string,inet.ipaddr.for
mat.util,inet.ipaddr.format.util.sql,inet.ipaddr.format.validate,inet
.ipaddr.ipv4,inet.ipaddr.ipv6,inet.ipaddr.mac",inet.ipaddr.format;ver
sion="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format.standard,inet.ipad
dr.format.string,inet.ipaddr.format.util",inet.ipaddr.format.large;ve
rsion="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.forma
t.string,inet.ipaddr.format.util",inet.ipaddr.format.standard;version
="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.format.str
ing,inet.ipaddr.format.util,inet.ipaddr.format.validate",inet.ipaddr.
format.string;version="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format.u
til",inet.ipaddr.format.util;version="5.3.0";uses:="inet.ipaddr,inet.
ipaddr.format,inet.ipaddr.format.standard,inet.ipaddr.format.string,i
net.ipaddr.format.util.sql",inet.ipaddr.format.util.sql;version="5.3.
0";uses:="inet.ipaddr.format.string,inet.ipaddr.format.util",inet.ipa
ddr.format.validate;version="5.3.0";uses:="inet.ipaddr,inet.ipaddr.fo
rmat,inet.ipaddr.format.standard,inet.ipaddr.mac",inet.ipaddr.ipv4;ve
rsion="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.forma
t.standard,inet.ipaddr.format.string,inet.ipaddr.format.util,inet.ipa
ddr.ipv6",inet.ipaddr.ipv6;version="5.3.0";uses:="inet.ipaddr,inet.ip
addr.format,inet.ipaddr.format.standard,inet.ipaddr.format.string,ine
t.ipaddr.format.util,inet.ipaddr.ipv4,inet.ipaddr.mac",inet.ipaddr.ma
c;version="5.3.0";uses:="inet.ipaddr,inet.ipaddr.format,inet.ipaddr.f
ormat.standard,inet.ipaddr.format.string,inet.ipaddr.format.util,inet
.ipaddr.ipv6"
Import-Package: inet.ipaddr;version="[5.3,6)",inet.ipaddr.format;versi
on="[5.3,6)",inet.ipaddr.format.large;version="[5.3,6)",inet.ipaddr.f
ormat.standard;version="[5.3,6)",inet.ipaddr.format.string;version="[
5.3,6)",inet.ipaddr.format.util;version="[5.3,6)",inet.ipaddr.format.
util.sql;version="[5.3,6)",inet.ipaddr.format.validate;version="[5.3,
6)",inet.ipaddr.ipv4;version="[5.3,6)",inet.ipaddr.ipv6;version="[5.3
,6)",inet.ipaddr.mac;version="[5.3,6)"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
TODAY: May 13 2020
Tool: Bnd-5.0.1.202003231327
TSTAMP: 1856

@seancfoley
Copy link
Owner

The osgi manifest is included with version 5.3.0 as shown above, and is now available from the releases page, from maven central, or from bintray

@swimmesberger
Copy link
Author

@seancfoley thanks for your work

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

No branches or pull requests

2 participants