summaryrefslogtreecommitdiff
path: root/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt
blob: 7ae0f5edc4c95645c86a4fb83f8c6c65646b6dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

package org.jetbrains.kotlin.config

import com.intellij.openapi.application.ApplicationManager

private const val APPLICATION_MANAGER_CLASS_NAME = "com.intellij.openapi.application.ApplicationManager"

val isJps: Boolean by lazy {
    /*
        Normally, JPS shouldn't have an ApplicationManager class in the classpath,
        but that's not true for JPS inside IDEA right now.
        Though Application is not properly initialized inside JPS so we can use it as a check.
     */
    return@lazy if (doesClassExist(APPLICATION_MANAGER_CLASS_NAME)) {
        ApplicationManager.getApplication() == null
    } else {
        true
    }
}

private fun doesClassExist(fqName: String): Boolean {
    val classPath = fqName.replace('.', '/') + ".class"
    return {}.javaClass.classLoader.getResource(classPath) != null
}