Skip to content

Commit

Permalink
Fix configuration cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
wyhasany committed May 25, 2021
1 parent b35fdd0 commit d6ecb3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.gradle.util.VersionNumber;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

Expand All @@ -47,14 +48,14 @@ public static void configureTestTask(Test test, ObjectFactory objectFactory, Pro
test.getInputs().property("retry.failOnPassedAfterRetry", adapter.getFailOnPassedAfterRetryInput());

test.getExtensions().add(TestRetryTaskExtension.class, TestRetryTaskExtension.NAME, extension);
test.doFirst(new ConditionalTaskAction(new InitTaskAction(adapter, objectFactory)));
test.doFirst(new ConditionalTaskAction(new InitTaskAction(adapter, objectFactory, test.getProject().getRootDir())));
test.doLast(new ConditionalTaskAction(new FinalizeTaskAction()));
}

private static RetryTestExecuter createRetryTestExecuter(Test task, TestRetryTaskExtensionAdapter extension, ObjectFactory objectFactory) {
private static RetryTestExecuter createRetryTestExecuter(Test task, TestRetryTaskExtensionAdapter extension, ObjectFactory objectFactory, File rootDir) {
TestExecuter<JvmTestExecutionSpec> delegate = getTestExecuter(task);
Instantiator instantiator = invoke(declaredMethod(AbstractTestTask.class, "getInstantiator"), task);
return new RetryTestExecuter(task, extension, delegate, instantiator, objectFactory);
return new RetryTestExecuter(task, extension, delegate, instantiator, objectFactory, rootDir);
}

private static TestExecuter<JvmTestExecutionSpec> getTestExecuter(Test task) {
Expand Down Expand Up @@ -117,15 +118,17 @@ private static class InitTaskAction implements Action<Test> {

private final TestRetryTaskExtensionAdapter adapter;
private final ObjectFactory objectFactory;
private final File rootDir;

public InitTaskAction(TestRetryTaskExtensionAdapter adapter, ObjectFactory objectFactory) {
public InitTaskAction(TestRetryTaskExtensionAdapter adapter, ObjectFactory objectFactory, File rootDir) {
this.adapter = adapter;
this.objectFactory = objectFactory;
this.rootDir = rootDir;
}

@Override
public void execute(@NotNull Test task) {
RetryTestExecuter retryTestExecuter = createRetryTestExecuter(task, adapter, objectFactory);
RetryTestExecuter retryTestExecuter = createRetryTestExecuter(task, adapter, objectFactory, rootDir);
setTestExecuter(task, retryTestExecuter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.gradle.api.Project;
import org.gradle.testretry.internal.config.TestRetryTaskExtensionAdapter;

import java.io.File;
import java.io.IOException;
import java.util.List;

Expand Down Expand Up @@ -55,12 +55,12 @@ public boolean wasModified(String path) {
}
}

static GitRepository create(Project project, TestRetryTaskExtensionAdapter extension) {
static GitRepository create(File rootDir, TestRetryTaskExtensionAdapter extension) {
if (!extension.getModifiedTestRetry()) {
return new NoRepository();
}
try (
Git git = Git.open(project.getRootDir())
Git git = Git.open(rootDir)
) {
Repository repository = git.getRepository();
AbstractTreeIterator oldTree = getTreeIterator("refs/heads/master", repository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.gradle.testretry.internal.filter.AnnotationInspectorImpl;
import org.gradle.testretry.internal.filter.RetryFilter;

import java.io.File;
import java.util.stream.Collectors;

public final class RetryTestExecuter implements TestExecuter<JvmTestExecutionSpec> {
Expand All @@ -44,12 +45,13 @@ public RetryTestExecuter(
TestRetryTaskExtensionAdapter extension,
TestExecuter<JvmTestExecutionSpec> delegate,
Instantiator instantiator,
ObjectFactory objectFactory
ObjectFactory objectFactory,
File rootDir
) {
this.extension = extension;
this.delegate = delegate;
this.testTask = task;
this.gitRepository = GitRepository.create(task.getProject(), extension);
this.gitRepository = GitRepository.create(rootDir, extension);
this.frameworkTemplate = new TestFrameworkTemplate(
testTask,
instantiator,
Expand Down

0 comments on commit d6ecb3b

Please sign in to comment.