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

Create modules in Java #9422

Merged
merged 54 commits into from
Feb 6, 2025
Merged

Create modules in Java #9422

merged 54 commits into from
Feb 6, 2025

Conversation

eunomie
Copy link
Member

@eunomie eunomie commented Jan 21, 2025

This PR allows to create Dagger modules using Java.

$ dagger init --sdk=java my-java-module

$ tree my-java-module
my-java-module
├── dagger.json
├── pom.xml
└── src
    └── main
        └── java
            └── io
                └── dagger
                    └── sample
                        └── module
                            ├── MyJavaModule.java
                            └── package-info.java

8 directories, 4 files

This will create the module with a default template. This template module is based on the same than Go and others, with the container-echo and grep-dir functions.

A default pom.xml is also generated.

Once done, it's possible to list the functions or call them:

$ dagger functions -m my-java-module

Name             Description
container-echo   Returns a container that echoes whatever string argument is provided
grep-dir         Returns lines that match a pattern in the files of the provided Directory
$ dagger call -q -m my-java-module container-echo "hello dagger" stdout

hello dagger

The java module code is using annotations to know what to expose and call:

  • @Module
  • @Object
  • @Function

The entrypoint code will be generated at build time. In that way it's close to the Go modules (not a generic endpoint at runtime only).

The default pom.xml set the main class to the generated entrypoint one automatically using the maven-shade plugin.

By default only the src directory and the pom.xml are necessary. But to keep a nice Developer Experience and help IDEs to complete code, all the Dagger SDK dependencies (the Dagger java sdk plus all the generated files for the different types and the entrypoint) can be generated and made available under the target/generated-sources directory:

  • dagger: the generated files based on Dagger introspection JSON
  • entrypoint: the generated entrypoint based on user's code
  • sdk: the sdk/java/dagger-java-sdk source code (this is not really generated sources but a way to make it available easily)
generated files
$ tree target
my-java-module/target
└── generated-sources
    ├── dagger
    │   └── io
    │       └── dagger
    │           └── client
    │               ├── BuildArg.java
    │               ├── CacheSharingMode.java
    │               ├── CacheVolume.java
    │               ├── CacheVolumeID.java
    │               ├── Client.java
    │               ├── Container.java
    │               ├── ContainerID.java
    │               ├── CurrentModule.java
    │               ├── CurrentModuleID.java
    │               ├── Directory.java
    │               ├── DirectoryID.java
    │               ├── EnumTypeDef.java
    │               ├── EnumTypeDefID.java
    │               ├── EnumValueTypeDef.java
    │               ├── EnumValueTypeDefID.java
    │               ├── EnvVariable.java
    │               ├── EnvVariableID.java
    │               ├── Error.java
    │               ├── ErrorID.java
    │               ├── FieldTypeDef.java
    │               ├── FieldTypeDefID.java
    │               ├── File.java
    │               ├── FileID.java
    │               ├── Function.java
    │               ├── FunctionArg.java
    │               ├── FunctionArgID.java
    │               ├── FunctionCall.java
    │               ├── FunctionCallArgValue.java
    │               ├── FunctionCallArgValueID.java
    │               ├── FunctionCallID.java
    │               ├── FunctionID.java
    │               ├── GeneratedCode.java
    │               ├── GeneratedCodeID.java
    │               ├── GitModuleSource.java
    │               ├── GitModuleSourceID.java
    │               ├── GitRef.java
    │               ├── GitRefID.java
    │               ├── GitRepository.java
    │               ├── GitRepositoryID.java
    │               ├── ImageLayerCompression.java
    │               ├── ImageMediaTypes.java
    │               ├── InputTypeDef.java
    │               ├── InputTypeDefID.java
    │               ├── InterfaceTypeDef.java
    │               ├── InterfaceTypeDefID.java
    │               ├── JSON.java
    │               ├── Label.java
    │               ├── LabelID.java
    │               ├── ListTypeDef.java
    │               ├── ListTypeDefID.java
    │               ├── LocalModuleSource.java
    │               ├── LocalModuleSourceID.java
    │               ├── Module.java
    │               ├── ModuleDependency.java
    │               ├── ModuleDependencyID.java
    │               ├── ModuleID.java
    │               ├── ModuleSource.java
    │               ├── ModuleSourceID.java
    │               ├── ModuleSourceKind.java
    │               ├── ModuleSourceView.java
    │               ├── ModuleSourceViewID.java
    │               ├── NetworkProtocol.java
    │               ├── ObjectTypeDef.java
    │               ├── ObjectTypeDefID.java
    │               ├── PipelineLabel.java
    │               ├── Platform.java
    │               ├── Port.java
    │               ├── PortForward.java
    │               ├── PortID.java
    │               ├── ReturnType.java
    │               ├── ScalarTypeDef.java
    │               ├── ScalarTypeDefID.java
    │               ├── Secret.java
    │               ├── SecretID.java
    │               ├── Service.java
    │               ├── ServiceID.java
    │               ├── Socket.java
    │               ├── SocketID.java
    │               ├── SourceMap.java
    │               ├── SourceMapID.java
    │               ├── Terminal.java
    │               ├── TerminalID.java
    │               ├── TypeDef.java
    │               ├── TypeDefID.java
    │               ├── TypeDefKind.java
    │               ├── Version.java
    │               └── Void.java
    ├── entrypoint
    │   └── io
    │       └── dagger
    │           └── gen
    │               └── entrypoint
    │                   └── Entrypoint.java
    └── sdk
        └── io
            └── dagger
                ├── client
                │   ├── Arguments.java
                │   ├── Convert.java
                │   ├── Dagger.java
                │   ├── DaggerQueryException.java
                │   ├── IDAble.java
                │   ├── InputValue.java
                │   ├── PrivateVisibilityStrategy.java
                │   ├── QueryBuilder.java
                │   ├── QueryPart.java
                │   ├── Scalar.java
                │   └── engineconn
                │       ├── CLIDownloader.java
                │       ├── CLIRunner.java
                │       ├── ConnectParams.java
                │       ├── Connection.java
                │       ├── FileFetcher.java
                │       └── Provisioning.java
                └── module
                    ├── Base.java
                    ├── annotation
                    │   ├── Function.java
                    │   ├── Module.java
                    │   └── Object.java
                    └── info
                        ├── FunctionInfo.java
                        ├── ModuleInfo.java
                        ├── ObjectInfo.java
                        └── ParameterInfo.java

19 directories, 112 files

Those files are not intended to be added to git. To re-generate them: dagger develop

[!WARNING]
Due to some issues between Docker Desktop, Java and MacBook Pro m4 (it looks like other machines are not impacted) in case of arm64 platform a specific flag is added to Java/Maven: -XX:UseSVE=0.
See for instance corretto/corretto-21#85

@eunomie eunomie requested a review from a team as a code owner January 21, 2025 11:04
@eunomie eunomie force-pushed the javasdk-modularize branch 4 times, most recently from 07a1fdd to 2e13194 Compare January 22, 2025 11:11
@eunomie eunomie force-pushed the javasdk-modularize branch from 2e13194 to 79a1793 Compare January 22, 2025 15:32
@eunomie
Copy link
Member Author

eunomie commented Jan 22, 2025

I improved the primitive types support, they are both working for returning types and arguments.
I also included your (@jcsirot ) improvements regarding javadoc parsing.

@eunomie eunomie force-pushed the javasdk-modularize branch 2 times, most recently from 19eaedb to b996ee1 Compare January 24, 2025 21:42
@eunomie eunomie force-pushed the javasdk-modularize branch from ba383c2 to 67c9da9 Compare January 28, 2025 10:09
@eunomie eunomie force-pushed the javasdk-modularize branch from 67c9da9 to bce6fb9 Compare January 28, 2025 14:30
Copy link
Member

@jedevc jedevc left a comment

Choose a reason for hiding this comment

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

I think this looks like a good start to me, just left some general integration points as comments.

Really not qualified to comment on any of the Java code - will trust you and @jcsirot on this 🎉

Would also like @helderco to take a look if possible, since he's more familiar with the process of how we've integrated with the other SDKs 🎉

Comment on lines +123 to +127
// - dagger-codegen-maven-plugin: this plugin will be used to generate the SDK code, from the introspection file,
// this means including the ability to call other projects (not part of the main dagger SDK)
// - this plugin is only used to build the SDK, the user module doesn't need it
// - dagger-java-annotation-processor: this will read dagger specific annotations (@Module, @Object, @Function)
// and generate the entrypoint to register the module and invoke the functions
Copy link
Member

Choose a reason for hiding this comment

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

I like this separation - I think this is actually the way we'd like to get all the SDKs to work eventually (see #7707).

@eunomie eunomie force-pushed the javasdk-modularize branch from 25e0fe0 to fd9472a Compare January 30, 2025 11:19
@eunomie eunomie requested a review from a team as a code owner January 30, 2025 11:19
@eunomie eunomie force-pushed the javasdk-modularize branch 2 times, most recently from f4a5149 to d75a52f Compare January 31, 2025 10:43
eunomie and others added 25 commits February 6, 2025 10:21
Like assert from golangci-lint module

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
so types are correctly handled. Use JsonConverter class to convert types to/from JSON

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Wasn't used and cause some confusion.
@module is optional, and only here to expose the module's description.
@object and @function are the ones required to create module objects.

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
they are not needed for module generation. And we still generate them
on the fly when needed to build locally.

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
/src/<user module>/sdk is replaced by /src/dagger-io
  that's where the sdk, java lib, etc will be built

<user module>/target/generated-sources/sdk is replaced by
  <user module>/target/generated-sources/dagger-io
    where the sdk/java source code will be put
<user module>/target/generated-sources/dagger is replaced by
  <user module>/target/generated-sources/dagger-module
    where the generated code from sdk/java and specific to the
    module will be put

Signed-off-by: Yves Brissaud <gh@lgtd.io>
That way we avoid "samples" and there's no conflict with the default
package io.dagger.module

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
That way we can express the full matrix of possibilities between
the two aspects.

