Skip to content

Commit

Permalink
Build with Java 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Oct 26, 2020
1 parent 9689bbb commit a140fb6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
10 changes: 8 additions & 2 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ configurations.all {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.named<JavaCompile>("compileJava") {
options.isFork = true
options.forkOptions.executable = "javac"
options.compilerArgs.addAll(listOf("--release", "8"))
}

val plugin: Configuration by configurations.creating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ private RewriteExtension getExtension() {

protected Environment environment() {
Environment.Builder env = Environment.builder()
.compileClasspath(
getJavaSources().getFiles().stream().map(File::toPath).collect(Collectors.toList())
).scanResources()
.scanClasspath(
getJavaSources().getFiles().stream().map(File::toPath).collect(Collectors.toList())
)
.scanUserHome();

File rewriteConfig = getExtension().getConfigFile();
if(rewriteConfig != null && rewriteConfig.exists()) {
if (rewriteConfig != null && rewriteConfig.exists()) {
try (FileInputStream is = new FileInputStream(rewriteConfig)) {
Map<Object, Object> gradleProps = getProject().getProperties().entrySet().stream()
.filter(entry -> entry.getKey() != null && entry.getValue() != null)
Expand All @@ -145,7 +145,7 @@ protected Environment environment() {
}

protected Collection<Change> listChanges() {
try(MeterRegistryProvider meterRegistryProvider = new MeterRegistryProvider(getLog(), metricsUri, metricsUsername, metricsPassword)) {
try (MeterRegistryProvider meterRegistryProvider = new MeterRegistryProvider(getLog(), metricsUri, metricsUsername, metricsPassword)) {
MeterRegistry meterRegistry = meterRegistryProvider.registry();

Environment env = environment();
Expand Down Expand Up @@ -181,9 +181,9 @@ protected Collection<Change> listChanges() {

sourceFiles.addAll(new PropertiesParser().parse(
getResources().getFiles().stream()
.filter(it -> it.isFile() && it.getName().endsWith(".properties"))
.map(File::toPath)
.collect(toList()),
.filter(it -> it.isFile() && it.getName().endsWith(".properties"))
.map(File::toPath)
.collect(toList()),
getProject().getProjectDir().toPath()
));

Expand All @@ -192,6 +192,7 @@ protected Collection<Change> listChanges() {
throw new RuntimeException(e);
}
}

private MeterRegistry registry;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;

public class RewriteExtension extends CodeQualityExtension {
private static final String magicalMetricsLogString = "LOG";

Expand Down Expand Up @@ -71,28 +73,28 @@ public void setMetricsUri(String value) {
metricsUri = value;
}


public void activeRecipe(String... profiles) {
activeRecipes.addAll(List.of(profiles));
activeRecipes.addAll(asList(profiles));
}

public void clearActiveRecipes() {
activeRecipes.clear();
}

public void setActiveRecipes(List<String> activeProfiles) {
this.activeRecipes.clear();
this.activeRecipes.addAll(activeProfiles);
}

public List<String> getActiveRecipes() {
return activeRecipes;
}

public void recipe(GradleRecipeConfiguration... profiles) {
this.recipes.addAll(List.of(profiles));
this.recipes.addAll(asList(profiles));
}

public List<GradleRecipeConfiguration> getRecipes() {
return List.copyOf(recipes);
return new ArrayList<>(recipes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.TaskAction;
import org.openrewrite.Change;
import org.openrewrite.java.tree.J;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collection;
import java.util.List;

public class RewriteFixTask extends AbstractRewriteTask {

Expand All @@ -46,8 +44,8 @@ public void execute() {
getLog().warn("Changes have been made to " +
change.getOriginal().getSourcePath() + " by: ");
}
for(String rule : change.getRulesThatMadeChanges()) {
log.warn(" " + rule);
for(String visitor : change.getVisitorsThatMadeChanges()) {
log.warn(" " + visitor);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;

/**
Expand All @@ -35,8 +36,8 @@ public void apply(Project project) {
maybeExtension = project.getExtensions().create("rewrite", RewriteExtension.class, project);
maybeExtension.setToolVersion("2.x");
}
final var extension = maybeExtension;
var tasks = project.getTasks();
final RewriteExtension extension = maybeExtension;
TaskContainer tasks = project.getTasks();

JavaPluginConvention javaPlugin = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSetContainer sourceSets = javaPlugin.getSourceSets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void execute() {
log.warn("Changes are suggested to " +
change.getOriginal().getSourcePath() +
" by:");
for (String rule : change.getRulesThatMadeChanges()) {
log.warn(" " + rule);
for (String visitor : change.getVisitorsThatMadeChanges()) {
log.warn(" " + visitor);
}
}

Expand Down

0 comments on commit a140fb6

Please sign in to comment.