-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add easier configuration cache test support in build logic tests (#88047
) (#88569) This is intended to help us getting closer to #57918 by implicitly testing our build logic configuration-cache support. Plugin and Task tests can be marked as configuration cache compatible now and we will always run then with configuration cache enabled. By default, gradle will fail the build if configuration cache problems have been detected during build execution. That should be in general better then adding explicit tests for testing configuration cache compatibility per Test class
- Loading branch information
Showing
4 changed files
with
225 additions
and
39 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...Test/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleInternalPluginFuncTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.fixtures | ||
|
||
import org.gradle.api.Plugin | ||
|
||
abstract class AbstractGradleInternalPluginFuncTest extends AbstractJavaGradleFuncTest { | ||
|
||
abstract <T extends Plugin> Class<T> getPluginClassUnderTest(); | ||
|
||
def setup() { | ||
buildFile << """ | ||
import ${getPluginClassUnderTest().getName()} | ||
plugins { | ||
// bring in build-tools-internal onto the classpath | ||
id 'elasticsearch.global-build-info' | ||
} | ||
// internally used plugins do not have a plugin id as they are | ||
// not intended to be used directly from build scripts | ||
plugins.apply(${getPluginClassUnderTest().getSimpleName()}) | ||
""" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
...org/elasticsearch/gradle/internal/test/ConfigurationCacheCompatibleAwareGradleRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.InvalidPluginMetadataException; | ||
import org.gradle.testkit.runner.InvalidRunnerConfigurationException; | ||
import org.gradle.testkit.runner.UnexpectedBuildFailure; | ||
import org.gradle.testkit.runner.UnexpectedBuildSuccess; | ||
|
||
import java.io.File; | ||
import java.io.Writer; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* A Gradle runner that delegates to another runner, optionally enabling the configuring cache parameter. | ||
*/ | ||
public class ConfigurationCacheCompatibleAwareGradleRunner extends GradleRunner { | ||
private GradleRunner delegate; | ||
private boolean ccCompatible; | ||
|
||
public ConfigurationCacheCompatibleAwareGradleRunner(GradleRunner delegate, boolean ccCompatible) { | ||
this.delegate = delegate; | ||
this.ccCompatible = ccCompatible; | ||
} | ||
|
||
@Override | ||
public GradleRunner withGradleVersion(String gradleVersion) { | ||
delegate.withGradleVersion(gradleVersion); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner withGradleInstallation(File file) { | ||
delegate.withGradleInstallation(file); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner withGradleDistribution(URI uri) { | ||
delegate.withGradleDistribution(uri); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner withTestKitDir(File file) { | ||
delegate.withTestKitDir(file); | ||
return this; | ||
} | ||
|
||
@Override | ||
public File getProjectDir() { | ||
return delegate.getProjectDir(); | ||
} | ||
|
||
@Override | ||
public GradleRunner withProjectDir(File projectDir) { | ||
delegate.withProjectDir(projectDir); | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<String> getArguments() { | ||
return delegate.getArguments(); | ||
} | ||
|
||
@Override | ||
public GradleRunner withArguments(List<String> arguments) { | ||
List<String> effectiveArgs = arguments; | ||
if (ccCompatible) { | ||
effectiveArgs = new ArrayList<>(arguments); | ||
effectiveArgs.add("--configuration-cache"); | ||
} | ||
delegate.withArguments(effectiveArgs); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner withArguments(String... arguments) { | ||
withArguments(List.of(arguments)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<? extends File> getPluginClasspath() { | ||
return delegate.getPluginClasspath(); | ||
} | ||
|
||
@Override | ||
public GradleRunner withPluginClasspath() throws InvalidPluginMetadataException { | ||
delegate.withPluginClasspath(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner withPluginClasspath(Iterable<? extends File> iterable) { | ||
delegate.withPluginClasspath(iterable); | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean isDebug() { | ||
return delegate.isDebug(); | ||
} | ||
|
||
@Override | ||
public GradleRunner withDebug(boolean b) { | ||
delegate.withDebug(b); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getEnvironment() { | ||
return delegate.getEnvironment(); | ||
} | ||
|
||
@Override | ||
public GradleRunner withEnvironment(Map<String, String> map) { | ||
delegate.withEnvironment(map); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner forwardStdOutput(Writer writer) { | ||
delegate.forwardStdOutput(writer); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner forwardStdError(Writer writer) { | ||
delegate.forwardStdOutput(writer); | ||
return this; | ||
} | ||
|
||
@Override | ||
public GradleRunner forwardOutput() { | ||
delegate.forwardOutput(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public BuildResult build() throws InvalidRunnerConfigurationException, UnexpectedBuildFailure { | ||
return delegate.build(); | ||
} | ||
|
||
@Override | ||
public BuildResult buildAndFail() throws InvalidRunnerConfigurationException, UnexpectedBuildSuccess { | ||
return delegate.buildAndFail(); | ||
} | ||
} |