From 1c04d74f98a8947abe33e589d921360441db2e4d Mon Sep 17 00:00:00 2001 From: Kamil Krzywanski Date: Sun, 2 Nov 2025 21:18:45 +0100 Subject: [PATCH] Refactor structure of project and bump plugins --- hotswap-agent-core/pom.xml | 22 ------------ .../java/org/hotswap/agent/HotswapAgent.java | 2 +- .../util/classloader/ClassLoaderHelper.java | 4 +-- .../agent/logging/AgentLoggerHandlerTest.java | 2 +- hotswap-agent-parent/pom.xml | 32 ++++++++++------- .../pom.xml | 8 ++--- .../hotswap-agent-deltaspike-plugin/pom.xml | 14 ++++---- plugin/hotswap-agent-mybatis-plugin/pom.xml | 19 ++++++++-- .../owb_jakarta/OwbJakartaPluginTest.java | 1 - plugin/hotswap-agent-owb-plugin/pom.xml | 2 +- .../agent/plugin/owb/OwbPluginTest.java | 1 - plugin/hotswap-agent-proxy-plugin/pom.xml | 35 +++++++++++++++++-- .../agent/plugin/proxy/TestClassAdapter.java | 8 ++--- .../methods/AddEnhancerMethodProxyTest.java | 17 ++++++--- .../test/methods/AddMethodProxyTest.java | 16 ++++++--- .../hotswap-agent-spring-boot-plugin/pom.xml | 4 +-- plugin/hotswap-agent-spring-plugin/pom.xml | 15 +------- 17 files changed, 115 insertions(+), 87 deletions(-) diff --git a/hotswap-agent-core/pom.xml b/hotswap-agent-core/pom.xml index 0f17ebb9b..5fa942ff9 100644 --- a/hotswap-agent-core/pom.xml +++ b/hotswap-agent-core/pom.xml @@ -16,28 +16,6 @@ default-tools - - !mac - - (,1.11) - - - - com.sun - tools - ${java.version} - system - true - ${java.home}/../lib/tools.jar - - - - - mac-tools - - - mac - (,1.11) diff --git a/hotswap-agent-core/src/main/java/org/hotswap/agent/HotswapAgent.java b/hotswap-agent-core/src/main/java/org/hotswap/agent/HotswapAgent.java index 984bbe831..bcd8e2a19 100644 --- a/hotswap-agent-core/src/main/java/org/hotswap/agent/HotswapAgent.java +++ b/hotswap-agent-core/src/main/java/org/hotswap/agent/HotswapAgent.java @@ -63,7 +63,7 @@ public static void agentmain(String args, Instrumentation inst) { public static void premain(String args, Instrumentation inst) { parseArgs(args); - LOGGER.info("Loading Hotswap agent {{}} - unlimited runtime class redefinition.", Version.version()); + LOGGER.info("Loading Hotswap agent {} - unlimited runtime class redefinition.", Version.version()); fixJboss7Modules(); PluginManager.getInstance().init(inst); LOGGER.debug("Hotswap agent initialized."); diff --git a/hotswap-agent-core/src/main/java/org/hotswap/agent/util/classloader/ClassLoaderHelper.java b/hotswap-agent-core/src/main/java/org/hotswap/agent/util/classloader/ClassLoaderHelper.java index ab3850210..51a42f031 100644 --- a/hotswap-agent-core/src/main/java/org/hotswap/agent/util/classloader/ClassLoaderHelper.java +++ b/hotswap-agent-core/src/main/java/org/hotswap/agent/util/classloader/ClassLoaderHelper.java @@ -81,9 +81,9 @@ public static boolean isClassLoderStarted(ClassLoader classLoader) { boolean isStarted; if ("org.apache.catalina.loader.WebappClassLoaderBase".equals(clazz.getSuperclass().getName())) { clazz = clazz.getSuperclass(); - isStarted = "STARTED".equals((String) ReflectionHelper.invoke(classLoader, clazz, "getStateName", new Class[] {}, null)); + isStarted = "STARTED".equals((String) ReflectionHelper.invoke(classLoader, clazz, "getStateName", new Class[] {})); } else { - isStarted = (boolean) ReflectionHelper.invoke(classLoader, clazz, "isStarted", new Class[] {}, null); + isStarted = (boolean) ReflectionHelper.invoke(classLoader, clazz, "isStarted", new Class[] {}); } return isStarted; } catch (Exception e) { diff --git a/hotswap-agent-core/src/test/java/org/hotswap/agent/logging/AgentLoggerHandlerTest.java b/hotswap-agent-core/src/test/java/org/hotswap/agent/logging/AgentLoggerHandlerTest.java index d93d41163..bec124f1e 100644 --- a/hotswap-agent-core/src/test/java/org/hotswap/agent/logging/AgentLoggerHandlerTest.java +++ b/hotswap-agent-core/src/test/java/org/hotswap/agent/logging/AgentLoggerHandlerTest.java @@ -18,7 +18,7 @@ */ package org.hotswap.agent.logging; -import org.hamcrest.text.StringContains; +import org.hamcrest.core.StringContains; import org.hotswap.agent.config.PluginManager; import org.jmock.Expectations; import org.jmock.Mockery; diff --git a/hotswap-agent-parent/pom.xml b/hotswap-agent-parent/pom.xml index bd05a8bf6..9e9ffbbc8 100644 --- a/hotswap-agent-parent/pom.xml +++ b/hotswap-agent-parent/pom.xml @@ -49,7 +49,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.14.1 1.8 1.8 @@ -58,24 +58,24 @@ org.apache.maven.plugins maven-dependency-plugin - 2.8 + 3.9.0 org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.1 org.apache.maven.plugins maven-surefire-plugin - 2.15 + 3.5.4 -XX:+AllowEnhancedClassRedefinition maven-failsafe-plugin - 2.17 + 3.5.4 @@ -160,7 +160,7 @@ false -javaagent:${org.hotswapagent:hotswap-agent-core:jar} -Xbootclasspath/a:"${org.hotswapagent:hotswap-agent-core:jar}:${project.build.OutputDirectory}" --> - ${dcevm.test.arguments} -javaagent:${org.hotswapagent:hotswap-agent-core:jar} + ${dcevm.test.arguments} -javaagent:${project.basedir}/../../hotswap-agent-core/target/hotswap-agent-core-${project.version}.jar ${java.home}/bin/java @@ -168,7 +168,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.2.2 + 1.7.3 minimum @@ -276,7 +276,7 @@ default-tools - 11 + (,11) @@ -301,22 +301,27 @@ junit junit - 4.13 + 4.13.2 test org.jmock jmock-junit4 - 2.6.0 + 2.13.1 test org.jmock jmock-legacy - 2.6.0 + 2.13.1 + test + + + org.ow2.asm + asm + 9.9 test - @@ -324,6 +329,9 @@ 2.0.2 dcevm -XX:+AllowEnhancedClassRedefinition -XX:HotswapAgent=external + --add-exports java.base/sun.security.action=ALL-UNNAMED + --add-exports java.base/sun.security.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED UTF-8 UTF-8 diff --git a/plugin/hotswap-agent-deltaspike-jakarta-plugin/pom.xml b/plugin/hotswap-agent-deltaspike-jakarta-plugin/pom.xml index 66430a43b..33ee85c91 100644 --- a/plugin/hotswap-agent-deltaspike-jakarta-plugin/pom.xml +++ b/plugin/hotswap-agent-deltaspike-jakarta-plugin/pom.xml @@ -187,9 +187,9 @@ org.apache.maven.plugins maven-surefire-plugin - + ${cdicontainer.version} - + @@ -233,9 +233,9 @@ org.apache.maven.plugins maven-surefire-plugin - + ${cdicontainer.version} - + diff --git a/plugin/hotswap-agent-deltaspike-plugin/pom.xml b/plugin/hotswap-agent-deltaspike-plugin/pom.xml index 5c216fe0c..c00ecd998 100644 --- a/plugin/hotswap-agent-deltaspike-plugin/pom.xml +++ b/plugin/hotswap-agent-deltaspike-plugin/pom.xml @@ -232,9 +232,9 @@ org.apache.maven.plugins maven-surefire-plugin - + ${cdicontainer.version} - + @@ -250,7 +250,7 @@ - 2.0.13 + 2.0.28 owb-${owb.version} @@ -318,9 +318,9 @@ org.apache.maven.plugins maven-surefire-plugin - + ${cdicontainer.version} - + @@ -364,9 +364,9 @@ org.apache.maven.plugins maven-surefire-plugin - + ${cdicontainer.version} - + diff --git a/plugin/hotswap-agent-mybatis-plugin/pom.xml b/plugin/hotswap-agent-mybatis-plugin/pom.xml index cbec88399..df05644fe 100644 --- a/plugin/hotswap-agent-mybatis-plugin/pom.xml +++ b/plugin/hotswap-agent-mybatis-plugin/pom.xml @@ -25,7 +25,11 @@ hotswap-agent-core ${project.version} - + + org.springframework + spring-tx + ${org.springframework.version} + org.mybatis mybatis @@ -108,5 +112,16 @@ - + + + + src/main/resources + + + + + src/test/resources + + + diff --git a/plugin/hotswap-agent-owb-jakarta-plugin/src/test/java/org/hotswap/agent/plugin/owb_jakarta/OwbJakartaPluginTest.java b/plugin/hotswap-agent-owb-jakarta-plugin/src/test/java/org/hotswap/agent/plugin/owb_jakarta/OwbJakartaPluginTest.java index 187240c90..d2536d070 100644 --- a/plugin/hotswap-agent-owb-jakarta-plugin/src/test/java/org/hotswap/agent/plugin/owb_jakarta/OwbJakartaPluginTest.java +++ b/plugin/hotswap-agent-owb-jakarta-plugin/src/test/java/org/hotswap/agent/plugin/owb_jakarta/OwbJakartaPluginTest.java @@ -208,7 +208,6 @@ public void hotswapPrototypeTestNotFailWhenHoldingInstanceBecauseSingletonInject @Test public void newBeanClassIsManagedBeanReRunTestOnlyAfterMvnClean() throws Exception { try { - ClassFile.MAJOR_VERSION = ClassFile.JAVA_11; // hack, ASM9 does not support java17 (owb 2.0.26) OwbJakartaPlugin.isTestEnvironment = true; Class clazz = getClass(); String path = clazz.getResource(clazz.getSimpleName() + ".class") diff --git a/plugin/hotswap-agent-owb-plugin/pom.xml b/plugin/hotswap-agent-owb-plugin/pom.xml index 6bf1583f4..75be461f2 100644 --- a/plugin/hotswap-agent-owb-plugin/pom.xml +++ b/plugin/hotswap-agent-owb-plugin/pom.xml @@ -11,7 +11,7 @@ hotswap-agent-owb-plugin - 2.0.13 + 2.0.28 diff --git a/plugin/hotswap-agent-owb-plugin/src/test/java/org/hotswap/agent/plugin/owb/OwbPluginTest.java b/plugin/hotswap-agent-owb-plugin/src/test/java/org/hotswap/agent/plugin/owb/OwbPluginTest.java index 03aebaab1..e04981631 100644 --- a/plugin/hotswap-agent-owb-plugin/src/test/java/org/hotswap/agent/plugin/owb/OwbPluginTest.java +++ b/plugin/hotswap-agent-owb-plugin/src/test/java/org/hotswap/agent/plugin/owb/OwbPluginTest.java @@ -206,7 +206,6 @@ public void hotswapPrototypeTestNotFailWhenHoldingInstanceBecauseSingletonInject @Test public void newBeanClassIsManagedBeanReRunTestOnlyAfterMvnClean() throws Exception { try { - ClassFile.MAJOR_VERSION = ClassFile.JAVA_11; // hack, ASM9 does not support java17 (owb 2.0.26) OwbPlugin.isTestEnvironment = true; Class clazz = getClass(); String path = clazz.getResource(clazz.getSimpleName() + ".class") diff --git a/plugin/hotswap-agent-proxy-plugin/pom.xml b/plugin/hotswap-agent-proxy-plugin/pom.xml index aada1f128..19290a28e 100644 --- a/plugin/hotswap-agent-proxy-plugin/pom.xml +++ b/plugin/hotswap-agent-proxy-plugin/pom.xml @@ -13,7 +13,7 @@ hotswap-agent-proxy-plugin - 5.3.30 + 5.3.39 @@ -41,13 +41,13 @@ org.ow2.asm asm - 7.0 + 9.9 test org.ow2.asm asm-commons - 7.0 + 9.9 test @@ -64,5 +64,34 @@ + + jdk9+ + + [1.9,) + + + + + maven-surefire-plugin + + 1 + false + + -XX:+AllowEnhancedClassRedefinition + -XX:HotswapAgent=external + -Xlog:redefine+class*=info + --add-exports java.base/sun.security.action=ALL-UNNAMED + --add-exports java.base/sun.security.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED + -Dblank + -javaagent:${project.basedir}/../../hotswap-agent-core/target/hotswap-agent-core-${project.version}.jar + + + + + + + diff --git a/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/TestClassAdapter.java b/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/TestClassAdapter.java index 38f157ed4..7679505f7 100644 --- a/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/TestClassAdapter.java +++ b/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/TestClassAdapter.java @@ -32,10 +32,10 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; +import org.objectweb.asm.commons.AnnotationRemapper; import org.objectweb.asm.commons.ClassRemapper; +import org.objectweb.asm.commons.MethodRemapper; import org.objectweb.asm.commons.Remapper; -import org.objectweb.asm.commons.RemappingAnnotationAdapter; -import org.objectweb.asm.commons.RemappingMethodAdapter; /** * @author Ivan Dubrov @@ -89,7 +89,7 @@ public String getClassName() { protected MethodVisitor createRemappingMethodAdapter(int access, String newDesc, MethodVisitor mv) { - return new RemappingMethodAdapter(access, newDesc, mv, remapper) { + return new MethodRemapper(mv, remapper) { @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { @@ -115,7 +115,7 @@ public AnnotationVisitor visitAnnotation(final String desc, AnnotationVisitor av = super.visitAnnotation(remapper.mapDesc(desc), visible); return av == null ? null - : new RemappingAnnotationAdapter(av, remapper) { + : new AnnotationRemapper(av, remapper) { @Override public void visitEnum(String name, String enumDesc, String value) { diff --git a/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddEnhancerMethodProxyTest.java b/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddEnhancerMethodProxyTest.java index 5c32f66d9..cf623c82d 100644 --- a/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddEnhancerMethodProxyTest.java +++ b/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddEnhancerMethodProxyTest.java @@ -105,7 +105,7 @@ public void addMethodToInterfaceAndImplementation() __toVersion__Delayed(1); Method method = getMethod(a, "getValue2"); - assertEquals(2, method.invoke(a, null)); + assertEquals(2, method.invoke(a)); } public static class SerializableNoOp @@ -142,14 +142,14 @@ public void accessNewMethodOnProxy() throws IllegalAccessException, Method method = getMethod(a, "getValue2"); assertEquals("getValue2", method.getName()); assertEquals(1, cb.getInvocationCount()); - assertEquals(2, method.invoke(a, null)); + assertEquals(2, method.invoke(a)); assertEquals(2, cb.getInvocationCount()); __toVersion__Delayed(2); method = getMethod(a, "getValue3"); assertEquals("getValue3", method.getName()); assertEquals(2, cb.getInvocationCount()); - assertEquals(3, method.invoke(a, null)); + assertEquals(3, method.invoke(a)); assertEquals(3, cb.getInvocationCount()); } @@ -180,11 +180,18 @@ public void accessNewMethodOnProxyCreatedAfterSwap() Method method = getMethod(a, "getValue2"); assertEquals("getValue2", method.getName()); assertEquals(1, cb.getInvocationCount()); - assertEquals(2, method.invoke(a, null)); + assertEquals(2, method.invoke(a)); assertEquals(2, cb.getInvocationCount()); } private Method getMethod(Object a, String methodName) { + + try{ + return a.getClass().getMethod(methodName); + } catch (NoSuchMethodException e) { + // continue to old approach + } + Method[] declaredMethods = a.getClass().getMethods(); Method m = null; for (Method method : declaredMethods) { @@ -198,4 +205,4 @@ private Method getMethod(Object a, String methodName) { return m; } -} \ No newline at end of file +} diff --git a/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddMethodProxyTest.java b/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddMethodProxyTest.java index 7fb68c8fa..320634eb6 100644 --- a/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddMethodProxyTest.java +++ b/plugin/hotswap-agent-proxy-plugin/src/test/java/org/hotswap/agent/plugin/proxy/test/methods/AddMethodProxyTest.java @@ -138,7 +138,7 @@ public void addMethodToInterfaceAndImplementation() throws IllegalAccessExceptio __toVersion__Delayed_JavaProxy(1); Method method = getMethod(a, "getValue2"); - assertEquals(2, method.invoke(a, null)); + assertEquals(2, method.invoke(a)); } @Test @@ -162,24 +162,30 @@ public void accessNewMethodOnProxy() throws IllegalAccessException, IllegalArgum public void accessNewMethodOnProxyCreatedAfterSwap() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { assert __version__() == 0; - A a = (A) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { A.class }, new DummyHandler( + A a = (A) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { A.class }, new DummyHandler( new AImpl())); assertEquals(1, a.getValue1()); __toVersion__Delayed_JavaProxy(1); - a = (A) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { A.class }, new DummyHandler( + a = (A) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { A.class }, new DummyHandler( new AImpl())); Method method = getMethod(a, "getValue2"); assertEquals("getValue2", method.getName()); - assertEquals(2, method.invoke(a, null)); + assertEquals(2, method.invoke(a)); method = getMethod(a, "getValue33"); assertEquals("getValue33", method.getName()); assertEquals(2, method.invoke(a, new Object[] { new Object[] { new Object() } })); } private Method getMethod(Object a, String methodName) { + try { + return a.getClass().getMethod(methodName); + } catch (NoSuchMethodException e) { + // Ignore + } + Method[] declaredMethods = a.getClass().getDeclaredMethods(); Method m = null; for (Method method : declaredMethods) { @@ -192,4 +198,4 @@ private Method getMethod(Object a, String methodName) { return m; } -} \ No newline at end of file +} diff --git a/plugin/hotswap-agent-spring-boot-plugin/pom.xml b/plugin/hotswap-agent-spring-boot-plugin/pom.xml index b3675da89..3fdfc47d3 100644 --- a/plugin/hotswap-agent-spring-boot-plugin/pom.xml +++ b/plugin/hotswap-agent-spring-boot-plugin/pom.xml @@ -58,7 +58,7 @@ cglib cglib - 2.2 + 3.3.0 test @@ -70,4 +70,4 @@ - \ No newline at end of file + diff --git a/plugin/hotswap-agent-spring-plugin/pom.xml b/plugin/hotswap-agent-spring-plugin/pom.xml index 9e94e9358..5d4f1a451 100644 --- a/plugin/hotswap-agent-spring-plugin/pom.xml +++ b/plugin/hotswap-agent-spring-plugin/pom.xml @@ -141,17 +141,4 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - - - \ No newline at end of file +