Skip to content

Commit

Permalink
issues/189: poc for exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmck3516 committed Nov 25, 2024
1 parent 8aab69a commit 213652b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions skippy-core/src/main/java/io/skippy/core/SkippyBuildApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
48 changes: 48 additions & 0 deletions skippy-gradle/src/main/java/io/skippy/gradle/SkippyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <ul>
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 213652b

Please sign in to comment.