Giter Site home page Giter Site logo

jbang-eclipse's People

Contributors

fbricon avatar maxandersen avatar renovate-bot avatar renovate[bot] avatar snjeza avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fbricon snjeza

jbang-eclipse's Issues

File not recognized as JBang if directives placed after import or package statements

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")));  ;;
    }
}

Import a script in a folder containing multiple scripts

In a folder ~/tmp/tmp1 create 2 files:

  • cli.java
  • log.java
Sources

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.

  • Both scripts appears in the cli.java project.
  • The dependencies are only resolved for the cli.java file

cli.java JBang project in Eclipse IDE

Download of sources?

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:

Jbang script in Eclipse IDE

But when I want to inspect one the the class of the declared dependency, I do not have access to the sources:
GitLabApi class opened in Eclipse without sources attached

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]

No errors reported during import/clean build

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.

JBang fails to install JDK on Windows

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?

Add support for Annotation Processors

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.

Add support for //PREVIEW

when a script contains //PREVIEW, preview features should be enabled at the JDT level

Since JBang v0.108.0

Support build.jbang

JBang now support a new build.jbang descriptor, see jbangdev/jbang@731399a

Supporting build.jbang files involves several tasks:

  • detect during JBang manual import (Eclipse)
  • detect during JBang automatic import (JDT.LS)
  • trigger JBangBuilder on change (Eclipse)
  • trigger JBangBuilder on change (JDT.LS)
  • report diagnostics (Eclipse)
  • report diagnostics (JDT.LS)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/CI.yml
  • actions/checkout v4
  • actions/setup-java v4
  • actions/cache v4
  • actions/upload-artifact v4
  • codecov/codecov-action v4-beta
maven
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
maven-wrapper
.mvn/wrapper/maven-wrapper.properties
  • maven 3.9.6
  • maven-wrapper 3.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

codecov.io reporting is broken (reports 0% coverage)

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 :

  • - name: Upload code coverage
    uses: codecov/codecov-action@v2
    if: github.ref == 'refs/heads/main' && runner.os == 'Linux'
    with:
    files: ./coverage/target/site/jacoco-aggregate/jacoco.xml
    flags: ${{ runner.os }} # optional
    name: ${{ runner.os }}-tests # optional
    verbose: true # optional (default = false)
  • jbang-eclipse/pom.xml

    Lines 123 to 157 in c61e6fc

    <profile>
    <id>code-coverage</id>
    <activation>
    <!-- Enable jacoco only on plugin projects -->
    <file>
    <exists>META-INF/MANIFEST.MF</exists>
    </file>
    </activation>
    <properties>
    <jacoco.dataFile>${project.basedir}/../target/jacoco.exec</jacoco.dataFile>
    </properties>
    <build>
    <plugins>
    <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.8</version>
    <executions>
    <execution>
    <goals>
    <goal>prepare-agent</goal>
    </goals>
    <configuration>
    <skip>true</skip>
    <includes>
    <include>${coverage.filter}</include>
    </includes>
    <!-- Merge reports from all executions -->
    </configuration>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
    </profile>
  • <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.8</version>
    <executions>
    <execution>
    <id>report</id>
    <phase>integration-test</phase>
    <goals>
    <goal>report-aggregate</goal>
    </goals>
    <configuration>
    <formats>
    <format>XML</format>
    <format>HTML</format>
    </formats>
    </configuration>
    </execution>
    </executions>
    </plugin>

Import a jbang script not having the *.java extension is not possible

As discussed here jbangdev/jbang#676 there are cases where you do not have a .java extension for your Jbang script.

Reproducer<1/summary>

Example:

  • In the folder ~/tmp/tmp2
  • Create the file 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:

Import Jbang Script in Eclipse IDE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.