Skip to content

Commit b3aa7f8

Browse files
Fix JavaSourceSet#gavFromPath for TypeTable jar layout
After #7528 TypeTable materializes artifacts as jar files inside the version directory rather than as a classes directory. The .tt branch in gavFromPath used fixed offsets that worked for the legacy directory layout but mis-sliced GAV components for the new jar layout. Compute versionIndex/artifactIndex off the tail and shift left by one when the trailing path component ends with .jar, so the slice points at the right components in either layout.
1 parent d3d2157 commit b3aa7f8

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

rewrite-java/src/main/java/org/openrewrite/java/marker/JavaSourceSet.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,15 @@ public static JavaSourceSet build(String sourceSetName, Collection<Path> classpa
471471
version = pathParts.get(pathParts.size() - 3);
472472
} else if (pathParts.contains(".tt")) {
473473
int ttIndex = pathParts.indexOf(".tt");
474-
if (pathParts.size() - ttIndex > 3) {
475-
groupId = String.join(".", pathParts.subList(ttIndex + 1, pathParts.size() - 2));
476-
artifactId = pathParts.get(pathParts.size() - 2);
477-
version = pathParts.get(pathParts.size() - 1);
474+
int last = pathParts.size() - 1;
475+
// Legacy layout ends at the version directory; post-#7528 layout adds
476+
// a trailing <artifact>-<version>.jar file inside the version directory.
477+
int versionIndex = pathParts.get(last).endsWith(".jar") ? last - 1 : last;
478+
int artifactIndex = versionIndex - 1;
479+
if (artifactIndex - (ttIndex + 1) >= 1) {
480+
groupId = String.join(".", pathParts.subList(ttIndex + 1, artifactIndex));
481+
artifactId = pathParts.get(artifactIndex);
482+
version = pathParts.get(versionIndex);
478483
}
479484
} else if (pathParts.size() >= 4) {
480485
version = pathParts.get(pathParts.size() - 2);

0 commit comments

Comments
 (0)