Feat: add IntelliJ integration tests for native API

- Add test JVM sources (Loop, Target) and API tests
  (AddToBootstrap/SystemClassLoaderSearch, AddToClassLoader,
  GetClassByName, GetLoadedClasses)
- Add injection module (Injection jar) for classloader tests
- Add copy-bin.bat to refresh resources/ from build output
- Remove obsolete java-loop/java-system-load tests
- Ignore IDE dirs and resources/ build artifacts
This commit is contained in:
xiaozhou233 committed 2026-08-17 00:16:24 +08:00
1 parent 6afa44f90a
commit 6bf2d31798
21 files changed
+217 -97

No files matched your search

+34 -4
View File
@@ -1,5 +1,35 @@
*.class
### IntelliJ IDEA ###
.idea/
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
*.log
*.dll
*.exe
build/
### JuiceAgent ###
resources/
+4
View File
@@ -0,0 +1,4 @@
@ECHO OFF
cp ../build/bin/*.dll ./resources
cp ../build/bin/*.exe ./resources
Binary file not shown.
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+5
View File
@@ -0,0 +1,5 @@
public class Injection {
public static void test() {
System.out.println("Injection Invoked!");
}
}
+6
View File
@@ -0,0 +1,6 @@
public class Target {
public static void targetTest() {
System.out.println("Target test!");
System.out.println("Modified!");
}
}
-14
View File
@@ -1,14 +0,0 @@
@echo off
setlocal
cd /d "%~dp0"
if not exist build mkdir build
javac -d build loop.java
if errorlevel 1 (
echo [ERROR] Build failed.
exit /b 1
)
echo [OK] Build succeeded: build\loop.class
endlocal
-12
View File
@@ -1,12 +0,0 @@
public class loop {
public static void main(String[] args) {
while (true) {
try {
System.out.println("Hello, World!");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
-16
View File
@@ -1,16 +0,0 @@
@echo off
setlocal
cd /d "%~dp0"
if not exist build\loop.class (
echo [ERROR] Build output not found. Run build.bat first.
exit /b 1
)
java -cp build loop
if errorlevel 1 (
echo [ERROR] Run failed.
exit /b 1
)
endlocal
-16
View File
@@ -1,16 +0,0 @@
import java.io.File;
import java.io.IOException;
public class Loader {
public static void main(String[] args) {
System.load(new File("./libinject.dll").getAbsolutePath());
System.out.println("Loaded libinject.dll");
System.out.println("====================================");
System.load(new File("./libloader.dll").getAbsolutePath());
System.out.println("Loaded libloader.dll");
System.out.println("====================================");
System.load(new File("./libagent.dll").getAbsolutePath());
System.out.println("Loaded libagent.dll");
}
}
-23
View File
@@ -1,23 +0,0 @@
@echo off
setlocal
cd /d "%~dp0"
set "SRC=..\..\build\bin"
echo [INFO] Copying build artifacts from "%SRC%" ...
xcopy /Y "%SRC%\libagent.dll" .\ >nul
xcopy /Y "%SRC%\libinject.dll" .\ >nul
xcopy /Y "%SRC%\libloader.dll" .\ >nul
echo [OK] Artifacts copied.
if not exist build mkdir build
javac -d build Loader.java
if errorlevel 1 (
echo [ERROR] Build failed.
exit /b 1
)
echo [OK] Build succeeded: build\Loader.class
endlocal
-12
View File
@@ -1,12 +0,0 @@
@echo off
setlocal
cd /d "%~dp0"
java -cp build Loader
if errorlevel 1 (
echo [ERROR] Run failed.
exit /b 1
)
pause
endlocal
Binary file not shown.
@@ -0,0 +1,34 @@
import java.io.File;
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
public class AddToBootstrapClassLoaderSearch {
public static void main(String[] args) {
System.load(new File("resources/libagent.dll").getAbsolutePath());
JuiceAgent.init("");
System.out.println("========= Before =========");
invokeTest();
System.out.println("========= After =========");
JuiceAgent.addToBootstrapClassLoaderSearch(new File("Injection.jar").getAbsolutePath());
invokeTest();
System.out.println("========= Done =========");
}
public static void invokeTest() {
try {
Class<?> clazz = Class.forName("Injection");
ClassLoader loader = clazz.getClassLoader();
System.out.println("ClassLoader: " + (loader == null ? "BootstrapClassLoader" : loader));
clazz.getMethod("test").invoke(null);
} catch (ClassNotFoundException e) {
System.err.println("Injection class not found: " + e.getMessage());
} catch (ReflectiveOperationException e) {
System.err.println("Invoke failed: " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
+30
View File
@@ -0,0 +1,30 @@
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
public class AddToClassLoader {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
System.load(new File("resources/libagent.dll").getAbsolutePath());
JuiceAgent.init("");
ClassLoader cl = new ClassLoader(){};
invokeTest(cl);
JuiceAgent.addToClassLoader(new File("Injection.jar").getAbsolutePath(), cl);
invokeTest(cl);
}
public static void invokeTest(ClassLoader cl) {
try {
Class<?> clz = cl.loadClass("Injection");
System.out.println("ClassLoader: " + clz.getClassLoader().toString());
clz.getMethod("test").invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,34 @@
import java.io.File;
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
public class AddToSystemClassLoaderSearch {
public static void main(String[] args) {
System.load(new File("resources/libagent.dll").getAbsolutePath());
JuiceAgent.init("");
System.out.println("========= Before =========");
invokeTest();
System.out.println("========= After =========");
JuiceAgent.addToSystemClassLoaderSearch(new File("Injection.jar").getAbsolutePath());
invokeTest();
System.out.println("========= Done =========");
}
public static void invokeTest() {
try {
Class<?> clazz = Class.forName("Injection");
ClassLoader loader = clazz.getClassLoader();
System.out.println("ClassLoader: " + loader);
clazz.getMethod("test").invoke(null);
} catch (ClassNotFoundException e) {
System.err.println("Injection class not found: " + e.getMessage());
} catch (ReflectiveOperationException e) {
System.err.println("Invoke failed: " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
+17
View File
@@ -0,0 +1,17 @@
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import java.io.File;
import java.util.Arrays;
public class GetClassByName {
public static void main(String[] args) {
System.load(new File("resources/libagent.dll").getAbsolutePath());
JuiceAgent.init("");
Class<?> clazz = JuiceAgent.getClassByName("java.lang.String");
System.out.println(clazz);
System.out.println(clazz.getName());
System.out.println(Arrays.toString(clazz.getDeclaredMethods()));
}
}
+13
View File
@@ -0,0 +1,13 @@
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import java.io.File;
import java.util.Arrays;
public class GetLoadedClasses {
public static void main(String[] args) {
System.load(new File("resources/libagent.dll").getAbsolutePath());
JuiceAgent.init("");
System.out.println(Arrays.toString(JuiceAgent.getLoadedClasses()));
}
}
+12
View File
@@ -0,0 +1,12 @@
public class Loop {
public static void echo() {
System.out.println("Loop!");
}
public static void main(String[] args) throws InterruptedException {
while(true) {
echo();
Thread.sleep(1000);
}
}
}
+5
View File
@@ -0,0 +1,5 @@
public class Target {
public static void targetTest() {
System.out.println("Target test!");
}
}
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="JuiceAgent-API-1.4.1+build.1" level="project" />
</component>
</module>