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

Improved support for large repositories #3118

Merged
merged 112 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
9578df3
Large repository handling
jkschneider Apr 29, 2023
3447ef3
rewrite-xml tests passing
jkschneider Apr 30, 2023
9245b03
AddGradleEnterpriseTest passing
sambsnyd Apr 30, 2023
7d55756
UpgradeGradleWrapper passing
sambsnyd Apr 30, 2023
f7114d7
License headers
sambsnyd Apr 30, 2023
fcd455a
Reject version of rocksdb which is broken on Windows
sambsnyd Apr 30, 2023
b07373e
Fix CreateTextFile. Move Groovy adaptability tests into a package whe…
sambsnyd Apr 30, 2023
b4369d0
Remove visitJavaSourceFile
jkschneider Apr 30, 2023
21b866e
Move org.openrewrite.java.cleanup to rewrite-static-analysis
jkschneider May 1, 2023
6a0c903
Move a few commonly used cleanup recipes back
jkschneider May 1, 2023
89f9cef
Move some recipes back from static-analysis that are actually formatt…
jkschneider May 1, 2023
6cf37e6
Move groovy cleanup tests to rewrite-static-analysis, fix other compi…
jkschneider May 1, 2023
d0fd4db
Fix UnnecessaryParentheses
jkschneider May 1, 2023
1189a7e
Fix SelectRecipeExamplesTest
jkschneider May 1, 2023
7d38eba
Fix more tests, move java-best-practices to rewrite-static-analysis
jkschneider May 1, 2023
5374093
Fix remaining tests
jkschneider May 1, 2023
c4ef8ed
Remove deprecated gradle parser builders
jkschneider May 1, 2023
be3b0cb
Remove some incubating annotations, order imports
jkschneider May 1, 2023
2d06674
Remove select deprecations
jkschneider May 1, 2023
8826d78
Remove `JavaParser#[gs]etSourceSet()` overrides
knutwannheden May 1, 2023
393e3cf
Make precondition of `ChangeMethodTargetToStatic` optional
knutwannheden May 1, 2023
f70ff95
Make sure `Preconditions.check()` also works with other source types
knutwannheden May 1, 2023
9142b06
Add a few more `stopAfterPreVisit()` directives
knutwannheden May 2, 2023
c74193c
Change return type of `ScanningRecipe#generate()`
knutwannheden May 2, 2023
806359c
Update call site for `ScanningRecipe#generate()`
knutwannheden May 2, 2023
0c7d94c
Don't attempt to instantiate abstract recipe classes
knutwannheden May 3, 2023
4b6fd87
Change top-level detection logic in `TreeVisitor#visit()`
knutwannheden May 4, 2023
d2bfb01
Reset `TreeVisitor#visitCount` after exiting top-level
knutwannheden May 4, 2023
c2327a4
Add `stopAfterPreVisit()` call to `AddImport#preVisit()`
knutwannheden May 4, 2023
66743b7
Update signatures of `Recipe#run()` methods
knutwannheden May 5, 2023
d6a8a65
Resolve some conflicts after rebasing
knutwannheden May 8, 2023
3865ab1
Changeset
jkschneider May 9, 2023
1f6bb4c
Merge branch 'main' into large-repositories
jkschneider May 9, 2023
b1359e8
SourceSet -> LargeSourceSet
jkschneider May 9, 2023
caca1fb
Polish
jkschneider May 9, 2023
0bf2cc2
Polish
jkschneider May 9, 2023
b1d3df4
Polish
jkschneider May 9, 2023
401026d
Fix constructor calls in `InMemoryLargeSourceSet`
knutwannheden May 9, 2023
1915bc3
Merge branch 'main' into large-repositories
jkschneider May 10, 2023
f990ad9
FindCallGraph public getVisitor
jkschneider May 10, 2023
728d070
Missing expected generated file check was in wrong place in RewriteTest
jkschneider May 10, 2023
6b98335
Recipe#generate can observe other files generated in the same cycle
jkschneider May 10, 2023
b2182fc
Add guard for loading yaml source, gracefully handling the loading er…
kunli2 May 9, 2023
c9e0f7b
Fix PlainText#withText
jkschneider May 10, 2023
2f967be
Merge branch 'main' into large-repositories
knutwannheden May 12, 2023
964bb51
Iteration on cachable, context-free java templating.
sambsnyd May 12, 2023
64716ff
Cleanup
sambsnyd May 12, 2023
7f5ab42
Refactor to `JavaTemplate.Builder#requiresContext(boolean)`
knutwannheden May 12, 2023
96837d2
Add `Cursor` parameter to `J#withTemplate()`
knutwannheden May 13, 2023
0b20816
Update all uses of `JavaTemplate#builder()` and `J#withTemplate()`
knutwannheden May 13, 2023
4e20663
Polish
knutwannheden May 13, 2023
a96aaed
ChangeText not extendable
jkschneider May 14, 2023
8c3ce34
Recipe#getDescription not optional
jkschneider May 14, 2023
f1c625e
Merge branch 'main' into large-repositories
jkschneider May 14, 2023
3d0e825
Polish AddDependency
jkschneider May 14, 2023
28ede57
Remove LargeSourceSet#flatMap and LargeSourceSet#concat
jkschneider May 15, 2023
b395191
Remove LargeSourceSet#getInitialState
jkschneider May 15, 2023
958df2e
Merge branch 'main' into context-free-templates
knutwannheden May 15, 2023
05e55a3
Merge branch 'main' into large-repositories
timtebeek May 15, 2023
b7dcea4
Updated `JavaTemplate` uses to context-free where possible
knutwannheden May 15, 2023
3057c46
Merge branch 'context-free-templates' into large-repositories
knutwannheden May 15, 2023
a699134
Fix bug in `RecipeSchedulerCheckingExpectedCycles`
knutwannheden May 15, 2023
9cc6487
`ScanningRecipe#getVisitor()` must implement `isAcceptable()`
knutwannheden May 15, 2023
f221c12
Merge remote-tracking branch 'origin/main' into large-repositories
knutwannheden May 16, 2023
c580239
Post-merge conflict resolution
knutwannheden May 16, 2023
cb914bc
Fix last failing test
knutwannheden May 16, 2023
2fb285f
Fix bug when replacing context-free method body
knutwannheden May 16, 2023
0caa4de
For now exclude lambdas and method references from context-free support
knutwannheden May 16, 2023
d47436d
Further simplify LargeSourceSet, remove ForkJoinScheduler
jkschneider May 15, 2023
ea361d2
Rename RecipeScheduler#mapForRecipeRecursively
jkschneider May 15, 2023
c7aeccc
LargeSourceSet edit/generate
jkschneider May 16, 2023
be5c2dd
Add simple test for context-free template caching
knutwannheden May 16, 2023
296a3c9
RewriteTest customizable LargeSourceSet builder
jkschneider May 17, 2023
a9affe9
Merge branch 'main' into large-repositories
jkschneider May 17, 2023
11b479e
Fix migration recipes
jkschneider May 17, 2023
d76b87d
Merge branch 'main' into large-repositories
kunli2 May 18, 2023
bff5444
Change ScanningRecipe's acc message id to use hashCode instead of UUI…
kunli2 May 20, 2023
9713d97
NullSkippingSet -> NullSkippingMap
jkschneider May 21, 2023
ef374db
Revert "Change ScanningRecipe's acc message id to use hashCode instea…
jkschneider May 21, 2023
c54310f
visitParameterizedType needs to call withType
jkschneider May 21, 2023
136a975
getRecipeList should not return new recipe instances
jkschneider May 21, 2023
ad79cc3
Javadoc on getRecipeList
jkschneider May 21, 2023
6c8626a
Add validation that Recipe#getRecipeList always returns the same refe…
jkschneider May 21, 2023
6cad09e
Propagate shared root cursor via `visit(Tree, ExecutionContext, Cursor)`
knutwannheden May 22, 2023
1beffcc
Fix compiler problem with Lombok `@Getter(lazy = true)`
knutwannheden May 22, 2023
acab1e0
Set root cursor before calling `TreeVisitor#isAcceptable()`
knutwannheden May 22, 2023
e8bd2ba
make RemoveGradleDependency recipe public
kunli2 May 23, 2023
98d497c
Add `@JsonIgnore` to `FindDeprecatedUses#recipeList`
knutwannheden May 23, 2023
2546f48
Fix bug in `SemanticallyEqual` when comparing modifiers
knutwannheden May 23, 2023
6d1ef86
Merge remote-tracking branch 'origin/main' into large-repositories
knutwannheden May 23, 2023
149000c
Fix failing HCL tests after root cursor sharing refactoring
knutwannheden May 23, 2023
76e79c3
Fix failing YAML tests after root cursor sharing refactoring
knutwannheden May 23, 2023
54970dd
Merge remote-tracking branch 'origin/main' into large-repositories
knutwannheden May 23, 2023
d78c367
Avoid J.ArrayType double visit on type
jkschneider May 23, 2023
e3a313b
Don't add types in use to `JavaSourceSet`
knutwannheden May 24, 2023
7e263b3
Restore ShortenFullyQualifiedTypeReferences from rewrite-static-analysis
knutwannheden May 24, 2023
51a630e
Eliminate double visit on AnnotatedType type
jkschneider May 24, 2023
8327aa2
chore: deprecate PartProvider, and change to use internal helper func…
kunli2 May 25, 2023
167bf4e
Merge remote-tracking branch 'origin/main' into large-repositories
knutwannheden May 26, 2023
e0016db
Fix error in `README.md`
knutwannheden May 26, 2023
ad2ec88
getRecipeList called once per cycle
jkschneider May 26, 2023
94cbe57
getInitialValue() -> getInitialValue(ExecutionContext)
jkschneider May 26, 2023
23e1c00
Remove recipeList validation from RewriteTest
jkschneider May 26, 2023
6c2338c
Remove deprecated Gradle recipes
jkschneider May 26, 2023
7d915e1
Merge branch 'main' into large-repositories
sambsnyd May 26, 2023
12c27cc
Get tests passing
sambsnyd May 27, 2023
0d80fec
Update benchmark code
jkschneider May 27, 2023
486c30e
Fixes compilation issues with gradle
May 29, 2023
e579dea
Revert "Fixes compilation issues with gradle"
May 30, 2023
0732f5e
Flush RecipeRunStats
jkschneider May 30, 2023
f53ae0c
Autodetecte
jkschneider May 30, 2023
0bab48d
Fix SourceFileResults data table (#3280)
sambsnyd May 30, 2023
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">OpenRewrite</h1>
<p align="center"><i></i><b>🎉 Automate software refactoring 🎉</b></i></p>
<p align="center"><i><b>🎉 Automate software refactoring 🎉</b></i></p>

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.ChangeMethodTargetToStatic;

import java.util.concurrent.TimeUnit;
Expand All @@ -44,6 +45,6 @@ public static void main(String[] args) throws RunnerException {
@Benchmark
public void changeMethodTargetToStatic(JavaCompilationUnitState state) {
new ChangeMethodTargetToStatic("org.junit.Assert assertThat(..)", "org.hamcrest.MatcherAssert", null, null)
.run(state.getSourceFiles());
.run(state.getSourceSet(), new InMemoryExecutionContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.ChangeType;

import java.util.concurrent.TimeUnit;
Expand All @@ -44,6 +45,6 @@ public static void main(String[] args) throws RunnerException {
@Benchmark
public void changeType(JavaCompilationUnitState state) {
new ChangeType("java.util.List", "java.util.Collection", null)
.run(state.getSourceFiles());
.run(state.getSourceSet(), new InMemoryExecutionContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.search.FindTypes;

import java.util.concurrent.TimeUnit;
Expand All @@ -43,6 +44,7 @@ public static void main(String[] args) throws RunnerException {

@Benchmark
public void findTypes(JavaCompilationUnitState state) {
new FindTypes("java.util.List", false).run(state.getSourceFiles());
new FindTypes("java.util.List", false)
.run(state.getSourceSet(), new InMemoryExecutionContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.LargeSourceSet;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.tree.J;

import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@State(Scope.Benchmark)
public class JavaCompilationUnitState {
List<J.CompilationUnit> sourceFiles;
List<SourceFile> sourceFiles;

@Setup(Level.Trial)
public void setup() throws URISyntaxException {
Expand Down Expand Up @@ -71,15 +74,20 @@ public void setup() throws URISyntaxException {
"org.eclipse.jgit")
// .logCompilationWarningsAndErrors(true)
.build()
.parse(inputs, null, new InMemoryExecutionContext(Throwable::printStackTrace));
.parse(inputs, null, new InMemoryExecutionContext(Throwable::printStackTrace))
.collect(Collectors.toList());
}

@TearDown(Level.Trial)
public void tearDown(Blackhole hole) {
hole.consume(sourceFiles.size());
}

public List<J.CompilationUnit> getSourceFiles() {
public LargeSourceSet getSourceSet() {
return new InMemoryLargeSourceSet(sourceFiles);
}

public List<SourceFile> getSourceFiles() {
return sourceFiles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.OrderImports;

import java.util.concurrent.TimeUnit;
Expand All @@ -35,7 +36,8 @@ public class OrderImportsBenchmark {

@Benchmark
public void orderImports(JavaCompilationUnitState state) {
new OrderImports(false).run(state.getSourceFiles());
new OrderImports(false)
.run(state.getSourceSet(), new InMemoryExecutionContext());
}

public static void main(String[] args) throws RunnerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.openrewrite.Parser;
import org.openrewrite.java.JavaParser;

import java.io.*;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.RemoveImport;
Expand All @@ -44,11 +45,16 @@ public String getDisplayName() {
return "Remove Function";
}

@Override
public String getDescription() {
return "Remove function.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new RemoveImport("java.util.function.Function");
return new RemoveImport<>("java.util.function.Function");
}
}.run(state.getSourceFiles());
}.run(state.getSourceSet(), new InMemoryExecutionContext());
}

public static void main(String[] args) throws RunnerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.SourceFile;
import org.openrewrite.Tree;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.TreeVisitorAdapter;
Expand All @@ -38,7 +39,7 @@ public class TreeVisitorAdapterBenchmark {

@Benchmark
public void adaptToJava(JavaCompilationUnitState cus) {
for (J.CompilationUnit cu : cus.getSourceFiles()) {
for (SourceFile cu : cus.getSourceFiles()) {
//noinspection unchecked
TreeVisitorAdapter.adapt(new TreeVisitor<Tree, Integer>() {
@Override
Expand All @@ -51,7 +52,7 @@ public Tree preVisit(Tree tree, Integer p) {

@Benchmark
public void noAdaptation(JavaCompilationUnitState cus) {
for (J.CompilationUnit cu : cus.getSourceFiles()) {
for (SourceFile cu : cus.getSourceFiles()) {
new JavaVisitor<>().visitNonNull(cu, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.UseStaticImport;

import java.util.concurrent.TimeUnit;
Expand All @@ -35,7 +36,8 @@ public class UseStaticImportBenchmark {

@Benchmark
public void useStaticImport(JavaCompilationUnitState state) {
new UseStaticImport("java.util.List remove(..)").run(state.getSourceFiles());
new UseStaticImport("java.util.List remove(..)")
.run(state.getSourceSet(), new InMemoryExecutionContext());
}

public static void main(String[] args) throws RunnerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.java.tree.J;
import org.openrewrite.SourceFile;

import java.util.Collections;
import java.util.IdentityHashMap;
Expand All @@ -41,7 +41,7 @@ public class WeighingJavaAstsBenchmark {
public void bloomFilter(JavaCompilationUnitState state, Blackhole blackhole) {
Bloom bloom = Bloom.construct(new long[0], 1);
long weight = 0;
for (J.CompilationUnit sourceFile : state.getSourceFiles()) {
for (SourceFile sourceFile : state.getSourceFiles()) {
weight += sourceFile.getWeight(t -> {
int id = System.identityHashCode(t);
if (bloom.mayContain(id)) {
Expand All @@ -58,7 +58,7 @@ public void bloomFilter(JavaCompilationUnitState state, Blackhole blackhole) {
public void identitySet(JavaCompilationUnitState state, Blackhole blackhole) {
Set<Object> uniqueTypes = Collections.newSetFromMap(new IdentityHashMap<>());
long weight = 0;
for (J.CompilationUnit sourceFile : state.getSourceFiles()) {
for (SourceFile sourceFile : state.getSourceFiles()) {
weight += sourceFile.getWeight(uniqueTypes::add);
}
blackhole.consume(weight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@PolyglotNamespace("OpenRewrite")
@NonNullApi
package org.openrewrite.benchmarks.java;

import org.openrewrite.PolyglotNamespace;
import org.openrewrite.internal.lang.NonNullApi;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openrewrite.benchmarks.maven;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
Expand All @@ -31,7 +32,9 @@
import org.openrewrite.xml.tree.Xml;

import java.nio.file.Paths;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Fork(1)
@Measurement(iterations = 2)
Expand All @@ -54,11 +57,12 @@ public static void main(String[] args) throws RunnerException {
}

@Benchmark
public void parse() {
public void parse(Blackhole blackhole) {
MavenExecutionContextView ctx = MavenExecutionContextView.view(new InMemoryExecutionContext());
ctx.setPomCache(pomCache);

Xml.Document maven = MavenParser.builder().build().parse(ctx, "" +
Optional<Xml.Document> maven = MavenParser.builder().build().parse(ctx,
"" +
"<project>" +
" <parent>" +
" <groupId>org.springframework.boot</groupId>" +
Expand All @@ -80,9 +84,8 @@ public void parse() {
" </dependency>" +
" </dependencies>" +
"</project>"
).get(0);
).findFirst();

// System.out.println(maven.getMarkers().findFirst(MavenResolutionResult.class).get().getDependencies()
// .get(org.openrewrite.maven.tree.Scope.Compile).size());
blackhole.consume(maven);
}
}
68 changes: 0 additions & 68 deletions rewrite-core/src/main/java/org/openrewrite/Applicability.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2023 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java;
package org.openrewrite;

import org.openrewrite.Recipe;
import java.util.List;

import java.lang.annotation.*;
public interface Changeset {
int size();

@Target(ElementType.PACKAGE)
@Retention(RetentionPolicy.CLASS)
public @interface RewriteSkip {
String[] recipes() default {};
Class<? extends Recipe>[] recipeClasses() default {};
List<Result> getPage(int start, int count);

default List<Result> getAllResults() {
return getPage(0, size());
}
}
Loading