Skip to content

Commit 65d3bef

Browse files
Merge pull request #201 from refactorfirst/#199-add-support-for-kotlin
#199 Process Kotlin codebases
2 parents 175a823 + 3a71e0d commit 65d3bef

149 files changed

Lines changed: 12906 additions & 1161 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.

‎AGENTS.md‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,47 @@
1313
- 11-module Maven build with data flowing left-to-right through the pipeline
1414
- Central DTO: `CodebaseGraphDTO` (JGraphT graphs + disharmony lists + metrics)
1515
- CLI entry point: `org.hjug.refactorfirst.Main` → `ReportCommand`
16-
- Fat jar location: `cli/target/refactor-first-cli-*.jar`
16+
- Fat jar location: `cli/target/cli-<version>.jar`
17+
- **Anonymous/synthetic classes are first-class graph members.** Java `Outer$N`/`Outer$` (anonymous/synthetic inner classes) and the Kotlin literal `"<anonymous>"` FQN are **not** sieved out by `GraphDependencyCollector`; they genuinely participate in cycles and can harbour antipatterns, so they are vertices in the class graph and rendered with `$` as the enclosing-class separator. `GraphDependencyCollector` keeps only the `from == to` self-edge guard, plus a degenerate-package guard so a packageless `"<anonymous>"` source never creates an `""` package-graph vertex. **Sink-only** anonymous/synthetic vertices (those with no outgoing edges) are suppressed only at render time in `HtmlReport.isSinkAnonymousOrSyntheticVertex` to keep the Class/Cycle Map DOT graph readable; active ones still render.
18+
- **Anonymous DOT node ids are source-file derived.** OpenRewrite attributes a Kotlin anonymous object / function-literal type with {@code "<anonymous>"} as the trailing simple-name segment of its FQN: standalone ({@code "<anonymous>"}) or, in real graphs (e.g. FXGL), prefixed by the enclosing class/package ({@code "dev.DeveloperWASDControl.<anonymous>"}). {@code HtmlReport.isAnonymousFqn(vertex)} detects a vertex when its trailing segment starts with {@code <}. {@code HtmlReport.renderSafeNodeId(vertex, codebaseGraphDTO)} then derives the enclosing owner from the vertex's mapped source-file path in {@code CodebaseGraphDTO.classToSourceFilePathMapping} (file base name without extension, e.g. {@code DeveloperWASDControl.kt} -> {@code DeveloperWASDControl}). The DOT node id renders as {@code DeveloperWASDControl_anonymous} and the human-readable label as {@code DeveloperWASDControl\$anonymous} ({@code $} escaped as {@code \$} for DOT). When no source path is mapped (or DTO is null) it degrades to the reversible {@code lt_}/{@code _gt} {@code <}/{@code >} encoding. The renderer is responsible for DOT/HTML-safe encoding of the literal {@code "<anonymous>"} FQN ({@code <}/{@code >} are illegal in Graphviz node ids; {@code <}/{@code >} escaping in HTML table labels).
19+
20+
## Kotlin analysis (hard dependency)
21+
22+
`rewrite-kotlin` (`org.openrewrite:rewrite-kotlin`) is a **non-optional
23+
compile dependency** of the `codebase-graph-builder` module, pulled in via that
24+
module's `rewrite-bom` import (`rewrite-bom:8.90.4`). The Kotlin
25+
parser is therefore always on the classpath of any consumer of
26+
`codebase-graph-builder`; there is no opt-in and no reflective "is Kotlin
27+
present?" guard. (An earlier, never-merged iteration made it `<optional>` with a
28+
`CompositeGraphBuilder.isKotlinAvailable()` reflection guard, but the Kotlin
29+
builder and visitors import `org.openrewrite.kotlin.*` directly and are
30+
constructed via `new`, so the guard was dead code — it would have thrown
31+
`NoClassDefFoundError` at `new KotlinSourceFileGraphBuilder()` before the guard
32+
could ever run. The guard has been removed and the optionality dropped.)
33+
34+
**Distribution impact:** because the dependency is mandatory, the Maven plugin
35+
and the CLI fat-jar bundle the Kotlin compiler —
36+
`kotlin-compiler-embeddable:2.x` (verified at `2.3.20` in this build) and its
37+
`kotlin-script-runtime` / `kotlin-daemon-embeddable` /
38+
`kotlinx-coroutines-core-jvm` transitives — into **every** consumer's runtime,
39+
including pure-Java projects that never contain a `.kt` file. As of this branch
40+
the CLI fat-jar is `cli/target/cli-<version>.jar` and measures **~144 MB**
41+
(verified via `du -sh cli/target/cli-0.10.0-SNAPSHOT.jar` after
42+
`mvn clean install -DskipTests`); the Kotlin compiler and its transitives are a
43+
material fraction of that. A pure-Java consumer therefore pays this size/cost
44+
(the dependency is always on the classpath regardless).
45+
46+
**No opt-out:** Kotlin analysis runs unconditionally — there is no
47+
`analyzeKotlin` switch on `GraphBuilderConfig`. The Kotlin parser is always
48+
exercised. The config field `kotlinLanguageLevel` is kept as a `String` to
49+
avoid importing `rewrite-kotlin`'s enum into the config DTO.
50+
51+
**Orchestration & fallback:** `CompositeGraphBuilder.getCodebaseGraphDTO(path,
52+
config)` is the single orchestrator — it builds the Java graph, then the Kotlin
53+
graph and merges them. A Kotlin build *failure* (parse error, IO, etc.) falls
54+
back to returning the Java-only DTO with a `log.warn`
55+
(`"Kotlin analysis failed; falling back to Java-only graph"`). This fallback
56+
is for build failures, not for "Kotlin is absent".
1757

