Skip to content

Commit a7f556d

Browse files
authored
Merge branch 'main' into lombok/normalize-getter
2 parents 3af395b + 3f52b88 commit a7f556d

15 files changed

+512
-15
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Update SDKMAN! candidates
3+
4+
on:
5+
workflow_dispatch: {}
6+
schedule:
7+
- cron: 0 10 * * MON
8+
9+
jobs:
10+
update-candidates:
11+
if: github.event_name != 'schedule' || github.repository_owner == 'openrewrite'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Update candidates
20+
run: curl https://api.sdkman.io/2/candidates/java/linux/versions/all | tr , '\n' > src/main/resources/sdkman-java.csv
21+
22+
# Commit and push
23+
- name: configure-git-user
24+
run: |
25+
git config user.email "[email protected]"
26+
git config user.name "team-moderne[bot]"
27+
- name: Create timestamp
28+
run: echo "NOW=$(date +'%Y-%m-%dT%H%M')" >> $GITHUB_ENV
29+
- name: Commit and push
30+
run: |
31+
git add src/main/resources/sdkman-java.csv
32+
git diff --quiet HEAD || (git commit -m "[Auto] SDKMAN! Java candidates as of ${{ env.NOW }}" && git push origin main)

gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
3+
distributionSha256Sum=7a00d51fb93147819aab76024feece20b6b84e420694101f276be952e08bef03
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (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://docs.moderne.io/licensing/moderne-source-available-license
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.java.migrate;
17+
18+
import lombok.EqualsAndHashCode;
19+
import lombok.Value;
20+
import org.jspecify.annotations.Nullable;
21+
import org.openrewrite.*;
22+
import org.openrewrite.binary.Binary;
23+
import org.openrewrite.quark.Quark;
24+
import org.openrewrite.remote.Remote;
25+
import org.openrewrite.text.PlainText;
26+
import org.openrewrite.text.PlainTextParser;
27+
28+
import java.io.IOException;
29+
import java.net.URISyntaxException;
30+
import java.net.URL;
31+
import java.nio.file.Files;
32+
import java.nio.file.Paths;
33+
import java.util.List;
34+
import java.util.regex.Matcher;
35+
import java.util.regex.Pattern;
36+
37+
import static java.util.Objects.requireNonNull;
38+
39+
@Value
40+
@EqualsAndHashCode(callSuper = false)
41+
public class UpdateSdkMan extends Recipe {
42+
43+
@Option(displayName = "Java version",
44+
description = "The Java version to update to.",
45+
required = false,
46+
example = "17")
47+
@Nullable
48+
String newVersion;
49+
50+
@Option(displayName = "Distribution",
51+
description = "The JVM distribution to use.",
52+
required = false,
53+
example = "tem")
54+
@Nullable
55+
String newDistribution;
56+
57+
@Override
58+
public String getDisplayName() {
59+
return "Update SDKMan Java version";
60+
}
61+
62+
@Override
63+
public String getDescription() {
64+
//language=markdown
65+
return "Update the SDKMAN JDK version in the `.sdkmanrc` file. Given a major release (e.g., 17), the recipe " +
66+
"will update the current distribution to the current default SDKMAN version of the specified major " +
67+
"release. The distribution option can be used to specify a specific JVM distribution. " +
68+
"Note that these must correspond to valid SDKMAN distributions.";
69+
}
70+
71+
@Override
72+
public Validated<Object> validate(ExecutionContext ctx) {
73+
return super.validate(ctx)
74+
.and(Validated.required("newVersion", newVersion)
75+
.or(Validated.required("newDistribution", newDistribution)));
76+
}
77+
78+
@Override
79+
public TreeVisitor<?, ExecutionContext> getVisitor() {
80+
TreeVisitor<?, ExecutionContext> visitor = new TreeVisitor<Tree, ExecutionContext>() {
81+
@Override
82+
public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
83+
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
84+
if (sourceFile instanceof Quark || sourceFile instanceof Remote || sourceFile instanceof Binary) {
85+
return sourceFile;
86+
}
87+
PlainText plainText = PlainTextParser.convert(sourceFile);
88+
89+
// Define a regex pattern to extract the version and distribution
90+
Pattern pattern = Pattern.compile("java=(.*?)([.a-z]*-.*)");
91+
Matcher matcher = pattern.matcher(plainText.getText());
92+
if (matcher.find()) {
93+
String ver = newVersion == null ? matcher.group(1) : newVersion;
94+
String dist = newDistribution == null ? matcher.group(2) : newDistribution;
95+
for (String candidate : readSdkmanJavaCandidates()) {
96+
if (candidate.startsWith(ver) && candidate.endsWith(dist)) {
97+
return plainText.withText(matcher.replaceFirst("java=" + candidate));
98+
}
99+
}
100+
}
101+
return sourceFile;
102+
}
103+
104+
private List<String> readSdkmanJavaCandidates() {
105+
URL resource = getClass().getResource("/sdkman-java.csv");
106+
if (resource != null) {
107+
try {
108+
return Files.readAllLines(Paths.get(resource.toURI()));
109+
} catch (IOException | URISyntaxException e) {
110+
throw new RuntimeException(e);
111+
}
112+
}
113+
throw new IllegalStateException("Could not find /sdkman-java.csv file");
114+
}
115+
};
116+
return Preconditions.check(new FindSourceFiles(".sdkmanrc"), visitor);
117+
}
118+
}

