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

Enable jbang integration in Quarkus #11542

Merged
merged 1 commit into from Aug 29, 2020

Conversation

maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Aug 23, 2020

This PR started out as trying to run a jar directly via quarkus; but after talking with @stuartwdouglas
taking another approach where jbang has a SPI to let quarkus (or any other framework) hook into the build process.

With this PR + jbang PR you can take the following file, save in quarkus.java and do:

jbang quarkus.java to run it
jbang --debug quarkus.java to debug it
jbang --native quarkus.java to get native image built (currently rely on docker; TBD use graalvm if available)

//usr/bin/env jbang "$0" "$@" ; exit $?
// //DEPS <dependency1> <dependency2>
//DEPS io.quarkus:quarkus-arc:999-SNAPSHOT

import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.QuarkusApplication;

import static java.lang.System.*;

public class quarkus {

    public static void main(String... args) {
        Quarkus.run(MyApp.class, args);
    }

    public static class MyApp implements QuarkusApplication {

        @Override
        public int run(String... args) throws Exception {
            System.out.println("Inside Quarkus!");
            return 0;
        }
    }
}

you can also do configuration using //CONFIG

//DEPS io.quarkus:quarkus-resteasy:999-SNAPSHOT
//DEPS io.quarkus:quarkus-container-image-jib:999-SNAPSHOT
//CONFIG quarkus.http.port=7777
//CONFIG quarkus.native.container-build=true
//CONFIG quarkus.container-image.build=true
//CONFIG quarkus.container-image.name=jbang-test

import io.quarkus.runtime.Quarkus;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello")
public class quarkus {

    public static void main(String... args) {
        Quarkus.run(args);
    }

    @GET
    public String sayHello() {
        return "hello";
    }
}

Things yet to do/being considered:

  • release jbang 0.40 with SPI enabled
  • transformation missing thus things like panache does not work (trivial fix)
  • Consider if //CONFIG should be //QCONFIG as it is quarkus specific
  • remove dependency on intermediate pom.xml and just work based on dependency list
  • enable dev:mode (package as mutable-jar and this should "just work")
  • enable run from IDE (currently it requires it to be packaged as jar)
    (work around is to do jbang --debug app.java and connect with debugger from there.)
  • consider if we should allow triggering thngs like openshift/kubernetes/funky deploy (all technical possible; just a question on if can make the UX experience sane from jbang side)

In addition this PR also try and make it possible to run app directly without having
pom.xml/build.gradle but not yet complete.

for now added .jar to zipfilesystem to avoid FileSystemNotFoundException and
then avoided introspection as if a gradle project.

But then hitting that appmodel is null.

@boring-cyborg boring-cyborg bot added area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins labels Aug 23, 2020
@gastaldi
Copy link
Contributor

@maxandersen try removing the main if you implement QuarkusApplication or add @QuarkusMain

@maxandersen
Copy link
Contributor Author

maxandersen commented Aug 26, 2020

@maxandersen try removing the main if you implement QuarkusApplication or add @QuarkusMain

what would that help/change ? (without it you can't run it from the IDE easily)

updated the example as missing arc and not passing class to run. now it works ;)

@maxandersen
Copy link
Contributor Author

maxandersen commented Aug 26, 2020

Pushed some changes from @stuartwdouglas enabling this level of crazyiness:

//DEPS io.quarkus:quarkus-resteasy:999-SNAPSHOT
//DEPS io.quarkus:quarkus-container-image-jib:999-SNAPSHOT
//CONFIG quarkus.http.port=7777
//CONFIG quarkus.native.container-build=true
//CONFIG quarkus.container-image.build=true
//CONFIG quarkus.container-image.name=jbang-test

import io.quarkus.runtime.Quarkus;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello")
public class quarkus {

    public static void main(String... args) {
        Quarkus.run(args);
    }

    @GET
    public String sayHello() {
        return "hello";
    }
}

This wont (yet) let jbang just run the jar standalone; but what it does do is letting quarkus participate during jbang build without a hard coupling between the two. Allowing you to have speedy startup AND generate native images ...

This relies on this jbang PR to work: jbangdev/jbang#261

@boring-cyborg boring-cyborg bot added area/arc Issue related to ARC (dependency injection) area/google-cloud-functions labels Aug 27, 2020
@maxandersen maxandersen marked this pull request as ready for review August 28, 2020 22:18
@maxandersen
Copy link
Contributor Author

