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 98 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
  •  
  •  
  •  
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;
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());
}
}
8 changes: 3 additions & 5 deletions rewrite-core/src/main/java/org/openrewrite/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public Cursor dropParentWhile(Predicate<Object> valuePredicate) {
return cursor;
}

@Incubating(since = "7.0.0")
@Nullable
public Cursor getParent(int levels) {
Cursor cursor = this;
Expand All @@ -219,7 +218,6 @@ public Cursor getParent() {
return getParent(1);
}

@Incubating(since = "7.0.0")
public Cursor getParentOrThrow(int levels) {
Cursor parent = getParent(levels);
if (parent == null) {
Expand All @@ -235,7 +233,7 @@ public Cursor getParentOrThrow() {
/**
* Return the first parent of the current cursor which points to an AST element, or the root cursor if the current
* cursor already points to the root AST element. This skips over non-tree Padding elements.
*
* <br/>
* If you do want to access Padding elements, use getParent() or getParentOrThrow(), which do not skip over these elements.
*
* @return a cursor which either points at the first non-padding parent of the current element
Expand Down Expand Up @@ -273,8 +271,8 @@ public <T> T computeMessageIfAbsent(String key, Function<String, ? extends T> ma
if (messages == null) {
messages = new HashMap<>();
}
@SuppressWarnings("unchecked") T t = (T) messages.computeIfAbsent(key, mappingFunction);
return t;
//noinspection unchecked
return (T) messages.computeIfAbsent(key, mappingFunction);
}

/**
Expand Down
1 change: 0 additions & 1 deletion rewrite-core/src/main/java/org/openrewrite/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

Expand Down
32 changes: 1 addition & 31 deletions rewrite-core/src/main/java/org/openrewrite/ExecutionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.openrewrite.internal.lang.Nullable;

import java.time.Duration;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
Expand All @@ -30,9 +29,9 @@
*/
public interface ExecutionContext {
String CURRENT_RECIPE = "org.openrewrite.currentRecipe";
String PARENT_RECIPE = "org.openrewrite.parentRecipe";
String UNCAUGHT_EXCEPTION_COUNT = "org.openrewrite.uncaughtExceptionCount";
String DATA_TABLES = "org.openrewrite.dataTables";
String RUN_TIMEOUT = "org.openrewrite.runTimeout";

@Incubating(since = "7.20.0")
default ExecutionContext addObserver(TreeObserver.Subscription observer) {
Expand Down Expand Up @@ -89,26 +88,6 @@ default void putCurrentRecipe(Recipe recipe) {
putMessage(CURRENT_RECIPE, recipe);
}

/**
* @return The previous parent recipe.
* @implNote For use in the {@link RecipeScheduler} only.
*/
@Nullable
@Incubating(since = "7.37.0")
default Recipe putParentRecipe(@Nullable Recipe recipe) {
Recipe previousParent = getMessage(PARENT_RECIPE);
putMessage(PARENT_RECIPE, recipe);
return previousParent;
}

/**
* The recipe that scheduled this recipe's execution via {@link Recipe#getApplicableTests()} or {@link Recipe#getSingleSourceApplicableTests()}.
*/
@Incubating(since = "7.37.0")
default Optional<Recipe> getParentRecipe() {
return Optional.ofNullable(getMessage(PARENT_RECIPE));
}

default int incrementAndGetUncaughtExceptionCount() {
int count = getMessage(UNCAUGHT_EXCEPTION_COUNT, 0) + 1;
putMessage(UNCAUGHT_EXCEPTION_COUNT, count);
Expand All @@ -118,13 +97,4 @@ default int incrementAndGetUncaughtExceptionCount() {
Consumer<Throwable> getOnError();

BiConsumer<Throwable, ExecutionContext> getOnTimeout();

/**
* @param inputs The number of inputs to the run. Allows the duration to be scaled to the number of inputs.
* @return The maximum duration a run (e.g. parse operation, recipe run) can take.
*/
@Incubating(since = "7.3.0")
default Duration getRunTimeout(int inputs) {
return Duration.ofHours(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
*/
package org.openrewrite;

import lombok.*;
import lombok.Value;
import lombok.With;
import org.openrewrite.internal.lang.Nullable;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

@Value
@With
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static java.util.Objects.requireNonNull;

@Value
@EqualsAndHashCode(callSuper = true)
public class FindBuildToolFailures extends Recipe {
Expand All @@ -49,10 +51,11 @@ public String getDescription() {
}

@Override
protected TreeVisitor<?, ExecutionContext> getVisitor() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public Tree visitSourceFile(SourceFile sourceFile, ExecutionContext ctx) {
public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
jkschneider marked this conversation as resolved.
Show resolved Hide resolved
return sourceFile.getMarkers().findFirst(BuildToolFailure.class)
.<Tree>map(failure -> {
String logFileContents = sourceFile.printAll();
Expand Down
54 changes: 27 additions & 27 deletions rewrite-core/src/main/java/org/openrewrite/FindGitProvenance.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
*/
package org.openrewrite;

import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.marker.GitProvenance;
import org.openrewrite.marker.Markup;
import org.openrewrite.table.DistinctGitProvenance;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;

import static java.util.Objects.requireNonNull;

public class FindGitProvenance extends ScanningRecipe<Set<GitProvenance>> {
// we are looking for substantive differences, not just ID differences
private static final UUID DONT_CONSIDER_ID_IN_HASH_CODE = UUID.randomUUID();

public class FindGitProvenance extends Recipe {
private final DistinctGitProvenance distinct = new DistinctGitProvenance(this);

@Override
Expand All @@ -41,35 +42,34 @@ public String getDescription() {
}

@Override
protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx) {
Set<GitProvenance> provenances = new HashSet<>();

// we are looking for substantive differences, not just ID differences
UUID dontConsiderIdInHashCode = UUID.randomUUID();
public Set<GitProvenance> getInitialValue() {
return new HashSet<>();
}

return ListUtils.map(before, sourceFile -> {
GitProvenance provenance = sourceFile.getMarkers().findFirst(GitProvenance.class).orElse(null);
if (provenance == null || !provenances.add(provenance.withId(dontConsiderIdInHashCode))) {
@Override
public TreeVisitor<?, ExecutionContext> getScanner(Set<GitProvenance> provenances) {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public Tree visit(@Nullable Tree tree, ExecutionContext executionContext) {
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
sourceFile.getMarkers().findFirst(GitProvenance.class).ifPresent(provenance ->
provenances.add(provenance.withId(DONT_CONSIDER_ID_IN_HASH_CODE)));
return sourceFile;
}
};
}

@Override
public Collection<SourceFile> generate(Set<GitProvenance> provenances, ExecutionContext ctx) {
for (GitProvenance provenance : provenances) {
distinct.insertRow(ctx, new DistinctGitProvenance.Row(
provenance.getOrigin(),
provenance.getBranch(),
provenance.getChange(),
provenance.getAutocrlf(),
provenance.getEol())
);
return Markup.info(sourceFile, String.format("GitProvenance:\n" +
" origin: %s\n" +
" branch: %s\n" +
" changeset: %s\n" +
" autocrlf: %s\n" +
" eol: %s",
provenance.getOrigin(),
provenance.getBranch(),
provenance.getChange(),
provenance.getAutocrlf() != null ? provenance.getAutocrlf().toString() : "null",
provenance.getEol() != null ? provenance.getEol().toString() : "null"));
});
}
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.marker.Markup;
import org.openrewrite.table.ParseFailures;

import static java.util.Objects.requireNonNull;

@Value
@EqualsAndHashCode(callSuper = true)
public class FindParseFailures extends Recipe {
Expand All @@ -37,10 +40,11 @@ public String getDescription() {
}

@Override
protected TreeVisitor<?, ExecutionContext> getVisitor() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public Tree visitSourceFile(SourceFile sourceFile, ExecutionContext ctx) {
public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
return sourceFile.getMarkers().findFirst(ParseExceptionResult.class)
.<Tree>map(exceptionResult -> {
failures.insertRow(ctx, new ParseFailures.Row(
Expand Down
10 changes: 7 additions & 3 deletions rewrite-core/src/main/java/org/openrewrite/FindQuarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.marker.SearchResult;
import org.openrewrite.quark.Quark;

import static java.util.Objects.requireNonNull;

@Value
@EqualsAndHashCode(callSuper = true)
public class FindQuarks extends Recipe {
Expand All @@ -30,14 +33,15 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Find instances of type `Quark`.";
return "`Quark` source files are pointers to the existence of a file without capturing any of the contents of the file.";
}

@Override
protected TreeVisitor<?, ExecutionContext> getVisitor() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public Tree visitSourceFile(SourceFile sourceFile, ExecutionContext executionContext) {
public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
if (sourceFile instanceof Quark) {
return SearchResult.found(sourceFile);
}
Expand Down
Loading