1858
## Testing Notes
1959
- JUnit 5 with parameterized tests
@@ -29,11 +69,31 @@
2969

3070
## Maven Plugin Usage
3171
Generate reports directly:
32-
`mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.8.0:htmlReport`
72+
`mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.9.0:htmlReport`
3373

3474
Configuration options (most important):
3575
- `showDetails`: Shows God Class metrics in table (default: false)
3676
- `backEdgeAnalysisCount`: 0 = analyze all back edges (default: 50)
3777
- `analyzeCycles`: Whether to analyze cycles (default: true)
3878
- `excludeTests`: Exclude test classes (default: true)
39-
- `minifyHtml`: Minify HTML report (default: false)
79+
- `minifyHtml`: Minify HTML report (default: false)
80+
81+
## CVE Pinning
82+
Transitive dependencies surfaced by an OWASP dependency-check are pinned centrally in the
83+
parent `pom.xml` `<dependencyManagement>` so child modules reference them by bare
84+
GAV (no `<version>`). If a new transitive surfaces, add its fixed-version pin to the parent's
85+
`<dependencyManagement>` block labelled "Centralized CVE mitigations",
86+
recording the CVE ID, the NVD-quoted CVSS, and the affected range in the
87+
comment, and drop the corresponding `<version>` from whichever child module introduced the
88+
transitive. Currently pinned:
89+
- `io.micrometer:micrometer-core:1.17.0` — CVE-2026-40984, CVSS 7.5, affected 1.9.0–1.9.17 / 1.13.0–1.13.18 / 1.14.0–1.14.15 / 1.15.0–1.15.11 / 1.16.0–1.16.5 (rewrite-core 8.86.0)
90+
- `io.quarkus.gizmo:gizmo:1.9.0` — CVSS > 8.0 advisory in 1.0.11, no public CVE (rewrite-core)
91+
- `org.apache.commons:commons-lang3:3.18.0` — CVE-2025-48924, CVSS 5.3, affected 3.0 before 3.18.0 (pmd-java, maven-reporting-impl)
92+
- `org.iq80.snappy:snappy:0.5` — CVE-2024-36124, CVSS 5.3 (maven-core)
93+
- `commons-beanutils:commons-beanutils:1.11.0` — CVE-2025-48734, CVSS 8.8 (maven-reporting-impl 4.0.0)
94+
95+
Note: `mvn clean install -Plocal` invokes the OWASP `dependency-check-maven`
96+
plugin which requires NVD network access; in sandboxed / offline environments
97+
the plugin emits HTTP 429 or `JdbcBatchUpdateException` and the build fails
98+
on a network precondition rather than a code issue.
99+
Re-verify any CVE ID quoted here against the NVD before bumping a pin; the citations were last verified on 2026-08-09.

