org.gradle.configurationcache.AbstractConfigurationCacheProcessInstrumentationIntegrationTest.groovy Maven / Gradle / Ivy
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.configurationcache
import org.gradle.process.ShellScript
abstract class AbstractConfigurationCacheProcessInstrumentationIntegrationTest extends AbstractConfigurationCacheIntegrationTest {
// Note that all tests use a relative path to the script because its absolute path may contain
// spaces and it breaks logic String.execute which splits the given string at spaces without
// any options to escape the space.
ShellScript baseScript = ShellScript.builder().printEnvironmentVariable('FOOBAR').printWorkingDir().writeTo(testDirectory, "test")
def setup() {
testDirectory.createDir(pwd)
settingsFile("enableFeaturePreview('STABLE_CONFIGURATION_CACHE')")
}
static String getPwd() {
return "tmp"
}
abstract static class VarInitializer {
final String description
VarInitializer(String description) {
this.description = description
}
String getGroovy(List cmd) {
throw new UnsupportedOperationException()
}
String getJava(List cmd) {
throw new UnsupportedOperationException()
}
String getKotlin(List cmd) {
throw new UnsupportedOperationException()
}
@Override
String toString() {
return description
}
}
static VarInitializer fromString() {
return new VarInitializer("String") {
@Override
String getGroovy(List cmd) {
return """String command = ${ShellScript.cmdToStringLiteral(cmd)} """
}
@Override
String getJava(List cmd) {
return """String command = ${ShellScript.cmdToStringLiteral(cmd)};"""
}
@Override
String getKotlin(List cmd) {
return """val command = ${ShellScript.cmdToStringLiteral(cmd)} """
}
}
}
static VarInitializer fromGroovyString() {
return new VarInitializer("GString") {
@Override
String getGroovy(List cmd) {
return """
String rawCommand = ${ShellScript.cmdToStringLiteral(cmd)}
def command = "\${rawCommand.toString()}"
"""
}
}
}
static VarInitializer fromStringArray() {
return new VarInitializer("String[]") {
@Override
String getGroovy(List cmd) {
return """String[] command = [${ShellScript.cmdToVarargLiterals(cmd)}]"""
}
@Override
String getJava(List cmd) {
return """String[] command = new String[] { ${ShellScript.cmdToVarargLiterals(cmd)} };"""
}
@Override
String getKotlin(List cmd) {
return """val command = arrayOf(${ShellScript.cmdToVarargLiterals(cmd)}) """
}
}
}
static VarInitializer fromStringList() {
return new VarInitializer("List") {
@Override
String getGroovy(List cmd) {
return """
def command = [${ShellScript.cmdToVarargLiterals(cmd)}]
"""
}
@Override
String getJava(List cmd) {
return """
List command = Arrays.asList(${ShellScript.cmdToVarargLiterals(cmd)});
"""
}
@Override
String getKotlin(List cmd) {
return """
val command = listOf(${ShellScript.cmdToVarargLiterals(cmd)})
"""
}
}
}
static VarInitializer fromObjectList() {
return new VarInitializer("List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy