diff --git a/skippy-core/src/main/java/io/skippy/core/SkippyBuildApi.java b/skippy-core/src/main/java/io/skippy/core/SkippyBuildApi.java
index 5fe5109..03ab92f 100644
--- a/skippy-core/src/main/java/io/skippy/core/SkippyBuildApi.java
+++ b/skippy-core/src/main/java/io/skippy/core/SkippyBuildApi.java
@@ -152,4 +152,12 @@ private Class> toClass(ClassFile classFile) {
throw new RuntimeException(e);
}
}
+
+ public void beforeTest(Class> testClass) {
+ SkippyTestApi.INSTANCE.before(testClass, null);
+ }
+
+ public void afterTest(Class> testClass) {
+ SkippyTestApi.INSTANCE.after(testClass, null);
+ }
}
\ No newline at end of file
diff --git a/skippy-gradle/src/main/java/io/skippy/gradle/SkippyPlugin.java b/skippy-gradle/src/main/java/io/skippy/gradle/SkippyPlugin.java
index cc36f64..af31e41 100644
--- a/skippy-gradle/src/main/java/io/skippy/gradle/SkippyPlugin.java
+++ b/skippy-gradle/src/main/java/io/skippy/gradle/SkippyPlugin.java
@@ -19,8 +19,15 @@
import io.skippy.core.Profiler;
import org.gradle.api.Project;
import org.gradle.api.tasks.testing.Test;
+import org.gradle.api.tasks.testing.TestDescriptor;
+import org.gradle.api.tasks.testing.TestListener;
+import org.gradle.api.tasks.testing.TestResult;
import org.gradle.testing.jacoco.plugins.JacocoPlugin;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
/**
* The Skippy plugin adds the
*
@@ -64,8 +71,49 @@ public void apply(Project project) {
});
});
+
+ action.getTasks().withType(Test.class, testTask -> {
+ testTask.finalizedBy("skippyAnalyze");
+ testTask.addTestListener(new TestListener() {
+ @Override
+ public void beforeSuite(TestDescriptor testDescriptor) {
+ }
+
+ @Override
+ public void afterSuite(TestDescriptor testDescriptor, TestResult testResult) {
+ }
+
+ @Override
+ public void beforeTest(TestDescriptor testDescriptor) {
+ var testClass = loadClass(testTask, testDescriptor.getClassName());
+ projectSettings.ifBuildSupportsSkippy(skippyBuildApi -> skippyBuildApi.beforeTest(testClass));
+ }
+
+ @Override
+ public void afterTest(TestDescriptor testDescriptor, TestResult testResult) {
+ var testClass = loadClass(testTask, testDescriptor.getClassName());
+ projectSettings.ifBuildSupportsSkippy(skippyBuildApi -> skippyBuildApi.afterTest(testClass));
+ }
+ });
+ });
+
projectSettings.ifBuildSupportsSkippy(skippyBuildApi -> skippyBuildApi.buildStarted());
});
}
+ private Class> loadClass(Test testTask, String className) {
+ try {
+ var urls = testTask.getClasspath().getFiles().stream().map(file -> {
+ try {
+ return file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }).toList();
+ var classloader = new URLClassLoader(urls.toArray(new URL[]{}));
+ return classloader.loadClass(className);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
}
\ No newline at end of file