forked from gradle/gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request gradle#20245 Capture updated system properties
- Loading branch information
Showing
27 changed files
with
2,447 additions
and
276 deletions.
There are no files selected for viewing
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
114 changes: 114 additions & 0 deletions
114
...ache/inputs/undeclared/SystemPropertyInstrumentationInDynamicGroovyIntegrationTest.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,114 @@ | ||
/* | ||
* 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.inputs.undeclared | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.configurationcache.AbstractConfigurationCacheIntegrationTest | ||
|
||
class SystemPropertyInstrumentationInDynamicGroovyIntegrationTest extends AbstractConfigurationCacheIntegrationTest { | ||
def "#method is instrumented in dynamic Groovy"() { | ||
def configurationCache = newConfigurationCacheFixture() | ||
|
||
given: | ||
// Why the separate plugin? The Project.getProperties() is available in the build.gradle as getProperties(). | ||
// Therefore, it is impossible to call System.getProperties() with static import there, and testing static | ||
// import is important because Groovy generates different code in this case. | ||
file("buildSrc/src/main/groovy/SomePlugin.groovy") << """ | ||
import ${Plugin.name} | ||
import ${Project.name} | ||
import static ${System.name}.clearProperty | ||
import static ${System.name}.getProperties | ||
import static ${System.name}.getProperty | ||
import static ${System.name}.setProperty | ||
class SomePlugin implements Plugin<Project> { | ||
void apply(Project project) { | ||
def returned = $method | ||
println("returned = \$returned") | ||
} | ||
} | ||
""" | ||
|
||
buildScript(""" | ||
apply plugin: SomePlugin | ||
""") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value") | ||
|
||
then: | ||
configurationCache.assertStateStored() | ||
outputContains("returned = some.value") | ||
problems.assertResultHasProblems(result) { | ||
withInput("Plugin class 'SomePlugin': system property 'some.property'") | ||
} | ||
|
||
where: | ||
method | _ | ||
"System.properties['some.property']" | _ | ||
"System.getProperties().get('some.property')" | _ | ||
"getProperties().get('some.property')" | _ | ||
"System.getProperty('some.property')" | _ | ||
"getProperty('some.property')" | _ | ||
"System.getProperty('some.property', 'default.value')" | _ | ||
"getProperty('some.property', 'default.value')" | _ | ||
"System.setProperty('some.property', 'new.value')" | _ | ||
"setProperty('some.property', 'new.value')" | _ | ||
"System.clearProperty('some.property')" | _ | ||
"clearProperty('some.property')" | _ | ||
} | ||
|
||
def "#setProperties is instrumented in dynamic Groovy"() { | ||
def configurationCache = newConfigurationCacheFixture() | ||
|
||
given: | ||
buildScript(""" | ||
import static ${System.name}.setProperties | ||
def newProps = new Properties() | ||
System.properties.forEach { k, v -> newProps[k] = v } | ||
newProps.replace("some.property", "new.value") | ||
${setProperties}(newProps) | ||
tasks.register("printProperty") { | ||
doLast { | ||
println("returned = \${System.getProperty("some.property")}") | ||
} | ||
} | ||
""") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value", "printProperty") | ||
|
||
then: | ||
configurationCache.assertStateStored() | ||
outputContains("returned = new.value") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value", "printProperty") | ||
|
||
then: | ||
configurationCache.assertStateLoaded() | ||
outputContains("returned = new.value") | ||
|
||
where: | ||
setProperties | _ | ||
"System.setProperties" | _ | ||
"setProperties" | _ | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...gurationcache/inputs/undeclared/SystemPropertyInstrumentationInJavaIntegrationTest.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,107 @@ | ||
/* | ||
* 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.inputs.undeclared | ||
|
||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.configurationcache.AbstractConfigurationCacheIntegrationTest | ||
|
||
class SystemPropertyInstrumentationInJavaIntegrationTest extends AbstractConfigurationCacheIntegrationTest { | ||
def "#method is instrumented in Java"() { | ||
def configurationCache = newConfigurationCacheFixture() | ||
|
||
given: | ||
file("buildSrc/src/main/java/SomePlugin.java") << """ | ||
import ${Plugin.name}; | ||
import ${Project.name}; | ||
public class SomePlugin implements Plugin<Project> { | ||
public void apply(Project project) { | ||
Object returned = $method; | ||
System.out.println("returned = " + returned); | ||
} | ||
} | ||
""" | ||
|
||
buildScript(""" | ||
apply plugin: SomePlugin | ||
""") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value") | ||
|
||
then: | ||
configurationCache.assertStateStored() | ||
outputContains("returned = some.value") | ||
problems.assertResultHasProblems(result) { | ||
withInput("Plugin class 'SomePlugin': system property 'some.property'") | ||
} | ||
|
||
where: | ||
method | _ | ||
"System.getProperties().get(\"some.property\")" | _ | ||
"System.getProperty(\"some.property\")" | _ | ||
"System.getProperty(\"some.property\", \"default.value\")" | _ | ||
"System.setProperty(\"some.property\", \"new.value\")" | _ | ||
"System.clearProperty(\"some.property\")" | _ | ||
} | ||
|
||
def "setProperties is instrumented in Java"() { | ||
def configurationCache = newConfigurationCacheFixture() | ||
|
||
given: | ||
file("buildSrc/src/main/java/SomePlugin.java") << """ | ||
import ${Plugin.name}; | ||
import ${Project.name}; | ||
import ${Properties.name}; | ||
public class SomePlugin implements Plugin<Project> { | ||
public void apply(Project project) { | ||
Properties newProps = new Properties(); | ||
System.getProperties().forEach(newProps::put); | ||
newProps.replace("some.property", "new.value"); | ||
System.setProperties(newProps); | ||
} | ||
} | ||
""" | ||
|
||
buildScript(""" | ||
apply plugin: SomePlugin | ||
tasks.register("printProperty") { | ||
doLast { | ||
println("returned = \${System.getProperty("some.property")}") | ||
} | ||
} | ||
""") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value", "printProperty") | ||
|
||
then: | ||
configurationCache.assertStateStored() | ||
outputContains("returned = new.value") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value", "printProperty") | ||
|
||
then: | ||
configurationCache.assertStateLoaded() | ||
outputContains("returned = new.value") | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...rationcache/inputs/undeclared/SystemPropertyInstrumentationInKotlinIntegrationTest.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,74 @@ | ||
/* | ||
* 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.inputs.undeclared | ||
|
||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.configurationcache.AbstractConfigurationCacheIntegrationTest | ||
|
||
class SystemPropertyInstrumentationInKotlinIntegrationTest extends AbstractConfigurationCacheIntegrationTest { | ||
def "#method is instrumented in Kotlin"() { | ||
def configurationCache = newConfigurationCacheFixture() | ||
|
||
given: | ||
// Why the separate plugin? The Project.getProperties() is available in the build.gradle.kts as getProperties(). | ||
file("buildSrc/src/main/kotlin/SomePlugin.kt") << """ | ||
import ${Plugin.name} | ||
import ${Project.name} | ||
class SomePlugin : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
val returned = $method | ||
println("returned = \$returned") | ||
} | ||
} | ||
""" | ||
|
||
file("buildSrc/build.gradle.kts") << """ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
""" | ||
|
||
buildScript(""" | ||
apply plugin: SomePlugin | ||
""") | ||
|
||
when: | ||
configurationCacheRun("-Dsome.property=some.value") | ||
|
||
then: | ||
configurationCache.assertStateStored() | ||
outputContains("returned = some.value") | ||
problems.assertResultHasProblems(result) { | ||
withInput("Plugin class 'SomePlugin': system property 'some.property'") | ||
ignoringUnexpectedInputs() | ||
} | ||
|
||
where: | ||
method | _ | ||
"System.getProperties().get(\"some.property\")" | _ | ||
"System.getProperty(\"some.property\")" | _ | ||
"System.getProperty(\"some.property\", \"default.value\")" | _ | ||
"System.setProperty(\"some.property\", \"new.value\")" | _ | ||
"System.clearProperty(\"some.property\")" | _ | ||
} | ||
} |
Oops, something went wrong.