Search code examples
kubernetescode-generationffiballerinabindgen

Ballerina -Using Java Library with Dependencies


I want to use the Java Kubernetes API Client in Ballerina.

I have read this, this and this.

The only place, where Java based dependencies are a matter is this.

If one of these classes is required later, the Bindgen tool could be re-run to generate the complete implementation of the Ballerina bindings.

  • How do I re-run it? With the same CLI options as for the inital run of bal bindgen?
  • How do I tell the already existing Kubernetes Client Java Bindings, that those dependencies are to be meant for them?
  • How do I tell bal bindgen to fill the stub dependency classes with the new bal bindgen result for each dependency?
  • How do I tell bal bindgen to not require specific class names, but at least accept a package prefix with a wildcard, to include all classes of this package?

This is the bal bindgen CLI line I ran.

bal bindgen -mvn io.kubernetes:client-java:18.0.1 --with-optional-types-param --with-optional-types-return --public --output "${path_output}" org.yaml.snakeyaml.Yaml java.io.FileInputStream java.io.InputStream java.util.Map

The classes are taken from the tutorial as a test.

This is the output of the bal bindgen run.

Resolving maven dependencies...

Updated the `Ballerina.toml` file with the new platform libraries.

The following JARs were added to the classpath:
        slf4j-api-2.0.6.jar
        google-http-client-gson-1.42.3.jar
        google-auth-library-credentials-1.16.0.jar
        guava-31.0.1-android.jar
        accessors-smart-2.4.2.jar
        oauth2-oidc-sdk-9.4.jar
        nimbus-jose-jwt-9.8.1.jar
        error_prone_annotations-2.16.jar
        bcutil-jdk18on-1.72.jar
        content-type-2.1.jar
        google-auth-library-oauth2-http-1.16.0.jar
        okhttp-4.10.0.jar
        commons-lang3-3.12.0.jar
        commons-collections4-4.4.jar
        gson-fire-1.8.5.jar
        httpcore-4.4.15.jar
        simpleclient_common-0.15.0.jar
        j2objc-annotations-1.3.jar
        opencensus-api-0.31.1.jar
        javax.annotation-api-1.3.2.jar
        commons-codec-1.15.jar
        client-java-proto-18.0.1.jar
        annotations-13.0.jar
        lang-tag-1.5.jar
        json-smart-2.4.2.jar
        logging-interceptor-4.10.0.jar
        okio-jvm-3.0.0.jar
        httpclient-4.5.13.jar
        adal4j-1.6.7.jar
        listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
        client-java-api-18.0.1.jar
        kotlin-stdlib-jdk8-1.6.10.jar
        commons-logging-1.2.jar
        jcip-annotations-1.0-1.jar
        simpleclient_tracer_otel_agent-0.15.0.jar
        commons-io-2.11.0.jar
        swagger-annotations-1.6.9.jar
        simpleclient_tracer_common-0.15.0.jar
        asm-8.0.1.jar
        bcpkix-jdk18on-1.72.jar
        simpleclient_tracer_otel-0.15.0.jar
        google-http-client-1.42.3.jar
        client-java-18.0.1.jar
        simpleclient_httpserver-0.15.0.jar
        jose4j-0.9.3.jar
        checker-qual-3.12.0.jar
        opencensus-contrib-http-util-0.31.1.jar
        kotlin-stdlib-common-1.5.31.jar
        bcprov-jdk18on-1.72.jar
        gson-2.10.1.jar
        failureaccess-1.0.1.jar
        kotlin-stdlib-1.6.20.jar
        auto-value-annotations-1.10.1.jar
        jsr305-3.0.2.jar
        protobuf-java-3.22.0.jar
        simpleclient-0.15.0.jar
        checker-compat-qual-2.5.5.jar
        grpc-context-1.27.2.jar
        kotlin-stdlib-jdk7-1.6.10.jar
        commons-compress-1.22.jar
        snakeyaml-2.0.jar

Generating bindings for: 
        java.util.Map
        java.io.FileInputStream
        org.yaml.snakeyaml.Yaml
        java.io.InputStream
        java.lang.Object

Generating dependency bindings for: 
        org.yaml.snakeyaml.introspector.BeanAccess
        java.util.function.BiFunction
        org.yaml.snakeyaml.DumperOptions$FlowStyle
        org.yaml.snakeyaml.constructor.BaseConstructor
        java.util.function.Function
        java.lang.Iterable
        org.yaml.snakeyaml.DumperOptions
        org.yaml.snakeyaml.nodes.Node
        java.util.function.BiConsumer
        org.yaml.snakeyaml.resolver.Resolver
        java.io.OutputStream
        java.util.Map$Entry
        java.util.Iterator
        java.util.Collection
        java.util.Set
        org.yaml.snakeyaml.LoaderOptions
        java.io.Reader
        org.yaml.snakeyaml.nodes.Tag
        java.io.File
        java.util.List
        java.io.FileDescriptor
        java.io.Writer
        org.yaml.snakeyaml.representer.Representer
        java.lang.Class
        org.yaml.snakeyaml.TypeDescription
        java.util.regex.Pattern
        java.nio.channels.FileChannel

Solution

  • How do I re-run it?

    If you need to re-run the bindgen command to generate the complete implementation of one or more dependent classes, as mentioned here, you can do so by running your initial command with the new classes appended at the end. The tool will replace the modified binding files where necessary.

    How do I tell the already existing Kubernetes Client Java Bindings, that those dependencies are to be meant for them?

    You don't need to explicitly link the newly generated dependency bindings to the already existing ones after you re-run the command. The tool automatically handles it during the regeneration process, as mentioned above.

    How do I tell bal bindgen to fill the stub dependency classes with the new bal bindgen result for each dependency?

    For that you will have to manually specify the qualified name of each dependency class (that you want to generate the complete implementation for) in your bindgen command, explicitly.

    How do I tell bal bindgen to not require specific class names, but at least accept a package prefix with a wildcard, to include all classes of this package?

    The bindgen tool does not support specifying a package prefix with a wildcard to include all classes of this package. The tool is designed to allow Ballerina developers to reuse existing Java libraries in their code by generating bindings for the public APIs of the library. Typically, you only need the complete bridge code for the Java APIs you want to access in your Ballerina program, and the tool's default behaviour is to leave other classes as dependent classes. This approach is recommended to avoid increasing complexity and compilation time.