Skip to content

Commit 55390f4

Browse files
Merge branch 'main' into greg-fix-before-recipe-idem
2 parents d07529d + 8004828 commit 55390f4

27 files changed

Lines changed: 239 additions & 134 deletions

File tree

rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ReloadableJava21TypeMapping implements JavaTypeMapping<Tree> {
4646
private final JavaTypeCache typeCache;
4747

4848
public JavaType type(@Nullable Type type) {
49-
if (type == null || type instanceof Type.ErrorType || type instanceof Type.PackageType || type instanceof Type.UnknownType ||
49+
if (type == null || type instanceof Type.ErrorType || type instanceof Type.PackageType || isUnknownType(type) ||
5050
type instanceof NullType) {
5151
return JavaType.Class.Unknown.getInstance();
5252
}
@@ -465,7 +465,7 @@ public JavaType.Primitive primitive(TypeTag tag) {
465465
}
466466

467467
if (selectType == null || selectType instanceof Type.ErrorType || symbol == null || symbol.kind == Kinds.Kind.ERR ||
468-
symbol.type instanceof Type.UnknownType) {
468+
isUnknownType(symbol.type)) {
469469
return null;
470470
}
471471

@@ -530,7 +530,7 @@ public JavaType.Primitive primitive(TypeTag tag) {
530530
exceptionTypes.add(javaType);
531531
}
532532
}
533-
} else if (selectType instanceof Type.UnknownType) {
533+
} else if (isUnknownType(selectType)) {
534534
returnType = JavaType.Unknown.getInstance();
535535
}
536536

@@ -751,4 +751,12 @@ private Object annotationElementValue(Object value) {
751751
}
752752
return JavaType.Unknown.getInstance();
753753
}
754+
755+
/**
756+
* Check for the `UnknownType` which existed up until JDK 22; starting with JDK 23 only the `ErrorType` is used.
757+
* Uses reflection to avoid compile-time dependency on the class, which was removed in JDK 24.
758+
*/
759+
public static boolean isUnknownType(@Nullable Type type) {
760+
return type != null && type.getClass().getName().equals("com.sun.tools.javac.code.Type$UnknownType");
761+
}
754762
}

rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeSignatureBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Set;
3131
import java.util.StringJoiner;
3232

33+
import static org.openrewrite.java.isolated.ReloadableJava21TypeMapping.isUnknownType;
3334

