braintree / braintree_java

Braintree Java library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
158 stars 99 forks source link

OSGi support #30

Closed lburgazzoli closed 8 years ago

lburgazzoli commented 8 years ago

This PR is aimed to add basic support for OSGi : add metadata to manifest

raymondberg commented 8 years ago

Thanks for the code submission, @lburgazzoli. It may take us a while to review this and get back to you. We'll let you know if we have any questions.

lburgazzoli commented 8 years ago

Thank you @raymondberg . It should not have any impact on the code, the goal is to add OSGi metedata in MANIFEST

lburgazzoli commented 8 years ago

Hello @raymondberg, have you had any time to check this PR ? We would like to include the camel-braintree component in the next release of camel and OSGi support is a pre-requisite.

raymondberg commented 8 years ago

We've been testing out your proposal internally, but the setup to get Apache Felix plugin on a typical JDK+Maven build seems overly complex. Are there any additional setup steps that you would recommend or that are required in order to simplify bundling OSGi-compliant JARs? We're seeing some problems for the OSGI POMs in Maven that we can't seem to get around: ​

mvn -Dpackaging=plugins install
[INFO] Scanning for projects...
[WARNING] POM for 'org.osgi:org.osgi.core:pom:4.3.1:runtime' is invalid.

​...

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Internal error in the plugin manager executing goal 'org.apache.felix:maven-bundle-plugin:3.0.1:manifest': Unable to load the mojo 'org.apache.felix:maven-bundle-plugin:3.0.1:manifest' in the plugin 'org.apache.felix:maven-bundle-plugin'. A required class is missing: org/apache/maven/project/DependencyResolutionException
org.apache.maven.project.DependencyResolutionException
[INFO] --------------------------------------------------

​ Our primary concern is making sure that any developer picking this SDK up would be able to get their development/build environment stable fairly quickly.

lburgazzoli commented 8 years ago

Is mvn -Dpackaging=plugins install what you do usually to install braintree_java jar ? Because it is not require by maven-bundle-plugin as it hooks into standard maven life-cycle so a simple mvn install generates an OSGi ready bundle without warnings:

$ mvn install -DskipTests=true
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Braintree Gateway Java Client Library 2.53.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ braintree-java ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ braintree-java ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 201 source files to /home/lburgazz/workspace/braintree_java/target/classes
[INFO] 
[INFO] --- maven-bundle-plugin:3.0.1:manifest (default) @ braintree-java ---
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ braintree-java ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ braintree-java ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.14.1:test (default-test) @ braintree-java ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-bundle-plugin:3.0.1:bundle (default-bundle) @ braintree-java ---
[INFO] 
[INFO] --- maven-failsafe-plugin:2.14.1:integration-test (default) @ braintree-java ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.14.1:verify (default) @ braintree-java ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ braintree-java ---
[INFO] Installing /home/lburgazz/workspace/braintree_java/target/braintree-java-2.53.0-SNAPSHOT.jar to /opt/sfw/tools/apache/maven-repo/com/braintreepayments/gateway/braintree-java/2.53.0-SNAPSHOT/braintree-java-2.53.0-SNAPSHOT.jar
[INFO] Installing /home/lburgazz/workspace/braintree_java/pom.xml to /opt/sfw/tools/apache/maven-repo/com/braintreepayments/gateway/braintree-java/2.53.0-SNAPSHOT/braintree-java-2.53.0-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-bundle-plugin:3.0.1:install (default-install) @ braintree-java ---
[INFO] Installing com/braintreepayments/gateway/braintree-java/2.53.0-SNAPSHOT/braintree-java-2.53.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.686 s
[INFO] Finished at: 2016-02-05T16:59:34+01:00
[INFO] Final Memory: 21M/305M
[INFO] ------------------------------------------------------------------------

What the plugin does is very simple as it check the dependencies and the structure of the project and generates an OSGi compliant MANIFEST, like:

Bnd-LastModified = 1449665218259
Build-Jdk = 1.8.0_66
Built-By = lburgazz
Created-By = Apache Maven Bundle Plugin
Implementation-Title = Braintree Gateway Java Client Library
Implementation-Version = 2.53.0-SNAPSHOT
Manifest-Version = 1.0
Tool = Bnd-3.0.0.201509101326

Bundle-Description = Java Client Library for Braintree Payments Gateway
Bundle-License = http://www.opensource.org/licenses/mit-license.php
Bundle-ManifestVersion = 2
Bundle-Name = Braintree Gateway Java Client Library
Bundle-SymbolicName = com.braintreepayments.gateway.braintree-java
Bundle-Version = 2.53.0.SNAPSHOT

Require-Capability = 
    osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.5))

Export-Package = 
    com.braintreegateway;uses:=com.braintreegateway.util;version=2.53.0,
    com.braintreegateway.exceptions;version=2.53.0,
    com.braintreegateway.util;uses:=com.braintreegateway;version=2.53.0,
    com.braintreegateway.test;version=2.53.0
Import-Package = 
    javax.crypto,
    javax.crypto.spec,
    javax.net.ssl,
    javax.xml.parsers,
    org.xml.sax,
    org.xml.sax.helpers

This change in the manifest has effect only for people using braintree_java in OSGi environments, everyone else should not even notice the difference.

The manifest do not need to be generated by the maven plugin so if you can manually set all the entries but you have to update them in case of changes made to the packages layout and dependencies.

raymondberg commented 8 years ago

We just released 2.55.0 which includes the OSGi support. Thanks for your help in developing this out, @lburgazzoli. We've tagged you in the changelog for your contributions!

lburgazzoli commented 8 years ago

@raymondberg thank you for mergint it however I do not see the changes on

This is very important for OSGi, any chanche to include them ?