@gastaldi @aloubyansky would like to see this enabled in 1.8 thus a fast review would be great - pretty please!

There are a bunch of files changed here but bulk of it is the jbang handler code which shouldnt affect anything as its completely isolated and only engaged when run inside jbang.

The others are just gotchas/issues jbang usage found that needed fixing anyway (TCCL classloader and non-default package name assumptions)

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

Found some minor issues, but otherwise LGTM


import java.io.File;
import java.nio.file.Path;
import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid star imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I don't use them but recently the formatter seem to make them happen.

@gastaldi
Copy link
Contributor

Mind squashing before merging this PR?

Done by implementing jbang experimental
SPI to let Quarkus participate in the build of a jar
+ passing //Q:CONFIG in as system properties.

Initial version supports building jar as well as native
image via docker.

 - various fixes for handling default packages in arc and metrics.
 - fixes a few places of class.forname not honoring TCCL
 - slightly open up appmodel to enable this but still reliant
   on pom.xml being bundled (future versions shouldn't)

Co-Authored: Alexey Loubyansky <olubyans@redhat.com>
Co-Authored: Stuart Douglas <stuart.w.douglas@gmail.com>
@maxandersen
Copy link
Contributor Author

Mind squashing before merging this PR?

sure - pushed with co-authors intact.

@gastaldi gastaldi added this to the 1.8.0 - master milestone Aug 29, 2020
@gastaldi gastaldi merged commit af6dd4b into quarkusio:master Aug 29, 2020
@gastaldi
Copy link
Contributor

Thanks, merged

@maxandersen
Copy link
Contributor Author

Proposal for release blog:

Experimental Quarkus Scripting via JBang

jbang lets you write and build single source java applications - requiring no maven nor gradle to build and it will even download Java for you.

We've added experimental support to let you take the following code, save it as quarkus.java and run it using jbang quarkus.java.

//usr/bin/env jbang "$0" "$@" ; exit $?
//REPOS xamdk=https://xam.dk/maven
//DEPS io.quarkus:quarkus-resteasy:1.8.0.CR1
//DEPS io.quarkus:quarkus-smallrye-openapi:1.8.0.CR1
//DEPS io.quarkus:quarkus-swagger-ui:1.8.0.CR1

//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager
//Q:CONFIG quarkus.swagger-ui.always-include=true

import io.quarkus.runtime.Quarkus;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello")
@ApplicationScoped
public class quarkus {

    @GET
    public String sayHello() {
        return "hello from Quarkus with jbang.dev";
    }

    public static void main(String[] args) {
        Quarkus.run(args);
    }
}

You can even run jbang --native quarkus.java to get a native image build assuming you have native-image installed.

This initial version has all the basics working making it possible to write full blown Quarkus applications - some features like devmode is not there yet nor resources (like initial index.html). Still, with the above you have the full REST example application and you can access https://0.0.0.0:8080/hello for the API and even https://0.0.0.0:8080/swaggeer-ui for OpenAPI browsing.

Provide feedback and let us see where it goes.

@gastaldi
Copy link
Contributor

Hey, what if we added that snippet in the jbang-catalog? It would be easier to run with jbang quarkus@quarkusio :)

@gastaldi
Copy link
Contributor

Maybe we can migrate the quickstarts to that too in the future

@maxandersen
Copy link
Contributor Author

Hey, what if we added that snippet in the jbang-catalog? It would be easier to run with jbang quarkus@quarkusio :)

once some version with quarkus in it is released we can do some interesting things in the catalog for sure. Just that in jbangs current form it only allows for single files thus not all quickstarts "fits".

I'm about to submit PR with basic docs for the jbang integration and you'll see the slight differences/limits there are when using single file.

@maxandersen maxandersen changed the title Attempt to enable Quarkus.run to work on a single jar Enable jbang integration in Quarkus Sep 4, 2020
@maxandersen maxandersen added the area/jbang Issues related to when using jbang.dev with Quarkus label Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/google-cloud-functions area/infinispan Infinispan area/jaxb area/jbang Issues related to when using jbang.dev with Quarkus area/kafka area/resteasy area/scheduler area/smallrye release/noteworthy-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants