Skip to content

Commit

Permalink
🦄 refactor: Move JavetReflectionObjectFactory to JavetBuddy
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Sep 30, 2024
1 parent 7e5ba66 commit 2e3470a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 334 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ object Config {
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
const val JACKSON_DATABIND = "com.fasterxml.jackson.core:jackson-databind:${Versions.JACKSON_DATABIND}"

// https://mvnrepository.com/artifact/com.caoccao.javet.buddy/javet-buddy
const val JAVET_BUDDY = "com.caoccao.javet.buddy:javet-buddy:${Versions.JAVET_BUDDY}"

// https://mvnrepository.com/artifact/org.eclipse.jetty.websocket/javax-websocket-server-impl
const val JETTY_JAVAX_WEBSOCKET_SERVER_IMPL =
"org.eclipse.jetty.websocket:javax-websocket-server-impl:${Versions.JETTY_WEBSOCKET}"
Expand All @@ -73,6 +76,7 @@ object Config {
const val JACKSON_DATABIND = "2.16.0"
const val JAVA_VERSION = "1.8"
const val JAVET = "3.1.8"
const val JAVET_BUDDY = "0.1.0"
const val JETTY_WEBSOCKET = "9.4.53.v20231009"
const val JUNIT = "5.10.1"
}
Expand Down Expand Up @@ -103,10 +107,12 @@ java {
dependencies {
testImplementation(Config.Projects.BYTE_BUDDY)
testImplementation(Config.Projects.JACKSON_DATABIND)
testImplementation(Config.Projects.JAVET_BUDDY)
testImplementation(Config.Projects.JETTY_JAVAX_WEBSOCKET_SERVER_IMPL)
testImplementation(Config.Projects.JETTY_WEBSOCKET_SERVER)
testImplementation(Config.Projects.JUNIT_JUPITER_API)
testImplementation(Config.Projects.JUNIT_JUPITER_PARAMS)
// testImplementation(files("../JavetBuddy/build/libs/javet-buddy-${Config.Versions.JAVET_BUDDY}.jar"))
testRuntimeOnly(Config.Projects.JUNIT_JUPITER_ENGINE)
}

Expand Down
29 changes: 4 additions & 25 deletions docs/reference/converters/proxy_converter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,30 +352,9 @@ Dynamic: Anonymous Object for Class

This feature is similar to the dynamic anonymous object for interface, but it allows implementing all methods exposed by a non-final Java class.

1. Add ``ByteBuddy`` to the dependency. You may skip this step if your project has already referenced ``ByteBuddy``.
1. Add ``ByteBuddy`` and ``JavetBuddy`` to the dependency. Please refer to `JavetBuddy <https://github.com/caoccao/JavetBuddy>`_ for detail.

.. code-block:: xml
<!-- Maven -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.10</version>
</dependency>
.. code-block:: kotlin
// Gradle Kotlin DSL
implementation("net.bytebuddy:byte-buddy:1.14.10")
.. code-block:: groovy
// Gradle Groovy DSL
implementation 'net.bytebuddy:byte-buddy:1.14.10'
2. Copy :extsource3:`JavetReflectionObjectFactory.java <../../../src/test/java/com/caoccao/javet/interop/proxy/JavetReflectionObjectFactory.java>` to your project. As Javet doesn't reference ``ByteBuddy`` directly, ``JavetReflectionObjectFactory`` has to stay at the test project.

3. Define a simple class ``DynamicClass`` for adding two integers.
2. Define a simple class ``DynamicClass`` for adding two integers.

.. code-block:: java
Expand All @@ -385,7 +364,7 @@ This feature is similar to the dynamic anonymous object for interface, but it al
}
}
4. Create an instance of a class which takes an instance of the ``DynamicClass``.
3. Create an instance of a class which takes an instance of the ``DynamicClass``.

.. code-block:: java
Expand All @@ -397,7 +376,7 @@ This feature is similar to the dynamic anonymous object for interface, but it al
}
};
5. Inject the implementation from JavaScript. Please note that dynamic object support is disabled by default and ``JavetReflectionObjectFactory`` needs to be set to the converter config for ``JavetProxyConverter`` to enable this feature.
4. Inject the implementation from JavaScript. Please note that dynamic object support is disabled by default and ``JavetReflectionObjectFactory`` needs to be set to the converter config for ``JavetProxyConverter`` to enable this feature.

.. code-block:: java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.caoccao.javet.interception.jvm;

import com.caoccao.javet.BaseTestJavetRuntime;
import com.caoccao.javet.buddy.interop.proxy.JavetReflectionObjectFactory;
import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.interop.converters.JavetProxyConverter;
import com.caoccao.javet.interop.proxy.JavetReflectionObjectFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.caoccao.javet.BaseTestJavetRuntime;
import com.caoccao.javet.annotations.*;
import com.caoccao.javet.buddy.interop.proxy.JavetReflectionObjectFactory;
import com.caoccao.javet.enums.JavetErrorType;
import com.caoccao.javet.enums.V8ConversionMode;
import com.caoccao.javet.enums.V8ProxyMode;
Expand All @@ -31,7 +32,6 @@
import com.caoccao.javet.interfaces.IJavetUniFunction;
import com.caoccao.javet.interop.V8Runtime;
import com.caoccao.javet.interop.proxy.IJavetDirectProxyHandler;
import com.caoccao.javet.interop.proxy.JavetReflectionObjectFactory;
import com.caoccao.javet.mock.MockCallbackReceiver;
import com.caoccao.javet.mock.MockDirectProxyFunctionHandler;
import com.caoccao.javet.mock.MockDirectProxyListHandler;
Expand Down
Loading

0 comments on commit 2e3470a

Please sign in to comment.