<commit_before>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.target.java

import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.execution.target.LanguageRuntimeType
import com.intellij.icons.AllIcons
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.lang.JavaVersion
import java.util.concurrent.CompletableFuture

class JavaLanguageRuntimeType : LanguageRuntimeType<JavaLanguageRuntimeConfiguration>(TYPE_ID) {
  override val icon = AllIcons.FileTypes.Java

  override val displayName = "Java"

  override val configurableDescription = "Configure Java"

  override val launchDescription = "Run Java application"

  override fun isApplicableTo(runConfig: RunnerAndConfigurationSettings) = true

  override fun createDefaultConfig() = JavaLanguageRuntimeConfiguration()

  override fun createSerializer(config: JavaLanguageRuntimeConfiguration): PersistentStateComponent<*> = config

  override fun createConfigurable(project: Project, config: JavaLanguageRuntimeConfiguration): Configurable =
    ServiceManager.getService(JavaLanguageRuntimeUIFactory::class.java).create(config)

  override fun createIntrospector(config: JavaLanguageRuntimeConfiguration): Introspector? {
    if (config.homePath.isNotBlank() && config.javaVersionString.isNotBlank()) return null

    return object : Introspector {
      override fun introspect(subject: Introspectable): CompletableFuture<*>? {
        if (config.homePath.isBlank()) {
          val home = subject.getEnvironmentVariable("JAVA_HOME")
          home?.let { config.homePath = home }
        }

        if (config.javaVersionString.isBlank()) {
          return null
        }

        return subject.promiseExecuteScript("java -version")
          .thenAccept {
            it?.let { StringUtil.splitByLines(it, true) }
              ?.firstOrNull()
              ?.let { JavaVersion.parse(it) }
              ?.let { config.javaVersionString = it.toString() }
          }
      }
    }
  }

  companion object {
    @JvmStatic
    val TYPE_ID = "JavaLanguageRuntime"
    private val LOG: Logger = Logger.getInstance(JavaLanguageRuntimeType::class.java)
  }
}<commit_msg>IDEA-234640 - [run.targets] JDK path and version are not detected<commit_after>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.target.java

import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.execution.target.LanguageRuntimeType
import com.intellij.icons.AllIcons
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.lang.JavaVersion
import java.util.concurrent.CompletableFuture

class JavaLanguageRuntimeType : LanguageRuntimeType<JavaLanguageRuntimeConfiguration>(TYPE_ID) {
  override val icon = AllIcons.FileTypes.Java

  override val displayName = "Java"

  override val configurableDescription = "Configure Java"

  override val launchDescription = "Run Java application"

  override fun isApplicableTo(runConfig: RunnerAndConfigurationSettings) = true

  override fun createDefaultConfig() = JavaLanguageRuntimeConfiguration()

  override fun createSerializer(config: JavaLanguageRuntimeConfiguration): PersistentStateComponent<*> = config

  override fun createConfigurable(project: Project, config: JavaLanguageRuntimeConfiguration): Configurable =
    ServiceManager.getService(JavaLanguageRuntimeUIFactory::class.java).create(config)

  override fun createIntrospector(config: JavaLanguageRuntimeConfiguration): Introspector? {
    if (config.homePath.isNotBlank() && config.javaVersionString.isNotBlank()) return null

    return object : Introspector {
      override fun introspect(subject: Introspectable): CompletableFuture<JavaLanguageRuntimeConfiguration>? {
        if (config.homePath.isBlank()) {
          val home = subject.getEnvironmentVariable("JAVA_HOME")
          home?.let { config.homePath = home }
        }

        if (config.javaVersionString.isNotBlank()) {
          return CompletableFuture.completedFuture(config)
        }

        return subject.promiseExecuteScript("java -version")
          .thenApply { output ->
            output?.let { StringUtil.splitByLines(output, true) }
              ?.firstOrNull()
              ?.let { JavaVersion.parse(it) }
              ?.let { config.javaVersionString = it.toString() }
            return@thenApply config
          }
      }
    }
  }

  companion object {
    @JvmStatic
    val TYPE_ID = "JavaLanguageRuntime"
  }
}
{'fraction_non_alphanumeric': 0.08498253783469151, 'fraction_numerical': 0.005044625533566162, 'mean_word_length': 4.170511534603811, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1797082', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1361, 'n_words': 300}