Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-17406: Introduce Version Catalogs #2706

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a0435d7
Introduce project-wide versions catalog
malliaridis Sep 10, 2024
f3f9dc0
Remove unused scriptDepVErsions.gradle
malliaridis Jul 12, 2024
efdabc4
Remove versionsPropsAreSorted gradle task
malliaridis Jul 13, 2024
fedc606
Replace versions.props references
malliaridis Jul 13, 2024
961c2bd
Migrate remaining dependencies and sync versions with versions.props
malliaridis Jul 13, 2024
c6a6933
Remove versions.props
malliaridis Jul 13, 2024
2d44f04
Remove palantir consistent versions plugin
malliaridis Jul 13, 2024
5e05300
Fix palantir's errorprone hacks
malliaridis Jul 17, 2024
f50e2c7
Add carrotsearch-dependencychecks plugin
malliaridis Jul 19, 2024
c74bfec
Use plugins from version catalog at remaining gradle files
malliaridis Jul 19, 2024
867fb11
Move buildSrc into a composite included build
malliaridis Jul 19, 2024
cb54484
Add and run tidy in included projects
malliaridis Jul 29, 2024
0585bba
Align and lock dependency versions
malliaridis Aug 22, 2024
cdc843f
Replace hamcrest-core with hamcrest
malliaridis Aug 22, 2024
6abab94
Add grpc bom
malliaridis Sep 5, 2024
db283a5
Sync netty versions with BOM
malliaridis Sep 10, 2024
98ec23e
Update licenses / hashes
malliaridis Sep 10, 2024
078ebbd
Fix dependency downgrade mistake from rebase
malliaridis Sep 10, 2024
05d30f2
Write locks
malliaridis Sep 10, 2024
83819ef
Update documentation about dependencies
malliaridis Aug 18, 2024
5825de2
Format version catalog
malliaridis Sep 11, 2024
94d8ca6
Remove unnecessary method reference
malliaridis Sep 16, 2024
eef39b2
Remove unnecessary method reference in getPackageVersion
malliaridis Sep 25, 2024
48c21cc
Fix typo in undercouch-download plugin
malliaridis Sep 25, 2024
50a4a81
Resolve eclipse.gradle null error and re-apply
malliaridis Sep 25, 2024
b895992
Fix errorprone issues
malliaridis Sep 25, 2024
101a323
Merge branch 'main' into SOLR-17406/rebase-version-catalogs
malliaridis Sep 30, 2024
6f92804
Migrate new modules to version catalogs
malliaridis Sep 30, 2024
3212b5b
Update licenses and sync versions
malliaridis Sep 30, 2024
699480d
Update list of consolidated configurations
malliaridis Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions buildSrc/build.gradle → build-tools/build-infra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,44 @@
* limitations under the License.
*/

plugins {
id "java-gradle-plugin"
alias(libs.plugins.diffplug.spotless) apply false
}

repositories {
mavenCentral()
}

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

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

// Add spotless/ tidy.
tasks.register("checkJdkInternalsExportedToGradle") {}
apply from: file('../../gradle/validation/spotless.gradle')

// Load common buildSrc and script deps.
apply from: file("scriptDepVersions.gradle")
java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.minJava.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.minJava.get())
}

