Skip to content

Commit

Permalink
Move buildSrc into a composite included build
Browse files Browse the repository at this point in the history
Move buildSrc into a composite included build (build-infra). Expose a plugin with buildinfra extension.

See apache/lucene@4afae6a
  • Loading branch information
malliaridis committed Jul 19, 2024
1 parent edce618 commit 06582e7
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 56 deletions.
25 changes: 21 additions & 4 deletions buildSrc/build.gradle → build-tools/build-infra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,34 @@
* limitations under the License.
*/

plugins {
id "java-gradle-plugin"
}

repositories {
mavenCentral()
}

ext {
// Minimum Java version required to compile buildSrc.
minJavaVersion = JavaVersion.VERSION_11
group = "org.apache"

gradlePlugin {
automatedPublishing = false

plugins {
buildInfra {
id = 'solr.build-infra'
implementationClass = 'org.apache.lucene.gradle.buildinfra.BuildInfraPlugin'
}
}
}

// Make sure the build environment is consistent.
apply from: file('../gradle/validation/check-environment.gradle')
apply from: file('../../gradle/validation/check-environment.gradle')

java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.minJava.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.minJava.get())
}

dependencies {
implementation gradleApi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* limitations under the License.
*/

// Use project's version catalog for centralized dependency management for
// buildSrc scripts too
rootProject.name = 'build-infra'

// Use project's version catalog for centralized dependency management
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
from(files("../../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class Checksum extends DefaultTask {
private FileCollection files;
private File outputDir;
private Algorithm algorithm;
private Algorithm algorithm = Checksum.Algorithm.SHA512;

public enum Algorithm {
MD5(new DigestUtils(DigestUtils.getMd5Digest())),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.lucene.gradle.buildinfra;

import org.apache.lucene.gradle.Checksum;
import org.apache.lucene.gradle.ProfileResults;
import org.apache.lucene.gradle.ErrorReportingTestListener;
import org.gradle.api.tasks.testing.TestDescriptor;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.testing.logging.TestLogging;
import java.nio.file.Path;
import org.apache.commons.codec.digest.DigestUtils;

public class BuildInfraPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project
.getExtensions()
.create(
BuildInfraExtension.NAME,
BuildInfraExtension.class);
}

public static class BuildInfraExtension {
public static final String NAME = "buildinfra";

public ErrorReportingTestListener newErrorReportingTestListener(TestLogging testLogging, Path spillDir, Path outputsDir, boolean verboseMode) {
return new ErrorReportingTestListener(testLogging, spillDir, outputsDir, verboseMode);
}

public DigestUtils sha1Digest() {
return new DigestUtils(DigestUtils.getSha1Digest());
}

public String getOutputLogName(TestDescriptor suite) {
return ErrorReportingTestListener.getOutputLogName(suite);
}

public Class<?> checksumClass() {
return Checksum.class;
}

public Class<?> profileResultsClass() {
return ProfileResults.class;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ version = "1.0.0-SNAPSHOT"
group = "org.apache.solr.tools"
description = 'Doclet-based javadoc validation'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.minJava.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.minJava.get())
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ["--release", targetCompatibility.toString()]
options.encoding = "UTF-8"
}
27 changes: 27 additions & 0 deletions build-tools/missing-doclet/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

rootProject.name = "missing-doclet"

// Use project's version catalog for centralized dependency management
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../gradle/libs.versions.toml"))
}
}
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import java.time.format.DateTimeFormatter

plugins {
id 'base'
id 'solr.build-infra'

alias(libs.plugins.carrotsearch.dependencychecks)
alias(libs.plugins.owasp.dependencycheck)
alias(libs.plugins.cutterslade.analyze)
Expand Down
1 change: 0 additions & 1 deletion dev-tools/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ as to the usefulness of the tools.

Description of dev-tools/ contents:

./missing-doclet -- JavaDoc validation doclet subproject
./doap/ -- Lucene and Solr project descriptors in DOAP RDF format.
./scripts/ -- Odds and ends for building releases, etc.
./test-patch/ -- Scripts for automatically validating patches
18 changes: 0 additions & 18 deletions dev-tools/solr-missing-doclet/settings.gradle

This file was deleted.

7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

[versions]

# @keep This is the minimum required Java version.
minJava = "11"
# @keep Gradle version to run the build
gradle = "8.4"

adobe-testing-s3mock = "2.17.0"
amazon-awssdk = "2.20.155"
antora = "3.1.4"
Expand Down Expand Up @@ -83,6 +88,8 @@ google-cloud-nio = "0.127.3"
google-cloud-storage = "2.27.0"
google-errorprone = "2.23.0"
google-guava = "32.1.3-jre"
# @keep This is GJF version for spotless/ tidy.
google-javaformat = "1.18.1"
google-re2j = "1.7"
grpc = "1.61.1"
gulp-cli = "2.3.0"
Expand Down
3 changes: 1 addition & 2 deletions gradle/testing/defaults-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.types.Commandline
import org.gradle.api.tasks.testing.logging.*
import org.apache.lucene.gradle.ErrorReportingTestListener

def resources = scriptResources(buildscript)
def verboseModeHookInstalled = false
Expand Down Expand Up @@ -173,7 +172,7 @@ allprojects {
}

def spillDir = getTemporaryDir().toPath()
def listener = new ErrorReportingTestListener(test.testLogging, spillDir, testOutputsDir.toPath(), verboseMode)
def listener = buildinfra.newErrorReportingTestListener(test.testLogging, spillDir, testOutputsDir.toPath(), verboseMode)
addTestOutputListener(listener)
addTestListener(listener)

Expand Down
4 changes: 1 addition & 3 deletions gradle/testing/failed-tests-at-end.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

import org.apache.lucene.gradle.ErrorReportingTestListener

// Display all failed tests at the end of the build.

def failedTests = new LinkedHashSet() // for dedupe due to weird afterTest classMethod issue
Expand All @@ -29,7 +27,7 @@ def genFailInfo(def task, TestDescriptor desc) {
historyUrl += "&tests.test=$desc.name"
historyUrl += " http://fucit.org/solr-jenkins-reports/history-trend-of-recent-failures.html#series/$name"
}
def logName = ErrorReportingTestListener.getOutputLogName(desc.parent ?: desc)
def logName = buildinfra.getOutputLogName(desc.parent ?: desc)
def output = file("${task.testOutputsDir}/${logName}")
def repro = "./gradlew ${task.project.path}:test --tests \"${name}\" ${task.project.testOptionsForReproduceLine}"
return ["name": name, "project": "${task.project.path}", "historyUrl": historyUrl, "output": output, "reproduce": repro]
Expand Down
4 changes: 1 addition & 3 deletions gradle/testing/profiling.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

import org.apache.lucene.gradle.ProfileResults;

def recordings = files()

allprojects {
Expand Down Expand Up @@ -48,7 +46,7 @@ allprojects {

gradle.buildFinished {
if (!recordings.isEmpty()) {
ProfileResults.printReport(recordings.getFiles().collect { it.toString() },
buildinfra.profileResultsClass().printReport(recordings.getFiles().collect { it.toString() },
propertyOrDefault(ProfileResults.MODE_KEY, ProfileResults.MODE_DEFAULT) as String,
Integer.parseInt(propertyOrDefault(ProfileResults.STACKSIZE_KEY, ProfileResults.STACKSIZE_DEFAULT)),
Integer.parseInt(propertyOrDefault(ProfileResults.COUNT_KEY, ProfileResults.COUNT_DEFAULT)),
Expand Down
3 changes: 2 additions & 1 deletion gradle/validation/check-environment.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.gradle.util.GradleVersion

configure(rootProject) {
ext {
expectedGradleVersion = '8.4'
expectedGradleVersion = libs.versions.gradle.get()
}

wrapper {
Expand All @@ -31,6 +31,7 @@ configure(rootProject) {
}

def currentJavaVersion = JavaVersion.current()
def minJavaVersion = JavaVersion.toVersion(libs.versions.minJava.get())
if (currentJavaVersion < minJavaVersion) {
throw new GradleException("At least Java ${minJavaVersion} is required, you are running Java ${currentJavaVersion} "
+ "[${System.getProperty('java.vm.name')} ${System.getProperty('java.vm.version')}]")
Expand Down
4 changes: 1 addition & 3 deletions gradle/validation/jar-checks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// 2) notice file
// 3) checksum validation/ generation.

import org.apache.commons.codec.digest.DigestUtils

// This should be false only for debugging.
def failOnError = true

Expand Down Expand Up @@ -148,7 +146,7 @@ subprojects {
jarName : file.toPath().getFileName().toString(),
path : file,
module : resolvedArtifact.moduleVersion,
checksum : provider { new DigestUtils(DigestUtils.sha1Digest).digestAsHex(file).trim() },
checksum : provider { buildinfra.sha1Digest().digestAsHex(file).trim() },
// We keep track of the files referenced by this dependency (sha, license, notice, etc.)
// so that we can determine unused dangling files later on.
referencedFiles: []
Expand Down
2 changes: 1 addition & 1 deletion gradle/validation/owasp-dependency-check.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ configure(rootProject) {
dependencyCheck {
failBuildOnCVSS = propertyOrDefault("validation.owasp.threshold", 7) as Integer
formats = ['ALL']
skipProjects = [':solr:solr-ref-guide', ':solr-missing-doclet']
skipProjects = [':solr:solr-ref-guide', ':missing-doclet']
skipConfigurations = ['unifiedClasspath', 'permitUnusedDeclared']
suppressionFile = file("${resources}/exclusions.xml")
analyzers {
Expand Down
6 changes: 3 additions & 3 deletions gradle/validation/rat-sources.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ allprojects {
exclude "dev-tools/scripts/README.md"
exclude "dev-tools/scripts/create_line_file_docs.py"

// The root project also includes patterns for the boostrap (buildSrc) and composite
// The root project also includes patterns for the include composite
// projects. Include their sources in the scan.
include "buildSrc/src/**"
include "dev-tools/solr-missing-doclet/src/**"
include "build-tools/build-infra/src/**"
include "build-tools/missing-doclet/src/**"
break

case ":solr:modules:clustering":
Expand Down
2 changes: 1 addition & 1 deletion gradle/validation/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ configure(project(":solr").subprojects) { prj ->
// it.licenseHeaderFile(file("${resources}/asl-header.txt"), '^(\\s*package)')
it.setLineEndings(Enum.valueOf(rootProject.buildscript.classLoader.loadClass("com.diffplug.spotless.LineEnding"), "UNIX"))
it.endWithNewline()
it.googleJavaFormat('1.18.1')
it.googleJavaFormat(libs.versions.google.javaformat.get())

it.custom('Refuse wildcard imports', { line ->
// Wildcard imports can't be resolved by spotless itself.
Expand Down
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fi

GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar"
if [ ! -e "$GRADLE_WRAPPER_JAR" ]; then
"$JAVACMD" $JAVA_OPTS "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "$GRADLE_WRAPPER_JAR"
"$JAVACMD" $JAVA_OPTS "$APP_HOME/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "$GRADLE_WRAPPER_JAR"
WRAPPER_STATUS=$?
if [ "$WRAPPER_STATUS" -eq 1 ]; then
echo "ERROR: Something went wrong. Make sure you're using Java version between 11 and 21."
Expand All @@ -173,7 +173,7 @@ CLASSPATH=$GRADLE_WRAPPER_JAR
# START OF LUCENE CUSTOMIZATION
# Generate gradle.properties if they don't exist
if [ ! -e "$APP_HOME/gradle.properties" ]; then
"$JAVACMD" $JAVA_OPTS "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java" "$APP_HOME/gradle/template.gradle.properties" "$APP_HOME/gradle.properties"
"$JAVACMD" $JAVA_OPTS "$APP_HOME/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java" "$APP_HOME/gradle/template.gradle.properties" "$APP_HOME/gradle.properties"
GENERATOR_STATUS=$?
if [ "$GENERATOR_STATUS" -ne 0 ]; then
exit $GENERATOR_STATUS
Expand Down
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ goto fail
@rem LUCENE-9266: verify and download the gradle wrapper jar if we don't have one.
set GRADLE_WRAPPER_JAR=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
IF NOT EXIST "%GRADLE_WRAPPER_JAR%" (
"%JAVA_EXE%" %JAVA_OPTS% "%APP_HOME%/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "%GRADLE_WRAPPER_JAR%"
"%JAVA_EXE%" %JAVA_OPTS% "%APP_HOME%/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "%GRADLE_WRAPPER_JAR%"
IF %ERRORLEVEL% EQU 1 goto failWithJvmMessage
IF %ERRORLEVEL% NEQ 0 goto fail
)
Expand All @@ -89,7 +89,7 @@ set CLASSPATH=%GRADLE_WRAPPER_JAR%
IF NOT EXIST "%APP_HOME%\gradle.properties" (
@rem local expansion is needed to check ERRORLEVEL inside control blocks.
setlocal enableDelayedExpansion
"%JAVA_EXE%" %JAVA_OPTS% "%APP_HOME%/buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java" "%APP_HOME%\gradle\template.gradle.properties" "%APP_HOME%\gradle.properties"
"%JAVA_EXE%" %JAVA_OPTS% "%APP_HOME%/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java" "%APP_HOME%\gradle\template.gradle.properties" "%APP_HOME%\gradle.properties"
IF %ERRORLEVEL% NEQ 0 goto fail
endlocal
)
Expand Down
Loading

0 comments on commit 06582e7

Please sign in to comment.