Skip to content

Commit 96bd8cb

Browse files
committed
Minor, move PluginCliParser and PluginURLClassLoader to subpackage
1 parent 534e8a5 commit 96bd8cb

File tree

3 files changed

+59
-42
lines changed

3 files changed

+59
-42
lines changed

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
3333
import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoot
3434
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
3535
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
36+
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
3637
import org.jetbrains.kotlin.cli.jvm.repl.ReplFromTerminal
3738
import org.jetbrains.kotlin.codegen.CompilationException
3839
import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/PluginCliParser.kt renamed to compiler/cli/src/org/jetbrains/kotlin/cli/jvm/plugins/PluginCliParser.kt

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 JetBrains s.r.o.
2+
* Copyright 2010-2017 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,20 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.jetbrains.kotlin.cli.jvm
17+
package org.jetbrains.kotlin.cli.jvm.plugins
1818

1919
import com.intellij.util.containers.MultiMap
2020
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
21+
import org.jetbrains.kotlin.cli.jvm.BundledCompilerPlugins
2122
import org.jetbrains.kotlin.compiler.plugin.*
2223
import org.jetbrains.kotlin.config.CompilerConfiguration
2324
import java.io.File
2425
import java.net.URL
25-
import java.net.URLClassLoader
2626
import java.util.*
2727

28-
2928
object PluginCliParser {
30-
3129
@JvmStatic
3230
fun loadPlugins(arguments: CommonCompilerArguments, configuration: CompilerConfiguration) {
3331
val classLoader = PluginURLClassLoader(
@@ -64,9 +62,7 @@ object PluginCliParser {
6462

6563
for (optionValue in optionValuesByPlugin[processor.pluginId].orEmpty()) {
6664
val option = declaredOptions[optionValue!!.optionName]
67-
if (option == null) {
68-
throw CliOptionProcessingException("Unsupported plugin option: $optionValue")
69-
}
65+
?: throw CliOptionProcessingException("Unsupported plugin option: $optionValue")
7066
optionsToValues.putValue(option, optionValue)
7167
}
7268

@@ -92,37 +88,3 @@ object PluginCliParser {
9288
}
9389
}
9490
}
95-
96-
private class PluginURLClassLoader(urls: Array<URL>, parent: ClassLoader) : ClassLoader(Thread.currentThread().contextClassLoader) {
97-
private val childClassLoader: SelfThenParentURLClassLoader = SelfThenParentURLClassLoader(urls, parent)
98-
99-
@Synchronized
100-
override fun loadClass(name: String, resolve: Boolean): Class<*> {
101-
return try {
102-
childClassLoader.findClass(name)
103-
}
104-
catch (e: ClassNotFoundException) {
105-
super.loadClass(name, resolve)
106-
}
107-
}
108-
109-
override fun getResources(name: String) = childClassLoader.getResources(name)
110-
111-
private class SelfThenParentURLClassLoader(urls: Array<URL>, val onFail: ClassLoader) : URLClassLoader(urls, null) {
112-
113-
public override fun findClass(name: String): Class<*> {
114-
val loaded = findLoadedClass(name)
115-
if (loaded != null) {
116-
return loaded
117-
}
118-
119-
return try {
120-
super.findClass(name)
121-
}
122-
catch (e: ClassNotFoundException) {
123-
onFail.loadClass(name)
124-
}
125-
126-
}
127-
}
128-
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2010-2017 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jetbrains.kotlin.cli.jvm.plugins
18+
19+
import java.net.URL
20+
import java.net.URLClassLoader
21+
import java.util.*
22+
23+
internal class PluginURLClassLoader(urls: Array<URL>, parent: ClassLoader) : ClassLoader(Thread.currentThread().contextClassLoader) {
24+
private val childClassLoader: SelfThenParentURLClassLoader = SelfThenParentURLClassLoader(urls, parent)
25+
26+
@Synchronized
27+
override fun loadClass(name: String, resolve: Boolean): Class<*> {
28+
return try {
29+
childClassLoader.findClass(name)
30+
}
31+
catch (e: ClassNotFoundException) {
32+
super.loadClass(name, resolve)
33+
}
34+
}
35+
36+
override fun getResources(name: String): Enumeration<URL> = childClassLoader.getResources(name)
37+
38+
private class SelfThenParentURLClassLoader(urls: Array<URL>, private val onFail: ClassLoader) : URLClassLoader(urls, null) {
39+
40+
public override fun findClass(name: String): Class<*> {
41+
val loaded = findLoadedClass(name)
42+
if (loaded != null) {
43+
return loaded
44+
}
45+
46+
return try {
47+
super.findClass(name)
48+
}
49+
catch (e: ClassNotFoundException) {
50+
onFail.loadClass(name)
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)