Skip to content

Commit 0e76221

Browse files
committed
Merge remote-tracking branch 'origin/main' into lunar-lynx
# Conflicts: # rewrite-javascript/rewrite/src/javascript/parser.ts
2 parents c286269 + 2fda680 commit 0e76221

747 files changed

Lines changed: 97632 additions & 13400 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/comment-pr.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/receive-pr.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

IDE.properties.tmp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rewrite-java-25
2727

2828
# Other language modules
2929

30+
rewrite-docker
3031
rewrite-gradle
3132
rewrite-groovy
3233
rewrite-hcl

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ allprojects {
2222
group = "org.openrewrite"
2323
description = "Eliminate tech-debt. Automatically."
2424
}
25+
26+
// Use this task locally between different dependency check runs to have updated analysis:
27+
// OSSINDEX_PASSWORD=... OSSINDEX_USERNAME=... gradle cleanReports dCAg --no-parallel
28+
tasks.register<Delete>("cleanReports") {
29+
description = "Removes build/reports folder from all modules"
30+
group = "owasp dependency-check"
31+
delete(allprojects.map { it.layout.buildDirectory.dir("reports") })
32+
}

rewrite-core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ tasks.withType<Javadoc> {
4646
// symbol: method onConstructor_()
4747
// location: @interface AllArgsConstructor
4848
// 1 error
49-
exclude("**/RpcObjectData.java")
49+
exclude("**/RpcObjectData.java", "**/RecipeDescriptor.java")
5050
}

rewrite-core/src/main/java/org/openrewrite/Checksum.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.IOException;
2727
import java.io.InputStream;
28+
import java.io.UncheckedIOException;
2829
import java.net.URI;
2930
import java.nio.charset.StandardCharsets;
3031
import java.nio.file.Files;
@@ -83,6 +84,10 @@ public static Checksum fromUri(HttpSender httpSender, URI uri, String algorithm)
8384
.withMethod(HttpSender.Method.GET)
8485
.build();
8586
try (HttpSender.Response response = httpSender.send(request)) {
87+
if (!response.isSuccessful()) {
88+
throw new UncheckedIOException(new IOException(
89+
"Failed to download checksum from " + uri + ": HTTP " + response.getCode()));
90+
}
8691
String hexString = new String(response.getBodyAsBytes(), StandardCharsets.UTF_8);
8792
return Checksum.fromHex(algorithm, hexString);
8893
}

rewrite-core/src/main/java/org/openrewrite/LargeSourceSet.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,17 @@ default void afterCycle(boolean lastCycle) {
9999
*/
100100
@Nullable
101101
SourceFile getBefore(Path sourcePath);
102+
103+
/**
104+
* Called when a recipe's {@code generate()} produces a file whose path collides with
105+
* an existing source file or with another generated file. The generated file is silently
106+
* dropped. Implementations may override this to detect the collision (e.g. the test
107+
* framework raises an assertion failure).
108+
*
109+
* @param sourcePath The colliding source path.
110+
* @param existingFile {@code true} if the collision is with an existing source file,
111+
* {@code false} if it's with another generated file.
112+
*/
113+
default void onGenerateCollision(Path sourcePath, boolean existingFile) {
114+
}
102115
}

