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

Add support for using JBang #575

Merged
merged 11 commits into from
May 27, 2022
Merged

Add support for using JBang #575

merged 11 commits into from
May 27, 2022

Conversation

maxandersen
Copy link
Contributor

@maxandersen maxandersen commented May 6, 2022

#Descripton

Adds support for jbang like there are for maven and gradle.

Advantage is you don't need to have extra files and deep structures if you are just doing some pulumi sripting.

Minimal requirement as implemented here is:

src/main.java
Pulumi.yaml
jbang.properties

Could even cut it down and look for src/main.java if no jbang.properties found.

Dependencies are done via //DEPSin the .java file, i.e.:

//DEPS com.pulumi:pulumi:${env.PULUMI_JAVA_SDK_VERSION:0.1.0}

or simply:

//DEPS com.pulumi:pulumi:0.1.0

notes:
Looks for jbang.properties as a marker similar to pom.xml and settings.gradle.
It is not required for jbang to work, thus we could also just look for a standard source file i.e. src/main.java

Also handles binary: myFile.java as a way to customize which of possible "scripts" to use.

Also allow using Groovy (.groovy) and Kotlin (.kt) via JBang, but that is untested for now.- Fix typo and use GAV that exist in maven central

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

Looks for `jbang.properties` as a marker similar to `pom.xml` and `settings.gradle`.
It is not required for jbang to work, thus we could also just look for a standard source file i.e. `src/main.java`

Also handles `binary: myFile.java` as a way to customize which of possible "scripts" to use.

Also allow using Groovy (.groovy) and Kotlin (.kt) via JBang, but that is untested for now.
@maxandersen
Copy link
Contributor Author

maxandersen commented May 7, 2022

todo:

  • hooking up with the code gen feature. Not sure if relevant/affected (Add a template for java-jbang templates#283)
  • how/when "build" command is called by pulumi. Is there a flag or specific sequence of commands to have it call build?

@AaronFriel
Copy link
Contributor

Related to this, if we want to add a template: https://github.com/pulumi/templates/pull/283/files

@maxandersen
Copy link
Contributor Author

Yes - I'm happy to complete this just looking for some pointers to my question in the pr description. Thanks!

cmdutil.Exit(err)
}
case ".java", ".kt", ".groovy":
cmd, err := probeJBangExecutor()
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this pathway is for letting users set binary: option in the Pulumi.yaml and have a non-standard entry-point file. Sounds great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

Thank you for contributing this! I'm just learning about JBang here but I love the idea - it's a great match for short Pulumi programs. Taking it out for a spin shortly.

Please let us know if you can resolve the merge conflicts or need some help with that.

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

Also - apologies for CI showing as red. This is a setup problem not necessarily a problem with code #557 - something I will be cleaning up next week.

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

how/when "build" command is called by pulumi. Is there a flag or specific sequence of commands to have it call build?

That's relatively simple to explain. Pulumi CLI would sometimes call InstallDependencies that would call the jvmExecutor "build". The intension here is to prebuild and pre-fetch dependencies. I believe this is called right after template expansion in pulumi new.

func (host *javaLanguageHost) InstallDependencies

An executor that does nothing for the "build" command I think should work fine also. It will simply defer the dep fetching until pulumi up is called.

t0yv0 and others added 4 commits May 27, 2022 11:13
Looks for `jbang.properties` as a marker similar to `pom.xml` and `settings.gradle`.
It is not required for jbang to work, thus we could also just look for a standard source file i.e. `src/main.java`

Also handles `binary: myFile.java` as a way to customize which of possible "scripts" to use.

Also allow using Groovy (.groovy) and Kotlin (.kt) via JBang, but that is untested for now.
@maxandersen
Copy link
Contributor Author

Please let us know if you can resolve the merge conflicts or need some help with that.

pushed fixes + rebase with main.

@maxandersen
Copy link
Contributor Author

An executor that does nothing for the "build" command I think should work fine also. It will simply defer the dep fetching until pulumi up is called.

so i think it should just work - but didn't find a way to trigger the code thus far.

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

Wonderful! Works on my machine, I'll find a way to hitch it up to CI and merge. Thank you!

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

/run-acceptance-tests

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

/run-acceptance-tests

@t0yv0 t0yv0 marked this pull request as ready for review May 27, 2022 19:39
@t0yv0 t0yv0 merged commit 916280f into pulumi:main May 27, 2022
@maxandersen
Copy link
Contributor Author

Want to merge pulumi/templates#283 too to get matching templates ?

@t0yv0
Copy link
Member

t0yv0 commented May 27, 2022

In principle yes, I'd wait until this change gets released next week though.

@maxandersen
Copy link
Contributor Author

I saw 0.3.0 was released but its release notes does not seem to include this change. Was something missing to make it in?

@t0yv0
Copy link
Member

t0yv0 commented Jun 6, 2022

Included in https://github.com/pulumi/pulumi-java/blob/main/CHANGELOG.md#030-2022-06-01 ? Where is it not propagating?

@maxandersen
Copy link
Contributor Author

https://github.com/pulumi/pulumi-java/releases latest release don't have it in the change log and it's still in the incoming change log as part of 0.4

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.

3 participants