Move ivy resolver to the main-kts to avoid classloading issues...
e.g. when main-kts is loaded in IDEA #KT-26828 fixed
This commit is contained in:
@@ -16,7 +16,6 @@ dependencies {
|
||||
compileOnly("com.jcabi:jcabi-aether:0.10.1")
|
||||
compileOnly("org.sonatype.aether:aether-api:1.13.1")
|
||||
compileOnly("org.apache.maven:maven-core:3.0.3")
|
||||
compileOnly("org.apache.ivy:ivy:2.4.0")
|
||||
testCompileOnly(project(":compiler:cli"))
|
||||
testCompile(project(":kotlin-test:kotlin-test-junit"))
|
||||
testRuntime(project(":kotlin-reflect"))
|
||||
@@ -25,7 +24,6 @@ dependencies {
|
||||
testRuntime("com.jcabi:jcabi-aether:0.10.1")
|
||||
testRuntime("org.sonatype.aether:aether-api:1.13.1")
|
||||
testRuntime("org.apache.maven:maven-core:3.0.3")
|
||||
testRuntime("org.apache.ivy:ivy:2.4.0")
|
||||
compileOnly(intellijDep()) { includeJars("openapi", "util") }
|
||||
testCompile(intellijDep()) { includeJars("openapi", "platform-api", "util") }
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ dependencies {
|
||||
compileOnly("com.jcabi:jcabi-aether:0.10.1")
|
||||
compileOnly("org.sonatype.aether:aether-api:1.13.1")
|
||||
compileOnly("org.apache.maven:maven-core:3.0.3")
|
||||
compileOnly("org.apache.ivy:ivy:2.4.0")
|
||||
testCompileOnly(project(":compiler:cli"))
|
||||
testCompile(project(":kotlin-test:kotlin-test-junit"))
|
||||
testRuntime(project(":kotlin-reflect"))
|
||||
@@ -25,7 +24,6 @@ dependencies {
|
||||
testRuntime("com.jcabi:jcabi-aether:0.10.1")
|
||||
testRuntime("org.sonatype.aether:aether-api:1.13.1")
|
||||
testRuntime("org.apache.maven:maven-core:3.0.3")
|
||||
testRuntime("org.apache.ivy:ivy:2.4.0")
|
||||
compileOnly(intellijDep()) { includeJars("openapi", "util") }
|
||||
testCompile(intellijDep()) { includeJars("openapi", "util") }
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ dependencies {
|
||||
compileOnly("com.jcabi:jcabi-aether:0.10.1")
|
||||
compileOnly("org.sonatype.aether:aether-api:1.13.1")
|
||||
compileOnly("org.apache.maven:maven-core:3.0.3")
|
||||
compileOnly("org.apache.ivy:ivy:2.4.0")
|
||||
testCompileOnly(project(":compiler:cli"))
|
||||
testCompile(project(":kotlin-test:kotlin-test-junit"))
|
||||
testRuntime(project(":kotlin-reflect"))
|
||||
@@ -25,7 +24,6 @@ dependencies {
|
||||
testRuntime("com.jcabi:jcabi-aether:0.10.1")
|
||||
testRuntime("org.sonatype.aether:aether-api:1.13.1")
|
||||
testRuntime("org.apache.maven:maven-core:3.0.3")
|
||||
testRuntime("org.apache.ivy:ivy:2.4.0")
|
||||
compileOnly(intellijDep()) { includeJars("openapi", "util") }
|
||||
testCompile(intellijDep()) { includeJars("openapi", "platform-api", "util") }
|
||||
}
|
||||
|
||||
-2
@@ -78,5 +78,3 @@ class LocalFilesResolver :
|
||||
class FilesAndMavenResolver :
|
||||
KotlinAnnotatedScriptDependenciesResolver(emptyList(), arrayListOf(DirectResolver(), MavenResolver()))
|
||||
|
||||
class FilesAndIvyResolver :
|
||||
KotlinAnnotatedScriptDependenciesResolver(emptyList(), arrayListOf(DirectResolver(), IvyResolver()))
|
||||
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.script.util.resolvers
|
||||
|
||||
import org.apache.ivy.Ivy
|
||||
import org.apache.ivy.core.LogOptions
|
||||
import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor
|
||||
import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor
|
||||
import org.apache.ivy.core.module.id.ModuleRevisionId
|
||||
import org.apache.ivy.core.resolve.ResolveOptions
|
||||
import org.apache.ivy.core.settings.IvySettings
|
||||
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.util.DefaultMessageLogger
|
||||
import org.apache.ivy.util.Message
|
||||
import org.jetbrains.kotlin.script.util.DependsOn
|
||||
import org.jetbrains.kotlin.script.util.Repository
|
||||
import java.io.File
|
||||
|
||||
class IvyResolver : Resolver {
|
||||
|
||||
private fun String.isValidParam() = isNotBlank()
|
||||
|
||||
override fun tryResolve(dependsOn: DependsOn): Iterable<File>? {
|
||||
val artifactId = when {
|
||||
dependsOn.groupId.isValidParam() || dependsOn.artifactId.isValidParam() -> {
|
||||
listOf(dependsOn.groupId, dependsOn.artifactId, dependsOn.version)
|
||||
}
|
||||
dependsOn.value.isValidParam() && dependsOn.value.count { it == ':' } == 2 -> {
|
||||
dependsOn.value.split(':')
|
||||
}
|
||||
else -> {
|
||||
error("Unknown set of arguments to maven resolver: ${dependsOn.value}")
|
||||
}
|
||||
}
|
||||
return resolveArtifact(artifactId)
|
||||
}
|
||||
|
||||
private val ivyResolvers = arrayListOf<URLResolver>()
|
||||
|
||||
private fun resolveArtifact(artifactId: List<String>): List<File> {
|
||||
|
||||
if (ivyResolvers.isEmpty() || ivyResolvers.none { it.name == "central" }) {
|
||||
ivyResolvers.add(
|
||||
URLResolver().apply {
|
||||
isM2compatible = true
|
||||
name = "central"
|
||||
addArtifactPattern("http://repo1.maven.org/maven2/$DEFAULT_ARTIFACT_PATTERN")
|
||||
}
|
||||
)
|
||||
}
|
||||
val ivySettings = IvySettings().apply {
|
||||
val resolver =
|
||||
if (ivyResolvers.size == 1) ivyResolvers.first()
|
||||
else ChainResolver().also {
|
||||
for (resolver in ivyResolvers) {
|
||||
it.add(resolver)
|
||||
}
|
||||
}
|
||||
addResolver(resolver)
|
||||
setDefaultResolver(resolver.name)
|
||||
}
|
||||
|
||||
val ivy = Ivy.newInstance(ivySettings)
|
||||
|
||||
val ivyfile = File.createTempFile("ivy", ".xml")
|
||||
ivyfile.deleteOnExit()
|
||||
|
||||
val moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(
|
||||
ModuleRevisionId.newInstance(artifactId[0], artifactId[1] + "-caller", "working")
|
||||
)
|
||||
|
||||
val depsDescriptor = DefaultDependencyDescriptor(
|
||||
moduleDescriptor,
|
||||
ModuleRevisionId.newInstance(artifactId[0], artifactId[1], artifactId[2]),
|
||||
false, false, true
|
||||
)
|
||||
moduleDescriptor.addDependency(depsDescriptor)
|
||||
|
||||
//creates an ivy configuration file
|
||||
XmlModuleDescriptorWriter.write(moduleDescriptor, ivyfile)
|
||||
|
||||
val resolveOptions = ResolveOptions().apply {
|
||||
confs = arrayOf("default")
|
||||
log = LogOptions.LOG_QUIET
|
||||
isOutputReport = false
|
||||
}
|
||||
|
||||
//init resolve report
|
||||
val report = ivy.resolve(ivyfile.toURI().toURL(), resolveOptions)
|
||||
|
||||
return report.allArtifactsReports.map { it.localFile }
|
||||
}
|
||||
|
||||
override fun tryAddRepo(annotation: Repository): Boolean {
|
||||
val urlStr = annotation.url.takeIf { it.isValidParam() } ?: annotation.value.takeIf { it.isValidParam() } ?: return false
|
||||
val url = urlStr.toRepositoryUrlOrNull() ?: return false
|
||||
ivyResolvers.add(
|
||||
URLResolver().apply {
|
||||
isM2compatible = true
|
||||
name = annotation.id.takeIf { it.isValidParam() } ?: url.host
|
||||
addArtifactPattern("${url.toString().let { if (it.endsWith('/')) it else "$it/" }}$DEFAULT_ARTIFACT_PATTERN")
|
||||
}
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_ARTIFACT_PATTERN = "[organisation]/[module]/[revision]/[artifact](-[revision]).[ext]"
|
||||
|
||||
init {
|
||||
Message.setDefaultLogger(DefaultMessageLogger(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
-4
@@ -18,7 +18,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.script.util.templates
|
||||
|
||||
import org.jetbrains.kotlin.script.util.FilesAndIvyResolver
|
||||
import org.jetbrains.kotlin.script.util.FilesAndMavenResolver
|
||||
import org.jetbrains.kotlin.script.util.LocalFilesResolver
|
||||
import kotlin.script.templates.ScriptTemplateDefinition
|
||||
@@ -29,9 +28,6 @@ abstract class StandardArgsScriptTemplateWithLocalResolving(val args: Array<Stri
|
||||
@ScriptTemplateDefinition(resolver = FilesAndMavenResolver::class, scriptFilePattern = ".*\\.kts")
|
||||
abstract class StandardArgsScriptTemplateWithMavenResolving(val args: Array<String>)
|
||||
|
||||
@ScriptTemplateDefinition(resolver = FilesAndIvyResolver::class, scriptFilePattern = ".*\\.kts")
|
||||
abstract class StandardArgsScriptTemplateWithIvyResolving(val args: Array<String>)
|
||||
|
||||
@ScriptTemplateDefinition(resolver = LocalFilesResolver::class, scriptFilePattern = ".*\\.kts")
|
||||
abstract class BindingsScriptTemplateWithLocalResolving(val bindings: Map<String, Any?>)
|
||||
|
||||
|
||||
-12
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
||||
import org.jetbrains.kotlin.script.util.templates.BindingsScriptTemplateWithLocalResolving
|
||||
import org.jetbrains.kotlin.script.util.templates.StandardArgsScriptTemplateWithIvyResolving
|
||||
import org.jetbrains.kotlin.script.util.templates.StandardArgsScriptTemplateWithLocalResolving
|
||||
import org.jetbrains.kotlin.script.util.templates.StandardArgsScriptTemplateWithMavenResolving
|
||||
import org.jetbrains.kotlin.utils.PathUtil.getResourcePathForClass
|
||||
@@ -106,17 +105,6 @@ done
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIvyResolveStdJUnitHelloWorld() {
|
||||
val scriptClass = compileScript("args-junit-hello-world.kts", StandardArgsScriptTemplateWithIvyResolving::class)
|
||||
Assert.assertNotNull(scriptClass)
|
||||
captureOut {
|
||||
scriptClass!!.getConstructor(Array<String>::class.java)!!.newInstance(arrayOf("a1"))
|
||||
}.let {
|
||||
Assert.assertEquals(argsHelloWorldOutput.linesSplitTrim(), it.linesSplitTrim())
|
||||
}
|
||||
}
|
||||
|
||||
private fun compileScript(
|
||||
scriptFileName: String,
|
||||
scriptTemplate: KClass<out Any>,
|
||||
|
||||
Reference in New Issue
Block a user