mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Track dependencies downloaded on the server's websocket.
This commit is contained in:
parent
a52dd19f3f
commit
5eb92ed10b
6 changed files with 50 additions and 12 deletions
|
@ -0,0 +1,5 @@
|
|||
package com.beust.kobalt.internal.eventbus
|
||||
|
||||
import org.eclipse.aether.repository.ArtifactRepository
|
||||
|
||||
class ArtifactDownloadedEvent(val artifactId: String, val repository: ArtifactRepository)
|
|
@ -13,6 +13,7 @@ import com.beust.kobalt.misc.KobaltLogger
|
|||
import com.beust.kobalt.misc.Versions
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.common.eventbus.EventBus
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import org.eclipse.aether.artifact.Artifact
|
||||
|
@ -73,9 +74,9 @@ class ExcludeOptionalDependencyFilter: DependencyFilter {
|
|||
}
|
||||
|
||||
@Singleton
|
||||
class Aether(val localRepo: File, val settings: KobaltSettings) {
|
||||
class Aether(val localRepo: File, val settings: KobaltSettings, val eventBus: EventBus) {
|
||||
private val system = Booter.newRepositorySystem()
|
||||
private val session = Booter.newRepositorySystemSession(system, localRepo, settings)
|
||||
private val session = Booter.newRepositorySystemSession(system, localRepo, settings, eventBus)
|
||||
private val classpathFilter = AndDependencyFilter(
|
||||
ExcludeOptionalDependencyFilter(),
|
||||
DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE))
|
||||
|
@ -245,7 +246,8 @@ class AetherDependency(val artifact: Artifact): IClasspathDependency, Comparable
|
|||
fun main(argv: Array<String>) {
|
||||
KobaltLogger.LOG_LEVEL = 1
|
||||
val id = "org.testng:testng:6.9.11"
|
||||
val aether = KobaltAether(KobaltSettings(KobaltSettingsXml()), Aether(File(homeDir(".aether")),KobaltSettings(KobaltSettingsXml())))
|
||||
val aether = KobaltAether(KobaltSettings(KobaltSettingsXml()), Aether(File(homeDir(".aether")),
|
||||
KobaltSettings(KobaltSettingsXml()), EventBus()))
|
||||
val r = aether.resolve(id)
|
||||
val r2 = aether.resolve(id)
|
||||
val d = org.eclipse.aether.artifact.DefaultArtifact("org.testng:testng:6.9")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.beust.kobalt.maven.aether
|
||||
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.google.common.eventbus.EventBus
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession
|
||||
import org.eclipse.aether.RepositorySystem
|
||||
import org.eclipse.aether.repository.LocalRepository
|
||||
|
@ -15,14 +16,15 @@ object Booter {
|
|||
// return org.eclipse.aether.examples.plexus.PlexusRepositorySystemFactory.newRepositorySystem();
|
||||
}
|
||||
|
||||
fun newRepositorySystemSession(system: RepositorySystem, repo: File, settings: KobaltSettings): DefaultRepositorySystemSession {
|
||||
fun newRepositorySystemSession(system: RepositorySystem, repo: File, settings: KobaltSettings,
|
||||
eventBus: EventBus): DefaultRepositorySystemSession {
|
||||
val session = MavenRepositorySystemUtils.newSession(settings)
|
||||
|
||||
val localRepo = LocalRepository(repo.absolutePath)
|
||||
session.localRepositoryManager = system.newLocalRepositoryManager(session, localRepo)
|
||||
|
||||
session.transferListener = ConsoleTransferListener()
|
||||
session.repositoryListener = ConsoleRepositoryListener()
|
||||
session.repositoryListener = ConsoleRepositoryListener(eventBus = eventBus)
|
||||
|
||||
// uncomment to generate dirty trees
|
||||
// session.setDependencyGraphTransformer( null );
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.beust.kobalt.maven.aether
|
||||
|
||||
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.common.eventbus.EventBus
|
||||
import org.eclipse.aether.AbstractRepositoryListener
|
||||
import org.eclipse.aether.RepositoryEvent
|
||||
import java.io.PrintStream
|
||||
|
@ -8,7 +10,8 @@ import java.io.PrintStream
|
|||
/**
|
||||
* A simplistic repository listener that logs events to the console.
|
||||
*/
|
||||
class ConsoleRepositoryListener @JvmOverloads constructor(out: PrintStream? = null) : AbstractRepositoryListener() {
|
||||
class ConsoleRepositoryListener @JvmOverloads constructor(out: PrintStream? = null, val eventBus: EventBus)
|
||||
: AbstractRepositoryListener() {
|
||||
companion object {
|
||||
val LOG_LEVEL = 4
|
||||
}
|
||||
|
@ -53,8 +56,10 @@ class ConsoleRepositoryListener @JvmOverloads constructor(out: PrintStream? = nu
|
|||
}
|
||||
|
||||
override fun artifactDownloaded(event: RepositoryEvent?) {
|
||||
if (event?.file != null) {
|
||||
log(1, "Downloaded artifact " + event!!.artifact + " from " + event.repository)
|
||||
if (event?.file != null && event?.artifact != null) {
|
||||
val artifact = event!!.artifact
|
||||
log(1, "Downloaded artifact " + artifact + " from " + event.repository)
|
||||
eventBus.post(ArtifactDownloadedEvent(artifact.toString(), event.repository))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.beust.kobalt.maven.aether.Aether
|
|||
import com.beust.kobalt.misc.DependencyExecutor
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.plugin.publish.BintrayApi
|
||||
import com.google.common.eventbus.EventBus
|
||||
import com.google.inject.AbstractModule
|
||||
import com.google.inject.Provider
|
||||
import com.google.inject.Singleton
|
||||
|
@ -49,13 +50,16 @@ public open class MainModule(val args: Args, val settings: KobaltSettings) : Abs
|
|||
bind(Args::class.java).toProvider(Provider<Args> {
|
||||
args
|
||||
})
|
||||
EventBus().let { eventBus ->
|
||||
bind(EventBus::class.java).toInstance(eventBus)
|
||||
bind(Aether::class.java).toInstance(Aether(settings.localRepo, settings, eventBus))
|
||||
}
|
||||
bind(PluginInfo::class.java).toProvider(Provider<PluginInfo> {
|
||||
PluginInfo.readKobaltPluginXml()
|
||||
}).`in`(Singleton::class.java)
|
||||
bind(KobaltSettings::class.java).toProvider(Provider<KobaltSettings> {
|
||||
settings
|
||||
}).`in`(Singleton::class.java)
|
||||
bind(Aether::class.java).toInstance(Aether(settings.localRepo,settings))
|
||||
|
||||
// bindListener(Matchers.any(), object: TypeListener {
|
||||
// override fun <I> hear(typeLiteral: TypeLiteral<I>?, typeEncounter: TypeEncounter<I>?) {
|
||||
|
|
|
@ -6,7 +6,10 @@ import com.beust.kobalt.api.Kobalt
|
|||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.app.Templates
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
|
||||
import com.google.common.collect.ListMultimap
|
||||
import com.google.common.eventbus.EventBus
|
||||
import com.google.common.eventbus.Subscribe
|
||||
import com.google.gson.Gson
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint
|
||||
import org.eclipse.jetty.websocket.api.Session
|
||||
|
@ -105,10 +108,26 @@ class GetDependenciesChatHandler : WebSocketListener {
|
|||
if (buildFileParams != null) {
|
||||
val buildFile = buildFileParams[0]
|
||||
|
||||
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
||||
|
||||
val result = if (buildFile != null) {
|
||||
// Track all the downloads that this dependency call might trigger and
|
||||
// send them as a progress message to the web socket
|
||||
val eventBus = getInstance(EventBus::class.java)
|
||||
val busListener = object {
|
||||
@Subscribe
|
||||
fun onArtifactDownloaded(event: ArtifactDownloadedEvent) {
|
||||
sendWebsocketCommand(s.remote, ProgressCommand.NAME,
|
||||
ProgressCommand(null, "Downloaded " + event.artifactId))
|
||||
}
|
||||
}
|
||||
eventBus.register(busListener)
|
||||
|
||||
// Get the dependencies for the requested build file and send progress to the web
|
||||
// socket for each project
|
||||
try {
|
||||
val dependencyData = Kobalt.INJECTOR.getInstance(DependencyData::class.java)
|
||||
val args = Kobalt.INJECTOR.getInstance(Args::class.java)
|
||||
val dependencyData = getInstance(DependencyData::class.java)
|
||||
val args = getInstance(Args::class.java)
|
||||
|
||||
dependencyData.dependenciesDataFor(buildFile, args, object : IProgressListener {
|
||||
override fun onProgress(progress: Int?, message: String?) {
|
||||
|
@ -116,15 +135,16 @@ class GetDependenciesChatHandler : WebSocketListener {
|
|||
}
|
||||
})
|
||||
} catch(ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
DependencyData.GetDependenciesData(errorMessage = ex.message)
|
||||
} finally {
|
||||
SparkServer.cleanUpCallback()
|
||||
eventBus.unregister(busListener)
|
||||
}
|
||||
} else {
|
||||
DependencyData.GetDependenciesData(
|
||||
errorMessage = "buildFile wasn't passed in the query parameter")
|
||||
}
|
||||
println("GOT DEPENDENCY DATA: $result")
|
||||
sendWebsocketCommand(s.remote, DependencyData.GetDependenciesData.NAME, result)
|
||||
s.close()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue