-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Gradle plugin for setup gradle test security policies (#76167)
Test execution hangs when building Elasticsearch plugins and extending ESTestCase fixes #76136
- Loading branch information
Showing
9 changed files
with
113 additions
and
15 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
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
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
63 changes: 63 additions & 0 deletions
63
...integTest/groovy/org/elasticsearch/gradle/test/GradleTestPolicySetupPluginFuncTest.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,63 @@ | ||
/* | ||
* 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.test | ||
|
||
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
class GradleTestPolicySetupPluginFuncTest extends AbstractGradleFuncTest { | ||
|
||
def "configures test tasks"() { | ||
given: | ||
file("src/test/java/org/acme/SysPropTest.java") << """ | ||
package org.acme; | ||
import static org.junit.Assert.*; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
public class SysPropTest { | ||
@Test | ||
public void verifySysProps() { | ||
assertNotNull(System.getProperty("gradle.dist.lib")); | ||
assertNotNull(System.getProperty("gradle.worker.jar")); | ||
assertEquals(System.getProperty("tests.gradle"), "true"); | ||
assertEquals(System.getProperty("tests.task"), ":test"); | ||
} | ||
} | ||
""" | ||
|
||
buildFile << """ | ||
plugins { | ||
id "elasticsearch.test-gradle-policy" | ||
id "java" | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
testImplementation "junit:junit:4.13" | ||
} | ||
""" | ||
|
||
when: | ||
def result = gradleRunner('test', '-g', "guh1").build() | ||
|
||
then: | ||
result.task(":test").outcome == TaskOutcome.SUCCESS | ||
|
||
when: // changing gradle user home | ||
result = gradleRunner('test', '-g', "guh2").build() | ||
then: // still up-to-date | ||
result.task(":test").outcome == TaskOutcome.UP_TO_DATE | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
build-tools/src/main/java/org/elasticsearch/gradle/test/GradleTestPolicySetupPlugin.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,35 @@ | ||
/* | ||
* 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.test; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.invocation.Gradle; | ||
import org.gradle.api.tasks.testing.Test; | ||
|
||
public class GradleTestPolicySetupPlugin implements Plugin<Project> { | ||
|
||
@Override | ||
public void apply(Project project) { | ||
Gradle gradle = project.getGradle(); | ||
project.getTasks().withType(Test.class).configureEach(test -> { | ||
test.systemProperty("tests.gradle", true); | ||
test.systemProperty("tests.task", test.getPath()); | ||
|
||
SystemPropertyCommandLineArgumentProvider nonInputProperties = new SystemPropertyCommandLineArgumentProvider(); | ||
// don't track these as inputs since they contain absolute paths and break cache relocatability | ||
nonInputProperties.systemProperty("gradle.dist.lib", gradle.getGradleHomeDir().getAbsolutePath() + "/lib"); | ||
nonInputProperties.systemProperty( | ||
"gradle.worker.jar", | ||
gradle.getGradleUserHomeDir().getAbsolutePath() + "/caches/" + gradle.getGradleVersion() + "/workerMain/gradle-worker.jar" | ||
); | ||
test.getJvmArgumentProviders().add(nonInputProperties); | ||
}); | ||
} | ||
} |
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