Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Feb 13, 2024
2 parents d60b4d5 + becbfc0 commit 10766cc
Show file tree
Hide file tree
Showing 482 changed files with 8,652 additions and 6,040 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ concurrency:
jobs:
build:
uses: openrewrite/gh-automation/.github/workflows/ci-gradle.yml@main
with:
java_version: 21
secrets:
gradle_enterprise_access_key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
gradle_enterprise_cache_username: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/dependency-check.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Dependency Submission

on:
workflow_run:
workflows: ["publish"]
types:
- completed

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v3
env:
# Exclude all dependencies that originate solely in the 'buildSrc' project
DEPENDENCY_GRAPH_EXCLUDE_PROJECTS: ':buildSrc'
# Exclude dependencies that are only resolved in test classpaths
DEPENDENCY_GRAPH_EXCLUDE_CONFIGURATIONS: '.*[Tt]est(Compile|Runtime)Classpath'
3 changes: 2 additions & 1 deletion IDE.properties.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rewrite-java
rewrite-java-test
rewrite-java-tck
rewrite-java-17
rewrite-java-21

# Other language modules

Expand All @@ -42,4 +43,4 @@ rewrite-bom

# Tools that are used less frequently to, for example, build new language parsers.

tools
#tools
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ See this [doc page](https://docs.openrewrite.org/reference/building-openrewrite-

## Refactoring at scale with Moderne

OpenRewrite's refactoring engine and recipes will always be open source. 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. Moderne is a complementary product that executes OpenRewrite recipes at scale on hundreds of millions of lines of code and enables mass-committing of results. Moderne freely runs a [public service](https://public.moderne.io) for the benefit of thousands of open source projects.
OpenRewrite's refactoring engine and recipes will always be open source. 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. Moderne is a complementary commercial product that executes OpenRewrite recipes at scale on hundreds of millions of lines of code and enables mass-committing of results and large scale impact analysis. Moderne freely runs an [open public service](https://app.moderne.io) for the benefit of tens of thousands of open source projects.

[![Moderne](./doc/video_preview.png)](https://youtu.be/Mq6bKAeGCz0)
To understand better how Moderne can help your team, [contact us here](https://www.moderne.io/try-moderne).

[![Moderne](./doc/video_preview.png)](https://youtu.be/cs-6FJ_mtro)

## Contributing

Expand Down
14 changes: 14 additions & 0 deletions doc/adr/0005-parser-lst-conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 5. Parser and LST Design Conventions and Best Practices

## Status

Draft

## Context

As we have developed parsers for more programming languages and data formats a number of conventions and best practices
have emerged. This document is intended to capture and codify those conventions and best practices.

## Decision


Binary file modified doc/video_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=9631d53cf3e74bfa726893aee1f8994fee4e060c401335946dba2156f440f24c
20 changes: 10 additions & 10 deletions gradlew.bat
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.tree.J;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@State(Scope.Benchmark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.UseStaticImport;

import java.util.concurrent.TimeUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.TreeVisitorAdapter;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.tree.J;

import java.util.concurrent.TimeUnit;

Expand Down
2 changes: 1 addition & 1 deletion rewrite-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

dependencies {
constraints {
rootProject.subprojects.filter { it != project && !it.name.contains("benchmark") }.sortedBy { it.name }.forEach {
rootProject.subprojects.filter { it != project && !it.name.contains("benchmark") && it.name != "tools" }.sortedBy { it.name }.forEach {
api(it)
}
}
Expand Down
1 change: 1 addition & 0 deletions rewrite-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
api("com.fasterxml.jackson.core:jackson-databind")
api("com.fasterxml.jackson.dataformat:jackson-dataformat-smile")
api("com.fasterxml.jackson.module:jackson-module-parameter-names")
api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("net.java.dev.jna:jna-platform:latest.release")

// Pinning okhttp while waiting on 5.0.0
Expand Down
7 changes: 3 additions & 4 deletions rewrite-core/src/main/java/org/openrewrite/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.Getter;
import lombok.Setter;
import org.intellij.lang.annotations.Language;

import java.lang.reflect.ParameterizedType;
Expand All @@ -41,6 +42,7 @@ public class DataTable<Row> {
@Language("markdown")
private final String description;

@Setter
private boolean enabled = true;

/**
Expand Down Expand Up @@ -72,15 +74,12 @@ public DataTable(Recipe recipe,
recipe.addDataTable(this);
}

@SuppressWarnings("unused")
public TypeReference<List<Row>> getRowsTypeReference() {
return new TypeReference<List<Row>>() {
};
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public void insertRow(ExecutionContext ctx, Row row) {
if (enabled && ctx.getCycle() <= maxCycle) {
ctx.computeMessage(ExecutionContext.DATA_TABLES, row, ConcurrentHashMap::new, (extract, allDataTables) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.nio.file.PathMatcher;

@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class DeleteSourceFiles extends Recipe {

@Option(displayName = "File pattern",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ default <V, C extends Collection<V>> C putMessageInCollection(String key, V valu
});
}

@SuppressWarnings("unused")
default <T> Set<T> putMessageInSet(String key, T value) {
return putMessageInCollection(key, value, HashSet::new);
}
Expand All @@ -84,11 +85,13 @@ default <T> T getMessage(String key, @Nullable T defaultValue) {

@Nullable <T> T pollMessage(String key);

@SuppressWarnings("unused")
default <T> T pollMessage(String key, T defaultValue) {
T t = pollMessage(key);
return t == null ? defaultValue : t;
}

@SuppressWarnings("unused")
default void putCurrentRecipe(Recipe recipe) {
putMessage(CURRENT_RECIPE, recipe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Set;

@Value
@EqualsAndHashCode(callSuper = true)
public class FindCollidingSourceFiles extends ScanningRecipe<FindCollidingSourceFiles.Accumulator>{
@EqualsAndHashCode(callSuper = false)
public class FindCollidingSourceFiles extends ScanningRecipe<FindCollidingSourceFiles.Accumulator> {

transient CollidingSourceFiles collidingSourceFiles = new CollidingSourceFiles(this);

Expand Down Expand Up @@ -56,10 +56,8 @@ public TreeVisitor<?, ExecutionContext> getScanner(Accumulator acc) {
public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
assert tree instanceof SourceFile;
Path p = ((SourceFile) tree).getSourcePath();
if(acc.getSourcePaths().contains(p)) {
if (!acc.getSourcePaths().add(p)) {
acc.getDuplicates().add(p);
} else {
acc.getSourcePaths().add(p);
}
return tree;
}
Expand All @@ -77,9 +75,9 @@ public TreeVisitor<?, ExecutionContext> getVisitor(Accumulator acc) {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
if(tree instanceof SourceFile) {
if (tree instanceof SourceFile) {
Path p = ((SourceFile) tree).getSourcePath();
if(acc.getDuplicates().contains(p)) {
if (acc.getDuplicates().contains(p)) {
collidingSourceFiles.insertRow(ctx, new CollidingSourceFiles.Row(
p.toString(),
tree.getClass().toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2024 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;

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.marker.DeserializationError;
import org.openrewrite.marker.LstProvenance;
import org.openrewrite.marker.Markup;
import org.openrewrite.marker.OutdatedSerializer;
import org.openrewrite.table.DeserializationErrorTable;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Optional;

import static java.time.ZoneOffset.UTC;

@Value
@EqualsAndHashCode(callSuper = false)
public class FindDeserializationErrors extends Recipe {

@Override
public String getDisplayName() {
return "Find deserialization errors";
}

@Override
public String getDescription() {
return "Produces a data table collecting all deserialization errors of serialized LSTs.";
}

transient DeserializationErrorTable dataTable = new DeserializationErrorTable(this);

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
@Override
public Tree preVisit(Tree tree, ExecutionContext ctx) {
stopAfterPreVisit();
return tree.getMarkers().findFirst(DeserializationError.class)
.map(error -> {
Optional<OutdatedSerializer> outdatedSerializer = tree.getMarkers().findFirst(OutdatedSerializer.class);
Optional<LstProvenance> lstProvenance = tree.getMarkers().findFirst(LstProvenance.class);
dataTable.insertRow(ctx, new DeserializationErrorTable.Row(
tree instanceof SourceFile ? ((SourceFile) tree).getSourcePath().toString() : null,
error.getMessage(),
error.getDetail(),
outdatedSerializer.map(OutdatedSerializer::getLanguage).orElse(null),
outdatedSerializer.map(OutdatedSerializer::getMinimumVersion).orElse(null),
outdatedSerializer.map(OutdatedSerializer::getActualVersion)
.orElseGet(() -> lstProvenance.map(LstProvenance::getBuildToolVersion).orElse(null)),
lstProvenance.map(LstProvenance::getTimestampUtc).map(Instant::toEpochMilli).orElse(null),
lstProvenance.map(LstProvenance::getTimestampUtc).map(ts -> ts.atZone(UTC)).map(ZonedDateTime::toString).orElse(null)
));

return Markup.info(tree, error.getMessage());
})
.orElse(tree);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static java.time.ZoneOffset.UTC;

@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class FindLstProvenance extends ScanningRecipe<FindLstProvenance.Accumulator> {

@Override
Expand All @@ -36,7 +36,7 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Produces a data table showing what versions of OpenRewrite/Moderne tooling was used to produce a given LST. ";
return "Produces a data table showing what versions of OpenRewrite/Moderne tooling was used to produce a given LST.";
}

transient LstProvenanceTable provenanceTable = new LstProvenanceTable(this);
Expand Down
Loading

0 comments on commit 10766cc

Please sign in to comment.