Last active
December 22, 2021 15:26
-
-
Save davidohana/1b83f6cbfadf14f6bd161737b9e5b7e7 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 getLoadedPackageGroupVersions(detailed: Boolean = false, vararg excludePrefixes: String): String { | |
fun getProductDetails(packageGroup: List<Package>): String { | |
val samplePackage = packageGroup.first() | |
val prodTitle = | |
"\t${samplePackage.implementationTitle} " + | |
"v(${samplePackage.implementationVersion}) by ${samplePackage.implementationVendor}" | |
if (!detailed) | |
return prodTitle | |
val details = packageGroup.map { "\t\t" + it.name }.sorted().joinToString("\n") | |
return prodTitle + "\n" + details | |
} | |
val packages = Package.getPackages() | |
val filteredPackages = packages.filterNot { | |
it.name.startsWithAny(*excludePrefixes) | |
} | |
val productGroups = | |
filteredPackages.groupBy { listOf(it.implementationTitle + it.implementationVersion + it.implementationVendor) } | |
val versionsText = | |
productGroups | |
.values | |
.map { getProductDetails(it) } | |
.sorted() | |
.joinToString("\n") | |
return "Versions of ${filteredPackages.size} loaded packages in ${productGroups.size} products:\n${versionsText}" | |
} | |
object App { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println(getLoadedPackageGroupVersions(detailed = false, "java.", "javax.", "jdk.", "sun.", "com.sun.")) | |
println(getLoadedPackageGroupVersions(detailed = true, "java.", "javax.", "jdk.", "sun.", "com.sun.")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment