Skip to content

Commit

Permalink
improvement: Remove java 8 errorprone support (#2061)
Browse files Browse the repository at this point in the history
Remove support for running errorprone witth java 8 target compatibility
  • Loading branch information
robert3005 authored Feb 4, 2022
1 parent 6891e9f commit 5426300
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 72 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2061.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Remove support for running errorprone witth java 8 target compatibility
links:
- https://github.com/palantir/gradle-baseline/pull/2061
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
import com.google.common.collect.MoreCollectors;
import com.palantir.baseline.IntellijSupport;
import com.palantir.baseline.extensions.BaselineErrorProneExtension;
import com.palantir.baseline.extensions.BaselineJavaVersionExtension;
import com.palantir.baseline.tasks.CompileRefasterTask;
import java.io.File;
import java.util.AbstractList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -40,12 +37,10 @@
import net.ltgt.gradle.errorprone.CheckSeverity;
import net.ltgt.gradle.errorprone.ErrorProneOptions;
import net.ltgt.gradle.errorprone.ErrorPronePlugin;
import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
Expand All @@ -56,14 +51,11 @@
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.testing.Test;
import org.gradle.process.CommandLineArgumentProvider;

public final class BaselineErrorProne implements Plugin<Project> {
private static final Logger log = Logging.getLogger(BaselineErrorProne.class);
public static final String EXTENSION_NAME = "baselineErrorProne";
private static final String ERROR_PRONE_JAVAC_VERSION = "9+181-r4173-1";
private static final String PROP_ERROR_PRONE_APPLY = "errorProneApply";
private static final String PROP_REFASTER_APPLY = "refasterApply";
private static final String DISABLE_PROPERTY = "com.palantir.baseline-error-prone.disable";
Expand Down Expand Up @@ -113,45 +105,6 @@ private static void applyToJavaProject(Project project) {
task.getRefasterRulesFile().set(refasterRulesFile);
});

// In case of java 8 we need to add errorprone javac compiler to bootstrap classpath of tasks that perform
// compilation or code analysis. ErrorProneJavacPluginPlugin handles JavaCompile cases via errorproneJavac
// configuration and we do similar thing for Test and Javadoc type tasks
if (!JavaVersion.current().isJava9Compatible()) {
project.getDependencies()
.add(
ErrorPronePlugin.JAVAC_CONFIGURATION_NAME,
"com.google.errorprone:javac:" + ERROR_PRONE_JAVAC_VERSION);
project.getConfigurations()
.named(ErrorPronePlugin.JAVAC_CONFIGURATION_NAME)
.configure(
conf -> {
List<File> bootstrapClasspath = Splitter.on(File.pathSeparator)
.splitToList(System.getProperty("sun.boot.class.path"))
.stream()
.map(File::new)
.collect(Collectors.toList());
FileCollection errorProneFiles = conf.plus(project.files(bootstrapClasspath));
project.getTasks()
.withType(Test.class)
.configureEach(test -> test.setBootstrapClasspath(errorProneFiles));
project.getTasks().withType(Javadoc.class).configureEach(javadoc -> javadoc.getOptions()
.setBootClasspath(new LazyConfigurationList(errorProneFiles)));
});
}

project.getPluginManager().withPlugin("com.palantir.baseline-java-version", unused -> {
BaselineJavaVersionExtension versionExtension =
project.getExtensions().getByType(BaselineJavaVersionExtension.class);
project.getDependencies()
.addProvider(
ErrorPronePlugin.JAVAC_CONFIGURATION_NAME,
versionExtension
.target()
.map(target -> target.asInt() == 8
? "com.google.errorprone:javac:" + ERROR_PRONE_JAVAC_VERSION
: null));
});

project.getTasks().withType(JavaCompile.class).configureEach(javaCompile -> {
((ExtensionAware) javaCompile.getOptions())
.getExtensions()
Expand Down Expand Up @@ -405,29 +358,4 @@ private static boolean checkExplicitlyDisabled(ErrorProneOptions errorProneOptio
return checks.get(check) == CheckSeverity.OFF
|| errorProneOptions.getErrorproneArgs().get().contains(String.format("-Xep:%s:OFF", check));
}

private static final class LazyConfigurationList extends AbstractList<File> {
private final FileCollection files;
private List<File> fileList;

private LazyConfigurationList(FileCollection files) {
this.files = files;
}

@Override
public File get(int index) {
if (fileList == null) {
fileList = ImmutableList.copyOf(files.getFiles());
}
return fileList.get(index);
}

@Override
public int size() {
if (fileList == null) {
fileList = ImmutableList.copyOf(files.getFiles());
}
return fileList.size();
}
}
}

0 comments on commit 5426300

Please sign in to comment.