mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Fix --checkVersions to work with Aether.
This commit is contained in:
parent
57ed92ca57
commit
539c6cbda3
2 changed files with 32 additions and 23 deletions
|
@ -23,7 +23,6 @@ import org.eclipse.aether.collection.CollectResult
|
|||
import org.eclipse.aether.graph.Dependency
|
||||
import org.eclipse.aether.graph.DependencyFilter
|
||||
import org.eclipse.aether.graph.DependencyNode
|
||||
import org.eclipse.aether.metadata.DefaultMetadata
|
||||
import org.eclipse.aether.repository.RemoteRepository
|
||||
import org.eclipse.aether.resolution.*
|
||||
import org.eclipse.aether.transfer.ArtifactNotFoundException
|
||||
|
@ -119,26 +118,33 @@ class Aether(val localRepo: File, val settings: KobaltSettings, val eventBus: Ev
|
|||
}
|
||||
|
||||
fun resolveVersion(artifact: Artifact): VersionRangeResult? {
|
||||
val metadata = DefaultMetadata(artifact.groupId, artifact.artifactId, "maven-metadata.xml",
|
||||
org.eclipse.aether.metadata.Metadata.Nature.RELEASE)
|
||||
|
||||
val r = system.resolveMetadata(session, kobaltRepositories.map {
|
||||
MetadataRequest(metadata, it, null).apply {
|
||||
isFavorLocalRepository = false
|
||||
}
|
||||
})
|
||||
val request = VersionRangeRequest(artifact, kobaltRepositories, null)
|
||||
val result = system.resolveVersionRange(session, request)
|
||||
return result
|
||||
}
|
||||
|
||||
private fun oldResolveVErsion() {
|
||||
// val artifact = DefaultArtifact(a.groupId, a.artifactId, null, "[0,)")
|
||||
// val r = system.resolveMetadata(session, kobaltRepositories.map {
|
||||
// MetadataRequest(metadata, it, null).apply {
|
||||
// isFavorLocalRepository = false
|
||||
// }
|
||||
// })
|
||||
|
||||
// val metadata = DefaultMetadata(artifact.groupId, artifact.artifactId, "maven-metadata.xml",
|
||||
// org.eclipse.aether.metadata.Metadata.Nature.RELEASE)
|
||||
//
|
||||
// kobaltRepositories.forEach {
|
||||
// val request = MetadataRequest(metadata, it, null).apply {
|
||||
// isFavorLocalRepository = false
|
||||
// }
|
||||
// val r = system.resolveMetadata(session, listOf(request))
|
||||
// println("Repo: $it " + r)
|
||||
// val md = system.resolveMetadata(session, listOf(request))
|
||||
// if (artifact.groupId.contains("org.testng")) {
|
||||
// println("DONOTCOMMIT")
|
||||
// }
|
||||
// println("Repo: $it " + md)
|
||||
// }
|
||||
val request = VersionRangeRequest(artifact, kobaltRepositories, null)
|
||||
val result = system.resolveVersionRange(session, request)
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
fun resolve(artifact: Artifact): List<ArtifactResult> {
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.beust.kobalt.KobaltException
|
|||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.MavenId
|
||||
import com.beust.kobalt.maven.aether.Aether
|
||||
import com.beust.kobalt.maven.aether.AetherDependency
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -11,7 +12,7 @@ import javax.inject.Inject
|
|||
* Find out if any newer versions of the dependencies are available.
|
||||
*/
|
||||
public class CheckVersions @Inject constructor(val depManager: DependencyManager,
|
||||
val executors : KobaltExecutors) {
|
||||
val executors : KobaltExecutors, val aether: Aether) {
|
||||
|
||||
fun run(projects: List<Project>) {
|
||||
val executor = executors.newExecutor("CheckVersions", 5)
|
||||
|
@ -19,17 +20,19 @@ public class CheckVersions @Inject constructor(val depManager: DependencyManager
|
|||
val newVersions = hashSetOf<String>()
|
||||
projects.forEach { project ->
|
||||
listOf(project.compileDependencies, project.testDependencies).forEach { cds ->
|
||||
cds.forEach { compileDependency ->
|
||||
if (MavenId.isMavenId(compileDependency.id)) {
|
||||
cds.forEach { dep ->
|
||||
if (MavenId.isMavenId(dep.id)) {
|
||||
try {
|
||||
val dep = depManager.create(compileDependency.shortId, project.directory)
|
||||
val other = compileDependency as AetherDependency
|
||||
if (dep.id != compileDependency.id
|
||||
&& Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) {
|
||||
newVersions.add(dep.id)
|
||||
val latestDep = depManager.create(dep.shortId, project.directory)
|
||||
val artifact = (latestDep as AetherDependency).artifact
|
||||
val versions = aether.resolveVersion(artifact)
|
||||
val highest = versions?.highestVersion?.toString()
|
||||
if (highest != null && highest != dep.id
|
||||
&& Versions.toLongVersion(highest) > Versions.toLongVersion(dep.version)) {
|
||||
newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest)
|
||||
}
|
||||
} catch(e: KobaltException) {
|
||||
log(1, " Cannot resolve ${compileDependency.shortId}. ignoring")
|
||||
log(1, " Cannot resolve ${dep.shortId}. ignoring")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue