jbang
jbang copied to clipboard
source-type not honored
copy this to clipboard:
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS dev.jbang:devkitman:0.1.2
//JAVA 21+
//PREVIEW
import dev.jbang.devkitman.*;
void main(String[] args) {
var jdkManager = JdkManager.create();
var jdk = jdkManager.getOrInstallJdk(args.length > 0 ? args[0] : "11+");
System.out.println("JDK: " + jdk);
System.out.println("Installed: " + jdkManager.listInstalledJdks());
System.out.println("Providers: " + JdkProviders.instance().allNames());
}
run it with pbpaste | jbang --source-type=java - and it still try to run this as .jsh even though its forced to be java.
Indeed, with --verbose it says:
[jbang] [0:268] Resolving resource ref: -
[jbang] [0:282] Resolved resource ref as: - (cached as: C:\Users\tako\.jbang\cache\stdins\e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.jsh)
Which is incorrect.
I also tried to copy the code to a file and name it test.jsh and then run jbang --source-type=java test.jsh. This also fails.
But with a different error:
...
[jbang] [0:281] Resolving resource ref: test2.jsh
[jbang] [0:298] Resolved resource ref as: test2.jsh (cached as: C:\Users\tako\.jbang\cache\scripts\e90699fcee8cfa5ae66c8c445e2a673c368a8eec1cef6812c701bcd9001265fb\test2.jsh.java)
...
C:\Users\tako\.jbang\cache\scripts\e90699fcee8cfa5ae66c8c445e2a673c368a8eec1cef6812c701bcd9001265fb\test2.jsh.java:8: error: bad file name: test2.jsh
Probably because we only ever used this option for files that had no extension. We should probably strip extensions before tacking on a new one. (Or simply fail before trying to compile saying that the option doesn't make sense given that the file already has a type)
tests passes - good work! thanks :)
@all-contributors add @lutzleonhardt for code