jbangdev / jbang-eclipse Goto Github PK
View Code? Open in Web Editor NEWJBang / Eclipse integration
License: Eclipse Public License 2.0
JBang / Eclipse integration
License: Eclipse Public License 2.0
//FILES path=filename should create a matching simlink
Will most likely rely on querying search.maven.org API
Specifically when run via jdt.ls, if a folder contains multiple files including main.java, only import main.java, the other files should be added via //SOURCES, hopefully.
@maxandersen does that sound correct?
A file is not recognized as a JBang script if the directives are placed after non-blank lines, eg. import or package statements:
import com.github.lalyos.jfiglet.FigletFont;
//DEPS com.github.lalyos:jfiglet:0.0.9
class hello {
public static void main(String... args) throws Exception {
System.out.println(FigletFont.convertOneLine(
"Hello " + ((args.length>0)?args[0]:"jbang"))); ;;
}
}
... to execute a file via JBang itself, in a console.
to select a different JBang runtime
In a folder ~/tmp/tmp1
create 2 files:
cli.java
log.java
cli.java:
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.6.3
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import java.util.concurrent.Callable;
@Command(name = "cli", mixinStandardHelpOptions = true, version = "cli 0.1",
description = "cli made with jbang")
class cli implements Callable<Integer> {
@Parameters(index = "0", description = "The greeting to print", defaultValue = "World!")
private String greeting;
public static void main(String... args) {
int exitCode = new CommandLine(new cli()).execute(args);
System.exit(exitCode);
}
@Override
public Integer call() throws Exception { // your business logic goes here...
System.out.println("Hello " + greeting);
return 0;
}
}
log.java:
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS ch.qos.reload4j:reload4j:1.2.19
import static java.lang.System.out;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import java.util.Arrays;
class log {
static final Logger logger = Logger.getLogger(log.class);
public static void main(String[] args) {
BasicConfigurator.configure();
logger.info("Welcome to jbang");
Arrays.asList(args).forEach(arg -> logger.warn("arg: " + arg));
logger.info("Hello from Java!");
}
}
Import the cli.java
script as Jbang project into Eclipse.
cli.java
project.cli.java
filejbang.io isn't a thing - jbang.dev is :)
Create new JBang scripts from JBang templates
macOS, this plugin is causing a never-ending build loop (for all projects in workspace)
I think it has to do with "refresh using native hooks" enabled
When I import my jbang script containing following headers:
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS org.gitlab4j:gitlab4j-api:5.0.1
It works well:
But when I want to inspect one the the class of the declared dependency, I do not have access to the sources:
Is this expected?
Tested version:
eclipse.buildId=4.26.0.20221201-1200
*** Plug-in Registry:
dev.jbang.eclipse.core (0.0.3.20230103-1009) "JBang Eclipse Core Plugin" [Active]
dev.jbang.eclipse.ui (0.0.3.20230103-1009) "JBang Eclipse UI Plugin" [Active]
... if no runtime is found
On JBang script import, a clean build is run. Because there's no delta, there's no JBang script to get info from.
There's currently no mapping between a JBang project and a default main script, we could rely on for running clean builds.
On Windows 10, when a script requires a missing JDK, JBang downloads and installs it. However the jbang info tools
command fails. After enabling verbose logging, I can see:
[jbang] jbang version 0.100.0
[jbang] Repositories: mavencentral=https://repo1.maven.org/maven2/
[jbang] System Java version detected as 16
[jbang] System Java version 16 incompatible, using JBang managed version 12
[jbang] Downloading JDK 12. Be patient, this can take several minutes...
[jbang] Downloading https://api.foojay.io/disco/v3.0/directuris?distro=aoj&javafx_bundled=false&libc_type=c_std_lib&archive_type=zip&operating_system=windows&package_type=jdk&version=12&architecture=x64&latest=available
[jbang] Redirected to: https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_windows_hotspot_12.0.2_10.zip
[jbang] Redirected to: https://objects.githubusercontent.com/github-production-release-asset-2e65be/172940752/ded7ee00-a9a2-11e9-97e3-f1ea4ddb0229?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20221112%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221112T155818Z&X-Amz-Expires=300&X-Amz-Signature=87b6030b0c905f028f5a5fd1e5cf6b046c9d308260ce33c560cd41ece69ead43&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=172940752&response-content-disposition=attachment%3B%20filename%3DOpenJDK12U-jdk_x64_windows_hotspot_12.0.2_10.zip&response-content-type=application%2Foctet-stream
[jbang] Downloaded file https://objects.githubusercontent.com/github-production-release-asset-2e65be/172940752/ded7ee00-a9a2-11e9-97e3-f1ea4ddb0229?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20221112%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221112T155818Z&X-Amz-Expires=300&X-Amz-Signature=87b6030b0c905f028f5a5fd1e5cf6b046c9d308260ce33c560cd41ece69ead43&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=172940752&response-content-disposition=attachment%3B%20filename%3DOpenJDK12U-jdk_x64_windows_hotspot_12.0.2_10.zip&response-content-type=application%2Foctet-stream
[jbang] Installing JDK 12...
[jbang] Unpacking to C:\Users\fbric.jbang\cache\jdks\12
[jbang] java.nio.file.FileSystemException: C:\Users\fbric.jbang\currentjdk: Le client ne dispose pas d?un privil?ge n?cessaire
[jbang] Creation of symbolic link failed.For potential causes and resolutions see https://www.jbang.dev/documentation/guide/latest/usage.html#usage-on-windows
[jbang] Now try creating a hard link instead of symbolic.
[jbang] Creation of hard link failed. Script must be on the same drive as $JBANG_CACHE_DIR (typically under $HOME) for hardlink creation to work. Or call the command with admin rights.
[jbang] [ERROR] Required Java version not possible to download or install. You can run with '--java 16' to force using the default installed Java.
[jbang] [ERROR] Unable to download or install JDK version 12
dev.jbang.cli.ExitException: Unable to download or install JDK version 12
at dev.jbang.net.JdkManager.downloadAndInstallJdk(JdkManager.java:153)
at dev.jbang.net.JdkManager.getInstalledJdk(JdkManager.java:114)
at dev.jbang.net.JdkManager.getCurrentJdk(JdkManager.java:107)
at dev.jbang.cli.BaseInfoCommand$ScriptInfo.(Info.java:103)
at dev.jbang.cli.BaseInfoCommand.getInfo(Info.java:187)
at dev.jbang.cli.Tools.doCall(Info.java:212)
at dev.jbang.cli.BaseCommand.call(BaseCommand.java:136)
at dev.jbang.cli.BaseCommand.call(BaseCommand.java:20)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
at dev.jbang.cli.JBang$3.handle(JBang.java:147)
at dev.jbang.cli.JBang$3.handle(JBang.java:142)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
at picocli.CommandLine.execute(CommandLine.java:2078)
at dev.jbang.Main.main(Main.java:14)
Caused by: dev.jbang.cli.ExitException: java.nio.file.AccessDeniedException: C:\Users\fbric.jbang\currentjdk -> C:\Users\fbric.jbang\cache\jdks\12
at dev.jbang.util.Util.createHardLink(Util.java:1157)
at dev.jbang.util.Util.createLink(Util.java:1129)
at dev.jbang.net.JdkManager.setDefaultJdk(JdkManager.java:269)
at dev.jbang.net.JdkManager.downloadAndInstallJdk(JdkManager.java:139)
... 17 more
Caused by: java.nio.file.AccessDeniedException: C:\Users\fbric.jbang\currentjdk -> C:\Users\fbric.jbang\cache\jdks\12
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsFileSystemProvider.createLink(WindowsFileSystemProvider.java:618)
at java.base/java.nio.file.Files.createLink(Files.java:1106)
at dev.jbang.util.Util.createHardLink(Util.java:1154)
... 20 more
So invoking JBang from a ProcessBuilder lacks necessary rights:
[jbang] Creation of symbolic link failed.For potential causes and resolutions see https://www.jbang.dev/documentation/guide/latest/usage.html#usage-on-windows
The link explains how to enable symlink creation, but that really doesn't seem necessary. The JDK has been installed locally, and on the next JBang invocation, it will be found and used without issues.
We could either ignore the error and reexecute the jbang command transparently, or jbang could provide a way to ignore symlink creation/failures.
@maxandersen thoughts?
Take this exemple relying on Autovalue:
//DEPS com.google.auto.value:auto-value-annotations:LATEST
//DEPS com.google.auto.value:auto-value:LATEST
//See https://github.com/google/auto/blob/master/value/userguide/index.md#with-maven
//JAVA 17+
import com.google.auto.value.AutoValue;
public class autovalued {
@AutoValue
abstract static class Animal {
static Animal create(String name, int numberOfLegs) {
return new AutoValue_autovalued_Animal(name, numberOfLegs);
}
abstract String name();
abstract int numberOfLegs();
}
public static void main(String[] args) {
Animal animal = Animal.create("dog", 4);
System.out.println(animal);
}
}
You get a compilation error AutoValue_autovalued_Animal cannot be resolved to a type
, because JDT APT is not automatically configured with the autovalue annotation processor.
when a script contains //PREVIEW
, preview features should be enabled at the JDT level
Since JBang v0.108.0
JBang now support a new build.jbang descriptor, see jbangdev/jbang@731399a
Supporting build.jbang files involves several tasks:
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
org.eclipse.tycho:tycho-p2-plugin
, org.eclipse.tycho:tycho-source-plugin
, org.eclipse.tycho:tycho-surefire-plugin
, org.eclipse.tycho:tycho-packaging-plugin
, org.eclipse.tycho.extras:tycho-sourceref-jgit
, org.eclipse.tycho:target-platform-configuration
, org.eclipse.tycho:tycho-maven-plugin
).github/workflows/CI.yml
actions/checkout v4
actions/setup-java v4
actions/cache v4
actions/upload-artifact v4
codecov/codecov-action v4-beta
coverage/pom.xml
org.jacoco:jacoco-maven-plugin 0.8.11
dev.jbang.eclipse.core/pom.xml
dev.jbang.eclipse.feature/pom.xml
dev.jbang.eclipse.ls/pom.xml
dev.jbang.eclipse.site/pom.xml
dev.jbang:jbang-maven-plugin 0.0.8
dev.jbang.eclipse.target/pom.xml
dev.jbang.eclipse.test/pom.xml
com.googlecode.maven-download-plugin:download-maven-plugin 1.8.1
dev.jbang.eclipse.ui/pom.xml
pom.xml
org.eclipse.tycho:tycho-maven-plugin 4.0.7
org.eclipse.tycho:target-platform-configuration 4.0.7
org.eclipse.tycho:tycho-source-plugin 4.0.7
org.eclipse.tycho.extras:tycho-sourceref-jgit 4.0.7
org.eclipse.tycho:tycho-packaging-plugin 4.0.7
org.eclipse.tycho:tycho-surefire-plugin 4.0.7
org.jacoco:jacoco-maven-plugin 0.8.11
org.eclipse.tycho:tycho-surefire-plugin 4.0.7
org.eclipse.tycho:tycho-source-plugin 4.0.7
org.eclipse.tycho:tycho-p2-plugin 4.0.7
.mvn/wrapper/maven-wrapper.properties
maven 3.9.6
maven-wrapper 3.2.0
so as to not rely on hardcoded sdman path
https://app.codecov.io/gh/jbangdev/jbang-eclipse/tree/main/ reports 0% coverage
not too surprising as I'm not at all familiar with it. Things to potentially tune :
jbang-eclipse/.github/workflows/CI.yml
Lines 48 to 55 in c61e6fc
Lines 123 to 157 in c61e6fc
jbang-eclipse/coverage/pom.xml
Lines 33 to 52 in c61e6fc
As discussed here jbangdev/jbang#676 there are cases where you do not have a .java
extension for your Jbang script.
Example:
~/tmp/tmp2
hello
with this content:///usr/bin/env jbang "$0" "$@" ; exit $?
import static java.lang.System.*;
public class hello {
public static void main(String... args) {
out.println("Hello World");
}
}
Currently those files can not be selected:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.