3435
class ReloadableJava21TypeSignatureBuilder implements JavaTypeSignatureBuilder {
3536
@Nullable
@@ -41,7 +42,7 @@ public String signature(@Nullable Object t) {
4142
}
4243

4344
private String signature(@Nullable Type type) {
44-
if (type == null || type instanceof Type.UnknownType || type instanceof NullType) {
45+
if (type == null || isUnknownType(type) || type instanceof NullType) {
4546
return "{undefined}";
4647
} else if (type instanceof Type.IntersectionClassType) {
4748
return intersectionSignature(type);
@@ -299,7 +300,7 @@ private String methodArgumentSignature(Type selectType) {
299300
return resolvedArgumentTypes.toString();
300301
} else if (selectType instanceof Type.ForAll) {
301302
return methodArgumentSignature(((Type.ForAll) selectType).qtype);
302-
} else if (selectType instanceof Type.JCNoType || selectType instanceof Type.UnknownType) {
303+
} else if (selectType instanceof Type.JCNoType || isUnknownType(selectType)) {
303304
return "{undefined}";
304305
}
305306

rewrite-java/src/main/java/org/openrewrite/java/JavaUnrestrictedClassLoader.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
105105
Path classFile = path.resolve(internalName);
106106
if (Files.exists(classFile)) {
107107
byte[] bytes = Files.readAllBytes(classFile);
108-
return defineClass(name, bytes, 0, bytes.length);
108+
try {
109+
return defineClass(name, bytes, 0, bytes.length);
110+
} catch (LinkageError e) {
111+
// On JDK 25+, cross-module type references in DocCommentTable can cause the
112+
// app classloader to load jdk.compiler classes before this classloader does.
113+
// Fall back to parent delegation for the already-loaded class.
114+
try {
115+
return super.loadClass(name);
116+
} catch (ClassNotFoundException cnfe) {
117+
throw e;
118+
}
119+
}
109120
}
110121
}
111122
} catch (IOException e) {

rewrite-javascript/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ val npmBuild = tasks.register<NpmTask>("npmBuild") {
124124
inputs.files(fileTree("rewrite/src"))
125125
.withPathSensitivity(PathSensitivity.RELATIVE)
126126
outputs.dir(file("rewrite/dist/"))
127-
outputs.cacheIf { true }
128127

129128
val versionTxt = file("src/main/resources/META-INF/version.txt")
130129
outputs.file(versionTxt)
@@ -174,7 +173,6 @@ val npmFixturesBuild = tasks.register<NpmTask>("npmFixturesBuild") {
174173
inputs.files(fileTree("rewrite/fixtures"))
175174
.withPathSensitivity(PathSensitivity.RELATIVE)
176175
outputs.dir(file("rewrite/dist-fixtures/"))
177-
outputs.cacheIf { true }
178176

179177
args = listOf("run", "build:fixtures")
180178
}
@@ -227,11 +225,6 @@ val npmPublish = tasks.register<NpmTask>("npmPublish") {
227225
args = provider { listOf("publish", npmPack.get().archiveFile.get().asFile.absolutePath) }
228226
if (!project.hasProperty("releasing")) {
229227
args.addAll("--tag", "next")
230-
// Skip publishing when nothing changed in the JavaScript implementation.
231-
// When npmBuild is restored from the build cache, version.txt retains the
232-
// timestamp from the original build, causing a conflict with the previously
233-
// published version on npmjs.
234-
onlyIf { npmBuild.get().state.didWork }
235228
}
236229

237230
workingDir.set(file("rewrite"))

rewrite-maven/src/main/java/org/openrewrite/maven/internal/MavenPomDownloader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public MavenMetadata downloadMetadata(GroupArtifactVersion gav, @Nullable Resolv
411411
int start = responseBody.indexOf("<a href=\"");
412412
while (start > 0) {
413413
start += 9;
414-
int end = responseBody.indexOf("\">", start);
414+
int end = responseBody.indexOf("\"", start);
415415
if (end < 0) {
416416
break;
417417
}

rewrite-maven/src/test/java/org/openrewrite/maven/internal/MavenPomDownloaderTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,42 @@ void deriveMetaDataFromHtmlBasedRepository() {
626626
new MavenPomDownloader(emptyMap(), ctx).downloadMetadata(new GroupArtifact("does.definitely.not", "exist"), null, List.of(repository)));
627627
}
628628

629+
@Issue("https://github.com/openrewrite/rewrite/issues/6739")
630+
@Test
631+
void deriveMetaDataFromHtmlWithTitleAttributes() throws Exception {
632+
try (MockWebServer server = new MockWebServer()) {
633+
server.setDispatcher(new Dispatcher() {
634+
@Override
635+
public MockResponse dispatch(RecordedRequest request) {
636+
if (request.getPath() != null && request.getPath().endsWith("maven-metadata.xml")) {
637+
return new MockResponse().setResponseCode(404);
638+
}
639+
return new MockResponse().setResponseCode(200).setBody(
640+
"""
641+
<html><body>
642+
<a href="../" title="../">../</a>
643+
<a href="1.0.0/" title="1.0.0/">1.0.0/</a>
644+
<a href="1.1.0/" title="1.1.0/">1.1.0/</a>
645+
<a href="2.0.0/" title="2.0.0/">2.0.0/</a>
646+
</body></html>
647+
"""
648+
);
649+
}
650+
});
651+
server.start();
652+
653+
MavenRepository repository = MavenRepository.builder()
654+
.id("html-with-title")
655+
.uri("http://%s:%d/".formatted(server.getHostName(), server.getPort()))
656+
.knownToExist(true)
657+
.deriveMetadataIfMissing(true)
658+
.build();
659+
MavenMetadata metaData = new MavenPomDownloader(emptyMap(), ctx)
660+
.downloadMetadata(new GroupArtifact("fred", "fred"), null, List.of(repository));
661+
assertThat(metaData.getVersioning().getVersions()).containsExactlyInAnyOrder("1.0.0", "1.1.0", "2.0.0");
662+
}
663+
}
664+
629665
@SuppressWarnings("ConstantConditions")
630666
@Test
631667
void mergeMetadata() throws Exception {

rewrite-python/rewrite/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dev = [
3636
"ruff>=0.1.0",
3737
]
3838
typing = [
39-
"ty>=0.0.15", # Required for type attribution with Java recipes
39+
"ty>=0.0.17", # Required for type attribution with Java recipes
4040
]
4141
publish = [
4242
"build>=1.0.0",

rewrite-python/rewrite/src/rewrite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# helps pytest to rewrite the assert statements in test.py
44
try:
5-
import pytest
5+
import pytest # ty: ignore[unresolved-import]
66
pytest.register_assert_rewrite("rewrite.test")
77
except ImportError:
88
pass # pytest not available, skip assert rewriting

rewrite-python/rewrite/src/rewrite/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def with_erroneous(self, erroneous: Optional[SourceFile]) -> 'ParseError':
141141
return self if erroneous is self._erroneous else replace(self, _erroneous=erroneous)
142142

143143
def printer(self, cursor: Cursor) -> TreeVisitor[Tree, PrintOutputCapture[P]]:
144-
return PrinterFactory.current().create_printer(cursor) # ty: ignore[possibly-missing-attribute] # PrinterFactory.current() is always set
144+
return PrinterFactory.current().create_printer(cursor) # ty: ignore[unresolved-attribute] # PrinterFactory.current() is always set
145145

146146
def is_acceptable(self, v: TreeVisitor[Any, P], p: P) -> bool:
147147
return v.is_adaptable_to(ParseErrorVisitor)

rewrite-python/rewrite/src/rewrite/python/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
VariableScope,
6868
YieldFrom,
6969
)
70-
from rewrite.python.support_types import PyComment
70+
from rewrite.python.support_types import PyComment # ty: ignore[unresolved-import]
7171
from rewrite.python.visitor import PythonVisitor
7272
from rewrite.python.style import (
7373
SpacesStyle,

0 commit comments

Comments
 (0)