gradle 之分支进程执行分析
@Override public void execute(final JvmTestExecutionSpec testExecutionSpec, TestResultProcessor testResultProcessor) { // 获取测试框架类型,junit或testng或junit5 final TestFramework testFramework = testExecutionSpec.getTestFramework(); // 返回一个工厂,用于在每个工作进程中创建一个 TestClassProcessor。 这个工厂被序列化到工作进程,然后它的 WorkerTestClassProcessorFactory.create(org.gradle.internal.service.ServiceRegistry) 方法被调用来创建测试处理器。 final WorkerTestClassProcessorFactory testInstanceFactory = testFramework.getProcessorFactory(); final WorkerLeaseRegistry.WorkerLease currentWorkerLease = workerLeaseRegistry.getCurrentWorkerLease(); final Set<File> classpath = ImmutableSet.copyOf(testExecutionSpec.getClasspath()); final Set<File> modulePath = ImmutableSet.copyOf(testExecutionSpec.getModulePath()); final List<String> testWorkerImplementationModules = testFramework.getTestWorkerImplementationModules(); final Factory<TestClassProcessor> forkingProcessorFactory = new Factory<TestClassProcessor>() { @Override public TestClassProcessor create() { return new ForkingTestClassProcessor(currentWorkerLease, workerFactory, testInstanceFactory, testExecutionSpec.getJavaForkOptions(), classpath, modulePath, testWorkerImplementationModules, testFramework.getWorkerConfigurationAction(), moduleRegistry, documentationRegistry); } }; final Factory<TestClassProcessor> reforkingProcessorFactory = new Factory<TestClassProcessor>() { @Override public TestClassProcessor create() { return new RestartEveryNTestClassProcessor(forkingProcessorFactory, testExecutionSpec.getForkEvery()); } }; processor = new PatternMatchTestClassProcessor(testFilter, new RunPreviousFailedFirstTestClassProcessor(testExecutionSpec.getPreviousFailedTestClasses(), new MaxNParallelTestClassProcessor(getMaxParallelForks(testExecutionSpec), reforkingProcessorFactory, actorFactory))); final FileTree testClassFiles = testExecutionSpec.getCandidateClassFiles(); Runnable detector; if (testExecutionSpec.isScanForTestClasses() && testFramework.getDetector() != null) { TestFrameworkDetector testFrameworkDetector = testFramework.getDetector(); testFrameworkDetector.setTestClasses(testExecutionSpec.getTestClassesDirs().getFiles()); testFrameworkDetector.setTestClasspath(classpath); detector = new DefaultTestClassScanner(testClassFiles, testFrameworkDetector, processor); } else { detector = new DefaultTestClassScanner(testClassFiles, null, processor); } new TestMainAction(detector, processor, testResultProcessor, clock, testExecutionSpec.getPath(), "Gradle Test Run " + testExecutionSpec.getIdentityPath()).run(); }