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

Introduce ability to recognize and execute user main method(s) #6499

Closed
dmlloyd opened this issue Jan 10, 2020 · 7 comments
Closed

Introduce ability to recognize and execute user main method(s) #6499

dmlloyd opened this issue Jan 10, 2020 · 7 comments
Labels
kind/enhancement New feature or request triage/out-of-date This issue/PR is no longer valid or relevant

Comments

@dmlloyd
Copy link
Member

dmlloyd commented Jan 10, 2020

Description
Introduce ability to recognize and execute user main method(s).

Requirements

  • Introduce a means to identify a method as a main method (e.g. an annotation)
  • Allow build-time configuration to specify which main method (if any) should be used for the build (can @Named be used for this?)
  • The main method should be allowed to optionally accept a String[] or List<String> which contains the command arguments (minus the arguments processed by Introduce config-based command line argument binding #6497)
  • The main method should be allowed to optionally return an int which contains the desired exit code
  • If the application shutdown fails with an exception, there should be a means to override the exit code.
  • A mechanism may be defined to allow users to customize the mapping of exception to exit code; if implemented, the mechanism should accept the exception and the originally requested exit code, and return the new exit code. If the mapping fails with an exception, an exit code of 1 should be used.
  • System.exit() should be called with the final exit code once all shutdown work is complete (at the end of the launcher main method).
  • If no main method is defined, then the waitForExit method defined in Introduce an exit request API with wait-for-exit method #6498 should be used, with the code returned from that method being used as the requested exit code

Exit codes reference

Code Description
0 Normal exit (no error, clean shutdown)
1 Exit due to uncaught exception
2 Exit due to configuration or usage error
10 (reserved due to its usage with JBoss)
@maxandersen
Copy link
Member

maxandersen commented Jan 14, 2020

Reading the proposed items I'm struggling to figure out if I'll be able to as follows:

class Main {
public static void main(String... args) {
    QuarkusApplication.start(Main::handler, args); 
} 

int handler(String... args) {
   ...
}
}

here I'm just using a method reference, but could also be a class.

Main point is that I'll have a plain static main that can be booted by Quarkus.

Or is the expectation all is always handled by Quarkus ?

@dmlloyd
Copy link
Member Author

dmlloyd commented Jan 14, 2020

That seems doable to me. We just have to be sure that the Quarkus build process has a way to know which entry point main to use during build.

@maxandersen
Copy link
Member

Yes, I assume we'll have a way to do both - the explicit main() method is mainly just for easy launching from IDE or command line jar runs.

@dodalovic
Copy link
Contributor

@maxandersen Just curious how far we are from this wonderful feature?
Cheers

@maxandersen
Copy link
Member

@dodalovic sorry - didn't see your ping here before now - see #7681 for current progress

@maxandersen
Copy link
Member

@stuartwdouglas how much of this is fullfilled by #7681 ?

@stuartwdouglas
Copy link
Member

Most of it, except for exception mapping for exit codes, which is going to be a follow up. Also failure due to config issue does not have it's own exit code, however that can be done as part of the exception mapping work.

@gsmet gsmet added the triage/out-of-date This issue/PR is no longer valid or relevant label May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request triage/out-of-date This issue/PR is no longer valid or relevant
Projects
None yet
Development

No branches or pull requests

6 participants