From b57532a028ba656c11487dba58224d774027ce45 Mon Sep 17 00:00:00 2001 From: Olya Gupalo Date: Fri, 15 Dec 2023 11:30:46 +0100 Subject: [PATCH 1/3] Upgrade Java+Javascript Embedding Example to GraalVM for JDK 21 (23.1.1) --- .github/workflows/polyglot-debug.yml | 4 +- polyglot-debug/README.MD | 43 +++++-- polyglot-debug/pom.xml | 105 +++++++++++++++++- polyglot-debug/src/main/java/module-info.java | 4 + .../java/org/graalvm/demos/PolyglotDebug.java | 1 + 5 files changed, 139 insertions(+), 18 deletions(-) create mode 100644 polyglot-debug/src/main/java/module-info.java diff --git a/.github/workflows/polyglot-debug.yml b/.github/workflows/polyglot-debug.yml index c51fdd870..23786d0ab 100644 --- a/.github/workflows/polyglot-debug.yml +++ b/.github/workflows/polyglot-debug.yml @@ -20,7 +20,7 @@ jobs: timeout-minutes: 15 strategy: matrix: - java-version: ['17', 'dev'] + java-version: ['21', 'dev'] steps: - uses: actions/checkout@v3 - uses: graalvm/setup-graalvm@v1 @@ -34,4 +34,4 @@ jobs: run: | cd polyglot-debug mvn --no-transfer-progress clean package - java -cp ./target/PolyglotDebug-1.0-SNAPSHOT.jar org.graalvm.demos.PolyglotDebug + mvn exec:exec diff --git a/polyglot-debug/README.MD b/polyglot-debug/README.MD index 5aea4e2bc..b6d02ca9b 100644 --- a/polyglot-debug/README.MD +++ b/polyglot-debug/README.MD @@ -1,23 +1,44 @@ -# GraalVM Java to JavaScript Polyglot Debugging +# Debugging a Java with JavaScript Embedding Application -This sample code helps to demonstrate simplicity of debugging and developing GraalVM Polyglot applications using __VS Code extensions__. +This sample code helps to demonstrate simplicity of debugging and developing GraalVM polyglot applications using Visual Studio (VS) Code extensions. ## Prerequisites -1. VS Code has to be installed. +1. Install VS Code and launch it. 2. Then go to VS Code Extensions activity panel and search for _GraalVM Extension Pack_, install it. The GraalVM Extension Pack will install all required extensions. -3. [Install GraalVM in VS Code](https://www.graalvm.org/latest/tools/vscode/graalvm-extension/#graalvm-installation-wizard): Navigate to Gr activity panel in VS Code and install some of the latest GraalVM __Enterprise Edition__ versions available from the list. +2. Open Visual Studio Code, navigate to Extensions activity panel in the left-hand side Activity Bar. Search for “GraalVM” in the search field. Find [GraalVM Tools for Java](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm), press Install. Reload will be required. +3. [Install GraalVM in VS Code](https://www.graalvm.org/latest/tools/vscode/graalvm-extension/#graalvm-installation-wizard): Navigate to Gr activity panel in VS Code and install the latest Oracle GraalVM version available from the list. 4. Confirm to set this as _Active GraalVM_ for VS Code. -5. Install the `js` component. -## Debugging the project - -Working with Polyglot project in VSCode is simple just open this sample. +## Build and Run the Application + +1. Open VS Code Terminal. +2. Clone the repository and navigate into the `polyglot-debug` directory: + ```bash + git clone https://github.com/graalvm/graalvm-demos + ``` + ```bash + cd graalvm-demos/polyglot-debug + ``` + +3. Build the application using Maven: + ```bash + mvn clean package + ``` +4. Run this application with the following command: + ```bash + mvn exec:exec + ``` + +## Debug the Application + +Working with a polyglot project in VS Code is simple just open this sample. It will be working out of the box with VS Code GraalVM extensions. -Place breakpoints either in Java or JavaScript code. +1. Place breakpoints either in Java or JavaScript code. + +2. To debug the project, go to __Run and Debug__ activity or simply press F5. -To debug the project go to __Run and Debug__ activity or simply press F5. -Choose **Launch Java 8+** as this is the Polyglot debugger provided by GraalVM extensions. +3. Choose **Launch Java 8+** as this is the Polyglot debugger provided by the GraalVM extension. That is, the sample is running under debugger on GraalVM. diff --git a/polyglot-debug/pom.xml b/polyglot-debug/pom.xml index 2826a0efe..d45f12f4c 100755 --- a/polyglot-debug/pom.xml +++ b/polyglot-debug/pom.xml @@ -3,12 +3,107 @@ 4.0.0 org.graalvm.demos PolyglotDebug - 1.0-SNAPSHOT + 1.0 jar UTF-8 - 1.8 - 1.8 + 23.1.1 - PolyglotDebug - \ No newline at end of file + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + + + org.graalvm.demos.PolyglotDebug + + + + + + assemble-all + package + + single + + + + + + maven-jar-plugin + 3.2.0 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + default-cli + + exec + + + + --module-path + + + -m + demo/org.graalvm.demos.PolyglotDebug + + + + + + ${JAVA_HOME}/bin/java + + + + + + + + org.graalvm.sdk + collections + ${graalvm.version} + + + org.graalvm.sdk + nativeimage + ${graalvm.version} + + + org.graalvm.sdk + word + ${graalvm.version} + + + org.graalvm.polyglot + polyglot + ${graalvm.version} + + + org.graalvm.polyglot + js + ${graalvm.version} + pom + + + + diff --git a/polyglot-debug/src/main/java/module-info.java b/polyglot-debug/src/main/java/module-info.java new file mode 100644 index 000000000..b2905e9ee --- /dev/null +++ b/polyglot-debug/src/main/java/module-info.java @@ -0,0 +1,4 @@ +module demo { + exports org.graalvm.demos; + requires org.graalvm.polyglot; +} \ No newline at end of file diff --git a/polyglot-debug/src/main/java/org/graalvm/demos/PolyglotDebug.java b/polyglot-debug/src/main/java/org/graalvm/demos/PolyglotDebug.java index bce77b340..c63021035 100644 --- a/polyglot-debug/src/main/java/org/graalvm/demos/PolyglotDebug.java +++ b/polyglot-debug/src/main/java/org/graalvm/demos/PolyglotDebug.java @@ -44,6 +44,7 @@ import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; + import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Source; import org.graalvm.polyglot.Value; From bdc899e7c6ca675c83fdeb4c11f9c34f8b526d42 Mon Sep 17 00:00:00 2001 From: Olya Gupalo Date: Fri, 15 Dec 2023 11:37:08 +0100 Subject: [PATCH 2/3] Text update --- polyglot-debug/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyglot-debug/README.MD b/polyglot-debug/README.MD index b6d02ca9b..219ba2fed 100644 --- a/polyglot-debug/README.MD +++ b/polyglot-debug/README.MD @@ -6,7 +6,7 @@ This sample code helps to demonstrate simplicity of debugging and developing Gra 1. Install VS Code and launch it. 2. Then go to VS Code Extensions activity panel and search for _GraalVM Extension Pack_, install it. The GraalVM Extension Pack will install all required extensions. -2. Open Visual Studio Code, navigate to Extensions activity panel in the left-hand side Activity Bar. Search for “GraalVM” in the search field. Find [GraalVM Tools for Java](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm), press Install. Reload will be required. +2. Open Visual Studio Code, navigate to Extensions activity panel in the left-hand side Activity Bar. Search for “GraalVM” in the search field. Find [GraalVM Tools for Java](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm), press Install. Reload if required. 3. [Install GraalVM in VS Code](https://www.graalvm.org/latest/tools/vscode/graalvm-extension/#graalvm-installation-wizard): Navigate to Gr activity panel in VS Code and install the latest Oracle GraalVM version available from the list. 4. Confirm to set this as _Active GraalVM_ for VS Code. From 5dd83ce2f151937f0b8c46c4779f543bf9c131f2 Mon Sep 17 00:00:00 2001 From: Olya Gupalo Date: Fri, 15 Dec 2023 11:41:24 +0100 Subject: [PATCH 3/3] Add dependency on org.graalvm.polyglot.tools --- polyglot-debug/README.MD | 7 +++---- polyglot-debug/pom.xml | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/polyglot-debug/README.MD b/polyglot-debug/README.MD index 219ba2fed..3a648464e 100644 --- a/polyglot-debug/README.MD +++ b/polyglot-debug/README.MD @@ -32,13 +32,12 @@ This sample code helps to demonstrate simplicity of debugging and developing Gra ## Debug the Application -Working with a polyglot project in VS Code is simple just open this sample. -It will be working out of the box with VS Code GraalVM extensions. +Debugging a polyglot application should work out of the box in VS Code with the GraalVM extension. -1. Place breakpoints either in Java or JavaScript code. +1. Place breakpoints in _PolyglotDebug.java_. 2. To debug the project, go to __Run and Debug__ activity or simply press F5. 3. Choose **Launch Java 8+** as this is the Polyglot debugger provided by the GraalVM extension. -That is, the sample is running under debugger on GraalVM. +That is, the sample is running using the GraalVM debugger. diff --git a/polyglot-debug/pom.xml b/polyglot-debug/pom.xml index d45f12f4c..cf28f2343 100755 --- a/polyglot-debug/pom.xml +++ b/polyglot-debug/pom.xml @@ -104,6 +104,12 @@ ${graalvm.version} pom + + org.graalvm.polyglot + tools + ${graalvm.version} + pom +