src/main/java/org/openrewrite/java/migrate/UpgradeJavaVersion.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public List<Recipe> getRecipeList() {
5959
new UseMavenCompilerPluginReleaseConfiguration(version),
6060
new UpdateMavenProjectPropertyJavaVersion(version),
6161
new org.openrewrite.jenkins.UpgradeJavaVersion(version, null),
62-
new UpdateJavaCompatibility(version, null, null, false, null)
62+
new UpdateJavaCompatibility(version, null, null, false, null),
63+
new UpdateSdkMan(String.valueOf(version), null)
6364
);
6465
}
6566

src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAddAnnotatedTypes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
4343
@Override
4444
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
4545
if (methodInputPattern.matches(method)) {
46-
return JavaTemplate.builder("#{any(jakarta.enterprise.inject.spi.AnnotatedType)}, null\"")
46+
return JavaTemplate.builder("#{any(jakarta.enterprise.inject.spi.AnnotatedType)}, null")
4747
.build()
4848
.apply(updateCursor(method),
4949
method.getCoordinates().replaceArguments(),

src/main/java/org/openrewrite/java/migrate/javax/AddJaxwsRuntime.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
231231
for (ResolvedDependency dependency : entry.getValue()) {
232232
if (groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId())) {
233233
maxScope = Scope.maxPrecedence(maxScope, entry.getKey());
234-
if (Scope.Compile.equals(maxScope)) {
234+
if (Scope.Compile == maxScope) {
235235
return maxScope;
236236
}
237237
break;

src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
import org.openrewrite.analysis.dataflow.Dataflow;
2727
import org.openrewrite.analysis.dataflow.analysis.SinkFlowSummary;
2828
import org.openrewrite.java.JavaIsoVisitor;
29-
import org.openrewrite.java.tree.Expression;
30-
import org.openrewrite.java.tree.J;
29+
import org.openrewrite.java.JavadocVisitor;
30+
import org.openrewrite.java.tree.*;
3131
import org.openrewrite.java.tree.J.VariableDeclarations.NamedVariable;
32-
import org.openrewrite.java.tree.JavaType;
33-
import org.openrewrite.java.tree.MethodCall;
3432

3533
import java.util.*;
3634
import java.util.concurrent.atomic.AtomicBoolean;
@@ -52,6 +50,19 @@ public JodaTimeScanner(JodaTimeRecipe.Accumulator acc) {
5250
this.acc = acc;
5351
}
5452

53+
@Override
54+
protected JavadocVisitor<ExecutionContext> getJavadocVisitor() {
55+
return new JavadocVisitor<ExecutionContext>(this) {
56+
/**
57+
* Do not visit the method referenced from the Javadoc, may cause recipe to fail.
58+
*/
59+
@Override
60+
public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx) {
61+
return reference;
62+
}
63+
};
64+
}
65+
5566
@Override
5667
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
5768
super.visitCompilationUnit(cu, ctx);

src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx)
210210
}
211211

212212
private J migrateMethodCall(MethodCall original, MethodCall updated) {
213-
if (!original.getMethodType().getDeclaringType().isAssignableFrom(JODA_CLASS_PATTERN)) {
213+
if (original.getMethodType() == null || !original.getMethodType().getDeclaringType().isAssignableFrom(JODA_CLASS_PATTERN)) {
214214
return updated; // not a joda type, no need to migrate
215215
}
216216
MethodTemplate template = AllTemplates.getTemplate(original);

src/main/java/org/openrewrite/java/migrate/joda/ScopeAwareVisitor.java

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class ScopeAwareVisitor extends JavaVisitor<ExecutionContext> {
3434

3535
@Override
3636
public J preVisit(J j, ExecutionContext ctx) {
37+
if (j instanceof J.ClassDeclaration) {
38+
scopes.push(new VariablesInScope(getCursor()));
39+
}
3740
if (j instanceof J.Block) {
3841
scopes.push(new VariablesInScope(getCursor()));
3942
}
@@ -50,9 +53,15 @@ public J preVisit(J j, ExecutionContext ctx) {
5053

5154
@Override
5255
public J postVisit(J j, ExecutionContext ctx) {
56+
if (j instanceof J.ClassDeclaration) {
57+
scopes.pop();
58+
}
5359
if (j instanceof J.Block) {
5460
scopes.pop();
5561
}
62+
if (j instanceof J.MethodDeclaration) {
63+
scopes.pop();
64+
}
5665
return super.postVisit(j, ctx);
5766
}
5867

src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static boolean isSingleVariableDefinition(J.VariableDeclarations vd) {
5555
TypeTree typeExpression = vd.getTypeExpression();
5656

5757
boolean definesSingleVariable = vd.getVariables().size() == 1;
58-
boolean isPureAssigment = JavaType.Primitive.Null.equals(vd.getType());
58+
boolean isPureAssigment = JavaType.Primitive.Null == vd.getType();
5959
if (!definesSingleVariable || isPureAssigment) {
6060
return false;
6161
}

src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForPrimitive.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ private Expression expandWithPrimitivTypeHint(J.VariableDeclarations vd, Express
117117
return initializer;
118118
}
119119

120-
boolean isLongLiteral = JavaType.Primitive.Long.equals(vd.getType());
120+
boolean isLongLiteral = JavaType.Primitive.Long == vd.getType();
121121
boolean inferredAsLong = valueSource.endsWith("l") || valueSource.endsWith("L");
122-
boolean isFloatLiteral = JavaType.Primitive.Float.equals(vd.getType());
122+
boolean isFloatLiteral = JavaType.Primitive.Float == vd.getType();
123123
boolean inferredAsFloat = valueSource.endsWith("f") || valueSource.endsWith("F");
124-
boolean isDoubleLiteral = JavaType.Primitive.Double.equals(vd.getType());
124+
boolean isDoubleLiteral = JavaType.Primitive.Double == vd.getType();
125125
boolean inferredAsDouble = valueSource.endsWith("d") || valueSource.endsWith("D") || valueSource.contains(".");
126126

127127
String typNotation = null;

src/main/java/org/openrewrite/java/migrate/lombok/LombokValueToRecord.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
117117
private boolean isRelevantClass(J.ClassDeclaration classDeclaration) {
118118
List<J.Annotation> allAnnotations = classDeclaration.getAllAnnotations();
119119
return classDeclaration.getType() != null &&
120-
!J.ClassDeclaration.Kind.Type.Record.equals(classDeclaration.getKind()) &&
120+
J.ClassDeclaration.Kind.Type.Record != classDeclaration.getKind() &&
121121
hasMatchingAnnotations(classDeclaration) &&
122122
!hasGenericTypeParameter(classDeclaration) &&
123123
classDeclaration.getBody().getStatements().stream().allMatch(this::isRecordCompatibleField) &&

src/main/resources/sdkman-java.csv

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
11.0.14.1-jbr
2+
11.0.15-trava
3+
11.0.25-albba
4+
11.0.25-amzn
5+
11.0.25-kona
6+
11.0.25-librca
7+
11.0.25-ms
8+
11.0.25-sapmchn
9+
11.0.25-sem
10+
11.0.25-tem
11+
11.0.25-zulu
12+
11.0.25.fx-librca
13+
11.0.25.fx-zulu
14+
17.0.12-graal
15+
17.0.12-jbr
16+
17.0.12-oracle
17+
17.0.13-albba
18+
17.0.13-amzn
19+
17.0.13-kona
20+
17.0.13-librca
21+
17.0.13-ms
22+
17.0.13-sapmchn
23+
17.0.13-sem
24+
17.0.13-tem
25+
17.0.13-zulu
26+
17.0.13.crac-librca
27+
17.0.13.crac-zulu
28+
17.0.13.fx-librca
29+
17.0.13.fx-zulu
30+
17.0.9-graalce
31+
21.0.2-graalce
32+
21.0.2-open
33+
21.0.5-amzn
34+
21.0.5-graal
35+
21.0.5-jbr
36+
21.0.5-kona
37+
21.0.5-librca
38+
21.0.5-ms
39+
21.0.5-oracle
40+
21.0.5-sapmchn
41+
21.0.5-sem
42+
21.0.5-tem
43+
21.0.5-zulu
44+
21.0.5.crac-librca
45+
21.0.5.crac-zulu
46+
21.0.5.fx-librca
47+
21.0.5.fx-zulu
48+
22.0.2-oracle
49+
22.1.0.1.r11-gln
50+
22.1.0.1.r17-gln
51+
22.3.5.r11-nik
52+
22.3.5.r17-mandrel
53+
22.3.5.r17-nik
54+
23-open
55+
23.0.1-amzn
56+
23.0.1-graal
57+
23.0.1-graalce
58+
23.0.1-librca
59+
23.0.1-oracle
60+
23.0.1-sapmchn
61+
23.0.1-tem
62+
23.0.1-zulu
63+
23.0.1.crac-zulu
64+
23.0.1.fx-librca
65+
23.0.1.fx-zulu
66+
23.0.6.fx-nik
67+
23.0.6.r17-mandrel
68+
23.0.6.r17-nik
69+
23.1.5.fx-nik
70+
23.1.5.r21-mandrel
71+
23.1.5.r21-nik
72+
24.0.2.r22-mandrel
73+
24.1.1.r23-mandrel
74+
24.1.1.r23-nik
75+
24.ea.22-graal
76+
24.ea.23-graal
77+
24.ea.24-graal
78+
24.ea.25-graal
79+
24.ea.26-open
80+
24.ea.27-open
81+
24.ea.28-open
82+
24.ea.29-open
83+
25.ea.1-graal
84+
25.ea.1-open
85+
25.ea.2-graal
86+
25.ea.2-open
87+
25.ea.3-open
88+
6.0.119-zulu
89+
7.0.352-zulu
90+
8.0.282-trava
91+
8.0.432-albba
92+
8.0.432-amzn
93+
8.0.432-kona
94+
8.0.432-librca
95+
8.0.432-sem
96+
8.0.432-tem
97+
8.0.432-zulu
98+
8.0.432.fx-librca
99+
8.0.432.fx-zulu

0 commit comments

Comments
 (0)