Migrate code to Kotlin#242
Conversation
3e37d48 to
b4dc108
Compare
|
@Pitterling, any thoughts? |
99a32ec to
d930008
Compare
|
May I kindly ask, what is the benefit of this migration? |
|
Null safety, better stdlib for collections, etc |
|
Ok, I expected something different that is specific to this project particularly. To me Kotlin has different a knowledge curve, longer compilation time, and IDEA IDE as a prerequisite. |
Frankly speaking, I do not think there's "the killer feature which makes Kotlin the only solution". However: I just do not want to read and maintain code that looks like https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/jdk.compiler/share/classes/com/sun/tools/javac/platform/PlatformUtils.java#L44-L65 Just in case, most of the current code in PR is auto-conversion from Java with minor cleanup, so it does not mean the current .kt files are "the best". For instance, I think it is worth replacing SAX (event-style) parsing of the configuration files with DOM-like parser that would read the document and convert it all at once. Currently, the parser is "too clever" (see I am sure there are cases when slightly less efficient code is good enough, so even if migration to Kotlin would increase compilation times I do not really care since speeding up the Kotlin compiler is in the priorities of the Kotlin team (see the roadmap ), and the compilation does include type verification (e.g. data types, null safety). So it reduces the number of tests I have to write manually. By the way, if tests are present, then the compilation time is less important as test execution still takes cycles. So it is not like I am saying "ok, I want to play with Kotlin, let's ksar be the first project". I am sure moving to Kotlin would help the further ksar evolution. |
|
Here's a recent report on ~2x improvement in the compilation time for the new K2 compiler: https://youtu.be/db19VFLZqJM?t=2651 |
39b15b9 to
98b2af8
Compare
Pure git rename of the migrated classes and tests from `.java` to `.kt` (and from `src/main/java` to `src/main/kotlin`). The file contents are left untouched here, so git records these as renames and `git log --follow` and `git blame` keep tracing through to the original Java history. The next commit rewrites the bodies to Kotlin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rewrite the renamed `.kt` files (see the previous commit) from Java to Kotlin, and update the build and the remaining Java UI to match. Revive the `kotlin_tests` branch on top of current master. The original migration (October 2021) branched from a point that master has since moved 163 commits beyond, so this re-applies the Kotlin sources and carries master's later changes into them rather than replaying the old commits verbatim: - `AllParser`: port the date-format auto-detection (`DATE_FORMATS` plus the prefer-most-recent-non-future rule) and the per-header formatter reset via the `parse_header`/`parseHeader` template split. - `Linux`/`kSar`: port the parser return codes (IGNORE/HEADER/NOGRAPH) and the localised sysstat "Average:" markers. - `Main`: switch logging control from log4j to logback and add the argument-parsing errors (unknown option, too many arguments). - `Graph`: replace the decimal separator before parsing and widen the legend line stroke. - Keep the NetBeans UI classes in Java; adapt their calls to the Kotlin accessors (`getGraphtree`, `getChartPanel`, `getMyparser`). Fix a bug introduced by the Kotlin migration of `NaturalComparator`: the word pattern matched single characters and the loop consumed a token on the short-circuited `find`, so `"sdc1"` sorted equal to `"sdc"`. Build: add the Kotlin JVM plugin (2.2.20, Gradle 9.5.1, JVM target 17); keep Checkstyle for the remaining Java UI sources. All 83 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@Pitterling , I've rebased the PR and incorporated all the changes since then. WDYT? |
Migrate the kSar core and tests from Java to Kotlin. The NetBeans UI classes stay in Java (they own the
.formfiles); their calls are adapted to the Kotlin accessors.Rebased onto current
master. The branch originally forked about 163 commits back, so this re-applies the Kotlin sources and carries master's later changes into them rather than replaying the old commits: the date-format auto-detection inAllParser, the parser return codes and localised sysstat markers inLinux/kSar, the log4j-to-logback switch and the argument parsing inMain, and the decimal-separator and legend-stroke handling inGraph.Also fixes a bug the original migration introduced in
NaturalComparator: the word pattern matched single characters and the loop dropped a token on the short-circuitedfind, so"sdc1"sorted equal to"sdc".Build: adds the Kotlin JVM plugin (2.2.20, JVM target 17) and keeps Checkstyle for the remaining Java UI sources.
How to verify
./gradlew build— Kotlin and Java compile, Checkstyle passes, and 83 tests pass (1 skipped: the date-format generator, enabled with-Pksar.generateDateFormats=true). The shadow jar runs:java -jar build/libs/ksar-*-all.jar -version.