This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 7a9ce356bc7 Gradle optimizations (#1319)
7a9ce356bc7 is described below
commit 7a9ce356bc7c90c8237437b1e16ed030e4d67900
Author: Tyler Bertrand <[email protected]>
AuthorDate: Mon Feb 6 11:17:02 2023 -0600
Gradle optimizations (#1319)
* Defined inputs and outputs for task validateJarLicenses
* Move functionality from copyTestResources task into processTestResources
task
* Resolves "overlapping output" issue preventing processTestResources from
being cached
* Provide system properties from CommandLineArgumentProviders
* Configures 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
* Apply relative pathing to inputs
* Lazily configure processTestResources and validateJarLicenses
---
gradle/documentation/render-javadoc.gradle | 8 ++---
gradle/java/folder-layout.gradle | 4 +--
gradle/testing/defaults-tests.gradle | 30 +++++++++++++++----
gradle/testing/randomization.gradle | 36 +++++++++++++++++------
gradle/validation/jar-checks.gradle | 12 ++++++--
gradle/validation/validate-log-calls.gradle | 1 +
gradle/validation/validate-source-patterns.gradle | 1 +
solr/modules/hadoop-auth/build.gradle | 4 +--
solr/modules/hdfs/build.gradle | 4 +--
solr/modules/sql/build.gradle | 4 +--
solr/solr-ref-guide/build.gradle | 4 +--
11 files changed, 77 insertions(+), 31 deletions(-)
diff --git a/gradle/documentation/render-javadoc.gradle
b/gradle/documentation/render-javadoc.gradle
index deb763c7b27..f39f53e53da 100644
--- a/gradle/documentation/render-javadoc.gradle
+++ b/gradle/documentation/render-javadoc.gradle
@@ -49,7 +49,7 @@ allprojects {
description "Generates Javadoc API documentation for each module. This
directly invokes javadoc tool."
group "documentation"
- taskResources = resources
+ taskResources = project.relativePath(resources)
dependsOn sourceSets.main.compileClasspath
classpath = sourceSets.main.compileClasspath
srcDirSet = sourceSets.main.java
@@ -61,7 +61,7 @@ allprojects {
description "Generates Javadoc API documentation for the site (relative
links)."
group "documentation"
- taskResources = resources
+ taskResources = project.relativePath(resources)
dependsOn sourceSets.main.compileClasspath
classpath = sourceSets.main.compileClasspath;
srcDirSet = sourceSets.main.java;
@@ -85,8 +85,8 @@ allprojects {
title = "Solr ${project.version} ${project.name} API"
offlineLinks += [
- "https://docs.oracle.com/en/java/javase/11/docs/api/":
javaJavadocPackages,
- "https://junit.org/junit4/javadoc/4.12/": junitJavadocPackages
+ "https://docs.oracle.com/en/java/javase/11/docs/api/":
project.relativePath(javaJavadocPackages),
+ "https://junit.org/junit4/javadoc/4.12/":
project.relativePath(junitJavadocPackages)
]
solrDocUrl = provider({ rootProject.solrDocUrl })
diff --git a/gradle/java/folder-layout.gradle b/gradle/java/folder-layout.gradle
index b4c5fcf471a..7b7163da1dc 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 7eec42b4f93..ea2addff4d7 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
],
@@ -66,8 +66,6 @@ allprojects {
testsCwd = file("${buildDir}/tmp/tests-cwd")
testsTmpDir = file(resolvedTestOption("tests.workDir"))
-
- commonSolrDir = project(":solr").projectDir
}
def verboseMode = resolvedTestOption("tests.verbose").toBoolean()
@@ -121,7 +119,13 @@ allprojects {
jvmArgs '--illegal-access=deny'
}
- systemProperty 'java.util.logging.config.file',
file("${resources}/logging.properties")
+ jvmArgumentProviders.add(
+ new LoggingFileArgumentProvider(
+ loggingConfigFile: file("${resources}/logging.properties"),
+ tempDir: testsTmpDir
+ )
+ )
+
systemProperty 'java.awt.headless', 'true'
systemProperty 'jdk.map.althashing.threshold', '0'
@@ -142,7 +146,6 @@ allprojects {
// Set up cwd and temp locations.
systemProperty("java.io.tmpdir", testsTmpDir)
- systemProperty("tempDir", testsTmpDir)
doFirst {
testsCwd.mkdirs()
testsTmpDir.mkdirs()
@@ -179,3 +182,20 @@ allprojects {
}
}
}
+
+class LoggingFileArgumentProvider implements CommandLineArgumentProvider {
+ @InputFile
+ @PathSensitive(PathSensitivity.RELATIVE)
+ File loggingConfigFile
+
+ @Internal
+ File tempDir
+
+ @Override
+ Iterable<String> asArguments() {
+ [
+ "-Djava.util.logging.config.file=$loggingConfigFile",
+ "-DtempDir=$tempDir"
+ ]
+ }
+}
diff --git a/gradle/testing/randomization.gradle
b/gradle/testing/randomization.gradle
index 51a2652e98c..0a4839194fc 100644
--- a/gradle/testing/randomization.gradle
+++ b/gradle/testing/randomization.gradle
@@ -34,6 +34,28 @@ buildscript {
}
}
+class SecurityArgumentProvider implements CommandLineArgumentProvider {
+ @Internal
+ File commonSolrDir
+
+ @InputFile
+ @PathSensitive(PathSensitivity.RELATIVE)
+ File javaSecurityPolicy
+
+ SecurityArgumentProvider(File commonSolrDir, File javaSecurityPolicy) {
+ this.commonSolrDir = commonSolrDir
+ this.javaSecurityPolicy = javaSecurityPolicy
+ }
+
+ @Override
+ Iterable<String> asArguments() {
+ [
+ "-Dcommon-solr.dir=$commonSolrDir",
+ "-Djava.security.policy=$javaSecurityPolicy"
+ ]
+ }
+}
+
def resources = scriptResources(buildscript)
// Pick the "root" seed from which everything else is derived.
@@ -109,11 +131,6 @@ configure(allprojects.findAll {project ->
project.path.startsWith(":solr") }) {
plugins.withType(JavaPlugin) {
ext {
testOptions += [
- [propName: 'common-solr.dir',
- value: project(":solr").projectDir,
- description: "Solr base dir.",
- includeInReproLine: false
- ],
[propName: 'solr.directoryFactory', value:
"org.apache.solr.core.MockDirectoryFactory", description: "Solr directory
factory."],
[propName: 'tests.src.home', value: null, description: "See
SOLR-14023."],
[propName: 'solr.tests.use.numeric.points', value: null,
description: "Point implementation to use (true=numerics, false=trie)."],
@@ -176,7 +193,7 @@ allprojects {
if (Boolean.parseBoolean(testOptionsResolved["tests.failfast"])) {
failFast true
}
-
+
// The Lucene version is only available after resolving was done, so
add lately using a provider:
jvmArgumentProviders.add({
def luceneMatchVersion = rootProject.luceneBaseVersionProvider.get()
@@ -185,13 +202,14 @@ allprojects {
"-Dtests.luceneMatchVersion=${luceneMatchVersion}",
]
} as CommandLineArgumentProvider)
-
+
// 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.
if
(Boolean.parseBoolean(testOptionsResolved["tests.useSecurityManager"])) {
- systemProperty 'common-solr.dir', commonSolrDir
+ def commonSolrDir = project(":solr").projectDir
+ def javaSecurityPolicy =
file("${resources}/policies/solr-tests.policy")
+ jvmArgumentProviders.add(new SecurityArgumentProvider(commonSolrDir,
javaSecurityPolicy))
systemProperty 'java.security.manager',
"org.apache.lucene.tests.util.TestSecurityManager"
- systemProperty 'java.security.policy',
file("${resources}/policies/solr-tests.policy")
def gradleUserHome = project.gradle.getGradleUserHomeDir()
systemProperty 'gradle.lib.dir',
Paths.get(project.class.location.toURI()).parent.toAbsolutePath().toString().replace('\\',
'/')
diff --git a/gradle/validation/jar-checks.gradle
b/gradle/validation/jar-checks.gradle
index cd8dd9cf656..da555ce9165 100644
--- a/gradle/validation/jar-checks.gradle
+++ b/gradle/validation/jar-checks.gradle
@@ -198,11 +198,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 + '/solr/licenses'))
+ .withPropertyName('licenses')
+ .withPathSensitivity(PathSensitivity.RELATIVE)
+ outputs.file(layout.buildDirectory.file(outputFileName))
+ .withPropertyName('validateJarLicensesResult')
+
doLast {
def errors = []
jarInfos.each { dep ->
@@ -248,7 +255,8 @@ subprojects {
}
}
}
-
+ def f = new File(project.buildDir.path + "/" + outputFileName)
+ f.text = errors
if (errors) {
def msg = "Certain license/ notice files are missing:\n - " +
errors.join("\n - ")
if (failOnError) {
diff --git a/gradle/validation/validate-log-calls.gradle
b/gradle/validation/validate-log-calls.gradle
index 6dc6c720113..fb1a81c5403 100644
--- a/gradle/validation/validate-log-calls.gradle
+++ b/gradle/validation/validate-log-calls.gradle
@@ -218,6 +218,7 @@ class ValidateLogCallsTask extends DefaultTask {
}
@InputFiles
+ @PathSensitive(PathSensitivity.RELATIVE)
FileCollection sourceFiles
@TaskAction
diff --git a/gradle/validation/validate-source-patterns.gradle
b/gradle/validation/validate-source-patterns.gradle
index d1756ff7d9c..eb178fb7220 100644
--- a/gradle/validation/validate-source-patterns.gradle
+++ b/gradle/validation/validate-source-patterns.gradle
@@ -126,6 +126,7 @@ class ValidateSourcePatternsTask extends DefaultTask {
private ProgressLoggerFactory progressLoggerFactory
@InputFiles
+ @PathSensitive(PathSensitivity.RELATIVE)
FileTree sourceFiles
@Inject
diff --git a/solr/modules/hadoop-auth/build.gradle
b/solr/modules/hadoop-auth/build.gradle
index 07867619401..6f0af582dbd 100644
--- a/solr/modules/hadoop-auth/build.gradle
+++ b/solr/modules/hadoop-auth/build.gradle
@@ -111,13 +111,13 @@ dependencies {
// of the Hadoop Authentication module so we can avoid duplication of the test
// resource files like schemas and SolrConfigs. This can be improved later by
making
// the test classes load the resources from core directories directly.
-task copySolrCoreTestResources(type: Copy) {
+tasks.register('copySolrCoreTestResources', Copy) {
from(project(':solr:core').sourceSets.test.resources.srcDirs) {
exclude '**/*.java'
}
into sourceSets.test.output.resourcesDir
}
-tasks.processTestResources.configure {
+tasks.named('processTestResources').configure {
dependsOn copySolrCoreTestResources
}
diff --git a/solr/modules/hdfs/build.gradle b/solr/modules/hdfs/build.gradle
index 8bc28f4975f..ad05e9bcd25 100644
--- a/solr/modules/hdfs/build.gradle
+++ b/solr/modules/hdfs/build.gradle
@@ -77,14 +77,14 @@ dependencies {
// of the HDFS module so we can avoid duplication of the test resource files
like
// schemas and SolrConfigs. This can be improved later by making the test
classes
// load the resources from core directories directly.
-task copySolrCoreTestResources(type: Copy) {
+tasks.register('copySolrCoreTestResources', Copy) {
from(project(':solr:core').sourceSets.test.resources.srcDirs) {
exclude '**/*.java'
}
into sourceSets.test.output.resourcesDir
}
-tasks.processTestResources.configure {
+tasks.named('processTestResources').configure {
dependsOn copySolrCoreTestResources
}
diff --git a/solr/modules/sql/build.gradle b/solr/modules/sql/build.gradle
index 45695e1dc22..b1053fad1b3 100644
--- a/solr/modules/sql/build.gradle
+++ b/solr/modules/sql/build.gradle
@@ -58,13 +58,13 @@ dependencies {
// of the SQL module so we can avoid duplication of the test resource files
like
// schemas and SolrConfigs. This can be improved later by making the test
classes
// load the resources from core directories directly.
-task copySolrCoreTestResources(type: Copy) {
+tasks.register('copySolrCoreTestResources', Copy) {
from(project(':solr:core').sourceSets.test.resources.srcDirs) {
exclude '**/*.java'
}
into sourceSets.test.output.resourcesDir
}
-tasks.processTestResources.configure {
+tasks.named('processTestResources').configure {
dependsOn copySolrCoreTestResources
}
diff --git a/solr/solr-ref-guide/build.gradle b/solr/solr-ref-guide/build.gradle
index f6fac9d98bf..46588291da4 100644
--- a/solr/solr-ref-guide/build.gradle
+++ b/solr/solr-ref-guide/build.gradle
@@ -535,13 +535,13 @@ dependencies {
// Copy all the test resource files from SolrJ to the build/resources/test
directory
// of the examples so we can avoid duplication of the test resource files like
// schemas and SolrConfigs.
-task copySolrjTestResources(type: Copy) {
+tasks.register('copySolrjTestResources', Copy) {
from(project(':solr:solrj').sourceSets.test.resources.srcDirs) {
exclude '**/*.java'
}
into sourceSets.test.output.resourcesDir
}
-tasks.processTestResources.configure {
+tasks.named('processTestResources').configure {
dependsOn copySolrjTestResources
}