From bb80c00fdf86cec8cbaabbb6015609bb3b163a47 Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Mon, 16 Sep 2024 08:02:07 +0100 Subject: [PATCH] api backwards compatibility --- .../pitest/coverage/execute/CoverageMinion.java | 6 +++++- .../environment/TransformationPlugin.java | 15 +++++++++++++-- .../mutationtest/execute/MutationTestMinion.java | 6 +++++- .../mocksupport/JavassistCoverageInterceptor.java | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pitest/src/main/java/org/pitest/coverage/execute/CoverageMinion.java b/pitest/src/main/java/org/pitest/coverage/execute/CoverageMinion.java index f86dd7177..b043e5318 100644 --- a/pitest/src/main/java/org/pitest/coverage/execute/CoverageMinion.java +++ b/pitest/src/main/java/org/pitest/coverage/execute/CoverageMinion.java @@ -34,6 +34,7 @@ import java.io.BufferedOutputStream; import java.io.IOException; +import java.lang.instrument.ClassFileTransformer; import java.net.Socket; import java.util.ArrayList; import java.util.Collections; @@ -123,7 +124,10 @@ public static void main(final String[] args) { private static void enableTransformations() { ClientPluginServices plugins = ClientPluginServices.makeForContextLoader(); for (TransformationPlugin each : plugins.findTransformations()) { - HotSwapAgent.addTransformer(each.makeCoverageTransformer()); + ClassFileTransformer transformer = each.makeCoverageTransformer(); + if (transformer != null) { + HotSwapAgent.addTransformer(transformer); + } } } diff --git a/pitest/src/main/java/org/pitest/mutationtest/environment/TransformationPlugin.java b/pitest/src/main/java/org/pitest/mutationtest/environment/TransformationPlugin.java index 0b172cbdd..9de0c0a1c 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/environment/TransformationPlugin.java +++ b/pitest/src/main/java/org/pitest/mutationtest/environment/TransformationPlugin.java @@ -5,7 +5,18 @@ import java.lang.instrument.ClassFileTransformer; public interface TransformationPlugin extends ClientClasspathPlugin { - ClassFileTransformer makeCoverageTransformer(); - ClassFileTransformer makeMutationTransformer(); + + @Deprecated + default ClassFileTransformer makeTransformer() { + return makeMutationTransformer(); + } + + default ClassFileTransformer makeCoverageTransformer() { + return null; + } + + default ClassFileTransformer makeMutationTransformer() { + return null; + } } diff --git a/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java b/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java index 80ea4189f..17908aa34 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java +++ b/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java @@ -37,6 +37,7 @@ import javax.management.NotificationListener; import javax.management.openmbean.CompositeData; import java.io.IOException; +import java.lang.instrument.ClassFileTransformer; import java.lang.management.MemoryNotificationInfo; import java.net.Socket; import java.util.Collection; @@ -169,7 +170,10 @@ private static List findTestsForTestClasses( private static void enableTransformations() { ClientPluginServices plugins = ClientPluginServices.makeForContextLoader(); for (TransformationPlugin each : plugins.findTransformations()) { - HotSwapAgent.addTransformer(each.makeMutationTransformer()); + ClassFileTransformer transformer = each.makeMutationTransformer(); + if (transformer != null) { + HotSwapAgent.addTransformer(transformer); + } } } diff --git a/pitest/src/main/java/org/pitest/mutationtest/mocksupport/JavassistCoverageInterceptor.java b/pitest/src/main/java/org/pitest/mutationtest/mocksupport/JavassistCoverageInterceptor.java index afb4accc2..6e2da7b27 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/mocksupport/JavassistCoverageInterceptor.java +++ b/pitest/src/main/java/org/pitest/mutationtest/mocksupport/JavassistCoverageInterceptor.java @@ -115,8 +115,12 @@ private static InputStream returnNormalBytes(final Object classPath, // so the best we can do is exclude pitest itself and some common classes. private static Predicate excluded() { return Prelude.or( + startsWith("org.objenesis."), + startsWith("net.bytebuddy."), startsWith("javassist."), startsWith("org.pitest."), + startsWith("com.groupcdg."), + startsWith("com.arcmutate."), startsWith("java."), startsWith("javax."), startsWith("com.sun."),