gradlePlugin {
automatedPublishing = false

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

dependencies {
implementation gradleApi()
implementation localGroovy()

implementation "commons-codec:commons-codec:${scriptDepVersions['commons-codec']}"
implementation libs.commonscodec.commonscodec
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@
* limitations under the License.
*/

rootProject.name = "missing-doclet"
rootProject.name = 'build-infra'

// Use project's version catalog for centralized dependency management
dependencyResolutionManagement {
versionCatalogs {
libs {
from(files("../../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

package org.apache.lucene.gradle;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Locale;
import org.apache.commons.codec.digest.DigestUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
Expand All @@ -39,16 +44,10 @@
import org.gradle.work.Incremental;
import org.gradle.work.InputChanges;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Locale;

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,288 @@
/*
* 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;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import org.gradle.api.internal.tasks.testing.logging.FullExceptionFormatter;
import org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.testing.TestDescriptor;
import org.gradle.api.tasks.testing.TestListener;
import org.gradle.api.tasks.testing.TestOutputEvent;
import org.gradle.api.tasks.testing.TestOutputListener;
import org.gradle.api.tasks.testing.TestResult;
import org.gradle.api.tasks.testing.logging.TestLogging;

/**
* An error reporting listener that queues test output streams and displays them on failure.
*
* <p>Heavily inspired by Elasticsearch's ErrorReportingTestListener (ASL 2.0 licensed).
*/
public class ErrorReportingTestListener implements TestOutputListener, TestListener {
private static final Logger LOGGER = Logging.getLogger(ErrorReportingTestListener.class);

private final TestExceptionFormatter formatter;
private final Map<TestKey, OutputHandler> outputHandlers = new ConcurrentHashMap<>();
private final Path spillDir;
private final Path outputsDir;
private final boolean verboseMode;

public ErrorReportingTestListener(
TestLogging testLogging, Path spillDir, Path outputsDir, boolean verboseMode) {
this.formatter = new FullExceptionFormatter(testLogging);
this.spillDir = spillDir;
this.outputsDir = outputsDir;
this.verboseMode = verboseMode;
}

@Override
public void onOutput(TestDescriptor testDescriptor, TestOutputEvent outputEvent) {
handlerFor(testDescriptor).write(outputEvent);
}

@Override
public void beforeSuite(TestDescriptor suite) {
// noop.
}

@Override
public void beforeTest(TestDescriptor testDescriptor) {
// Noop.
}

@Override
public void afterSuite(final TestDescriptor suite, TestResult result) {
if (suite.getParent() == null || suite.getName().startsWith("Gradle")) {
return;
}

TestKey key = TestKey.of(suite);
try {
OutputHandler outputHandler = outputHandlers.get(key);
if (outputHandler != null) {
long length = outputHandler.length();
if (length > 1024 * 1024 * 10) {
LOGGER.warn(
String.format(
Locale.ROOT,
"WARNING: Test %s wrote %,d bytes of output.",
suite.getName(),
length));
}
}

boolean echoOutput = Objects.equals(result.getResultType(), TestResult.ResultType.FAILURE);
boolean dumpOutput = echoOutput;

// If the test suite failed, report output.
if (dumpOutput || echoOutput) {
Files.createDirectories(outputsDir);
Path outputLog = outputsDir.resolve(getOutputLogName(suite));

// Save the output of a failing test to disk.
try (Writer w = Files.newBufferedWriter(outputLog, StandardCharsets.UTF_8)) {
if (outputHandler != null) {
outputHandler.copyTo(w);
}
}

if (echoOutput && !verboseMode) {
synchronized (this) {
System.out.println("");
System.out.println(
suite.getClassName()
+ " > test suite's output saved to "
+ outputLog
+ ", copied below:");
try (BufferedReader reader =
Files.newBufferedReader(outputLog, StandardCharsets.UTF_8)) {
char[] buf = new char[1024];
int len;
while ((len = reader.read(buf)) >= 0) {
System.out.print(new String(buf, 0, len));
}
System.out.println();
}
}
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
OutputHandler handler = outputHandlers.remove(key);
if (handler != null) {
try {
handler.close();
} catch (IOException e) {
LOGGER.error("Failed to close output handler for: " + key, e);
}
}
}
}

private static Pattern SANITIZE = Pattern.compile("[^a-zA-Z .\\-_0-9]+");

public static String getOutputLogName(TestDescriptor suite) {
return SANITIZE.matcher("OUTPUT-" + suite.getName() + ".txt").replaceAll("_");
}

@Override
public void afterTest(TestDescriptor testDescriptor, TestResult result) {
// Include test failure exception stacktrace(s) in test output log.
if (result.getResultType() == TestResult.ResultType.FAILURE) {
if (result.getExceptions().size() > 0) {
String message = formatter.format(testDescriptor, result.getExceptions());
handlerFor(testDescriptor).write(message);
}
}
}

private OutputHandler handlerFor(TestDescriptor descriptor) {
// Attach output of leaves (individual tests) to their parent.
if (!descriptor.isComposite()) {
descriptor = descriptor.getParent();
}
return outputHandlers.computeIfAbsent(TestKey.of(descriptor), (key) -> new OutputHandler());
}

public static class TestKey {
private final String key;

private TestKey(String key) {
this.key = key;
}

public static TestKey of(TestDescriptor d) {
StringBuilder key = new StringBuilder();
key.append(d.getClassName());
key.append("::");
key.append(d.getName());
key.append("::");
key.append(d.getParent() == null ? "-" : d.getParent().toString());
return new TestKey(key.toString());
}

@Override
public boolean equals(Object o) {
return o != null && o.getClass() == this.getClass() && Objects.equals(((TestKey) o).key, key);
}

@Override
public int hashCode() {
return key.hashCode();
}

@Override
public String toString() {
return key;
}
}

private class OutputHandler implements Closeable {
// Max single-line buffer before automatic wrap occurs.
private static final int MAX_LINE_WIDTH = 1024 * 4;

private final SpillWriter buffer;

// internal stream.
private final PrefixedWriter sint;
// stdout
private final PrefixedWriter sout;
// stderr
private final PrefixedWriter serr;

// last used stream (so that we can flush it properly and prefixes are not screwed up).
private PrefixedWriter last;

public OutputHandler() {
buffer =
new SpillWriter(
() -> {
try {
return Files.createTempFile(spillDir, "spill-", ".tmp");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});

Writer sink = buffer;
if (verboseMode) {
sink = new StdOutTeeWriter(buffer);
}

sint = new PrefixedWriter(" > ", sink, MAX_LINE_WIDTH);
sout = new PrefixedWriter(" 1> ", sink, MAX_LINE_WIDTH);
serr = new PrefixedWriter(" 2> ", sink, MAX_LINE_WIDTH);
last = sint;
}

public void write(TestOutputEvent event) {
write(
(event.getDestination() == TestOutputEvent.Destination.StdOut ? sout : serr),
event.getMessage());
}

public void write(String message) {
write(sint, message);
}

public long length() throws IOException {
return buffer.length();
}

private void write(PrefixedWriter out, String message) {
try {
if (out != last) {
last.completeLine();
last = out;
}
out.write(message);
} catch (IOException e) {
throw new UncheckedIOException("Unable to write to test output.", e);
}
}

public void copyTo(Writer out) throws IOException {
flush();
buffer.copyTo(out);
}

public void flush() throws IOException {
sout.completeLine();
serr.completeLine();
buffer.flush();
}

@Override
public void close() throws IOException {
buffer.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public void run(Path source, Path destination) throws IOException {
fileContent = fileContent.replace(entry.getKey(), String.valueOf(entry.getValue()));
}
Files.writeString(
destination, fileContent, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW);
destination, fileContent, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW);
}
}
Loading
Loading