Skip to content

Commit

Permalink
Javenode v0.3.0 (#4)
Browse files Browse the repository at this point in the history
* Upgraded Javet to v3.0.2
* Removed all reflection calls to improve performance
  • Loading branch information
caoccao authored Nov 26, 2023
1 parent de81c3f commit 8640367
Show file tree
Hide file tree
Showing 93 changed files with 1,976 additions and 1,093 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/linux_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ jobs:
java-version: 8

- name: Build the artifact
run: gradle build test
run: gradle build generatePomFileForGeneratePomPublication

- name: Upload the artifact
uses: actions/upload-artifact@v3
with:
name: javenode
path: build/libs/javenode*.jar
path: |
build/libs/*.jar
build/libs/*.pom
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javenode</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

.. code-block:: kotlin
implementation("com.caoccao.javet:javenode:0.2.0")
implementation("com.caoccao.javet:javenode:0.3.0")
Gradle Groovy DSL
^^^^^^^^^^^^^^^^^

.. code-block:: groovy
implementation 'com.caoccao.javet:javenode:0.2.0'
implementation 'com.caoccao.javet:javenode:0.3.0'
Hello Javenode (Static Import)
------------------------------
Expand All @@ -78,7 +78,7 @@ Hello Javenode (Static Import)
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime();
JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
eventLoop.loadStaticModules(JNModuleType.CONSOLE, JNModuleType.TIMERS);
eventLoop.loadStaticModules(JNModuleType.Console, JNModuleType.Timers);
v8Runtime.getExecutor("const a = [];\n" +
"setTimeout(() => a.push('Hello Javenode'), 10);").executeVoid();
eventLoop.await();
Expand All @@ -92,8 +92,8 @@ Hello Javenode (Dynamic Import)
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime();
JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
eventLoop.loadStaticModules(JNModuleType.CONSOLE);
eventLoop.registerDynamicModules(JNModuleType.TIMERS_PROMISES);
eventLoop.loadStaticModules(JNModuleType.Console);
eventLoop.registerDynamicModules(JNModuleType.TimersPromises);
v8Runtime.getExecutor(
"import { setTimeout } from 'timers/promises';\n" +
"const a = [];\n" +
Expand Down
113 changes: 102 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,83 @@
import org.gradle.internal.os.OperatingSystem

object Config {
const val GROUP_ID = "com.caoccao.javet"
const val NAME = "Javenode"
const val VERSION = Versions.JAVENODE
const val URL = "https://github.com/caoccao/Javenode"

object Pom {
const val ARTIFACT_ID = "javenode"
const val DESCRIPTION =
"Javenode is Java + V8 + Node.js. It is a Node.js simulator with Java in V8."

object Developer {
const val ID = "caoccao"
const val EMAIL = "[email protected]"
const val NAME = "Sam Cao"
const val ORGANIZATION = "caoccao.com"
const val ORGANIZATION_URL = "https://www.caoccao.com"
}

object License {
const val NAME = "APACHE LICENSE, VERSION 2.0"
const val URL = "https://github.com/caoccao/Javenode/blob/main/LICENSE"
}

object Scm {
const val CONNECTION = "scm:git:git://github.com/Javenode.git"
const val DEVELOPER_CONNECTION = "scm:git:ssh://github.com/Javenode.git"
}
}

object Projects {
const val JAVET = "com.caoccao.javet:javet:${Versions.JAVET}"
const val JAVET_LINUX_ARM64 = "com.caoccao.javet:javet-linux-arm64:${Versions.JAVET}"
const val JAVET_MACOS = "com.caoccao.javet:javet-macos:${Versions.JAVET}"
const val JUNIT_JUPITER_API = "org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT_JUPITER}"
const val JUNIT_JUPITER_ENGINE = "org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT_JUPITER}"

// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
const val JUNIT_JUPITER_API = "org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT}"

// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
const val JUNIT_JUPITER_ENGINE = "org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT}"

// https://mvnrepository.com/artifact/io.vertx/vertx-core
const val VERTX = "io.vertx:vertx-core:${Versions.VERTX}"
}

object Versions {
const val JAVET = "3.0.0"
const val JUNIT_JUPITER = "5.10.0"
const val VERTX = "4.1.3"
const val JAVA_VERSION = "1.8"
const val JAVET = "3.0.2"
const val JAVENODE = "0.3.0"
const val JUNIT = "5.10.1"
const val VERTX = "4.4.6"
}
}

plugins {
java
`java-library`
`maven-publish`
}

repositories {
mavenCentral()
}

group = "com.caoccao.javet"
version = "0.2.0"

group = Config.GROUP_ID
version = Config.VERSION

repositories {
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
withJavadocJar()
}

dependencies {
val os = OperatingSystem.current()
val cpuArch = System.getProperty("os.arch")
Expand Down Expand Up @@ -96,7 +140,54 @@ tasks.withType<Javadoc> {
options.encoding = "UTF-8"
}

java {
withSourcesJar()
withJavadocJar()
publishing {
publications {
create<MavenPublication>("generatePom") {
from(components["java"])
pom {
artifactId = Config.Pom.ARTIFACT_ID
description.set(Config.Pom.DESCRIPTION)
groupId = Config.GROUP_ID
name.set(Config.NAME)
url.set(Config.URL)
version = Config.VERSION
licenses {
license {
name.set(Config.Pom.License.NAME)
url.set(Config.Pom.License.URL)
}
}
developers {
developer {
id.set(Config.Pom.Developer.ID)
email.set(Config.Pom.Developer.EMAIL)
name.set(Config.Pom.Developer.NAME)
organization.set(Config.Pom.Developer.ORGANIZATION)
organizationUrl.set(Config.Pom.Developer.ORGANIZATION_URL)
}
}
scm {
connection.set(Config.Pom.Scm.CONNECTION)
developerConnection.set(Config.Pom.Scm.DEVELOPER_CONNECTION)
tag.set(Config.Versions.JAVENODE)
url.set(Config.URL)
}
properties.set(
mapOf(
"maven.compiler.source" to Config.Versions.JAVA_VERSION,
"maven.compiler.target" to Config.Versions.JAVA_VERSION,
)
)
}
}
}
}

tasks {
withType(Test::class.java) {
useJUnitPlatform()
}
withType<GenerateMavenPom> {
destination = file("$buildDir/libs/${Config.Pom.ARTIFACT_ID}-${Config.VERSION}.pom")
}
}
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DOCUMENTATION_OPTIONS = {
VERSION: '0.2.0',
VERSION: '0.3.0',
LANGUAGE: 'en, zh-CN',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Sam Cao'

# The full version, including alpha/beta/rc tags
release = '0.2.0'
release = '0.3.0'


# -- General configuration ---------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="#" /><link rel="search" title="Search" href="search.html" />

<link rel="shortcut icon" href="_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 --><title>Index - Javenode 0.2.0 documentation</title>
<link rel="shortcut icon" href="_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 --><title>Index - Javenode 0.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/tabs.css?v=4c969af8" />
Expand Down Expand Up @@ -122,7 +122,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">Javenode 0.2.0 documentation</div></a>
<a href="index.html"><div class="brand">Javenode 0.3.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand All @@ -148,7 +148,7 @@
<img class="sidebar-logo" src="_static/logo.png" alt="Logo"/>
</div>

<span class="sidebar-brand-text">Javenode 0.2.0 documentation</span>
<span class="sidebar-brand-text">Javenode 0.3.0 documentation</span>

</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
Expand Down Expand Up @@ -248,7 +248,7 @@ <h1 id="index">Index</h1>

</aside>
</div>
</div><script src="_static/documentation_options.js?v=184a5140"></script>
</div><script src="_static/documentation_options.js?v=3419d779"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
Expand Down
20 changes: 10 additions & 10 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Tutorial" href="tutorial/index.html" />

<link rel="shortcut icon" href="_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 -->
<title>Javenode 0.2.0 documentation</title>
<title>Javenode 0.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/tabs.css?v=4c969af8" />
Expand Down Expand Up @@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="#"><div class="brand">Javenode 0.2.0 documentation</div></a>
<a href="#"><div class="brand">Javenode 0.3.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand All @@ -150,7 +150,7 @@
<img class="sidebar-logo" src="_static/logo.png" alt="Logo"/>
</div>

<span class="sidebar-brand-text">Javenode 0.2.0 documentation</span>
<span class="sidebar-brand-text">Javenode 0.3.0 documentation</span>

</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
Expand Down Expand Up @@ -268,20 +268,20 @@ <h3>Maven<a class="headerlink" href="#maven" title="Link to this heading">#</a><
<div class="highlight-xml notranslate"><div class="highlight"><pre><span></span><span class="nt">&lt;dependency&gt;</span>
<span class="w"> </span><span class="nt">&lt;groupId&gt;</span>com.caoccao.javet<span class="nt">&lt;/groupId&gt;</span>
<span class="w"> </span><span class="nt">&lt;artifactId&gt;</span>javenode<span class="nt">&lt;/artifactId&gt;</span>
<span class="w"> </span><span class="nt">&lt;version&gt;</span>0.2.0<span class="nt">&lt;/version&gt;</span>
<span class="w"> </span><span class="nt">&lt;version&gt;</span>0.3.0<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
</pre></div>
</div>
</section>
<section id="gradle-kotlin-dsl">
<h3>Gradle Kotlin DSL<a class="headerlink" href="#gradle-kotlin-dsl" title="Link to this heading">#</a></h3>
<div class="highlight-kotlin notranslate"><div class="highlight"><pre><span></span><span class="n">implementation</span><span class="p">(</span><span class="s">&quot;com.caoccao.javet:javenode:0.2.0&quot;</span><span class="p">)</span>
<div class="highlight-kotlin notranslate"><div class="highlight"><pre><span></span><span class="n">implementation</span><span class="p">(</span><span class="s">&quot;com.caoccao.javet:javenode:0.3.0&quot;</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="gradle-groovy-dsl">
<h3>Gradle Groovy DSL<a class="headerlink" href="#gradle-groovy-dsl" title="Link to this heading">#</a></h3>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="n">implementation</span><span class="w"> </span><span class="s1">&#39;com.caoccao.javet:javenode:0.2.0&#39;</span>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="n">implementation</span><span class="w"> </span><span class="s1">&#39;com.caoccao.javet:javenode:0.3.0&#39;</span>
</pre></div>
</div>
</section>
Expand All @@ -290,7 +290,7 @@ <h3>Gradle Groovy DSL<a class="headerlink" href="#gradle-groovy-dsl" title="Link
<h2>Hello Javenode (Static Import)<a class="headerlink" href="#hello-javenode-static-import" title="Link to this heading">#</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">V8Runtime</span><span class="w"> </span><span class="n">v8Runtime</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">V8Host</span><span class="p">.</span><span class="na">getV8Instance</span><span class="p">().</span><span class="na">createV8Runtime</span><span class="p">();</span>
<span class="w"> </span><span class="n">JNEventLoop</span><span class="w"> </span><span class="n">eventLoop</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">JNEventLoop</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">loadStaticModules</span><span class="p">(</span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">CONSOLE</span><span class="p">,</span><span class="w"> </span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">TIMERS</span><span class="p">);</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">loadStaticModules</span><span class="p">(</span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">Console</span><span class="p">,</span><span class="w"> </span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">Timers</span><span class="p">);</span>
<span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;const a = [];\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w"> </span><span class="s">&quot;setTimeout(() =&gt; a.push(&#39;Hello Javenode&#39;), 10);&quot;</span><span class="p">).</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">await</span><span class="p">();</span>
Expand All @@ -303,8 +303,8 @@ <h2>Hello Javenode (Static Import)<a class="headerlink" href="#hello-javenode-st
<h2>Hello Javenode (Dynamic Import)<a class="headerlink" href="#hello-javenode-dynamic-import" title="Link to this heading">#</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">V8Runtime</span><span class="w"> </span><span class="n">v8Runtime</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">V8Host</span><span class="p">.</span><span class="na">getV8Instance</span><span class="p">().</span><span class="na">createV8Runtime</span><span class="p">();</span>
<span class="w"> </span><span class="n">JNEventLoop</span><span class="w"> </span><span class="n">eventLoop</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">JNEventLoop</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">loadStaticModules</span><span class="p">(</span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">CONSOLE</span><span class="p">);</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">registerDynamicModules</span><span class="p">(</span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">TIMERS_PROMISES</span><span class="p">);</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">loadStaticModules</span><span class="p">(</span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">Console</span><span class="p">);</span>
<span class="w"> </span><span class="n">eventLoop</span><span class="p">.</span><span class="na">registerDynamicModules</span><span class="p">(</span><span class="n">JNModuleType</span><span class="p">.</span><span class="na">TimersPromises</span><span class="p">);</span>
<span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span>
<span class="w"> </span><span class="s">&quot;import { setTimeout } from &#39;timers/promises&#39;;\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w"> </span><span class="s">&quot;const a = [];\n&quot;</span><span class="w"> </span><span class="o">+</span>
Expand Down Expand Up @@ -381,7 +381,7 @@ <h1>Documents<a class="headerlink" href="#documents" title="Link to this heading

</aside>
</div>
</div><script src="_static/documentation_options.js?v=184a5140"></script>
</div><script src="_static/documentation_options.js?v=3419d779"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
Expand Down
Loading

0 comments on commit 8640367

Please sign in to comment.