jbangdev / jbang

Unleash the power of Java - JBang Lets Students, Educators and Professional Developers create, edit and run self-contained source-only Java programs with unprecedented ease.
https://jbang.dev
MIT License
1.44k stars 159 forks source link

Catalog templates with multiple files with Qute #include does not work #1332

Open nandorholozsnyak opened 2 years ago

nandorholozsnyak commented 2 years ago

Describe the bug If a template is having Qute #includes in it, at initialization JBang will not be able to resolve the dependency templates.

Example template file with includes, of course it works "localy" but if you are not having the files locally it will not be able to resolve it. https://github.com/nandorholozsnyak/jbang-cloud/blob/main/aws/aws-lambda.java.qute

{#include aws/header.java.qute /}

{#include aws/body.java.qute eventClass='InputObject' /}

{#include aws/input.java.qute /}

{#include aws/output.java.qute /}

https://github.com/nandorholozsnyak/jbang-cloud/blob/main/aws/header.java.qute https://github.com/nandorholozsnyak/jbang-cloud/blob/main/aws/body.java.qute https://github.com/nandorholozsnyak/jbang-cloud/blob/main/aws/input.java.qute https://github.com/nandorholozsnyak/jbang-cloud/blob/main/aws/output.java.qute

To Reproduce

$ jbang catalog add --name cloud https://github.com/nandorholozsnyak/jbang-cloud/blob/main/jbang-catalog.json
[jbang] Catalog 'cloud' added to '/home/xxx/.jbang/jbang-catalog.json'

$ jbang template list
agent = Agent template
cli = CLI template
hello = Basic Hello World template
hello.groovy = Basic groovy Hello World template
hello.kt = Basic kotlin Hello World template
q-aws-lambda = Quarkus AWS Lambda template
q-aws-lambda-ecs-event-tf = Quarkus AWS Lambda template to handle ECS event
q-aws-lambda-s3 = Quarkus AWS Lambda template with incoming S3 event
q-aws-lambda-s3-tf = Quarkus AWS Lambda template with incoming S3 event
q-aws-lambda-sqs = Quarkus AWS Lambda template with incoming SQS event
q-aws-lambda-sqs-tf = Quarkus AWS Lambda template with incoming SQS event
q-aws-lambda-tf = Quarkus AWS Lambda template with Terraform template. Use the -Dnative-function flag to have native image based Terraform resources
qcli = Quarkus CLI template
qmetrics = Quarkus Metrics template
qrest = Quarkus REST template
readme.md = Basic markdown readme template

$ jbang init --verbose -t=q-aws-lambda@cloud QuarkusLambda.java
[jbang] jbang version 0.92.2
[jbang] Reading catalog from /home/xxx/.jbang/jbang-catalog.json
[jbang] Retrieved file from cache https://raw.githubusercontent.com/nandorholozsnyak/jbang-cloud/main/jbang-catalog.json = /home/xxx/.jbang/cache/urls/1c2070ad1eaabad178cdc2c3958f28c72fdc9d884877eebb0df89cf9331c53c1/jbang-catalog.json
[jbang] Reading catalog from /home/xxx/.jbang/cache/urls/1c2070ad1eaabad178cdc2c3958f28c72fdc9d884877eebb0df89cf9331c53c1/jbang-catalog.json
[jbang] Obtained catalog from https://github.com/nandorholozsnyak/jbang-cloud/blob/main/jbang-catalog.json
[jbang] Retrieved file from cache https://raw.githubusercontent.com/nandorholozsnyak/jbang-cloud/main/aws/aws-lambda.java.qute = /home/xxx/.jbang/cache/urls/f8ca9d6d645c6de41273fc8b1ccef40cad73483c050a392c9a5dd0545a9478dc/aws-lambda.java.qute
[jbang] Retrieved file from cache https://raw.githubusercontent.com/nandorholozsnyak/jbang-cloud/main/aws/application.properties = /home/xxx/.jbang/cache/urls/bbba929e3d30ed7a55c85ced4d66fd8f66b8ce9153e6ebd21d7b6d50cfa39148/application.properties
[jbang] File /home/xxx/jbang-reproducer/QuarkusLambda.java already exists. Will not initialize.

Expected behavior I think JBang should be able to resolve remote files that are included in the templates as dependencies.

JBang version [jbang] jbang version 0.92.2

maxandersen commented 2 years ago

Yeah. That's an oversight. We already have a resolver for local templates in classpath so just need to extend it to resolve relatively to Origin for the template.

You want to give a go on making a pr for it ?

nandorholozsnyak commented 2 years ago

Sounds cool. I'm already having an open PR for weeks now :D Nowadays I'm so busy, I would not say it is so super urgent, but in the upcoming days I will not have time for it, but I would be curious about the implementation.