
org.gradle.ide.fixtures.IdeCommandLineUtil.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2018 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.ide.fixtures
import com.google.common.collect.Maps
import groovy.transform.CompileStatic
import org.gradle.api.Transformer
import org.gradle.test.fixtures.file.TestFile
import org.gradle.util.CollectionUtils
import org.gradle.util.GUtil
@CompileStatic
abstract class IdeCommandLineUtil {
private IdeCommandLineUtil() {}
static String generateGradleProbeInitFile(String ideTaskName, String ideCommandLineTool) {
return """
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS_FULL
Properties gatherEnvironment() {
Properties properties = new Properties()
properties.JAVA_HOME = String.valueOf(System.getenv('JAVA_HOME'))
properties.GRADLE_USER_HOME = String.valueOf(gradle.gradleUserHomeDir.absolutePath)
properties.GRADLE_OPTS = String.valueOf(System.getenv('GRADLE_OPTS'))
return properties
}
void assertEquals(key, expected, actual) {
assert expected[key] == actual[key]
if (expected[key] != actual[key]) {
throw new GradleException(""\"
Environment's \$key did not match!
Expected: \${expected[key]}
Actual: \${actual[key]}
""\")
}
}
rootProject {
def gradleEnvironment = file("gradle-environment")
tasks.matching { it.name == '$ideTaskName' }.all { ideTask ->
ideTask.doLast {
def writer = gradleEnvironment.newOutputStream()
gatherEnvironment().store(writer, null)
writer.close()
}
}
gradle.buildFinished {
if (!gradleEnvironment.exists()) {
throw new GradleException("could not determine if $ideCommandLineTool is using the correct environment, did $ideTaskName task run?")
} else {
def expectedEnvironment = new Properties()
expectedEnvironment.load(gradleEnvironment.newInputStream())
def actualEnvironment = gatherEnvironment()
assertEquals('JAVA_HOME', expectedEnvironment, actualEnvironment)
assertEquals('GRADLE_USER_HOME', expectedEnvironment, actualEnvironment)
assertEquals('GRADLE_OPTS', expectedEnvironment, actualEnvironment)
}
}
}
"""
}
static List buildEnvironment(TestFile testDirectory) {
Map envvars = Maps.newHashMap()
envvars.putAll(System.getenv())
Properties props = GUtil.loadProperties(testDirectory.file("gradle-environment"))
assert !props.isEmpty()
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy