Skip to content

Commit

Permalink
Failed to build JLine Graal demo: NoClassDefFoundError, fixes #615
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Dec 6, 2020
1 parent 54218bc commit ec1115d
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 59 deletions.
2 changes: 1 addition & 1 deletion build.config
Expand Up @@ -15,5 +15,5 @@ function command_repl() {
}

function command_graal() {
exec demo/target/graal $*
exec graal/target/graal $*
}
36 changes: 1 addition & 35 deletions demo/pom.xml
Expand Up @@ -25,7 +25,7 @@
<properties>
<automatic.module.name>org.jline.demo</automatic.module.name>
</properties>

<dependencies>
<dependency>
<groupId>org.jline</groupId>
Expand Down Expand Up @@ -105,11 +105,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -187,40 +182,11 @@
<include>data.json</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>reflection-config.json</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<skip>${native.image.skip}</skip>
<imageName>graal</imageName>
<mainClass>org.jline.demo.Graal</mainClass>
<buildArgs>
--no-fallback
--report-unsupported-elements-at-runtime
--allow-incomplete-classpath
-H:ReflectionConfigurationFiles=reflection-config.json
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
125 changes: 125 additions & 0 deletions graal/pom.xml
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2002-2020, the original author or authors.
This software is distributable under the BSD license. See the terms of the
BSD license in the documentation provided with this software.
https://opensource.org/licenses/BSD-3-Clause
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.17.2-SNAPSHOT</version>
</parent>

<artifactId>jline-graal</artifactId>
<name>JLine Graal Demo</name>

<properties>
<automatic.module.name>org.jline.graal</automatic.module.name>
</properties>

<dependencies>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
</dependency>

<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</dependency>

<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-root</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>reflection-config.json</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<skip>${native.image.skip}</skip>
<imageName>graal</imageName>
<mainClass>org.jline.demo.graal.Graal</mainClass>
<buildArgs>
--no-fallback
--report-unsupported-elements-at-runtime
--allow-incomplete-classpath
-H:ReflectionConfigurationFiles=reflection-config.json
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>

</project>
Expand Up @@ -6,12 +6,13 @@
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.demo;
package org.jline.demo.graal;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Supplier;

import org.jline.console.impl.Builtins;
import org.jline.console.impl.Builtins.Command;
Expand All @@ -21,7 +22,6 @@
import org.jline.reader.*;
import org.jline.reader.LineReader.Option;
import org.jline.reader.impl.DefaultParser;
import org.jline.reader.impl.DefaultParser.Bracket;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.terminal.Terminal.Signal;
Expand All @@ -32,36 +32,31 @@

public class Graal {

private static Path workDir() {
return Paths.get(System.getProperty("user.dir"));
}

public static void main(String[] args) {
try {
Supplier<Path> workDir = () -> Paths.get(System.getProperty("user.dir"));
//
// Parser & Terminal
//
DefaultParser parser = new DefaultParser();
parser.setEofOnUnclosedBracket(Bracket.CURLY, Bracket.ROUND, Bracket.SQUARE);
parser.setEofOnUnclosedQuote(true);
parser.setEscapeChars(null);
parser.setRegexCommand("[:]{0,1}[a-zA-Z!]{1,}\\S*"); // change default regex to support shell commands
parser.setRegexVariable(null); // we do not have console variables!
Terminal terminal = TerminalBuilder.builder().build();
Thread executeThread = Thread.currentThread();
terminal.handle(Signal.INT, signal -> executeThread.interrupt());
//
// Command registeries
// Command registries
//
File file = new File(Graal.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
String root = file.getCanonicalPath().replace("graal", "").replaceAll("\\\\", "/"); // forward slashes works better also in windows!
String root = file.getCanonicalPath().replace("graal", "")
.replaceAll("\\\\", "/"); // forward slashes works better also in windows!
ConfigurationPath configPath = new ConfigurationPath(Paths.get(root), Paths.get(root));
Set<Builtins.Command> commands = new HashSet<>(Arrays.asList(Builtins.Command.values()));
commands.remove(Command.TTOP); // ttop command is not supported in GraalVM
Builtins builtins = new Builtins(commands, Graal::workDir, configPath, null);
Repl.MyCommands myCommands = new Repl.MyCommands(Graal::workDir);
SystemRegistryImpl systemRegistry = new SystemRegistryImpl(parser, terminal, Graal::workDir, configPath);
systemRegistry.setCommandRegistries(builtins, myCommands);
Builtins builtins = new Builtins(commands, workDir, configPath, null);
SystemRegistryImpl systemRegistry = new SystemRegistryImpl(parser, terminal, workDir, configPath);
systemRegistry.setCommandRegistries(builtins);
//
// LineReader
//
Expand All @@ -82,10 +77,9 @@ public static void main(String[] args) {
reader.setVariable(LineReader.BLINK_MATCHING_PAREN, 0); // if enabled cursor remains in begin parenthesis (gitbash)
}
//
// complete command registeries
// complete command registries
//
builtins.setLineReader(reader);
myCommands.setLineReader(reader);
//
// widgets and console initialization
//
Expand All @@ -98,9 +92,8 @@ public static void main(String[] args) {
System.out.println(terminal.getName() + ": " + terminal.getType());
while (true) {
try {
systemRegistry.cleanUp(); // delete temporary variables and reset output streams
systemRegistry.cleanUp(); // reset output streams
String line = reader.readLine("graal> ");
line = parser.getCommand(line).startsWith("!") ? line.replaceFirst("!", "! ") : line;
Object result = systemRegistry.execute(line);
if (result != null) {
System.out.println(result);
Expand All @@ -113,10 +106,10 @@ public static void main(String[] args) {
break;
}
catch (Exception e) {
systemRegistry.trace(true, e); // print exception and save it to console variable
systemRegistry.trace(true, e); // print exception
}
}
systemRegistry.close(); // persist pipeline completer names etc
systemRegistry.close();
}
catch (Throwable t) {
t.printStackTrace();
Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Expand Up @@ -94,7 +94,7 @@
<groovy.version>3.0.6</groovy.version>
<ivy.version>2.5.0</ivy.version>
<graal.version>19.3.1</graal.version>

<surefire.argLine />
</properties>

Expand Down Expand Up @@ -255,7 +255,7 @@
<artifactId>groovy-console</artifactId>
<version>${groovy.version}</version>
</dependency>

<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
Expand Down Expand Up @@ -543,7 +543,7 @@
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>${graal.version}</version>
</plugin>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -606,6 +606,7 @@
<module>style</module>
<module>jline</module>
<module>demo</module>
<module>graal</module>
</modules>

</project>

0 comments on commit ec1115d

Please sign in to comment.