Last active
December 22, 2021 09:53
-
-
Save davidohana/915dd73b385dd6911976aa28b50ccd3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.startsWithAny(vararg prefixes: String): Boolean { | |
return prefixes.any { this.startsWith(it) } | |
} | |
fun getLoadedPackageVersions(vararg excludePrefixes: String): String { | |
val packages = Package.getPackages() | |
val filteredPackages = packages.filterNot { | |
it.name.startsWithAny(*excludePrefixes) | |
} | |
val versionsText = filteredPackages | |
.map { "\t${it.name}: ${it.implementationTitle} v(${it.implementationVersion}) by ${it.implementationVendor}" } | |
.sorted() | |
.joinToString("\n") | |
return "Versions of ${filteredPackages.size} loaded packages:\n${versionsText}" | |
} | |
object App { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println(getLoadedPackageVersions("java.", "javax.", "jdk.", "sun.", "com.sun.")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment