-
Notifications
You must be signed in to change notification settings - Fork 6
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
Generate events using jsonschema2pojo and mustache template #58
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Just some comments on the CDEventsGenerator class which hold most of the logic here. But I don't see anything disruptive, apart from indentation/whitespaces/formatting (So anything you can see from the linting log)
I'll take a second look another day
} catch (IOException e) { | ||
throw new CDEventsException("Exception occurred while generating class file from Json schema ", e); | ||
} | ||
System.out.println("Rendered event-template has been written to file - "+classFile.getAbsolutePath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be logged with a logger or printing is fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will be changing to logger for all the required logs
String predicate = type[3]; | ||
String capitalizedSubject = StringUtils.capitalize(subject); | ||
if(subject.equals("pipelinerun")){ | ||
capitalizedSubject = subject.substring(0, 1).toUpperCase() + subject.substring(1, 8) + subject.substring(8, 9).toUpperCase() + subject.substring(9); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you trying to capitalize only char 0 and char 8 in the string?
capitalizedSubject = subject.substring(0, 1).toUpperCase() + subject.substring(1, 8) + subject.substring(8, 9).toUpperCase() + subject.substring(9); | |
capitalizedSubject = StringUtils.capitalize(subject.substring(0, 8)) + | |
StringUtils.capitalize(subject.substring(8)); |
If you import a newer version of StringUtils you can capitalize the first character of a substring this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that's right using the StringUtils.capitalize() in the previous line, I can update to this simplified one based on your suggestion,
capitalizedSubject = capitalizedSubject.substring(0, 8) + StringUtils.capitalize(subject.substring(8));
@rjalander thank you, excited to see this happening!! |
Thank you for your comment @afrittoli |
@afrittoli is this a good idea to keep a release branch of Java-sdk as of now before this PR gets merged into main as generated code for v0.1.2 version ? |
I would recommend continuing regular development on |
pom.xml
Outdated
@@ -105,6 +105,18 @@ | |||
<artifactId>jackson-databind</artifactId> | |||
</dependency> | |||
|
|||
<dependency> | |||
<groupId>commons-lang</groupId> | |||
<artifactId>commons-lang</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use latest versions as much as possible. In particular commons-lang3 supersedes commons-lang
https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
pom.xml
Outdated
@@ -128,6 +140,12 @@ | |||
<version>${packageurl.version}</version> | |||
</dependency> | |||
|
|||
<dependency> | |||
<groupId>com.github.spullara.mustache.java</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dependency required at runtime or only during code generation? If the latter then change to <scope>provided</scope>
as well as adding <optional>true</optional>
, as this dependency should not leak to consumers.
pom.xml
Outdated
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the previous comment on the mustache dependency. Might be worth separating code generation from generated code consumption. That is, migrate this project to a multi module Maven setup, putting code generators in one module, and cdevents Java sdk in another. Otherwise we risk exposing the code generator and its dependencies as part of the runtime dependencies required by consumers of cdevents-java-sdk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code as suggested with multi modules generator
and sdk
based on your commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. However, the release workflow in .github/workflows/release.yml
and the root pom.xml
require some changes:
release.yml
- change
./mvnw -ntp -B --file pom.xml -Prelease
to./mvnw -ntp -B --file pom.xml -Prelease -pl :cdevents-sdk-java-parent
pom.xml
- update
version.jreleaser.plugin
to1.7.0
- update
<pluginManagement>
by adding
<plugin>
<groupId>org.jreleaser</groupId>
<artifactId>jreleaser-maven-plugin</artifactId>
<version>${version.jreleaser.plugin}</version>
</plugin>
Latest changes are 👍 |
Thank you all for your review and comments, @aalmiray @afrittoli Can you please approve this PR If no other comments, I will be creating another PR which generates all other events pointing to v0.1.2 schemas of spec repository as submodule |
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Co-authored-by: Lapenta Francesco Davide <37077655+lapentad@users.noreply.github.com> Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Co-authored-by: Lapenta Francesco Davide <37077655+lapentad@users.noreply.github.com> Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
generator/pom.xml
Outdated
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generator Maven module needs no test dependencies. These can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I will create a Unit testing for generator code in the coming PR. Is that fine to keep this dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great that unit tests will be added, maybe you can add the dependency along with the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. It's a good practice to add only the minimum reqs for a given unit of work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Removed
sdk/pom.xml
Outdated
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the library must remain Java 8 compatible. The parent pom defines compiler properties for Java 1.8
. Remove this plugin definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this plugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hold on a second. The moditect plugin was added because the codebase was set to Java 8 as a baseline. If the baseline moves to 11 then this plugin may be removed BUT and explicit module descriptor must be added.
@afrittoli has the Java 8 baseline changed recently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin I requested for removal is the compiler
plugin because it explicitly overrides source/target compatibility to 11
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of any change from Java 8 to Java 11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we mentioned in the DEVELOPMENT readme "Java 9 is a minimum requirement to build the project",
@aalmiray is that readme need to be updated / any changes needed in the pom.xml ?
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
36a7509
to
9c10633
Compare
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Thank you all for the review, @afrittoli @aalmiray Could you please approve If no other comments to address. |
Also the Spinnaker PR; spinnaker/echo#1295, is dependent on the Java-SDK to produce CDevents from Spinnaker. |
Hello @rjalander - yes, this does not seem to me like a dependency for v0.1.2 - I think we already agreed that the SDK is ready for v0.1.2. Is there anything else holding the release? Would you be happy to do the release or would you like me to do it? |
Ok, that will be great If we do release with the master changes as of now, yes can you please create a new release. |
Not a blocker for releasing |
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
@afrittoli @aalmiray please let me know If any other comments that needs to be addressed to get this PR approved/merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rjalander - it's great to see this happening!
I'm a bit worried about all the events being deleted and only a few ones being added as generated. All the tests are deleted too, and new one are added for the new generated code, which makes it harder to verify that the new code still behaves the same as the old one.
If you're confident that the new code preserves functionality, it's ok for me, hopefully this is a one-off for the transition to generated code.
In the next PR I will be adding other generated events which will have the same tests running to make sure the generated code works as expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - let's go for it!
@aalmiray If it's ok for you I would go ahead and merge this. |
Yes we can Squash and merge. |
@afrittoli can you please merge this PR, I will create a follow up PR for the next set of changes. |
🎉 This issue has been resolved in |
Initial changes to generate events using jsonschema2pojo and mustache template, /src/main/resources/template/event-template.mustache
pom.xml has the plugin to generate jsonschema2pojo and plugin to run the main class from CDEventsGenerator to create events using mustache template.
Running ./mvnw verify
Note: