diff --git a/build.gradle b/build.gradle index 6192469..605492c 100644 --- a/build.gradle +++ b/build.gradle @@ -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() diff --git a/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestClassProcessor.java b/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestClassProcessor.java index 0b59bce..4ffd81f 100644 --- a/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestClassProcessor.java +++ b/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestClassProcessor.java @@ -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; @@ -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; @@ -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 @@ -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)); } } diff --git a/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestFramework.java b/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestFramework.java index 77512f2..8b671a7 100644 --- a/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestFramework.java +++ b/src/main/java/org/embulk/gradle/embulk_plugins/EmbulkJUnitPlatformTestFramework.java @@ -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; } @@ -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) { diff --git a/src/test/java/org/embulk/gradle/embulk_plugins/TestSimple.java b/src/test/java/org/embulk/gradle/embulk_plugins/TestSimple.java index 6e795eb..38196e8 100644 --- a/src/test/java/org/embulk/gradle/embulk_plugins/TestSimple.java +++ b/src/test/java/org/embulk/gradle/embulk_plugins/TestSimple.java @@ -53,5 +53,7 @@ public void test(@TempDir Path tempDir) throws IOException { System.out.println(line); } System.out.println("============================================================"); + + runGradle(projectDir, "embulkPluginTest"); } } diff --git a/src/test/resources/testSimple/src/test/java/Test.java b/src/test/resources/testSimple/src/test/java/Test.java new file mode 100644 index 0000000..a065407 --- /dev/null +++ b/src/test/resources/testSimple/src/test/java/Test.java @@ -0,0 +1,2 @@ +public class Test { +}