"Fossies" - the Fresh Open Source Software Archive 
Member "gradle-8.1.1/subprojects/smoke-test/src/smokeTest/groovy/org/gradle/smoketests/AbstractAndroidSantaTrackerSmokeTest.groovy" (20 Apr 2023, 6356 Bytes) of package /linux/misc/gradle-8.1.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Java source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "AbstractAndroidSantaTrackerSmokeTest.groovy":
8.0.2_vs_8.1.0.
1 /*
2 * Copyright 2020 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.gradle.smoketests
18
19 import org.gradle.api.JavaVersion
20 import org.gradle.integtests.fixtures.daemon.DaemonLogsAnalyzer
21 import org.gradle.internal.scan.config.fixtures.ApplyGradleEnterprisePluginFixture
22 import org.gradle.test.fixtures.file.TestFile
23 import org.gradle.test.fixtures.file.TestNameTestDirectoryProvider
24 import org.gradle.testkit.runner.BuildResult
25 import org.gradle.testkit.runner.TaskOutcome
26 import org.gradle.testkit.runner.internal.ToolingApiGradleExecutor
27 import org.junit.Rule
28
29 class AbstractAndroidSantaTrackerSmokeTest extends AbstractSmokeTest {
30
31 protected static final Iterable<String> TESTED_AGP_VERSIONS = TestedVersions.androidGradle.versions
32
33 @Rule
34 TestNameTestDirectoryProvider temporaryFolder = new TestNameTestDirectoryProvider(getClass())
35 TestFile homeDir
36
37 String kotlinVersion = TestedVersions.kotlin.latestStable()
38
39 def setup() {
40 homeDir = temporaryFolder.createDir("test-kit-home")
41 }
42
43 def cleanup() {
44 // The daemons started by test kit need to be killed, so no locked files are left behind.
45 DaemonLogsAnalyzer.newAnalyzer(homeDir.file(ToolingApiGradleExecutor.TEST_KIT_DAEMON_DIR_NAME)).killAll()
46 }
47
48 protected void setupCopyOfSantaTracker(TestFile targetDir) {
49 copyRemoteProject("santaTracker", targetDir)
50 ApplyGradleEnterprisePluginFixture.applyEnterprisePlugin(targetDir.file("settings.gradle"))
51 }
52
53 protected BuildResult buildLocation(File projectDir, String agpVersion) {
54 return runnerForLocation(projectDir, agpVersion, "assembleDebug").build()
55 }
56
57 protected BuildResult buildLocationMaybeExpectingWorkerExecutorDeprecation(File location, String agpVersion) {
58 return runnerForLocation(location, agpVersion,"assembleDebug")
59 .deprecations(SantaTrackerDeprecations) {
60 expectAndroidWorkerExecutionSubmitDeprecationWarning(agpVersion)
61 }.build()
62 }
63
64 static class SantaTrackerDeprecations extends BaseDeprecations implements WithAndroidDeprecations {
65 SantaTrackerDeprecations(SmokeTestGradleRunner runner) {
66 super(runner)
67 }
68 }
69
70 protected BuildResult cleanLocation(File projectDir, String agpVersion) {
71 return runnerForLocation(projectDir, agpVersion, "clean").build()
72 }
73
74 protected SmokeTestGradleRunner runnerForLocation(File projectDir, String agpVersion, String... tasks) {
75 def runnerArgs = [[
76 // TODO: the versions of KGP we use still access Task.project from a cacheIf predicate
77 // A workaround for this has been added to TaskExecutionAccessCheckers;
78 // TODO once we remove it, uncomment the flag below or upgrade AGP
79 // "-Dorg.gradle.configuration-cache.internal.task-execution-access-pre-stable=true",
80 "-DagpVersion=$agpVersion",
81 "-DkotlinVersion=$kotlinVersion",
82 "--stacktrace"],
83 tasks].flatten()
84 def runner = runner(*runnerArgs)
85 .withProjectDir(projectDir)
86 .withTestKitDir(homeDir)
87 .forwardOutput()
88 if (JavaVersion.current().isJava9Compatible()) {
89 runner.withJvmArguments(
90 "-Xmx8g", "-XX:MaxMetaspaceSize=1024m", "-XX:+HeapDumpOnOutOfMemoryError",
91 "--add-opens", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
92 "--add-opens", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
93 "--add-opens", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
94 "--add-opens", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
95 "--add-opens", "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
96 "--add-opens", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
97 "--add-opens", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
98 "--add-opens", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED"
99 )
100 }
101 if (AGP_VERSIONS.isAgpNightly(agpVersion)) {
102 def init = AGP_VERSIONS.createAgpNightlyRepositoryInitScript()
103 runner.withArguments([runner.arguments, ['-I', init.canonicalPath]].flatten())
104 }
105 return runner
106 }
107
108 protected static boolean verify(BuildResult result, Map<String, TaskOutcome> outcomes) {
109 println "> Expecting ${outcomes.size()} tasks with outcomes:"
110 outcomes.values().groupBy { it }.sort().forEach { outcome, instances -> println "> - $outcome: ${instances.size()}" }
111
112 def outcomesWithMatchingTasks = outcomes.findAll { result.task(it.key) }
113 def hasMatchingTasks = outcomesWithMatchingTasks.size() == outcomes.size() && outcomesWithMatchingTasks.size() == result.tasks.size()
114 if (!hasMatchingTasks) {
115 println "> Tasks missing: " + (outcomes.findAll { !outcomesWithMatchingTasks.keySet().contains(it.key) })
116 println "> Tasks in surplus: " + (result.tasks.findAll { !outcomesWithMatchingTasks.keySet().contains(it.path) })
117 println "> Updated definitions:"
118 result.tasks
119 .toSorted { a, b -> a.path <=> b.path }
120 .forEach { task ->
121 println "'${task.path}': ${task.outcome},"
122 }
123 }
124
125 boolean allOutcomesMatched = true
126 outcomesWithMatchingTasks.each { taskName, expectedOutcome ->
127 def taskOutcome = result.task(taskName)?.outcome
128 if (taskOutcome != expectedOutcome) {
129 println "> Task '$taskName' was $taskOutcome but should have been $expectedOutcome"
130 allOutcomesMatched = false
131 }
132 }
133 return hasMatchingTasks && allOutcomesMatched
134 }
135 }