Skip to content

Commit

Permalink
Use its own TestClassProcessorFactory
Browse files Browse the repository at this point in the history
dmikurube committed Sep 10, 2024
1 parent e0368bf commit ce28cc9
Showing 2 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is based on a copy from Gradle 8.10 with modifications.
*
* It is licensed under the Apache License, Version 2.0.
*/

/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.embulk.junit5;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import org.gradle.api.internal.tasks.testing.TestClassProcessor;
import org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory;
import org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformSpec;
import org.gradle.internal.UncheckedException;
import org.gradle.internal.actor.ActorFactory;
import org.gradle.internal.id.IdGenerator;
import org.gradle.internal.time.Clock;

/**
* Implementation of {@link WorkerTestClassProcessorFactory} which instantiates a {@code JUnitPlatformTestClassProcessor}.
* This class is loaded on test workers themselves and acts as the entry-point to running JUnit Platform tests on a test worker.
*/
public class EmbulkJUnitPlatformTestClassProcessorFactory implements WorkerTestClassProcessorFactory, Serializable {
public EmbulkJUnitPlatformTestClassProcessorFactory(final JUnitPlatformSpec spec) {
this.spec = spec;
}

@Override
public TestClassProcessor create(
final IdGenerator<?> idGenerator,
final ActorFactory actorFactory,
final Clock clock) {
try {
Class<?> clazz = getClass().getClassLoader().loadClass("org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor");
Constructor<?> constructor = clazz.getConstructor(JUnitPlatformSpec.class, IdGenerator.class, ActorFactory.class, Clock.class);
return (TestClassProcessor) constructor.newInstance(spec, idGenerator, actorFactory, clock);
} catch (final Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}

private final JUnitPlatformSpec spec;
}
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
import org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory;
import org.gradle.api.internal.tasks.testing.detection.TestFrameworkDetector;
import org.gradle.api.internal.tasks.testing.filter.DefaultTestFilter;
import org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformSpec;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.provider.Provider;
@@ -103,13 +104,14 @@ public WorkerTestClassProcessorFactory getProcessorFactory() {
}

validateOptions(this.options);
/*
return new JUnitPlatformTestClassProcessorFactory(new JUnitPlatformSpec(
filter.toSpec(), options.getIncludeEngines(), options.getExcludeEngines(),
options.getIncludeTags(), options.getExcludeTags(), dryRun.get()
return new EmbulkJUnitPlatformTestClassProcessorFactory(new JUnitPlatformSpec(
this.filter.toSpec(),
this.options.getIncludeEngines(),
this.options.getExcludeEngines(),
this.options.getIncludeTags(),
this.options.getExcludeTags(),
this.dryRun.get()
));
*/
return null;
}

/**
@@ -134,8 +136,7 @@ public Action<WorkerProcessBuilder> getWorkerConfigurationAction() {
@Internal
@Override
public List<TestFrameworkDistributionModule> getWorkerApplicationModulepathModules() {
return Collections.emptyList(); // (TestFramework)
// return DISTRIBUTION_MODULES; (JUnitPlatformTetFramework)
return DISTRIBUTION_MODULES;
}

/**

0 comments on commit ce28cc9

Please sign in to comment.