JPMS support (JVM 9+)
Closed this issue · 4 comments
Hi
I was planning to use the library in a Java JPMS project. As you might know, even the extended support for Oracle Java 8 LTS will end in Dec 2030. All the later versions of JVM provide support for module paths / JPMS. I noticed that the package structure of the project basically prevents it from being used in a "modern" modular project. This basically assumes a certain kind of package structure + a module-info file. Even if the project doesn't provide the module info, a more significant issue is that the classes should be placed in a unique location with the module name as the package prefix. According to semver rules this project's version is still per 1.0.0 so changing the API wouldn't be a huge problem at this point.
For instance, all the current structure could be moved to a io.github.davidepianca98
package in each sub-module. This could be simply done by moving the files, adjusting/adding the package declarations and imports. Rather straightforward, but this of course breaks the API completely. I did a test build with a modified project structure and it seems to work just fine.
Here's a short script for mass converting the files, but it needs further fixes for imports:
PREFIX=io/github/davidepianca98/kmqtt
PREFIX2="${PREFIX//\//.}"
git clone https://github.com/davidepianca98/KMQTT KMQTT
mkdir -p kmqtt-new
for dir in $(find KMQTT/ -maxdepth 1 -type d -name 'km*'); do
mkdir -p ${dir/KMQTT/kmqtt-new}
done
for f in $(find KMQTT/ -type f -name '*kt'); do
D="$(dirname "$f")"
D="${D/KMQTT/kmqtt-new}"
D="${D/kotlin/kotlin/$PREFIX}"
F="$(basename $f)"
mkdir -p "$D"
# adjust the package declarations
echo $D|sed 's|\([^/]*/\)\{5\}|package |;s/\//./g;s/$/;/' > "$D/$F"
# remove old package declarations
sed 's/^package .*//g' "$f" >> "$D/$F"
# adjust FQNs for imports
sed -i "s/^import mqtt/import ${PREFIX2}.mqtt/g;s/^import socket/import ${PREFIX2}.socket/g;s/^import toUByteArray/import ${PREFIX2}.toUByteArray/g;s/^import validateUTF8String/import ${PREFIX2}.validateUTF8String/g;s/^import validatePayloadFormat/import ${PREFIX2}.validatePayloadFormat/g;s/^import currentTimeMillis/import ${PREFIX2}.currentTimeMillis/g" "$D/$F"
done
Hello, thank you very much for opening the issue and proposing a solution. I really do not know how I missed the full package name for so long.
As you already did all the work, do you mind opening a pull request with the changes? io.github.davidepianca98
is fine to keep in line with the current package name. I am ok with breaking compatibility as this was a mistake all along.
Ok, so the version I needed and tested only sets up the jvm build (and uses maven) so I don't think sharing that will be of any use. I ran the script and adjusted the package names, imports, and relocated the kt files here: https://github.com/miasma/KMQTT/tree/adjust-packages
It probably needs more work for relocating the resource files. I'm not too familiar with the multi-platform builds and couldn't figure out how to build all the targets, so there's still work to do, but I hope this helps.
Sorry for the huge delay, the change has been made here be36104 and will be included in the next release.