rewrite-core/src/main/java/org/openrewrite/Recipe.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ public String getInstanceNameSuffix() {
203203
* A set of strings used for categorizing related recipes. For example
204204
* "testing", "junit", "spring". Any individual tag should consist of a
205205
* single word, all lowercase.
206-
*
207-
* @return The tags.
208206
*/
209207
@Getter
210208
final Set<String> tags = emptySet();
@@ -225,11 +223,21 @@ public final RecipeDescriptor getDescriptor() {
225223

226224
protected RecipeDescriptor createRecipeDescriptor() {
227225
List<OptionDescriptor> options = getOptionDescriptors();
228-
ArrayList<RecipeDescriptor> recipeList1 = new ArrayList<>();
229-
for (Recipe next : getRecipeList()) {
230-
recipeList1.add(next.getDescriptor());
226+
List<RecipeDescriptor> preconditionDescriptors = emptyList();
227+
if (this instanceof RecipePreconditions) {
228+
RecipePreconditions recipeWithPreconditions = (RecipePreconditions) this;
229+
List<Recipe> preconditions = recipeWithPreconditions.getPreconditions();
230+
preconditionDescriptors = new ArrayList<>(preconditions.size());
231+
for (Recipe precondition : preconditions) {
232+
preconditionDescriptors.add(precondition.getDescriptor());
233+
}
234+
}
235+
236+
List<Recipe> recipeList = getRecipeList();
237+
List<RecipeDescriptor> recipeDescriptors = new ArrayList<>(recipeList.size());
238+
for (Recipe next : recipeList) {
239+
recipeDescriptors.add(next.getDescriptor());
231240
}
232-
recipeList1.trimToSize();
233241

234242
URI recipeSource;
235243
try {
@@ -239,7 +247,7 @@ protected RecipeDescriptor createRecipeDescriptor() {
239247
}
240248

241249
return new RecipeDescriptor(getName(), getDisplayName(), getInstanceName(), getDescription(), getTags(),
242-
getEstimatedEffortPerOccurrence(), options, recipeList1, getDataTableDescriptors(),
250+
getEstimatedEffortPerOccurrence(), options, preconditionDescriptors, recipeDescriptors, getDataTableDescriptors(),
243251
getMaintainers(), getContributors(), getExamples(), recipeSource);
244252
}
245253

@@ -449,12 +457,7 @@ public final RecipeRun run(LargeSourceSet before, ExecutionContext ctx, int maxC
449457

450458
@SuppressWarnings("unused")
451459
public Validated<Object> validate(ExecutionContext ctx) {
452-
Validated<Object> validated = validate();
453-
454-
for (Recipe recipe : getRecipeList()) {
455-
validated = validated.and(recipe.validate(ctx));
456-
}
457-
return validated;
460+
return validate();
458461
}
459462

460463
/**
@@ -475,9 +478,6 @@ public Validated<Object> validate() {
475478
validated = Validated.invalid(field.getName(), null, "Unable to access " + clazz.getName() + "." + field.getName(), e);
476479
}
477480
}
478-
for (Recipe recipe : getRecipeList()) {
479-
validated = validated.and(recipe.validate());
480-
}
481481
return validated;
482482
}
483483

@@ -561,6 +561,10 @@ public Recipe withOptions(@Nullable Map<String, Object> options) {
561561
Map<String, Object> option = new HashMap<>();
562562
option.put("value", value);
563563
objectMapper.updateValue(optionDescriptor, option);
564+
565+
if (optionDescriptor.getType().equals("List")) {
566+
m.put(optionDescriptor.getName(), Arrays.asList(((String) value).split(",")));
567+
}
564568
}
565569
}
566570
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2026 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite;
17+
18+
import lombok.EqualsAndHashCode;
19+
import lombok.Value;
20+
import org.jspecify.annotations.Nullable;
21+
22+
import java.net.URI;
23+
24+
@Value
25+
@EqualsAndHashCode(callSuper = false)
26+
public class RecipeNotFoundException extends RuntimeException {
27+
String recipeName;
28+
29+
@Nullable
30+
URI source;
31+
32+
public RecipeNotFoundException(String recipeName) {
33+
this(recipeName, null);
34+
}
35+
36+
public RecipeNotFoundException(String recipeName, @Nullable URI source) {
37+
super("Unable to find recipe " + recipeName + (source == null ? "" : " listed in " + source));
38+
this.recipeName = recipeName;
39+
this.source = source;
40+
}
41+
}

rewrite-core/src/main/java/org/openrewrite/RecipeScheduler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ private LargeSourceSet runRecipeCycles(Recipe recipe, LargeSourceSet sourceSet,
7373
// use cases like sharing a `JavaTypeCache` between `JavaTemplate` parsers).
7474
Cursor rootCursor = new Cursor(null, Cursor.ROOT_VALUE);
7575
try {
76-
RecipeRunCycle<LargeSourceSet> cycle = new RecipeRunCycle<>(recipe, i, rootCursor, ctxWithWatch,
77-
recipeRunStats, searchResults, sourceFileResults, errorsTable, LargeSourceSet::edit);
76+
RecipeRunCycle<LargeSourceSet> cycle = createRecipeRunCycle(recipe, i, rootCursor, ctxWithWatch, recipeRunStats, searchResults, sourceFileResults, errorsTable);
7877
ctxWithWatch.putCycle(cycle);
7978
after.beforeCycle(i == maxCycles);
8079

@@ -117,6 +116,11 @@ private LargeSourceSet runRecipeCycles(Recipe recipe, LargeSourceSet sourceSet,
117116
return after;
118117
}
119118

119+
protected RecipeRunCycle<LargeSourceSet> createRecipeRunCycle(Recipe recipe, int cycle, Cursor rootCursor, WatchableExecutionContext ctxWithWatch, RecipeRunStats recipeRunStats, SearchResults searchResults, SourcesFileResults sourceFileResults, SourcesFileErrors errorsTable) {
120+
return new RecipeRunCycle<>(recipe, cycle, rootCursor, ctxWithWatch,
121+
recipeRunStats, searchResults, sourceFileResults, errorsTable, LargeSourceSet::edit);
122+
}
123+
120124
private void recursiveOnComplete(Recipe recipe, ExecutionContext ctx) {
121125
recipe.onComplete(ctx);
122126
for (Recipe r : recipe.getRecipeList()) {

0 commit comments

Comments
 (0)