Cherry pick the banglets and such from wip-l1summercoat, this will be the basis for...
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMTestFramework.java
blobc2f42dfda355872a7583afa4eda668a57146cd2d
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.multivm;
12 import cc.squirreljme.plugin.multivm.ident.SourceTargetClassifier;
13 import java.io.IOException;
14 import java.util.Collections;
15 import java.util.LinkedHashMap;
16 import java.util.List;
17 import java.util.Map;
18 import javax.inject.Inject;
19 import lombok.Getter;
20 import org.gradle.api.Action;
21 import org.gradle.api.internal.tasks.testing.TestFramework;
22 import org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory;
23 import org.gradle.api.internal.tasks.testing.detection.TestFrameworkDetector;
24 import org.gradle.api.tasks.Internal;
25 import org.gradle.api.tasks.testing.TestFrameworkOptions;
26 import org.gradle.process.internal.worker.WorkerProcessBuilder;
28 /**
29 * Test framework for SquirrelJME.
31 * @since 2022/09/11
33 public class VMTestFramework
34 implements TestFramework
36 /** The name of this framework. */
37 public final String declaredDisplayName =
38 "SquirrelJME Test Framework";
40 /** Is this framework immutable? */
41 @Internal
42 public final boolean immutable =
43 false;
45 /** Our test task. */
46 @Internal
47 @Getter
48 protected final VMModernTestTask task;
50 /** The classifier. */
51 @Internal
52 @Getter
53 protected final SourceTargetClassifier classifier;
55 /**
56 * Initializes the test framework.
58 * @param __vmTestTask The test task we are using.
59 * @param __classifier The classifier to use.
60 * @since 2022/09/11
62 @Inject
63 public VMTestFramework(VMModernTestTask __vmTestTask,
64 SourceTargetClassifier __classifier)
66 this.task = __vmTestTask;
67 this.classifier = __classifier;
70 /**
71 * {@inheritDoc}
72 * @since 2022/09/11
74 @Override
75 public void close()
76 throws IOException
80 /**
81 * {@inheritDoc}
82 * @since 2022/09/11
84 @Override
85 public TestFrameworkDetector getDetector()
87 return new VMTestFrameworkDetector(
88 VMHelpers.runningTests(this.task.getProject(),
89 this.classifier.getSourceSet()).tests);
92 /**
93 * Is this an immutable test framework?
95 * @return If this is immutable.
96 * @since 2022/09/11
98 public boolean getImmutable()
100 return this.immutable;
104 * {@inheritDoc}
105 * @since 2022/09/11
107 @Override
108 public TestFrameworkOptions getOptions()
110 return new TestFrameworkOptions();
114 * {@inheritDoc}
115 * @since 2022/09/11
117 @Override
118 public WorkerTestClassProcessorFactory getProcessorFactory()
120 // Get the tests we are going to run, since we need to calculate how
121 // to run the test, and everything must be serialized through it
122 Map<String, CandidateTestFiles> tests = VMHelpers.runningTests(
123 this.task.getProject(), this.classifier.getSourceSet()).tests;
125 // Determine setup for general suite runs
126 SuiteRunParameters runSuite = VMTestTaskAction.runSuite(this.task,
127 this.classifier);
129 // Calculate run parameters for each test
130 Map<String, TestRunParameters> runParams = new LinkedHashMap<>();
131 for (Map.Entry<String, CandidateTestFiles> test : tests.entrySet())
132 runParams.put(test.getKey(), VMTestTaskAction.runTest(this.task,
133 this.classifier, runSuite, test.getKey(),
134 test.getValue()));
136 // Run the processor, this must be serializable
137 return new VMTestFrameworkWorkerTestClassProcessorFactory(
138 tests, runParams, this.task.getProject().getName());
142 * {@inheritDoc}
143 * @since 2022/09/11
145 @Override
146 public Action<WorkerProcessBuilder> getWorkerConfigurationAction()
148 return new VMTestFrameworkWorkerConfigurationAction();
152 * {@inheritDoc}
153 * @since 2022/09/11
155 @Override
156 public List<String> getTestWorkerImplementationModules()
158 // No modules are used
159 return Collections.emptyList();