Created
July 11, 2020 19:55
-
-
Save d10xa/2f10f4b0673e56a6617f7ca20d326859 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import $ivy.`io.get-coursier::coursier:2.0.0-RC6-21` | |
import coursier._ | |
import java.io.File | |
import java.io.FileInputStream | |
import scala.concurrent.ExecutionContext | |
def extractMainClassName(file: File): Option[String] = { | |
val jarStream = | |
new java.util.jar.JarInputStream(new FileInputStream(file)) | |
val mf = jarStream.getManifest | |
Option(mf.getMainAttributes).flatMap(attrs => | |
Option(attrs.getValue("Main-Class")) | |
) | |
} | |
def fetchDependencyMainClassUnsafe(d: Dependency): List[String] = | |
Fetch() | |
.addDependencies(d) | |
.run() | |
.filter(_.getName == s"${d.module.name.value}-${d.version}.jar") | |
.toList | |
.flatMap(extractMainClassName) | |
def fetchVersionsUnsafe(module: Module): List[String] = | |
Versions() | |
.withModule(module) | |
.result() | |
.unsafeRun()(ExecutionContext.global) | |
.results | |
.collect { case (_, Right(value)) => value } | |
.flatMap(_.available) | |
.toList | |
val module = Module( | |
Organization("io.swagger.codegen.v3"), | |
ModuleName("swagger-codegen-cli") | |
) | |
fetchVersionsUnsafe(module) | |
.foreach { version => | |
val mainClassOpt = | |
fetchDependencyMainClassUnsafe(Dependency(module, version)) | |
println(s"$version: $mainClassOpt") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment