You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2023/03/06 18:26:56 UTC
[lucene] branch branch_9x updated: Gradle optimizations (#12150)
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 4a5cacf06ec Gradle optimizations (#12150)
4a5cacf06ec is described below
commit 4a5cacf06ec1da58aabfa46a83c04aa0b0bebab9
Author: Tyler Bertrand <12...@users.noreply.github.com>
AuthorDate: Mon Mar 6 12:17:37 2023 -0600
Gradle optimizations (#12150)
* Define inputs and outputs for task validateJarLicenses
* Lazily configure validateJarLicenses
* Move functionality from copyTestResources task into processTestResources task
* Lazily configure processTestResources
* Altered TestCustomAnalyzer.testStopWordsFromFile() to find resources in updated location
* Resolve "overlapping output" issue preventing processTestResources from being cached
* Provide system properties from CommandLineArgumentProviders
* Configure certain system properties as inputs to take advantage of UP-TO-DATE checking
* Applies the correct pathing strategies to take full advantage of caching even if builds are executed from different locations on disk
* Make validateSourcePatterns task cacheable by removing .gradle directory from its input
---
gradle/java/folder-layout.gradle | 4 +--
gradle/testing/defaults-tests.gradle | 30 +++++++++++++++++++---
gradle/testing/randomization.gradle | 27 ++++++++++++++++---
gradle/validation/jar-checks.gradle | 13 ++++++++--
gradle/validation/validate-source-patterns.gradle | 5 +---
.../lucene/analysis/custom/TestCustomAnalyzer.java | 8 +++++-
6 files changed, 70 insertions(+), 17 deletions(-)
diff --git a/gradle/java/folder-layout.gradle b/gradle/java/folder-layout.gradle
index 8b21f81b479..bc3da14a088 100644
--- a/gradle/java/folder-layout.gradle
+++ b/gradle/java/folder-layout.gradle
@@ -25,13 +25,11 @@ allprojects {
test.resources.srcDirs = ['src/test-files']
}
- task copyTestResources(type: Copy) {
+ tasks.named('processTestResources').configure {
from('src/test') {
exclude '**/*.java'
}
- into sourceSets.test.java.classesDirectory
}
- processTestResources.dependsOn copyTestResources
// if 'src/tools' exists, add it as a separate sourceSet.
if (file('src/tools/java').exists()) {
diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradle
index d23fcdc267a..9f50cda8ca7 100644
--- a/gradle/testing/defaults-tests.gradle
+++ b/gradle/testing/defaults-tests.gradle
@@ -34,7 +34,7 @@ allprojects {
// asserts, debug output.
[propName: 'tests.verbose', value: false, description: "Enables verbose mode (emits full test outputs immediately)."],
[propName: 'tests.workDir',
- value: { -> file("${buildDir}/tmp/tests-tmp") },
+ value: { -> project.relativePath(file("${buildDir}/tmp/tests-tmp")) },
description: "Working directory for forked test JVMs",
includeInReproLine: false
],
@@ -124,7 +124,15 @@ allprojects {
// (if the runner JVM does not support them, it will fail tests):
jvmArgs '--add-modules', 'jdk.unsupported,jdk.management'
- systemProperty 'java.util.logging.config.file', file("${resources}/logging.properties")
+ def loggingConfigFile = layout.projectDirectory.file("${resources}/logging.properties")
+ def tempDir = layout.projectDirectory.dir(testsTmpDir.toString())
+ jvmArgumentProviders.add(
+ new LoggingFileArgumentProvider(
+ loggingConfigFile: loggingConfigFile,
+ tempDir: tempDir
+ )
+ )
+
systemProperty 'java.awt.headless', 'true'
systemProperty 'jdk.map.althashing.threshold', '0'
@@ -145,7 +153,6 @@ allprojects {
// Set up cwd and temp locations.
systemProperty("java.io.tmpdir", testsTmpDir)
- systemProperty("tempDir", testsTmpDir)
doFirst {
testsCwd.mkdirs()
testsTmpDir.mkdirs()
@@ -189,3 +196,20 @@ allprojects {
}
}
}
+
+class LoggingFileArgumentProvider implements CommandLineArgumentProvider {
+ @InputFile
+ @PathSensitive(PathSensitivity.RELATIVE)
+ RegularFile loggingConfigFile
+
+ @Internal
+ Directory tempDir
+
+ @Override
+ Iterable<String> asArguments() {
+ [
+ "-Djava.util.logging.config.file=${loggingConfigFile.getAsFile()}",
+ "-DtempDir=${tempDir.getAsFile()}"
+ ]
+ }
+}
diff --git a/gradle/testing/randomization.gradle b/gradle/testing/randomization.gradle
index aa5125fe2cb..e4b395b1019 100644
--- a/gradle/testing/randomization.gradle
+++ b/gradle/testing/randomization.gradle
@@ -167,18 +167,18 @@ allprojects {
// Enable security manager, if requested. We could move the selection of security manager and security policy
// to each project's build/ configuration but it seems compact enough to keep it here for now.
+ def securityArgumentProvider = new SecurityArgumentProvider(commonDir: project(":lucene").layout.projectDirectory)
if (Boolean.parseBoolean(testOptionsResolved["tests.useSecurityManager"])) {
if (project.path.endsWith(".tests")) {
// LUCENE-10301: for now, do not use the security manager for modular tests (test framework is not available).
} else if (project.path == ":lucene:replicator") {
systemProperty 'java.security.manager', "org.apache.lucene.tests.util.TestSecurityManager"
- systemProperty 'java.security.policy', file("${resources}/policies/replicator-tests.policy")
+ securityArgumentProvider.javaSecurityPolicy = layout.projectDirectory.file("${resources}/policies/replicator-tests.policy")
} else if (project.path.startsWith(":lucene")) {
systemProperty 'java.security.manager', "org.apache.lucene.tests.util.TestSecurityManager"
- systemProperty 'java.security.policy', file("${resources}/policies/tests.policy")
+ securityArgumentProvider.javaSecurityPolicy = layout.projectDirectory.file("${resources}/policies/tests.policy")
}
-
- systemProperty 'common.dir', commonDir
+ jvmArgumentProviders.add(securityArgumentProvider)
def gradleUserHome = project.gradle.getGradleUserHomeDir()
systemProperty 'gradle.lib.dir', Paths.get(project.class.location.toURI()).parent.toAbsolutePath().toString().replace('\\', '/')
@@ -227,3 +227,22 @@ allprojects {
}
}
}
+
+class SecurityArgumentProvider implements CommandLineArgumentProvider {
+ @Internal
+ Directory commonDir
+
+ @InputFile
+ @Optional
+ @PathSensitive(PathSensitivity.RELATIVE)
+ RegularFile javaSecurityPolicy
+
+ @Override
+ Iterable<String> asArguments() {
+ def args = ["-Dcommon.dir=${commonDir.getAsFile()}"]
+ if (javaSecurityPolicy) {
+ args.add("-Djava.security.policy=${javaSecurityPolicy.getAsFile()}")
+ }
+ return args
+ }
+}
diff --git a/gradle/validation/jar-checks.gradle b/gradle/validation/jar-checks.gradle
index 9741656d2b0..90cf31e92bb 100644
--- a/gradle/validation/jar-checks.gradle
+++ b/gradle/validation/jar-checks.gradle
@@ -181,11 +181,18 @@ subprojects {
// where 'jar-or-prefix' can be any '-'-delimited prefix of the dependency JAR's name.
// So for 'commons-io' it can be 'commons-io-LICENSE-foo.txt' or
// 'commons-LICENSE.txt'
- task validateJarLicenses() {
+ tasks.register('validateJarLicenses') {
group = 'Dependency validation'
description = "Validate license and notice files of dependencies"
dependsOn collectJarInfos
+ def outputFileName = 'validateJarLicenses'
+ inputs.dir(file(project.rootDir.path + '/lucene/licenses'))
+ .withPropertyName('licenses')
+ .withPathSensitivity(PathSensitivity.RELATIVE)
+ outputs.file(layout.buildDirectory.file(outputFileName))
+ .withPropertyName('validateJarLicensesResult')
+
doLast {
def errors = []
jarInfos.each { dep ->
@@ -231,7 +238,9 @@ subprojects {
}
}
}
-
+ // Required to take advantage of incremental building and the build cache
+ def f = new File(project.buildDir.path + "/" + outputFileName)
+ f.write(errors.toString(), "UTF-8")
if (errors) {
def msg = "Certain license/ notice files are missing:\n - " + errors.join("\n - ")
if (failOnError) {
diff --git a/gradle/validation/validate-source-patterns.gradle b/gradle/validation/validate-source-patterns.gradle
index 1300d63f756..b1121ccbb50 100644
--- a/gradle/validation/validate-source-patterns.gradle
+++ b/gradle/validation/validate-source-patterns.gradle
@@ -80,14 +80,11 @@ allprojects {
// default excludes.
exclude '**/build/**'
exclude '**/.idea/**'
+ exclude '**/.gradle/**'
if (project == rootProject) {
// ourselves :-)
exclude 'gradle/validation/validate-source-patterns.gradle'
-
- // gradle and idea folders.
- exclude '.gradle/**'
- exclude '.idea/**'
} else {
// ignore txt files in source resources and tests.
exclude 'src/**/*.txt'
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/custom/TestCustomAnalyzer.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/custom/TestCustomAnalyzer.java
index a65ff284c13..e8afbba095b 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/custom/TestCustomAnalyzer.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/custom/TestCustomAnalyzer.java
@@ -266,7 +266,13 @@ public class TestCustomAnalyzer extends BaseTokenStreamTestCase {
CustomAnalyzer.builder(this.getDataPath(""))
.withTokenizer("whitespace")
.addTokenFilter(
- "stop", "ignoreCase", "true", "words", "teststop.txt", "format", "wordset")
+ "stop",
+ "ignoreCase",
+ "true",
+ "words",
+ this.getDataPath("teststop.txt").toString(),
+ "format",
+ "wordset")
.build();
assertAnalyzesTo(a, "foo Foo Bar", new String[0]);
a.close();