‎change-proneness-ranker/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636

3737
</dependencies>
3838

39-
</project>
39+
</project>

‎change-proneness-ranker/src/main/java/org/hjug/git/GitLogReader.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
public class GitLogReader implements AutoCloseable {
2222

2323
static final String JAVA_FILE_TYPE = ".java";
24+
static final String KOTLIN_FILE_TYPE = ".kt";
2425

2526
private Repository gitRepository;
2627

@@ -173,7 +174,9 @@ public TreeMap<Integer, Integer> captureChangeCountByCommitTimestamp() throws IO
173174
int count = 0;
174175
for (DiffEntry entry : getDiffEntries(newer, older)) {
175176
if (entry.getNewPath().endsWith(JAVA_FILE_TYPE)
176-
|| entry.getOldPath().endsWith(JAVA_FILE_TYPE)) {
177+
|| entry.getOldPath().endsWith(JAVA_FILE_TYPE)
178+
|| entry.getNewPath().endsWith(KOTLIN_FILE_TYPE)
179+
|| entry.getOldPath().endsWith(KOTLIN_FILE_TYPE)) {
177180
count++;
178181
}
179182
}
@@ -212,7 +215,8 @@ Map<Integer, Integer> walkFirstCommit(RevCommit firstCommit) throws IOException
212215
if (treeWalk.isSubtree()) {
213216
treeWalk.enterSubtree();
214217
} else {
215-
if (treeWalk.getPathString().endsWith(JAVA_FILE_TYPE)) {
218+
if (treeWalk.getPathString().endsWith(JAVA_FILE_TYPE)
219+
|| treeWalk.getPathString().endsWith(KOTLIN_FILE_TYPE)) {
216220
firstCommitCount++;
217221
}
218222
}

‎change-proneness-ranker/src/test/java/org/hjug/git/GitLogReaderGetRepoUrlTest.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Path;
1010
import org.eclipse.jgit.api.Git;
1111
import org.eclipse.jgit.api.errors.GitAPIException;
12+
import org.eclipse.jgit.transport.URIish;
1213
import org.junit.jupiter.api.AfterEach;
1314
import org.junit.jupiter.api.BeforeEach;
1415
import org.junit.jupiter.api.Test;
@@ -40,7 +41,7 @@ void tearDown() {
4041
void testGetRepoUrlWithGitHubSshOrigin() throws Exception {
4142
git.remoteAdd()
4243
.setName("origin")
43-
.setUri(new org.eclipse.jgit.transport.URIish("git@github.com:user/repo.git"))
44+
.setUri(new URIish("git@github.com:user/repo.git"))
4445
.call();
4546

4647
try (GitLogReader gitLogReader = new GitLogReader(projectBaseDir)) {
@@ -54,7 +55,7 @@ void testGetRepoUrlWithGitHubSshOrigin() throws Exception {
5455
void testGetRepoUrlWithGitLabSshOrigin() throws Exception {
5556
git.remoteAdd()
5657
.setName("origin")
57-
.setUri(new org.eclipse.jgit.transport.URIish("git@gitlab.com:user/repo.git"))
58+
.setUri(new URIish("git@gitlab.com:user/repo.git"))
5859
.call();
5960

6061
try (GitLogReader gitLogReader = new GitLogReader(projectBaseDir)) {
@@ -68,7 +69,7 @@ void testGetRepoUrlWithGitLabSshOrigin() throws Exception {
6869
void testGetRepoUrlWithBitBucketSshOrigin() throws Exception {
6970
git.remoteAdd()
7071
.setName("origin")
71-
.setUri(new org.eclipse.jgit.transport.URIish("git@bitbucket.org:user/repo.git"))
72+
.setUri(new URIish("git@bitbucket.org:user/repo.git"))
7273
.call();
7374

7475
try (GitLogReader gitLogReader = new GitLogReader(projectBaseDir)) {
@@ -82,7 +83,7 @@ void testGetRepoUrlWithBitBucketSshOrigin() throws Exception {
8283
void testGetRepoUrlWithHttpsOrigin() throws Exception {
8384
git.remoteAdd()
8485
.setName("origin")
85-
.setUri(new org.eclipse.jgit.transport.URIish("https://github.com/user/repo.git"))
86+
.setUri(new URIish("https://github.com/user/repo.git"))
8687
.call();
8788

8889
try (GitLogReader gitLogReader = new GitLogReader(projectBaseDir)) {

‎cli/pom.xml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
<name>RefactorFirst CLI</name>
1616

1717
<properties>
18-
<maven.compiler.source>11</maven.compiler.source>
19-
<maven.compiler.target>11</maven.compiler.target>
2018
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2119
</properties>
2220

@@ -93,4 +91,4 @@
9391
</plugins>
9492
</build>
9593

96-
</project>
94+
</project>

‎codebase-graph-builder/pom.xml‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<dependencyManagement>
1717
<dependencies>
1818
<dependency>
19-
<groupId>org.openrewrite.recipe</groupId>
20-
<artifactId>rewrite-recipe-bom</artifactId>
21-
<version>3.34.0</version>
19+
<groupId>org.openrewrite</groupId>
20+
<artifactId>rewrite-bom</artifactId>
21+
<version>8.90.4</version>
2222
<type>pom</type>
2323
<scope>import</scope>
2424
</dependency>
@@ -34,12 +34,9 @@
3434
<groupId>org.jgrapht</groupId>
3535
<artifactId>jgrapht-core</artifactId>
3636
</dependency>
37-
38-
<!-- Addresses CVE-2026-40984 introduced through rewrite-core 8.86.0 -->
3937
<dependency>
4038
<groupId>io.micrometer</groupId>
4139
<artifactId>micrometer-core</artifactId>
42-
<version>1.10.0</version>
4340
</dependency>
4441
<dependency>
4542
<groupId>org.openrewrite</groupId>
@@ -49,24 +46,24 @@
4946
<groupId>org.openrewrite</groupId>
5047
<artifactId>rewrite-java-17</artifactId>
5148
</dependency>
52-
<dependency>
53-
<groupId>org.openrewrite</groupId>
54-
<artifactId>rewrite-java-11</artifactId>
55-
</dependency>
5649
<dependency>
5750
<groupId>org.openrewrite</groupId>
5851
<artifactId>rewrite-java</artifactId>
5952
</dependency>
6053

61-
<!--gizmo 1.0.11, used by rewrite-core has a CVSS score > 8.0 -->
54+
<!--gizmo 1.0.11, used by rewrite-core has a CVSS score > 8.0 — pinned
55+
in parent <dependencyManagement>. -->
6256
<dependency>
6357
<groupId>io.quarkus.gizmo</groupId>
6458
<artifactId>gizmo</artifactId>
65-
<version>1.9.0</version>
6659
</dependency>
6760
<dependency>
6861
<groupId>org.openrewrite</groupId>
6962
<artifactId>rewrite-core</artifactId>
7063
</dependency>
64+
<dependency>
65+
<groupId>org.openrewrite</groupId>
66+
<artifactId>rewrite-kotlin</artifactId>
67+
</dependency>
7168
</dependencies>
72-
</project>
69+
</project>

0 commit comments

Comments
 (0)