Skip to content

Commit

Permalink
Remove idea/src/META-INF/extensions/{kotlin2jvm.xml,kotlin2js.xml}
Browse files Browse the repository at this point in the history
Keep the EnvironmentConfigFiles enum because its values are used in
determining whether the environment is going to be used for JVM or
non-JVM project analysis, but remove the actual files.

Drop EnvironmentConfigFiles.EMPTY and replace its only usage in
preprocessor with JVM_CONFIG_FILES: it's easier and won't affect
anything
  • Loading branch information
udalov committed Nov 15, 2017
1 parent 7ace303 commit afc9d3e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 61 deletions.
2 changes: 0 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@

<fileset dir="idea/src">
<include name="META-INF/extensions/common.xml"/>
<include name="META-INF/extensions/kotlin2jvm.xml"/>
<include name="META-INF/extensions/kotlin2js.xml"/>
</fileset>

<zipgroupfileset dir="${basedir}/lib" includes="*.jar"/>
Expand Down
4 changes: 1 addition & 3 deletions compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ val jar: Jar by tasks
jar.apply {
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from("../idea/src").apply {
include("META-INF/extensions/common.xml",
"META-INF/extensions/kotlin2jvm.xml",
"META-INF/extensions/kotlin2js.xml")
include("META-INF/extensions/common.xml")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,9 @@

package org.jetbrains.kotlin.cli.jvm.compiler;

import java.util.Arrays;
import java.util.List;

public enum EnvironmentConfigFiles {
JVM_CONFIG_FILES("extensions/common.xml", "extensions/kotlin2jvm.xml"),
JS_CONFIG_FILES("extensions/common.xml", "extensions/kotlin2js.xml"),
NATIVE_CONFIG_FILES("extensions/common.xml"),
METADATA_CONFIG_FILES("extensions/common.xml"),
EMPTY();

private final List<String> files;

EnvironmentConfigFiles(String... fileArray) {
files = Arrays.asList(fileArray);
}

public List<String> getFiles() {
return files;
}
JVM_CONFIG_FILES,
JS_CONFIG_FILES,
NATIVE_CONFIG_FILES,
METADATA_CONFIG_FILES,
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ import org.jetbrains.kotlin.script.StandardScriptDefinition
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
import java.util.zip.ZipFile
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.jvm.isAccessible

class KotlinCoreEnvironment private constructor(
parentDisposable: Disposable,
Expand Down Expand Up @@ -385,14 +383,15 @@ class KotlinCoreEnvironment private constructor(
private var ourApplicationEnvironment: JavaCoreApplicationEnvironment? = null
private var ourProjectCount = 0

@JvmStatic fun createForProduction(
@JvmStatic
fun createForProduction(
parentDisposable: Disposable, configuration: CompilerConfiguration, configFiles: EnvironmentConfigFiles
): KotlinCoreEnvironment {
setCompatibleBuild()
val appEnv = getOrCreateApplicationEnvironmentForProduction(configuration, configFiles.files)
val appEnv = getOrCreateApplicationEnvironmentForProduction(configuration)
// Disposing of the environment is unsafe in production then parallel builds are enabled, but turning it off universally
// breaks a lot of tests, therefore it is disabled for production and enabled for tests
if (!(System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY).toBooleanLenient() ?: false)) {
if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY).toBooleanLenient() != true) {
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
Disposer.register(parentDisposable, Disposable {
Expand All @@ -418,33 +417,33 @@ class KotlinCoreEnvironment private constructor(
}

@TestOnly
@JvmStatic fun createForTests(
parentDisposable: Disposable, configuration: CompilerConfiguration, extensionConfigs: EnvironmentConfigFiles
@JvmStatic
fun createForTests(
parentDisposable: Disposable, initialConfiguration: CompilerConfiguration, extensionConfigs: EnvironmentConfigFiles
): KotlinCoreEnvironment {
val config = configuration.copy()
if (config.getList(JVMConfigurationKeys.SCRIPT_DEFINITIONS).isEmpty()) {
config.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, StandardScriptDefinition)
val configuration = initialConfiguration.copy()
if (configuration.getList(JVMConfigurationKeys.SCRIPT_DEFINITIONS).isEmpty()) {
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, StandardScriptDefinition)
}
// Tests are supposed to create a single project and dispose it right after use
return KotlinCoreEnvironment(parentDisposable,
createApplicationEnvironment(parentDisposable, config, extensionConfigs.files,
unitTestMode = true),
config,
extensionConfigs)
return KotlinCoreEnvironment(
parentDisposable,
createApplicationEnvironment(parentDisposable, configuration, unitTestMode = true),
configuration,
extensionConfigs
)
}

// used in the daemon for jar cache cleanup
val applicationEnvironment: JavaCoreApplicationEnvironment? get() = ourApplicationEnvironment

private fun getOrCreateApplicationEnvironmentForProduction(
configuration: CompilerConfiguration, configFilePaths: List<String>
): JavaCoreApplicationEnvironment {
private fun getOrCreateApplicationEnvironmentForProduction(configuration: CompilerConfiguration): JavaCoreApplicationEnvironment {
synchronized (APPLICATION_LOCK) {
if (ourApplicationEnvironment != null)
return ourApplicationEnvironment!!

val parentDisposable = Disposer.newDisposable()
ourApplicationEnvironment = createApplicationEnvironment(parentDisposable, configuration, configFilePaths, unitTestMode = false)
ourApplicationEnvironment = createApplicationEnvironment(parentDisposable, configuration, unitTestMode = false)
ourProjectCount = 0
Disposer.register(parentDisposable, Disposable {
synchronized (APPLICATION_LOCK) {
Expand All @@ -467,7 +466,6 @@ class KotlinCoreEnvironment private constructor(
private fun createApplicationEnvironment(
parentDisposable: Disposable,
configuration: CompilerConfiguration,
configFilePaths: List<String>,
unitTestMode: Boolean
): JavaCoreApplicationEnvironment {
Extensions.cleanRootArea(parentDisposable)
Expand All @@ -476,9 +474,7 @@ class KotlinCoreEnvironment private constructor(
override fun createJrtFileSystem(): VirtualFileSystem? = CoreJrtFileSystem()
}

for (configPath in configFilePaths) {
registerApplicationExtensionPointsAndExtensionsFrom(configuration, configPath)
}
registerApplicationExtensionPointsAndExtensionsFrom(configuration, "extensions/common.xml")

registerApplicationServicesForCLI(applicationEnvironment)
registerApplicationServices(applicationEnvironment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Preprocessor(val logger: Logger = SystemOutLogger) {

init {
val configuration = CompilerConfiguration()
val environment = KotlinCoreEnvironment.createForProduction(Disposable { }, configuration, EnvironmentConfigFiles.EMPTY)
val environment = KotlinCoreEnvironment.createForProduction(Disposable { }, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)

val project = environment.project
jetPsiFactory = KtPsiFactory(project)
Expand Down
6 changes: 0 additions & 6 deletions idea/src/META-INF/extensions/kotlin2js.xml

This file was deleted.

6 changes: 0 additions & 6 deletions idea/src/META-INF/extensions/kotlin2jvm.xml

This file was deleted.

2 changes: 0 additions & 2 deletions idea/src/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2725,8 +2725,6 @@
</extensionPoints>

<extensions defaultExtensionNs="org.jetbrains.kotlin">
<xi:include href="extensions/kotlin2jvm.xml" xpointer="xpointer(/idea-plugin/extensions/*)"/>
<xi:include href="extensions/kotlin2js.xml" xpointer="xpointer(/idea-plugin/extensions/*)"/>
<quickFixContributor implementation="org.jetbrains.kotlin.idea.quickfix.QuickFixRegistrar"/>

<declarationAttributeAltererExtension implementation="org.jetbrains.kotlin.allopen.ide.IdeAllOpenDeclarationAttributeAltererExtension"/>
Expand Down

0 comments on commit afc9d3e

Please sign in to comment.