Skip to content

Commit

Permalink
Make commons and graalvm js dependences optional for pdxu-io
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Aug 5, 2023
1 parent 9cc51b7 commit 0bdcda0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ jlink {
'org.kordamp.ikonli.materialdesign',
'jdk.zipfs',
'io.github.ititus.ddsiio',
'jdk.accessibility'
'jdk.accessibility',
'org.graalvm.js'
]
}

Expand Down
2 changes: 2 additions & 0 deletions pdxu-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ dependencies {
implementation project(':pdxu-io')
implementation project(':pdxu-model')

implementation 'org.graalvm.js:js:22.3.0'

implementation 'info.picocli:picocli:4.6.3'
annotationProcessor 'info.picocli:picocli-codegen:4.6.3'
testImplementation 'info.picocli:picocli:4.6.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
CommandLine.HelpCommand.class,
RenderCommand.class
},
header = "Runsthe Pdx-Unlimiter application."
header = "Runs the Pdx-Unlimiter application."
)
class MainCommand implements Runnable {

Expand Down
1 change: 1 addition & 0 deletions pdxu-app/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
requires javafx.media;
requires info.picocli;
requires com.sun.jna;
requires org.graalvm.js;
requires com.sun.jna.platform;
requires org.jnativehook;
requires jdk.localedata;
Expand Down
3 changes: 1 addition & 2 deletions pdxu-io/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ repositories {
apply from: "$rootDir/gradle/module_gen.gradle"

dependencies {
implementation 'org.graalvm.js:js:22.3.0'
compileOnly 'org.graalvm.js:js:22.3.0'
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
compileOnly files("$project.buildDir/generated-modules/commons-lang3-3.12.0.jar")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class NodeEvaluator {

private static final Context JAVASCRIPT_CONTEXT = Context.newBuilder("js").option("engine.WarnInterpreterOnly", "false").build();
private static Context JAVASCRIPT_CONTEXT;
private static final NumberFormat FORMATTER = new DecimalFormat("#0.0000000");

public static void evaluateArrayNode(ArrayNode arrayNode) {
Expand Down Expand Up @@ -39,6 +39,14 @@ public static void evaluateArrayNode(ArrayNode arrayNode, NodeEnvironment enviro
}

public static Node evaluateValueNode(ValueNode node, NodeEnvironment environment) {
if (ModuleLayer.boot().findModule("org.graalvm.js").isEmpty()) {
throw new UnsupportedOperationException("Node evaluation is only supported with module org.graalvm.js in module path");
}

if (JAVASCRIPT_CONTEXT == null) {
JAVASCRIPT_CONTEXT = Context.newBuilder("js").option("engine.WarnInterpreterOnly", "false").build();
}

var expression = node.getInlineMathExpression();
if (expression.isPresent()) {
var string = expression.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.crschnick.pdxu.io.parser;

import com.crschnick.pdxu.io.node.*;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;
import java.nio.charset.Charset;
Expand All @@ -11,6 +10,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.function.Predicate;

public final class TextFormatParser {
Expand Down Expand Up @@ -56,18 +56,23 @@ public static TextFormatParser stellaris() {

public static TextFormatParser ck2() {
return new TextFormatParser(
SystemUtils.IS_OS_MAC ? StandardCharsets.UTF_8 : Charset.forName("windows-1252"),
isMacOs() ? StandardCharsets.UTF_8 : Charset.forName("windows-1252"),
TaggedNode.NO_TAGS,
s -> false);
}

public static TextFormatParser vic2() {
return new TextFormatParser(
SystemUtils.IS_OS_MAC ? StandardCharsets.UTF_8 : Charset.forName("windows-1252"),
isMacOs() ? StandardCharsets.UTF_8 : Charset.forName("windows-1252"),
TaggedNode.NO_TAGS,
s -> false);
}

private static boolean isMacOs() {
String osName = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
return osName.contains("mac") || osName.contains("darwin");
}

private final Charset charset;
private final TaggedNode.TagType[] possibleTags;
private final Predicate<String> keyWithoutEquals;
Expand Down
3 changes: 1 addition & 2 deletions pdxu-io/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports com.crschnick.pdxu.io.savegame;
exports com.crschnick.pdxu.io.node;

requires org.apache.commons.lang;
requires org.graalvm.js;
requires static org.graalvm.js;
requires static lombok;
}

0 comments on commit 0bdcda0

Please sign in to comment.