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 #2646

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0d36879
Introduce project-wide versions catalog
malliaridis Jul 12, 2024
4d2ff7c
Remove unused scriptDepVErsions.gradle
malliaridis Jul 12, 2024
58f6280
Remove versionsPropsAreSorted gradle task
malliaridis Jul 13, 2024
3227e94
Replace versions.props references
malliaridis Jul 13, 2024
e90d7ec
Migrate remaining dependencies and sync versions with versions.props
malliaridis Jul 13, 2024
0af4420
Remove versions.props
malliaridis Jul 13, 2024
9a03c8c
Remove palantir consistent versions plugin
malliaridis Jul 13, 2024
9a61540
Merge remote-tracking branch 'refs/remotes/origin/main' into introduc…
malliaridis Jul 17, 2024
789cc43
Fix palantir's errorprone hacks
malliaridis Jul 17, 2024
ef14e98
Add carrotsearch-dependencychecks plugin
malliaridis Jul 19, 2024
edce618
Use plugins from version catalog at remaining gradle files
malliaridis Jul 19, 2024
06582e7
Move buildSrc into a composite included build
malliaridis Jul 19, 2024
89fa0eb
Merge remote-tracking branch 'refs/remotes/origin/main' into introduc…
malliaridis Jul 29, 2024
8ec9b9c
Add and run tidy in included projects
malliaridis Jul 29, 2024
0a721f1
Merge branch 'main' into introduce-version-catalog
malliaridis Aug 13, 2024
f402a0b
Update minor and patch versions
malliaridis Aug 15, 2024
7306428
Align and lock versions
malliaridis Aug 17, 2024
da12792
Downgrade incompatible / problematic library versions
malliaridis Aug 17, 2024
93400cd
Fix dependency issues and update versions.lock
malliaridis Aug 17, 2024
36fe19f
Update licenses, notices and checksums of dependencies
malliaridis Aug 18, 2024
da5feba
Merge branch 'main' into introduce-version-catalog
malliaridis Aug 18, 2024
03e62df
Format version catalog with versionCatalogFormat
malliaridis Aug 18, 2024
1ee764c
Add keep clauses for classpath libraries
malliaridis Aug 18, 2024
cfe8652
Update documentation about dependencies
malliaridis Aug 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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