Make script resolving annotations repeatable, fix multiple repos usage

Also avoid "unknown resolver central" errors on ivy resolving
#KT-27050 fixed
This commit is contained in:
Ilya Chernikov
2018-09-25 12:49:05 +02:00
parent 0d103e7f0c
commit 43a4b84b44
2 changed files with 15 additions and 5 deletions
@@ -19,10 +19,14 @@ package org.jetbrains.kotlin.script.util
// in case of flat or direct resolvers the value should be a direct path or file name of a jar respectively // in case of flat or direct resolvers the value should be a direct path or file name of a jar respectively
// in case of maven resolver the maven coordinates string is accepted (resolved with com.jcabi.aether library) // in case of maven resolver the maven coordinates string is accepted (resolved with com.jcabi.aether library)
@Target(AnnotationTarget.FILE) @Target(AnnotationTarget.FILE)
@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class DependsOn(val value: String = "", val groupId: String = "", val artifactId: String = "", val version: String = "") annotation class DependsOn(val value: String = "", val groupId: String = "", val artifactId: String = "", val version: String = "")
// only flat directory repositories are supported now, so value should be a path to a directory with jars // only flat directory repositories are supported now, so value should be a path to a directory with jars
// TODO: support other types of repos // TODO: support other types of repos
@Target(AnnotationTarget.FILE) @Target(AnnotationTarget.FILE)
@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class Repository(val value: String = "", val id: String = "", val url: String = "") annotation class Repository(val value: String = "", val id: String = "", val url: String = "")
@@ -13,6 +13,7 @@ import org.apache.ivy.core.module.id.ModuleRevisionId
import org.apache.ivy.core.resolve.ResolveOptions import org.apache.ivy.core.resolve.ResolveOptions
import org.apache.ivy.core.settings.IvySettings import org.apache.ivy.core.settings.IvySettings
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter
import org.apache.ivy.plugins.resolver.ChainResolver
import org.apache.ivy.plugins.resolver.URLResolver import org.apache.ivy.plugins.resolver.URLResolver
import org.apache.ivy.util.DefaultMessageLogger import org.apache.ivy.util.DefaultMessageLogger
import org.apache.ivy.util.Message import org.apache.ivy.util.Message
@@ -43,7 +44,7 @@ class IvyResolver : Resolver {
private fun resolveArtifact(artifactId: List<String>): List<File> { private fun resolveArtifact(artifactId: List<String>): List<File> {
if (ivyResolvers.isEmpty()) { if (ivyResolvers.isEmpty() || ivyResolvers.none { it.name == "central" }) {
ivyResolvers.add( ivyResolvers.add(
URLResolver().apply { URLResolver().apply {
isM2compatible = true isM2compatible = true
@@ -53,10 +54,15 @@ class IvyResolver : Resolver {
) )
} }
val ivySettings = IvySettings().apply { val ivySettings = IvySettings().apply {
for (resolver in ivyResolvers) { val resolver =
addResolver(resolver) if (ivyResolvers.size == 1) ivyResolvers.first()
} else ChainResolver().also {
setDefaultResolver(ivyResolvers.first().name) for (resolver in ivyResolvers) {
it.add(resolver)
}
}
addResolver(resolver)
setDefaultResolver(resolver.name)
} }
val ivy = Ivy.newInstance(ivySettings) val ivy = Ivy.newInstance(ivySettings)