Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve deprecation checks for smoke tests #17044

Merged
merged 26 commits into from May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9ee255c
Remove expectations about AGP versions < 4.0
lptr May 2, 2021
8193ff6
Move deprecation waring expectations to smoke-test specific GradleRunner
lptr May 2, 2021
e732b1f
Expose SmokeTestGradleRunner in more places
lptr May 2, 2021
4ad6833
Add expectations for a number of recently introduced deprecations
lptr May 2, 2021
d6df8a0
More expectations for WorkerExecutor.submit() deprecation
lptr May 2, 2021
dac7247
Add missing deprecation warning expecatation
lptr May 2, 2021
add9c78
Replace deprecated Report.enabled with Report.required
lptr May 2, 2021
f1fe8b3
Ignore deprecation warnings in the Gradle build
lptr May 2, 2021
7616daf
Add more expected deprecations
lptr May 2, 2021
9c47c54
Add missing deprecation warning
lptr May 2, 2021
95ef332
Add followup todos
lptr May 2, 2021
23ad309
Fix unnecessary cast
lptr May 2, 2021
df727e3
Add more expected deprecations for AGP tests
lptr May 2, 2021
c7a2838
Do something special when configuration caching is enabled
lptr May 3, 2021
0799506
Introduce expectLegacyDeprecationWarning()
lptr May 3, 2021
7bfc329
Link to Freefair AspectJ issue
lptr May 3, 2021
56a6d9e
Link to Gretty issue
lptr May 3, 2021
844d2d3
Link to Nebula plugin issue
lptr May 3, 2021
4b7e1f0
Refer to some followup issues
lptr May 4, 2021
0c33856
Add expected deprecations in Play plugin smoke test
rieske May 5, 2021
fd3b924
Fix typo
rieske May 5, 2021
58bc224
Fix Android smoke test deprecation expectations
rieske May 5, 2021
d01b93f
Merge branch 'master' into lptr/smoke-tests/link-deprecation-followup
rieske May 6, 2021
ae2f62f
Update smoke test deprecation expectations mitigating Kotlin 1.5.0-RC…
rieske May 7, 2021
fac2fae
Update smoke test deprecation expectation for config cache execution
rieske May 7, 2021
7e50f6c
Simplify conditional deprecation warnings in smoke tests
rieske May 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -243,7 +243,7 @@ fun Project.extractAllReportsFromCI() {

gradle.taskGraph.afterTask {
if (state.failure != null && this is Reporting<*>) {
this.reports.filter { it.name in capturedReportingTypes && it.isEnabled && it.destination.exists() }
this.reports.filter { it.name in capturedReportingTypes && it.required.get() && it.destination.exists() }
.forEach { report ->
val linkName = "${this::class.java.simpleName.split("_")[0]} Report ($path)" // Strip off '_Decorated' addition to class names
// see: ciReporting.gradle
Expand Down
Expand Up @@ -22,13 +22,11 @@ import org.gradle.internal.scan.config.fixtures.ApplyGradleEnterprisePluginFixtu
import org.gradle.test.fixtures.file.TestFile
import org.gradle.test.fixtures.file.TestNameTestDirectoryProvider
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.internal.DefaultGradleRunner
import org.gradle.testkit.runner.internal.ToolingApiGradleExecutor
import org.gradle.util.GradleVersion
import org.junit.Rule


class AbstractAndroidSantaTrackerSmokeTest extends AbstractSmokeTest {

protected static final Iterable<String> TESTED_AGP_VERSIONS = TestedVersions.androidGradle.versions
Expand All @@ -55,15 +53,30 @@ class AbstractAndroidSantaTrackerSmokeTest extends AbstractSmokeTest {
return runnerForLocation(projectDir, agpVersion, "assembleDebug").build()
}

protected BuildResult buildLocationMaybeExpectingWorkerExecutorDeprecation(File location, String agpVersion) {
return runnerForLocationMaybeExpectingWorkerExecutorDeprecation(location, agpVersion, "assembleDebug")
.build()
}

protected SmokeTestGradleRunner runnerForLocationMaybeExpectingWorkerExecutorDeprecation(File location, String agpVersion, String... tasks) {
return runnerForLocation(location, agpVersion, tasks)
.expectLegacyDeprecationWarningIf(agpVersion.startsWith("4.1"),
"The WorkerExecutor.submit() method has been deprecated. " +
"This is scheduled to be removed in Gradle 8.0. " +
"Please use the noIsolation(), classLoaderIsolation() or processIsolation() method instead. " +
"See https://docs.gradle.org/${GradleVersion.current().version}/userguide/upgrading_version_5.html#method_workerexecutor_submit_is_deprecated for more details."
)
}

protected BuildResult cleanLocation(File projectDir, String agpVersion) {
return runnerForLocation(projectDir, agpVersion, "clean").build()
}

protected GradleRunner runnerForLocation(File projectDir, String agpVersion, String... tasks) {
protected SmokeTestGradleRunner runnerForLocation(File projectDir, String agpVersion, String... tasks) {
def runner = runner(*[["-DagpVersion=$agpVersion", "-DkotlinVersion=${TestedVersions.kotlin.latest()}", "--stacktrace"], tasks].flatten())
.withProjectDir(projectDir)
.withTestKitDir(homeDir)
.forwardOutput() as DefaultGradleRunner
.forwardOutput()
if (JavaVersion.current().isJava9Compatible()) {
runner.withJvmArguments(
"-Xmx8g", "-XX:MaxMetaspaceSize=1024m", "-XX:+HeapDumpOnOutOfMemoryError",
Expand Down
Expand Up @@ -24,7 +24,6 @@ import org.gradle.integtests.fixtures.executer.IntegrationTestBuildContext
import org.gradle.internal.jvm.inspection.JvmInstallationMetadata
import org.gradle.test.fixtures.file.TestFile
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.Requires
import org.gradle.util.TestPrecondition

Expand Down Expand Up @@ -66,14 +65,16 @@ abstract class AbstractGradleceptionSmokeTest extends AbstractSmokeTest {
result = runnerFor(tasks, testKitDir).buildAndFail()
}

private GradleRunner runnerFor(List<String> tasks, File testKitDir) {
private SmokeTestGradleRunner runnerFor(List<String> tasks, File testKitDir) {
List<String> gradleArgs = tasks + GRADLE_BUILD_TEST_ARGS
return testKitDir != null
def runner = testKitDir != null
? runnerWithTestKitDir(testKitDir, gradleArgs)
: runner(*gradleArgs)
runner.ignoreDeprecationWarnings()
return runner
}

private GradleRunner runnerWithTestKitDir(File testKitDir, List<String> gradleArgs) {
private SmokeTestGradleRunner runnerWithTestKitDir(File testKitDir, List<String> gradleArgs) {
runner(*(gradleArgs + ["-g", IntegrationTestBuildContext.INSTANCE.gradleUserHomeDir.absolutePath]))
.withTestKitDir(testKitDir)
}
Expand Down
Expand Up @@ -32,7 +32,6 @@ import org.gradle.internal.featurelifecycle.LoggingDeprecatedFeatureHandler
import org.gradle.internal.operations.trace.BuildOperationTrace
import org.gradle.test.fixtures.dsl.GradleDsl
import org.gradle.test.fixtures.file.TestFile
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.internal.DefaultGradleRunner
import org.junit.Rule
Expand Down Expand Up @@ -231,8 +230,8 @@ abstract class AbstractSmokeTest extends Specification {
file
}

GradleRunner runner(String... tasks) {
GradleRunner gradleRunner = GradleRunner.create()
SmokeTestGradleRunner runner(String... tasks) {
def gradleRunner = GradleRunner.create()
.withGradleInstallation(IntegrationTestBuildContext.INSTANCE.gradleHomeDir)
.withTestKitDir(IntegrationTestBuildContext.INSTANCE.gradleUserHomeDir)
.withProjectDir(testProjectDir.root)
Expand All @@ -241,6 +240,7 @@ abstract class AbstractSmokeTest extends Specification {
tasks.toList() + outputParameters() + repoMirrorParameters() + configurationCacheParameters()
) as DefaultGradleRunner
gradleRunner.withJvmArguments(["-Xmx8g", "-XX:MaxMetaspaceSize=1024m", "-XX:+HeapDumpOnOutOfMemoryError"])
return new SmokeTestGradleRunner(gradleRunner)
}

private List<String> configurationCacheParameters() {
Expand Down Expand Up @@ -309,7 +309,7 @@ abstract class AbstractSmokeTest extends Specification {
FileUtils.copyDirectory(smokeTestDirectory, testProjectDir.root)
}

protected GradleRunner useAgpVersion(String agpVersion, GradleRunner runner) {
protected SmokeTestGradleRunner useAgpVersion(String agpVersion, SmokeTestGradleRunner runner) {
def extraArgs = [AGP_VERSIONS.OVERRIDE_VERSION_CHECK]
if (AGP_VERSIONS.isAgpNightly(agpVersion)) {
def init = AGP_VERSIONS.createAgpNightlyRepositoryInitScript()
Expand Down Expand Up @@ -342,37 +342,7 @@ abstract class AbstractSmokeTest extends Specification {
RepoScriptBlockUtil.googleRepository(dsl)
}

protected static void expectNoDeprecationWarnings(BuildResult result) {
verifyDeprecationWarnings(result, [])
}

protected static void expectDeprecationWarnings(BuildResult result, String... warnings) {
if (warnings.length == 0) {
throw new IllegalArgumentException("Use expectNoDeprecationWarnings() when no deprecation warnings are to be expected")
}
verifyDeprecationWarnings(result, warnings as List)
}

private static void verifyDeprecationWarnings(BuildResult result, List<String> remainingWarnings) {
def lines = result.output.readLines()
int foundDeprecations = 0
lines.eachWithIndex { String line, int lineIndex ->
if (remainingWarnings.remove(line)) {
foundDeprecations++
return
}
assert !containsDeprecationWarning(line), "Found an unexpected deprecation warning on line ${lineIndex + 1}: $line"
}
assert remainingWarnings.empty, "Expected ${remainingWarnings.size()} deprecation warnings, found ${foundDeprecations} deprecation warnings:\n${remainingWarnings.collect { " - $it" }.join("\n")}"
}

private static boolean containsDeprecationWarning(String line) {
line.contains("has been deprecated and is scheduled to be removed in Gradle") ||
line.contains("has been deprecated. This is scheduled to be removed in Gradle")
}

void copyRemoteProject(String remoteProject, File targetDir) {
new TestFile(new File("build/$remoteProject")).copyTo(targetDir)
}

}
Expand Up @@ -19,12 +19,11 @@ package org.gradle.smoketests
import org.gradle.integtests.fixtures.UnsupportedWithConfigurationCache
import org.gradle.integtests.fixtures.android.AndroidHome
import org.gradle.internal.reflect.validation.ValidationMessageChecker
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.util.GradleVersion
import org.gradle.util.internal.VersionNumber

import static org.gradle.internal.reflect.validation.Severity.ERROR

/**
* For these tests to run you need to set ANDROID_SDK_ROOT to your Android SDK directory
*
Expand Down Expand Up @@ -84,45 +83,15 @@ class AndroidPluginsSmokeTest extends AbstractPluginValidatingSmokeTest implemen
))

when: 'first build'
def result = runner.build()
def result = buildMaybeExpectingWorkerExecutorDeprecation(runner, agpVersion)

then:
result.task(':app:compileDebugJavaWithJavac').outcome == TaskOutcome.SUCCESS
result.task(':library:assembleDebug').outcome == TaskOutcome.SUCCESS
result.task(':app:assembleDebug').outcome == TaskOutcome.SUCCESS

and:
def agpBaseVersion = baseVersionNumberOf(agpVersion)
def threeDotSixBaseVersion = baseVersionNumberOf("3.6.0")
if (agpBaseVersion < threeDotSixBaseVersion) {
assert result.output.contains(JAVA_COMPILE_DEPRECATION_MESSAGE)
} else {
assert !result.output.contains(JAVA_COMPILE_DEPRECATION_MESSAGE)
if (agpBaseVersion == baseVersionNumberOf("3.6.4")) {
expectDeprecationWarnings(
result,
"Internal API constructor DefaultDomainObjectSet(Class<T>) has been deprecated. " +
"This is scheduled to be removed in Gradle 8.0. Please use ObjectFactory.domainObjectSet(Class<T>) instead. " +
"See https://docs.gradle.org/${GradleVersion.current().version}/userguide/custom_gradle_types.html#domainobjectset for more details.",
"The WorkerExecutor.submit() method has been deprecated. " +
"This is scheduled to be removed in Gradle 8.0. Please use the noIsolation(), classLoaderIsolation() or processIsolation() method instead. " +
"See https://docs.gradle.org/${GradleVersion.current().version}/userguide/upgrading_version_5.html#method_workerexecutor_submit_is_deprecated for more details."
)
} else if (agpVersion.startsWith('4.0.2')) {
expectDeprecationWarnings(
result,
"The WorkerExecutor.submit() method has been deprecated. " +
"This is scheduled to be removed in Gradle 8.0. Please use the noIsolation(), classLoaderIsolation() or processIsolation() method instead. " +
"See https://docs.gradle.org/${GradleVersion.current().version}/userguide/upgrading_version_5.html#method_workerexecutor_submit_is_deprecated for more details."
)
} else if (agpVersion.startsWith('4.1')) {
expectDeprecationWarnings(result, "The WorkerExecutor.submit() method has been deprecated. " +
"This is scheduled to be removed in Gradle 8.0. Please use the noIsolation(), classLoaderIsolation() or processIsolation() method instead. " +
"See https://docs.gradle.org/${GradleVersion.current().version}/userguide/upgrading_version_5.html#method_workerexecutor_submit_is_deprecated for more details.")
} else {
expectNoDeprecationWarnings(result)
}
}
assert !result.output.contains(JAVA_COMPILE_DEPRECATION_MESSAGE)

and:
assertConfigurationCacheStateStored()
Expand All @@ -133,18 +102,15 @@ class AndroidPluginsSmokeTest extends AbstractPluginValidatingSmokeTest implemen
then:
result.task(':app:compileDebugJavaWithJavac').outcome == TaskOutcome.UP_TO_DATE
result.task(':library:assembleDebug').outcome == TaskOutcome.UP_TO_DATE
// In AGP 3.4 and 3.5 some of the dependencies of `:app:assembleDebug` are invalid and are thus forced to re-execute every time
result.task(':app:assembleDebug').outcome == (VersionNumber.parse(agpVersion) < VersionNumber.parse("3.6.0")
? TaskOutcome.SUCCESS
: TaskOutcome.UP_TO_DATE)
result.task(':app:assembleDebug').outcome == TaskOutcome.UP_TO_DATE
result.task(':app:processDebugAndroidTestManifest').outcome == TaskOutcome.UP_TO_DATE

and:
assertConfigurationCacheStateLoaded()

when: 'abi change on library'
abiChange.run()
result = runner.build()
result = buildMaybeExpectingWorkerExecutorDeprecation(runner, agpVersion)

then: 'dependent sources are recompiled'
result.task(':library:compileDebugJavaWithJavac').outcome == TaskOutcome.SUCCESS
Expand All @@ -157,7 +123,7 @@ class AndroidPluginsSmokeTest extends AbstractPluginValidatingSmokeTest implemen

when: 'clean re-build'
useAgpVersion(agpVersion, this.runner('clean')).build()
result = runner.build()
result = buildMaybeExpectingWorkerExecutorDeprecation(runner, agpVersion)

then:
result.task(':app:compileDebugJavaWithJavac').outcome == TaskOutcome.SUCCESS
Expand All @@ -174,8 +140,13 @@ class AndroidPluginsSmokeTest extends AbstractPluginValidatingSmokeTest implemen
].combinations()
}

private VersionNumber baseVersionNumberOf(String versionString) {
VersionNumber.parse(versionString).baseVersion
private static BuildResult buildMaybeExpectingWorkerExecutorDeprecation(SmokeTestGradleRunner runner, String agpVersion) {
return runner
.expectLegacyDeprecationWarningIf(agpVersion.startsWith('4.1'),
"The WorkerExecutor.submit() method has been deprecated. " +
"This is scheduled to be removed in Gradle 8.0. Please use the noIsolation(), classLoaderIsolation() or processIsolation() method instead. " +
"See https://docs.gradle.org/${GradleVersion.current().version}/userguide/upgrading_version_5.html#method_workerexecutor_submit_is_deprecated for more details.")
.build()
}

/**
Expand Down
Expand Up @@ -43,7 +43,7 @@ class AndroidSantaTrackerCachingSmokeTest extends AbstractAndroidSantaTrackerSmo
setupCopyOfSantaTracker(relocatedDir)

when: 'clean build'
buildLocation(originalDir, agpVersion)
buildLocationMaybeExpectingWorkerExecutorDeprecation(originalDir, agpVersion)

then:
assertConfigurationCacheStateStored()
Expand All @@ -55,7 +55,7 @@ class AndroidSantaTrackerCachingSmokeTest extends AbstractAndroidSantaTrackerSmo
assertConfigurationCacheStateLoaded()

when: 'clean cached build'
BuildResult relocatedResult = buildLocation(relocatedDir, agpVersion)
BuildResult relocatedResult = buildLocationMaybeExpectingWorkerExecutorDeprecation(relocatedDir, agpVersion)

then:
assertConfigurationCacheStateStored()
Expand All @@ -70,7 +70,7 @@ class AndroidSantaTrackerCachingSmokeTest extends AbstractAndroidSantaTrackerSmo

when: 'clean cached build, reusing configuration cache when enabled'
cleanLocation(relocatedDir, agpVersion)
buildLocation(relocatedDir, agpVersion)
buildLocationMaybeExpectingWorkerExecutorDeprecation(relocatedDir, agpVersion)

then:
assertConfigurationCacheStateLoaded()
Expand Down