Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikurube committed Dec 13, 2023
1 parent f189b05 commit f6bf7c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ java {
}

dependencies {
compileOnly "org.junit.jupiter:junit-jupiter-api:5.10.1"
compileOnly "org.junit.jupiter:junit-jupiter-engine:5.10.1"
compileOnly "org.junit.platform:junit-platform-launcher:1.10.1"
implementation gradleApi()

testImplementation gradleTestKit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.gradle.api.internal.tasks.testing.TestResultProcessor;
import org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher;
import org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor;
import org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformSpec;
import org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestExecutionListener;
import org.gradle.internal.UncheckedException;
import org.gradle.internal.actor.Actor;
import org.gradle.internal.actor.ActorFactory;
Expand All @@ -35,9 +37,11 @@
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.PostDiscoveryFilter;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;


import javax.annotation.Nonnull;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
Expand All @@ -56,6 +60,7 @@ public class EmbulkJUnitPlatformTestClassProcessor extends AbstractJUnitTestClas

public EmbulkJUnitPlatformTestClassProcessor(JUnitPlatformSpec spec, IdGenerator<?> idGenerator, ActorFactory actorFactory, Clock clock) {
super(spec, idGenerator, actorFactory, clock);
System.out.println("!!!!!!");
}

@Override
Expand Down Expand Up @@ -95,7 +100,7 @@ public void execute(@Nonnull String testClassName) {

private void processAllTestClasses() {
Launcher launcher = LauncherFactory.create();
launcher.registerTestExecutionListeners(new JUnitPlatformTestExecutionListener(resultProcessor, clock, idGenerator));
launcher.registerTestExecutionListeners((TestExecutionListener) new JUnitPlatformTestExecutionListener(resultProcessor, clock, idGenerator));
launcher.execute(createLauncherDiscoveryRequest(testClasses));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,30 @@
import java.util.List;

public class EmbulkJUnitPlatformTestFramework extends JUnitPlatformTestFramework {
private final DefaultTestFilter filter2;

public EmbulkJUnitPlatformTestFramework(final DefaultTestFilter filter) {
super(filter);
this.filter2 = filter;
}

@Override
public WorkerTestClassProcessorFactory getProcessorFactory() {
return super.getProcessorFactory();
/*
return super.getProcessorFactory();
*/
if (!JavaVersion.current().isJava8Compatible()) {
throw new UnsupportedJavaRuntimeException("Running JUnit Platform requires Java 8+, please configure your test java executable with Java 8 or higher.");
}
return new JUnitPlatformTestClassProcessorFactory(new JUnitPlatformSpec(options,
filter.getIncludePatterns(), filter.getExcludePatterns(),
filter.getCommandLineIncludePatterns()));
*/
return new EmbulkJUnitPlatformTestClassProcessorFactory(new JUnitPlatformSpec(this.getOptions(),
filter2.getIncludePatterns(), filter2.getExcludePatterns(),
filter2.getCommandLineIncludePatterns()));
}

static class JUnitPlatformTestClassProcessorFactory implements WorkerTestClassProcessorFactory, Serializable {
static class EmbulkJUnitPlatformTestClassProcessorFactory implements WorkerTestClassProcessorFactory, Serializable {
private final JUnitPlatformSpec spec;

JUnitPlatformTestClassProcessorFactory(JUnitPlatformSpec spec) {
EmbulkJUnitPlatformTestClassProcessorFactory(JUnitPlatformSpec spec) {
this.spec = spec;
}

Expand All @@ -80,7 +83,9 @@ public TestClassProcessor create(ServiceRegistry serviceRegistry) {
IdGenerator<?> idGenerator = serviceRegistry.get(IdGenerator.class);
Clock clock = serviceRegistry.get(Clock.class);
ActorFactory actorFactory = serviceRegistry.get(ActorFactory.class);
Class<?> clazz = getClass().getClassLoader().loadClass("org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor");
// Class<?> clazz = getClass().getClassLoader().loadClass("org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor");
Class<?> clazz = getClass().getClassLoader().loadClass("org.embulk.gradle.embulk_plugins.EmbulkJUnitPlatformTestClassProcessor");

Constructor<?> constructor = clazz.getConstructor(JUnitPlatformSpec.class, IdGenerator.class, ActorFactory.class, Clock.class);
return (TestClassProcessor) constructor.newInstance(spec, idGenerator, actorFactory, clock);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ public void test(@TempDir Path tempDir) throws IOException {
System.out.println(line);
}
System.out.println("============================================================");

runGradle(projectDir, "embulkPluginTest");
}
}
2 changes: 2 additions & 0 deletions src/test/resources/testSimple/src/test/java/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Test {
}

0 comments on commit f6bf7c1

Please sign in to comment.