Skip to content

Commit

Permalink
java-runtime.min-version = 11 and gradle-api.min-version = 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
remal committed Jan 22, 2025
1 parent 8a80e56 commit 2240cb0
Show file tree
Hide file tree
Showing 35 changed files with 194 additions and 225 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ If there is a compatibility issue and the Lombok annotation processor has to be

# Migration guide

## Version 2.* to 3.*

The minimum Java version is 11 (from 8).
The minimum Gradle version is 7.0 (from 6.7).

## Version 1.* to 2.*

* Package name was changed from `name.remal.gradleplugins.lombok` to `name.remal.gradle_plugins.lombok`.
12 changes: 6 additions & 6 deletions build-generate-LombokConfigurationKeys.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ generateSources.forMainSourceSet.java {
classFile("${project.calculateBaseJavaPackage()}.config", 'LombokConfigurationKeys') {
addStaticImport("lombok.AccessLevel", "PRIVATE")

addImport("com.google.common.collect.ImmutableList")
addImport("java.util.List")
addImport("javax.annotation.Nullable")
addImport("lombok.NoArgsConstructor")
addImport("lombok.val")

line("@NoArgsConstructor(access = PRIVATE)")
suppressWarningsLine("checkstyle:LineLength", "checkstyle:RightCurlyAlone")
suppressWarningsLine("checkstyle:LineLength", "checkstyle:RightCurlyAlone", "checkstyle:SeparatorWrapComma")
block("public abstract class ${simpleName}") { classContent ->
line("")
line("private static final List<LombokConfigurationKey> KEYS = ImmutableList.<LombokConfigurationKey>builder()")
line("private static final List<LombokConfigurationKey> KEYS = List.of(")

FileTree lombokSourcesTree = injections.objects.fileCollection().asFileTree
configurations.lombokSources.files.forEach { File file ->
Expand Down Expand Up @@ -97,14 +96,15 @@ generateSources.forMainSourceSet.java {

boolean isDeprecated = field.annotations.any { it.name.identifier == 'Deprecated' }

classContent.line(" .add(LombokConfigurationKey.builder()")
String delim = foundLombokConfigProperties.size() == 1 ? '' : ','

classContent.line(" ${delim}LombokConfigurationKey.builder()")
classContent.line(" .name(\"${classContent.escapeString(configKey)}\")")
classContent.line(" .description(${initializer.getArgument(1)})")
if (isDeprecated) {
classContent.line(" .deprecated(true)")
}
classContent.line(" .build()")
classContent.line(" )")

return super.visit(field, arg)
}
Expand All @@ -123,7 +123,7 @@ generateSources.forMainSourceSet.java {
}
}

line(" .build();")
line(" );")

line("")
line("@Nullable")
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
String rootGroupId = project.ext.rootGroupId = "name.remal.gradle-plugins.${rootProject.name}"
String rootArtifactId = project.ext.rootArtifactId = rootProject.name
String rootSnapshotVersion = project.ext.rootSnapshotVersion = '2-SNAPSHOT'
String rootSnapshotVersion = project.ext.rootSnapshotVersion = '3-SNAPSHOT'
dependencies {
//classpath("$rootGroupId:$rootArtifactId:$rootSnapshotVersion") { version { strictly(rootSnapshotVersion) } }
classpath 'name.remal.gradle-plugins.toolkit:build-logic:0.71.1'
Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
java-runtime.min-version = 8
gradle-api.min-version = 6.7
java-runtime.min-version = 11
gradle-api.min-version = 7.0

#disable-compilation = true
#java-runtime.version = 8
#gradle-api.version = 8.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import static java.lang.String.format;
import static java.lang.String.join;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.exists;
import static java.nio.file.Files.isRegularFile;
import static java.nio.file.Files.readAllBytes;
import static java.nio.file.Files.readString;
import static name.remal.gradle_plugins.lombok.LibrariesToTestCompatibility.getLibraryNotation;
import static name.remal.gradle_plugins.toolkit.PathUtils.deleteRecursively;
import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Path;
import lombok.RequiredArgsConstructor;
import lombok.val;
import name.remal.gradle_plugins.toolkit.testkit.MinSupportedJavaVersion;
import name.remal.gradle_plugins.toolkit.testkit.functional.GradleProject;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -61,7 +59,7 @@ void beforeEach() {
}

private Path getGeneratedFile(String relativePath) {
val path = project.getProjectDir().toPath()
var path = project.getProjectDir().toPath()
.resolve(relativePath);
if (!exists(path)) {
throw new AssertionError("File not found: " + path);
Expand Down Expand Up @@ -161,8 +159,7 @@ void mapstruct() throws Throwable {

project.assertBuildSuccessfully("compileJava");

val contentBytes = readAllBytes(getGeneratedFile(APT_GENERATED_FOLDER + "/pkg/TestClassMapperImpl.java"));
val content = new String(contentBytes, UTF_8);
var content = readString(getGeneratedFile(APT_GENERATED_FOLDER + "/pkg/TestClassMapperImpl.java"));
assertThat(content).contains("TestClassWithBuilder.builder()");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import lombok.val;
import name.remal.gradle_plugins.toolkit.JavaInstallationMetadataUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.JavaVersion;
Expand Down Expand Up @@ -67,8 +66,8 @@ public void execute() {
AtomicReference<JavaExecSpec> execSpecRef = new AtomicReference<>();

getExecOperations().javaexec(execSpec -> {
val javaLauncher = getJavaLauncher().get();
val javaVersion = Optional.of(javaLauncher.getMetadata())
var javaLauncher = getJavaLauncher().get();
var javaVersion = Optional.of(javaLauncher.getMetadata())
.map(JavaInstallationMetadataUtils::getJavaInstallationVersionOf)
.orElseGet(JavaVersion::current);
if (shouldJavacPackageOpenJvmArgsBeAdded(javaVersion)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import lombok.NoArgsConstructor;
import lombok.val;

@NoArgsConstructor(access = PRIVATE)
abstract class AnnotationProcessorsLombokOrderUtils {
Expand All @@ -40,15 +39,15 @@ public static List<File> withFixedAnnotationProcessorFilesOrder(@Nullable Collec
return emptyList();
}

val filesList = new ArrayList<>(files);
var filesList = new ArrayList<>(files);
filesList.sort(comparing(AnnotationProcessorsLombokOrderUtils::getFileOrder));
return unmodifiableList(filesList);
}

private static int getFileOrder(File file) {
val fileName = file.getName();
var fileName = file.getName();

for (val entry : FILE_NAME_ORDERS.entrySet()) {
for (var entry : FILE_NAME_ORDERS.entrySet()) {
if (entry.getKey().matcher(fileName).matches()) {
return entry.getValue();
}
Expand All @@ -63,13 +62,13 @@ public static List<String> withFixedAnnotationProcessorsOrder(@Nullable Collecti
return emptyList();
}

val processorsList = new ArrayList<>(processors);
var processorsList = new ArrayList<>(processors);
processorsList.sort(comparing(AnnotationProcessorsLombokOrderUtils::getProcessorOrder));
return unmodifiableList(processorsList);
}

private static int getProcessorOrder(String processor) {
for (val entry : PROCESSOR_ORDERS.entrySet()) {
for (var entry : PROCESSOR_ORDERS.entrySet()) {
if (entry.getKey().matcher(processor).matches()) {
return entry.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.errorprone.annotations.ForOverride;

Check failure on line 8 in src/main/java/name/remal/gradle_plugins/lombok/BaseCreateLombokJar.java

View workflow job for this annotation

GitHub Actions / codespell

errorprone ==> error-prone
import java.io.File;
import lombok.SneakyThrows;
import lombok.val;
import org.gradle.api.GradleException;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Internal;
Expand Down Expand Up @@ -38,8 +37,8 @@ protected BaseCreateLombokJar(String command) {
@Override
@SneakyThrows
protected void afterExecute(JavaExecSpec execSpec) {
val generatedFileName = getGeneratedFileName();
val generatedFile = new File(execSpec.getWorkingDir(), generatedFileName);
var generatedFileName = getGeneratedFileName();
var generatedFile = new File(execSpec.getWorkingDir(), generatedFileName);
if (!generatedFile.isFile()) {
throw new GradleException(format(
"%s file can't be found: %s",
Expand All @@ -48,7 +47,7 @@ protected void afterExecute(JavaExecSpec execSpec) {
));
}

val outputFile = getOutputFile().get().getAsFile();
var outputFile = getOutputFile().get().getAsFile();

move(
generatedFile.toPath(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package name.remal.gradle_plugins.lombok;

import static java.util.Collections.singletonList;

import java.util.List;
import org.gradle.api.tasks.CacheableTask;

Expand All @@ -14,7 +12,7 @@ public CreateLombokRuntimeJar() {

@Override
protected List<String> createArgs() {
return singletonList("--create");
return List.of("--create");
}

@Override
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/name/remal/gradle_plugins/lombok/Delombok.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.createDirectories;
import static java.nio.file.Files.write;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static name.remal.gradle_plugins.toolkit.PathUtils.createParentDirectories;
Expand All @@ -16,7 +15,6 @@
import java.util.Optional;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.val;
import name.remal.gradle_plugins.toolkit.ObjectUtils;
import org.gradle.api.Action;
import org.gradle.api.file.ConfigurableFileCollection;
Expand All @@ -40,7 +38,7 @@ public abstract class Delombok extends AbstractLombokTask {
public Delombok() {
super("delombok");

val project = getProject();
var project = getProject();

getOutputDir().convention(
project.getLayout().getBuildDirectory().dir(getName())
Expand Down Expand Up @@ -98,7 +96,7 @@ protected List<String> createArgs() {
getOutputDir().finalizeValue();
args.add(String.format("--target=%s", getOutputDir().get().getAsFile().getAbsolutePath()));

val inputFiles = getInputFiles().getFiles().stream()
var inputFiles = getInputFiles().getFiles().stream()
.filter(File::exists)
.collect(toList());
if (inputFiles.isEmpty()) {
Expand All @@ -109,20 +107,20 @@ protected List<String> createArgs() {
.forEach(args::add);


val argsFileContent = args.stream()
var argsFileContent = args.stream()
.map(arg -> arg.replace("\\", "\\\\"))
.map(arg -> arg.replace(" ", "\\ "))
.collect(joining("\n"));
val argsFile = new File(getTemporaryDir(), getName() + ".args");
var argsFile = new File(getTemporaryDir(), getName() + ".args");
write(createParentDirectories(argsFile.toPath()), argsFileContent.getBytes(UTF_8));

return singletonList('@' + argsFile.getAbsolutePath());
return List.of('@' + argsFile.getAbsolutePath());
}

@Override
@SneakyThrows
protected void beforeExecute(JavaExecSpec execSpec) {
val outputDir = getOutputDir().get().getAsFile();
var outputDir = getOutputDir().get().getAsFile();
deleteRecursively(outputDir.toPath());
createDirectories(outputDir.toPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.List;
import lombok.SneakyThrows;
import lombok.val;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;

Expand Down Expand Up @@ -61,15 +60,15 @@ public abstract class DelombokFormat {
List<String> toArgs() {
List<String> args = new ArrayList<>();

for (val method : DelombokFormat.class.getMethods()) {
for (var method : DelombokFormat.class.getMethods()) {
if (isGetterOf(method, Property.class)) {
val property = (Property<?>) method.invoke(this);
var property = (Property<?>) method.invoke(this);
Object value = property.getOrNull();
if (value == null) {
continue;
}

val name = getPropertyNameForGetter(method);
var name = getPropertyNameForGetter(method);

if (value instanceof Boolean) {
if (TRUE.equals(value)) {
Expand All @@ -90,13 +89,13 @@ List<String> toArgs() {
@SneakyThrows
@SuppressWarnings("unchecked")
void convention(DelombokFormat other) {
for (val method : DelombokFormat.class.getMethods()) {
for (var method : DelombokFormat.class.getMethods()) {
if (!isGetterOf(method, Property.class)) {
continue;
}

val thisProperty = (Property<Object>) method.invoke(this);
val otherProperty = (Property<Object>) method.invoke(other);
var thisProperty = (Property<Object>) method.invoke(this);
var otherProperty = (Property<Object>) method.invoke(other);
if (thisProperty != null && otherProperty != null) {
thisProperty.convention(otherProperty);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package name.remal.gradle_plugins.lombok;

import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toUnmodifiableList;
import static lombok.AccessLevel.PRIVATE;

import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import lombok.NoArgsConstructor;
import lombok.val;
import org.gradle.api.JavaVersion;

@NoArgsConstructor(access = PRIVATE)
public abstract class JavacPackagesToOpenUtils {

private static final List<String> JAVAC_PACKAGES_TO_OPEN = ImmutableList.of(
private static final List<String> JAVAC_PACKAGES_TO_OPEN = List.of(
/*
"jdk.compiler/com.sun.tools.javac.code",
"jdk.compiler/com.sun.tools.javac.comp",
Expand All @@ -30,10 +28,9 @@ public abstract class JavacPackagesToOpenUtils {
*/
);

private static final List<String> JAVAC_PACKAGE_OPEN_JVM_ARGS = ImmutableList.copyOf(JAVAC_PACKAGES_TO_OPEN.stream()
private static final List<String> JAVAC_PACKAGE_OPEN_JVM_ARGS = JAVAC_PACKAGES_TO_OPEN.stream()
.map(it -> format("--add-opens=%s=ALL-UNNAMED", it))
.collect(toList())
);
.collect(toUnmodifiableList());

public static boolean shouldJavacPackageOpenJvmArgsBeAdded(JavaVersion javaVersion) {
return javaVersion.isJava9Compatible();
Expand All @@ -49,7 +46,7 @@ public static List<String> withJavacPackageOpens(@Nullable Collection<String> ar
result.addAll(args);
}

for (val jvmArg : getJavacPackageOpenJvmArgs()) {
for (var jvmArg : getJavacPackageOpenJvmArgs()) {
if (!result.contains(jvmArg)) {
result.add(jvmArg);
}
Expand Down
Loading

0 comments on commit 2240cb0

Please sign in to comment.