Skip to content

Commit

Permalink
Merge branch 'main' into testUpgradePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Dec 13, 2024
2 parents 0211c3f + cdb945f commit 1057a82
Show file tree
Hide file tree
Showing 501 changed files with 27,056 additions and 7,420 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v4
env:
Expand Down
61 changes: 0 additions & 61 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,3 @@ jobs:
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main
with:
recipe: 'org.openrewrite.recipes.OpenRewriteBestPracticesSubset'
rewrite_yml: |
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.OpenRewriteBestPracticesSubset
displayName: OpenRewrite best practices
description: Best practices for OpenRewrite recipe development.
recipeList:
- org.openrewrite.recipes.JavaRecipeBestPracticesSubset
- org.openrewrite.recipes.RecipeTestingBestPracticesSubset
- org.openrewrite.recipes.RecipeNullabilityBestPracticesSubset
#- org.openrewrite.java.OrderImports
- org.openrewrite.java.format.EmptyNewlineAtEndOfFile
- org.openrewrite.staticanalysis.InlineVariable
- org.openrewrite.staticanalysis.MissingOverrideAnnotation
- org.openrewrite.staticanalysis.UseDiamondOperator
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.JavaRecipeBestPracticesSubset
displayName: Java Recipe best practices
description: Best practices for Java recipe development.
preconditions:
- org.openrewrite.java.search.FindTypes:
fullyQualifiedTypeName: org.openrewrite.Recipe
checkAssignability: true
recipeList:
- org.openrewrite.java.recipes.BlankLinesAroundFieldsWithAnnotations
- org.openrewrite.java.recipes.ExecutionContextParameterName
- org.openrewrite.java.recipes.MissingOptionExample
- org.openrewrite.java.recipes.RecipeEqualsAndHashCodeCallSuper
- org.openrewrite.java.recipes.UseTreeRandomId
- org.openrewrite.staticanalysis.NeedBraces
#- org.openrewrite.staticanalysis.RemoveSystemOutPrintln
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.RecipeTestingBestPracticesSubset
displayName: Recipe testing best practices
description: Best practices for testing recipes.
preconditions:
- org.openrewrite.java.search.FindTypes:
fullyQualifiedTypeName: org.openrewrite.test.RewriteTest
checkAssignability: true
recipeList:
- org.openrewrite.java.recipes.RewriteTestClassesShouldNotBePublic
#- org.openrewrite.java.recipes.SelectRecipeExamples
- org.openrewrite.java.recipes.SourceSpecTextBlockIndentation
- org.openrewrite.java.testing.cleanup.RemoveTestPrefix
- org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
- org.openrewrite.staticanalysis.NeedBraces
- org.openrewrite.staticanalysis.RemoveSystemOutPrintln
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.RecipeNullabilityBestPracticesSubset
displayName: Recipe nullability best practices
description: Use OpenRewrite internal nullability annotations; drop JetBrains annotations; use `package-info.java` instead.
recipeList:
- org.openrewrite.staticanalysis.NullableOnMethodReturnType
- org.openrewrite.java.RemoveAnnotation:
annotationPattern: '@org.jetbrains.annotations.NotNull'
- org.openrewrite.java.RemoveAnnotation:
annotationPattern: '@jakarta.annotation.Nonnull'
- org.openrewrite.java.jspecify.MigrateToJspecify
1 change: 1 addition & 0 deletions IDE.properties.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rewrite-test
# language parser.

rewrite-java
rewrite-java-lombok
rewrite-java-test
rewrite-java-tck
rewrite-java-17
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<h1 align="center">Fast, repeatable refactoring for developers</h1>