For now, to set a default value implies the value to be nullable
(optional in term of Dagger API).

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Bumps the sdk-java group with 4 updates in the /sdk/java directory: io.smallrye:smallrye-graphql-client-api, io.smallrye:smallrye-graphql-client-implementation-vertx, [io.netty:netty-common](https://github.com/netty/netty) and [org.assertj:assertj-core](https://github.com/assertj/assertj).

Updates `io.smallrye:smallrye-graphql-client-api` from 2.12.0 to 2.12.1

Updates `io.smallrye:smallrye-graphql-client-implementation-vertx` from 2.12.0 to 2.12.1

Updates `io.smallrye:smallrye-graphql-client-implementation-vertx` from 2.12.0 to 2.12.1

Updates `io.netty:netty-common` from 4.1.116.Final to 4.1.117.Final
- [Commits](netty/netty@netty-4.1.116.Final...netty-4.1.117.Final)

Updates `org.assertj:assertj-core` from 3.27.2 to 3.27.3
- [Release notes](https://github.com/assertj/assertj/releases)
- [Commits](assertj/assertj@assertj-build-3.27.2...assertj-build-3.27.3)

---
updated-dependencies:
- dependency-name: io.smallrye:smallrye-graphql-client-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.smallrye:smallrye-graphql-client-implementation-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.smallrye:smallrye-graphql-client-implementation-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.netty:netty-common
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: org.assertj:assertj-core
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: sdk-java
...

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Java + docker desktop + macos 15.3 is not a nice combo with a lot
of java crashes.
Those are old (but supported) java version that look like to work
as expected.

Signed-off-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
@eunomie eunomie force-pushed the javasdk-modularize branch from 136baab to f7fef23 Compare February 6, 2025 09:21
@helderco helderco merged commit 859e82d into dagger:main Feb 6, 2025
58 checks passed
@helderco
Copy link
Contributor

helderco commented Feb 6, 2025

Thanks, @eunomie and @jcsirot! Good base to iterate on improvements 🚀

vikram-dagger pushed a commit to vikram-dagger/dagger that referenced this pull request Feb 7, 2025
* Add annotations to for module declaration and an annotation processor skeleton

This annotation processor will collect type info into a file in order to register objects and functions when the module is called.

Signed-off-by: Jean-Christophe Sirot <jcsirot@gmail.com>

* reads description from javadoc

Only in case `description` field of the annotation is not set.
That way it's still possible to override it, specifically for Dagger,
but on the other hand it's now possible to only use Java features and
not provide fields so there's no duplication.

Before:

    @ModuleFunction(value="echo", description="Returns a contain...")
    public Container containerEcho(String stringArg) {

After:
    /// Returns a container that echoes...
    @ModuleFunction
    public Container echo(String stringArg) {

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* refactor annotations and entrypoint

Rename annotation classes so they are simpler: Module, Object, Function.
As close as possible to the Dagger wording.

I also moved the info objects (the ones used to generate the json file)
to the dagger-java-sdk part so they can also be used to read the json
file.

Almost created the registry part of the entrypoint: it creates the right
dagger module structure, but now it needs to create the right JSON
output.
This entrypoint can be used as the entrypoint of a module. It's intended
to be generic (based on the json file for now, maybe on the annotation
in the future). So the module side only needs to declare the mainClass
to io.dagger.module.Entrypoint

For instance by adding this to the pom.xml:

      <dependencies>
        <dependency>
          <groupId>io.dagger</groupId>
          <artifactId>dagger-java-sdk</artifactId>
          <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
          <groupId>io.dagger</groupId>
          <artifactId>dagger-java-annotation-processor</artifactId>
          <version>1.0.0-SNAPSHOT</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
      <build>
        <pluginManagement>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
              <verbose>false</verbose>
              <annotationProcessorPaths>
                <path>
                  <groupId>io.dagger</groupId>
                  <artifactId>dagger-java-annotation-processor</artifactId>
                  <version>1.0.0-SNAPSHOT</version>
                </path>
              </annotationProcessorPaths>
              <annotationProcessors>
                <annotationProcessor>io.dagger.annotation.processor.DaggerModuleAnnotationProcessor</annotationProcessor>
              </annotationProcessors>
            </configuration>
          </plugin>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.5.0</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>io.dagger.module.Entrypoint</mainClass>
                    </transformer>
                  </transformers>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>

This should be good to create a jar with all the dependencies:

    ./mvnw clean package

This includes the management of the annotations.

And then the generated jar declares the right entrypoint, so this should
be good to run with:

    dagger run java -jar dagger-module.jar

This will not completely work as the module part is not done, so the
dagger engine doesn't know about the module and so the registration
can't be done.
But that's a different story. The goal here was to be able to:

 - document with annotations
 - create a first basic entrypoint
 - declare as much as possible in the SDK so it's easy to integrate

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add a module.Base class

This is a very simple one, just provided so that modules don't have
define the `dag` field.
In some way this is just to enforce some conventions.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix annotation processor, set type of parameter

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* correctly reads the dagger module info json file

I'm using gson, but I'll have a second look to avoid it and keep
dependencies minimal. But for now it solves the issue.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* ensure descriptions are not empty

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* ensure type is not null

start dealing with types, but needs more work to ensure everything is
compatible

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* return the module ID when registering

make the Scalar.convert method public to be able to convert to JSON.
Not sure that's the best way, but at least for now it unblocks it.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* wip java module

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* migrate to palantir/javapoet

As of 2020-10-10, Square's JavaPoet project is deprecated

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add 0.15.2 schema

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* generate code for the entrypoint

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve runtime code

add comments, clean build and final image

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add template for dagger init

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* generate all java files and support dagger develop

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* enable -XX:UseSVE=0 flag based on platform

Only enable it when architecture is arm64.

Enable it at the base of maven and jre container used so it's transparent
for all actions based on those containers.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* format code using com.spotify.fmt

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* bump java dependencies

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve type handling in entrypoint

handles primitive and class based types, as well as lists and enums
for return types and parameters

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* make module Base class abstract

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* use fmt-maven-plugin on build

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* mention modules in sdk/java readme

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* cover entrypoint generation by a test

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix runtime lint errors

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* Parse javadoc to get modules, functions and parameters descriptions

Co-authored-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>

* make Convert class a final class

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* handle primitive types in return and args

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve convert code and assignable types

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix fields/method with reserverd java words

Like assert from golangci-lint module

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* allow to check if values of scalars are identical

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* use dedicated json (de)serializers

so types are correctly handled. Use JsonConverter class to convert types to/from JSON

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* allow to set argument as optional

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* cover code generation from annotations

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* allow to set a default value to parameters

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* remove @module value (module name)

Wasn't used and cause some confusion.
@module is optional, and only here to expose the module's description.
@object and @function are the ones required to create module objects.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix ignore/generated path

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix initialization of primitive types

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* replace sed calls

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* remove Java from built in SDKs

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* connect java sdk into the CI

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* remove schema files

they are not needed for module generation. And we still generate them
on the fly when needed to build locally.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add quotes to default string values if needed

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve type management

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add more details about java sdk internal to the README

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* replace 'sdk' by more meaningful names

/src/<user module>/sdk is replaced by /src/dagger-io
  that's where the sdk, java lib, etc will be built

<user module>/target/generated-sources/sdk is replaced by
  <user module>/target/generated-sources/dagger-io
    where the sdk/java source code will be put
<user module>/target/generated-sources/dagger is replaced by
  <user module>/target/generated-sources/dagger-module
    where the generated code from sdk/java and specific to the
    module will be put

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* update default java package to io.dagger.modules.<usermodule>

That way we avoid "samples" and there's no conflict with the default
package io.dagger.module

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* only import needed files to build

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* handle generation when referencing non yet existing classes

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* replace @optional by @nullable + @default

That way we can express the full matrix of possibilities between
the two aspects.

For now, to set a default value implies the value to be nullable
(optional in term of Dagger API).

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* chore(deps): bump the sdk-java group across 1 directory with 4 updates

Bumps the sdk-java group with 4 updates in the /sdk/java directory: io.smallrye:smallrye-graphql-client-api, io.smallrye:smallrye-graphql-client-implementation-vertx, [io.netty:netty-common](https://github.com/netty/netty) and [org.assertj:assertj-core](https://github.com/assertj/assertj).

Updates `io.smallrye:smallrye-graphql-client-api` from 2.12.0 to 2.12.1

Updates `io.smallrye:smallrye-graphql-client-implementation-vertx` from 2.12.0 to 2.12.1

Updates `io.smallrye:smallrye-graphql-client-implementation-vertx` from 2.12.0 to 2.12.1

Updates `io.netty:netty-common` from 4.1.116.Final to 4.1.117.Final
- [Commits](netty/netty@netty-4.1.116.Final...netty-4.1.117.Final)

Updates `org.assertj:assertj-core` from 3.27.2 to 3.27.3
- [Release notes](https://github.com/assertj/assertj/releases)
- [Commits](assertj/assertj@assertj-build-3.27.2...assertj-build-3.27.3)

---
updated-dependencies:
- dependency-name: io.smallrye:smallrye-graphql-client-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.smallrye:smallrye-graphql-client-implementation-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.smallrye:smallrye-graphql-client-implementation-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.netty:netty-common
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: org.assertj:assertj-core
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: sdk-java
...

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix warnings in pom.xml

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* rollback images to java 17 to work with latest desktop/mac

Java + docker desktop + macos 15.3 is not a nice combo with a lot
of java crashes.
Those are old (but supported) java version that look like to work
as expected.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* rename io.dagger.module.Base to io.dagger.module.AbstractModule

Signed-off-by: Yves Brissaud <gh@lgtd.io>

---------

Signed-off-by: Jean-Christophe Sirot <jcsirot@gmail.com>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Co-authored-by: Jean-Christophe Sirot <jcsirot@gmail.com>
Co-authored-by: dependabot [bot] <support@github.com>
jasonmccallister pushed a commit to jasonmccallister/dagger that referenced this pull request Feb 20, 2025
* Add annotations to for module declaration and an annotation processor skeleton

This annotation processor will collect type info into a file in order to register objects and functions when the module is called.

Signed-off-by: Jean-Christophe Sirot <jcsirot@gmail.com>

* reads description from javadoc

Only in case `description` field of the annotation is not set.
That way it's still possible to override it, specifically for Dagger,
but on the other hand it's now possible to only use Java features and
not provide fields so there's no duplication.

Before:

    @ModuleFunction(value="echo", description="Returns a contain...")
    public Container containerEcho(String stringArg) {

After:
    /// Returns a container that echoes...
    @ModuleFunction
    public Container echo(String stringArg) {

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* refactor annotations and entrypoint

Rename annotation classes so they are simpler: Module, Object, Function.
As close as possible to the Dagger wording.

I also moved the info objects (the ones used to generate the json file)
to the dagger-java-sdk part so they can also be used to read the json
file.

Almost created the registry part of the entrypoint: it creates the right
dagger module structure, but now it needs to create the right JSON
output.
This entrypoint can be used as the entrypoint of a module. It's intended
to be generic (based on the json file for now, maybe on the annotation
in the future). So the module side only needs to declare the mainClass
to io.dagger.module.Entrypoint

For instance by adding this to the pom.xml:

      <dependencies>
        <dependency>
          <groupId>io.dagger</groupId>
          <artifactId>dagger-java-sdk</artifactId>
          <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
          <groupId>io.dagger</groupId>
          <artifactId>dagger-java-annotation-processor</artifactId>
          <version>1.0.0-SNAPSHOT</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
      <build>
        <pluginManagement>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
              <verbose>false</verbose>
              <annotationProcessorPaths>
                <path>
                  <groupId>io.dagger</groupId>
                  <artifactId>dagger-java-annotation-processor</artifactId>
                  <version>1.0.0-SNAPSHOT</version>
                </path>
              </annotationProcessorPaths>
              <annotationProcessors>
                <annotationProcessor>io.dagger.annotation.processor.DaggerModuleAnnotationProcessor</annotationProcessor>
              </annotationProcessors>
            </configuration>
          </plugin>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.5.0</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>io.dagger.module.Entrypoint</mainClass>
                    </transformer>
                  </transformers>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>

This should be good to create a jar with all the dependencies:

    ./mvnw clean package

This includes the management of the annotations.

And then the generated jar declares the right entrypoint, so this should
be good to run with:

    dagger run java -jar dagger-module.jar

This will not completely work as the module part is not done, so the
dagger engine doesn't know about the module and so the registration
can't be done.
But that's a different story. The goal here was to be able to:

 - document with annotations
 - create a first basic entrypoint
 - declare as much as possible in the SDK so it's easy to integrate

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add a module.Base class

This is a very simple one, just provided so that modules don't have
define the `dag` field.
In some way this is just to enforce some conventions.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix annotation processor, set type of parameter

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* correctly reads the dagger module info json file

I'm using gson, but I'll have a second look to avoid it and keep
dependencies minimal. But for now it solves the issue.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* ensure descriptions are not empty

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* ensure type is not null

start dealing with types, but needs more work to ensure everything is
compatible

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* return the module ID when registering

make the Scalar.convert method public to be able to convert to JSON.
Not sure that's the best way, but at least for now it unblocks it.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* wip java module

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* migrate to palantir/javapoet

As of 2020-10-10, Square's JavaPoet project is deprecated

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add 0.15.2 schema

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* generate code for the entrypoint

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve runtime code

add comments, clean build and final image

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add template for dagger init

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* generate all java files and support dagger develop

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* enable -XX:UseSVE=0 flag based on platform

Only enable it when architecture is arm64.

Enable it at the base of maven and jre container used so it's transparent
for all actions based on those containers.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* format code using com.spotify.fmt

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* bump java dependencies

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve type handling in entrypoint

handles primitive and class based types, as well as lists and enums
for return types and parameters

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* make module Base class abstract

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* use fmt-maven-plugin on build

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* mention modules in sdk/java readme

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* cover entrypoint generation by a test

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix runtime lint errors

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* Parse javadoc to get modules, functions and parameters descriptions

Co-authored-by: Yves Brissaud <gh@lgtd.io>
Signed-off-by: Yves Brissaud <gh@lgtd.io>

* make Convert class a final class

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* handle primitive types in return and args

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve convert code and assignable types

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix fields/method with reserverd java words

Like assert from golangci-lint module

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* allow to check if values of scalars are identical

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* use dedicated json (de)serializers

so types are correctly handled. Use JsonConverter class to convert types to/from JSON

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* allow to set argument as optional

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* cover code generation from annotations

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* allow to set a default value to parameters

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* remove @module value (module name)

Wasn't used and cause some confusion.
@module is optional, and only here to expose the module's description.
@object and @function are the ones required to create module objects.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix ignore/generated path

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix initialization of primitive types

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* replace sed calls

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* remove Java from built in SDKs

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* connect java sdk into the CI

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* remove schema files

they are not needed for module generation. And we still generate them
on the fly when needed to build locally.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add quotes to default string values if needed

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* improve type management

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* add more details about java sdk internal to the README

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* replace 'sdk' by more meaningful names

/src/<user module>/sdk is replaced by /src/dagger-io
  that's where the sdk, java lib, etc will be built

<user module>/target/generated-sources/sdk is replaced by
  <user module>/target/generated-sources/dagger-io
    where the sdk/java source code will be put
<user module>/target/generated-sources/dagger is replaced by
  <user module>/target/generated-sources/dagger-module
    where the generated code from sdk/java and specific to the
    module will be put

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* update default java package to io.dagger.modules.<usermodule>

That way we avoid "samples" and there's no conflict with the default
package io.dagger.module

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* only import needed files to build

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* handle generation when referencing non yet existing classes

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* replace @optional by @nullable + @default

That way we can express the full matrix of possibilities between
the two aspects.

For now, to set a default value implies the value to be nullable
(optional in term of Dagger API).

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* chore(deps): bump the sdk-java group across 1 directory with 4 updates

Bumps the sdk-java group with 4 updates in the /sdk/java directory: io.smallrye:smallrye-graphql-client-api, io.smallrye:smallrye-graphql-client-implementation-vertx, [io.netty:netty-common](https://github.com/netty/netty) and [org.assertj:assertj-core](https://github.com/assertj/assertj).

Updates `io.smallrye:smallrye-graphql-client-api` from 2.12.0 to 2.12.1

Updates `io.smallrye:smallrye-graphql-client-implementation-vertx` from 2.12.0 to 2.12.1

Updates `io.smallrye:smallrye-graphql-client-implementation-vertx` from 2.12.0 to 2.12.1

Updates `io.netty:netty-common` from 4.1.116.Final to 4.1.117.Final
- [Commits](netty/netty@netty-4.1.116.Final...netty-4.1.117.Final)

Updates `org.assertj:assertj-core` from 3.27.2 to 3.27.3
- [Release notes](https://github.com/assertj/assertj/releases)
- [Commits](assertj/assertj@assertj-build-3.27.2...assertj-build-3.27.3)

---
updated-dependencies:
- dependency-name: io.smallrye:smallrye-graphql-client-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.smallrye:smallrye-graphql-client-implementation-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.smallrye:smallrye-graphql-client-implementation-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: io.netty:netty-common
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: sdk-java
- dependency-name: org.assertj:assertj-core
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: sdk-java
...

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* fix warnings in pom.xml

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* rollback images to java 17 to work with latest desktop/mac

Java + docker desktop + macos 15.3 is not a nice combo with a lot
of java crashes.
Those are old (but supported) java version that look like to work
as expected.

Signed-off-by: Yves Brissaud <gh@lgtd.io>

* rename io.dagger.module.Base to io.dagger.module.AbstractModule

Signed-off-by: Yves Brissaud <gh@lgtd.io>

---------

Signed-off-by: Jean-Christophe Sirot <jcsirot@gmail.com>
Signed-off-by: Yves Brissaud <gh@lgtd.io>
Co-authored-by: Jean-Christophe Sirot <jcsirot@gmail.com>
Co-authored-by: dependabot [bot] <support@github.com>
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.

5 participants