Skip to content

Commit

Permalink
add graaljs pom to exec sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed May 7, 2019
1 parent 36e037a commit 80f7b2c
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 0 deletions.
287 changes: 287 additions & 0 deletions samples/graaljs-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
<?xml version="1.0"?>
<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.bsc.processor</groupId>
<artifactId>java2ts-processor-parent</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>

<artifactId>graaljs-sample</artifactId>
<name>java2ts-processor::graaljs::sample - ${project.version}</name>
<description>graaljs sample</description>
<packaging>pom</packaging>

<properties>
<graalvm.version>1.0.0-rc16</graalvm.version>
<compiler.dir>${project.build.directory}/compiler</compiler.dir>
</properties>

<profiles>
<profile>
<id>jdk11</id>
<activation>
<jdk>11</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>profiler</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>chromeinspector</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI --module-path=${compiler.dir} --upgrade-module-path=${compiler.dir}/compiler.jar</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.graalvm.compiler</groupId>
<artifactId>compiler</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>compiler.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>truffle-api.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>graal-sdk.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${compiler.dir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>--module-path</argument>
<!-- automatically creates the modulepath using all project dependencies, also adding the project build directory -->
<modulepath/>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
<classpath/>
<argument>-XX:+UnlockExperimentalVMOptions</argument>
<argument>-XX:+EnableJVMCI</argument>
<argument>--upgrade-module-path=${compiler.dir}/compiler.jar</argument>
<argument>org.bsc.java2ts.JSRun$Graaljs</argument>
<argument>${project.build.directory}/js/main.js</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>nograal</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>--module-path</argument>
<!-- automatically creates the modulepath using all project dependencies, also adding the project build directory -->
<modulepath/>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
<classpath/>
<argument>org.bsc.java2ts.JSRun$Graaljs</argument>
<argument>${project.build.directory}/js/main.js</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>${JAVA_HOME}/bin/java</executable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jdk8</id>
<activation>
<jdk>1.8</jdk>
<file>
<missing>${java.home}/lib/truffle/truffle-api.jar</missing>
</file>
</activation>
<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>profiler</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>chromeinspector</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.bsc.java2ts.JSRun$Graaljs</argument>
<argument>${project.build.directory}/js/main.js</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>${JAVA_HOME}/bin/java</executable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>--module-path</argument>
<!-- automatically creates the modulepath using all project dependencies, also adding the project build directory -->
<modulepath/>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
<classpath/>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>${JAVA_HOME}/bin/java</executable>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
<classpath/>
<argument>org.bsc.java2ts.JSRun$Graaljs</argument>
<argument>${project.build.directory}/js/main.js</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
20 changes: 20 additions & 0 deletions samples/src/main/java/org/bsc/java2ts/JSRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,25 @@ public static void main(String[] args) throws Exception {
}

}

public static class Graaljs {
public static void main(String[] args) throws Exception {
final ScriptEngineManager manager = new ScriptEngineManager();

final ScriptEngine service = manager.getEngineByName("graal.js");

service.put( "$ARG", args );

if( args.length == 0 ) {
System.out.printf( "usage:\tJSRun.Graaljs <file>.js\n");
}
try( java.io.Reader app = new java.io.FileReader(args[0])) {
service.eval( app );
}
}

}



}

0 comments on commit 80f7b2c

Please sign in to comment.