The OpenRewrite project is an automated refactoring ecosystem for source code, enabling developers to effectively eliminate technical debt within their repositories.
The OpenRewrite project (managed by [Moderne](https://www.moderne.ai/)) is an open-source automated refactoring ecosystem for source code, enabling developers to effectively eliminate technical debt within their repositories.

It consists of an auto-refactoring engine that runs prepackaged, open source refactoring recipes for common framework migrations, security fixes, and stylistic consistency tasks—reducing your coding effort from hours or days to minutes. Build tool plugins like [OpenRewrite Gradle Plugin](https://docs.openrewrite.org/reference/gradle-plugin-configuration) and [OpenRewrite Maven Plugin](https://docs.openrewrite.org/reference/rewrite-maven-plugin) help you run these recipes on one repository at a time.

Expand Down
2 changes: 1 addition & 1 deletion doc/adr/0003-oss-contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Provide guidelines for open source contributors to Rewrite projects.

### Backlog project

OSS maintainers should regularly assign new issues to the [Backlog](https://github.com/orgs/openrewrite/projects/1) project. By default, issues begin in the icebox and are pulled forward to the backlog when work is anticipated soon.
OSS maintainers should regularly assign new issues to the [Backlog](https://github.com/orgs/openrewrite/projects/4/views/10) project. By default, issues begin in the icebox and are pulled forward to the backlog when work is anticipated soon.

### Milestones

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
1 change: 1 addition & 0 deletions rewrite-benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
jmh(project(":rewrite-maven"))
jmh("org.rocksdb:rocksdbjni:latest.release")
jmh("org.openjdk.jmh:jmh-core:latest.release")
jmh("org.openjdk.jol:jol-core:latest.release")
jmh("io.github.fastfilter:fastfilter:latest.release")

// Nebula doesn't like having jmhAnnotationProcessor without jmh so we just add it twice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,53 @@
*/
package org.openrewrite.benchmarks.java;

import org.jspecify.annotations.Nullable;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jol.info.GraphLayout;
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.internal.AdaptiveRadixJavaTypeCache;
import org.openrewrite.java.internal.JavaTypeCache;

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

@State(Scope.Benchmark)
public class JavaCompilationUnitState {
JavaParser.Builder<? extends JavaParser, ?> javaParser;
List<SourceFile> sourceFiles;
List<Path> inputs;
JavaTypeCache snappyTypeCache;
AdaptiveRadixJavaTypeCache radixMapTypeCache;
MapJavaTypeCache typeCache;

public static void main(String[] args) throws URISyntaxException {
new JavaCompilationUnitState().setup();
}

@Setup(Level.Trial)
public void setup() throws URISyntaxException {
Path rewriteRoot = Paths.get(ChangeTypeBenchmark.class.getResource("./")
.toURI()).resolve("../../../../../../../../").normalize();

List<Path> inputs = Arrays.asList(
inputs = Arrays.asList(
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/lang/Nullable.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/lang/NullUtils.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/MetricsHelper.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/ListUtils.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/PropertyPlaceholderHelper.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/RecipeIntrospectionUtils.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/Tree.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/ExecutionContext.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/InMemoryExecutionContext.java"),
Expand All @@ -61,21 +76,45 @@ public void setup() throws URISyntaxException {
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/Result.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/SourceFile.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/Recipe.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/ScanningRecipe.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/Validated.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/ValidationException.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/TreeVisitor.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/TreeObserver.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/config/DeclarativeRecipe.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/config/ResourceLoader.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/config/ClasspathScanningLoader.java"),
rewriteRoot.resolve("rewrite-core/src/main/java/org/openrewrite/config/RecipeIntrospectionException.java")
);

sourceFiles = JavaParser.fromJavaVersion()
.classpath("jsr305", "classgraph", "jackson-annotations", "micrometer-core", "slf4j-api",
"org.openrewrite.jgit")
javaParser = JavaParser.fromJavaVersion()
.classpath("jsr305", "classgraph", "jackson-annotations", "micrometer-core",
"jgit", "jspecify", "lombok", "annotations");
// .logCompilationWarningsAndErrors(true)
.build()
.parse(inputs, null, new InMemoryExecutionContext(Throwable::printStackTrace))

typeCache = new MapJavaTypeCache();
JavaParser parser = javaParser.typeCache(typeCache).build();
sourceFiles = parser
.parse(inputs, null, new InMemoryExecutionContext())
.collect(Collectors.toList());

radixMapTypeCache = new AdaptiveRadixJavaTypeCache();
for (Map.Entry<String, Object> entry : typeCache.map().entrySet()) {
radixMapTypeCache.put(entry.getKey(), entry.getValue());
}

snappyTypeCache = new JavaTypeCache();
for (Map.Entry<String, Object> entry : typeCache.map().entrySet()) {
snappyTypeCache.put(entry.getKey(), entry.getValue());
}
}

void printMemory() {
long retainedSize = GraphLayout.parseInstance(radixMapTypeCache).totalSize();
System.out.printf("Retained AdaptiveRadixTree size: %10d bytes\n", retainedSize);
retainedSize = GraphLayout.parseInstance(snappyTypeCache).totalSize();
System.out.printf("Retained Snappy size: %10d bytes\n", retainedSize);
}

@TearDown(Level.Trial)
Expand All @@ -90,4 +129,41 @@ public LargeSourceSet getSourceSet() {
public List<SourceFile> getSourceFiles() {
return sourceFiles;
}

static class MapJavaTypeCache extends JavaTypeCache {

Map<String, Object> typeCache = new HashMap<>();

@Override
public <T> @Nullable T get(String signature) {
//noinspection unchecked
return (T) typeCache.get(signature);
}

@Override
public void put(String signature, Object o) {
typeCache.put(signature, o);
}

public Map<String, Object> map() {
return typeCache;
}

@Override
public void clear() {
typeCache.clear();
}

@Override
public int size() {
return typeCache.size();
}

@Override
public MapJavaTypeCache clone() {
MapJavaTypeCache clone = (MapJavaTypeCache) super.clone();
clone.typeCache = new HashMap<>(this.typeCache);
return clone;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@State(Scope.Benchmark)
Expand All @@ -38,10 +39,13 @@ public void setup() throws URISyntaxException, IOException {
throw new RuntimeException("Unable to create directory");
}

sourceFiles = new ArrayList<>(1_000);
for (int i = 0; i < 1_000; i++) {
Files.writeString(test.resolve("Test" + i + ".java"),
"package test; class Test" + i + " {}");
sourceFiles = new ArrayList<>(100);
// to add some "meat to the bones"
String whitespace = String.join("", Collections.nCopies(1_000, " "));
for (int i = 0; i < 100; i++) {
Path path = test.resolve("Test" + i + ".java");
Files.writeString(path, "package test; class Test%d {%s}".formatted(i, whitespace));
sourceFiles.add(path);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2022 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.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.benchmarks.java;

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;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.internal.AdaptiveRadixJavaTypeCache;
import org.openrewrite.java.internal.JavaTypeCache;

import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;

@Fork(1)
@Measurement(iterations = 2)
@Warmup(iterations = 2)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@Threads(4)
public class JavaParserBenchmark {

@Benchmark
public void snappy(JavaCompilationUnitState state, Blackhole bh) {
JavaTypeCache typeCache = new JavaTypeCache();
JavaParser parser = state.javaParser.typeCache(typeCache).build();
parser
.parse(state.inputs, null, new InMemoryExecutionContext())
.forEach(bh::consume);
}

@Benchmark
public void adaptiveRadix(JavaCompilationUnitState state, Blackhole bh) {
AdaptiveRadixJavaTypeCache typeCache = new AdaptiveRadixJavaTypeCache();
JavaParser parser = state.javaParser.typeCache(typeCache).build();
parser
.parse(state.inputs, null, new InMemoryExecutionContext())
.forEach(bh::consume);
}

public static void main(String[] args) throws RunnerException, URISyntaxException {
Options opt = new OptionsBuilder()
.include(JavaParserBenchmark.class.getSimpleName())
.addProfiler(GCProfiler.class)
.shouldFailOnError(true)
.build();
new Runner(opt).run();
JavaCompilationUnitState state = new JavaCompilationUnitState();
state.setup();
state.printMemory();
}
}
Loading

0 comments on commit 1057a82

Please sign in to comment.