Skip to content

Commit

Permalink
Disable config cache for old Gradle versions
Browse files Browse the repository at this point in the history
Signed-off-by: Lőrinc Pap <[email protected]>
  • Loading branch information
Lőrinc Pap committed Jun 1, 2021
1 parent dc0ffda commit 5d339c8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Set;
import java.util.concurrent.Callable;

import static org.gradle.testretry.internal.config.TestTaskConfigurer.supportsPropertyConventions;

public final class TestRetryTaskExtensionAdapter {

// for testing only
Expand Down Expand Up @@ -53,10 +55,6 @@ public TestRetryTaskExtensionAdapter(
initialize(extension, this.useConventions);
}

private static boolean supportsPropertyConventions(VersionNumber gradleVersion) {
return gradleVersion.compareTo(VersionNumber.parse("5.1")) >= 0;
}

private static void initialize(TestRetryTaskExtension extension, boolean gradle51OrLater) {
if (gradle51OrLater) {
extension.getMaxRetries().convention(DEFAULT_MAX_RETRIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static void configureTestTask(Test test, ObjectFactory objectFactory, Pro

test.getInputs().property("retry.failOnPassedAfterRetry", adapter.getFailOnPassedAfterRetryInput());

Provider<Boolean> isDeactivatedByTestDistributionPlugin = shouldTestRetryPluginBeDeactivated(test, objectFactory, providerFactory);
Provider<Boolean> isDeactivatedByTestDistributionPlugin =
shouldTestRetryPluginBeDeactivated(test, objectFactory, providerFactory, gradleVersion);
test.getInputs().property("isDeactivatedByTestDistributionPlugin", isDeactivatedByTestDistributionPlugin);

test.getExtensions().add(TestRetryTaskExtension.class, TestRetryTaskExtension.NAME, extension);
Expand All @@ -57,13 +58,31 @@ public static void configureTestTask(Test test, ObjectFactory objectFactory, Pro
test.doLast(new ConditionalTaskAction(isDeactivatedByTestDistributionPlugin, new FinalizeTaskAction()));
}

private static Provider<Boolean> shouldTestRetryPluginBeDeactivated(Test test, ObjectFactory objectFactory, ProviderFactory providerFactory) {
Provider<Boolean> provider = providerFactory.provider(() -> callShouldTestRetryPluginBeDeactivated(test));
Property<Boolean> result = objectFactory.property(Boolean.class).convention(provider);
result.finalizeValueOnRead();
private static Provider<Boolean> shouldTestRetryPluginBeDeactivated(
Test test,
ObjectFactory objectFactory,
ProviderFactory providerFactory,
VersionNumber gradleVersion
) {
Provider<Boolean> result = providerFactory.provider(() -> callShouldTestRetryPluginBeDeactivated(test));
if (supportsPropertyConventions(gradleVersion)) {
Property<Boolean> property = objectFactory.property(Boolean.class).convention(result);
if (supportsFinalizeValueOnRead(gradleVersion)) {
property.finalizeValueOnRead();
}
result = property;
}
return result;
}

public static boolean supportsPropertyConventions(VersionNumber gradleVersion) {
return gradleVersion.compareTo(VersionNumber.parse("5.1")) >= 0;
}

private static boolean supportsFinalizeValueOnRead(VersionNumber gradleVersion) {
return gradleVersion.compareTo(VersionNumber.parse("6.1")) >= 0;
}

private static boolean callShouldTestRetryPluginBeDeactivated(Test test) {
Object distributionExtension = test.getExtensions().findByName("distribution");
if (distributionExtension == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import java.util.stream.Collectors;

import static org.gradle.testretry.internal.executer.framework.TestFrameworkStrategy.gradleVersionIsAtLeast;

public final class RetryTestExecuter implements TestExecuter<JvmTestExecutionSpec> {

private final TestRetryTaskExtensionAdapter extension;
Expand Down Expand Up @@ -121,7 +123,7 @@ public void failWithNonRetriedTestsIfAny() {
}

private JvmTestExecutionSpec createRetryJvmExecutionSpec(JvmTestExecutionSpec spec, TestFramework retryTestFramework) {
if (TestFrameworkStrategy.gradleVersionIsAtLeast("6.4")) {
if (gradleVersionIsAtLeast("6.4")) {
// This constructor is in Gradle 6.4+
return new JvmTestExecutionSpec(
retryTestFramework,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.Map;
import java.util.Optional;

import static org.gradle.testretry.internal.executer.framework.TestFrameworkStrategy.gradleVersionIsAtLeast;

final class TestNgTestFrameworkStrategy implements TestFrameworkStrategy {

private static final Logger LOGGER = LoggerFactory.getLogger(TestNgTestFrameworkStrategy.class);
Expand Down Expand Up @@ -73,7 +75,7 @@ public TestFramework createRetrying(TestFrameworkTemplate template, TestNames fa
}

private TestNGTestFramework createTestFramework(TestFrameworkTemplate template, DefaultTestFilter retriedTestFilter) {
if (TestFrameworkStrategy.gradleVersionIsAtLeast("6.6")) {
if (gradleVersionIsAtLeast("6.6")) {
return new TestNGTestFramework(template.task, template.task.getClasspath(), retriedTestFilter, template.objectFactory);
} else {
try {
Expand Down

0 comments on commit 5d339c8

Please sign in to comment.