All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.build.BuildMetaInfo.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
/*
 * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * 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.build

import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.PluginClasspaths
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
import kotlin.reflect.KClass

interface BuildMetaInfo {
    val isEAP: Boolean
    val compilerBuildVersion: String
    val languageVersionString: String
    val apiVersionString: String
    val multiplatformEnable: Boolean
    val metadataVersionMajor: Int
    val metadataVersionMinor: Int
    val metadataVersionPatch: Int
    val ownVersion: Int
    val coroutinesVersion: Int
    val multiplatformVersion: Int
    val pluginClasspaths: String
}

abstract class BuildMetaInfoFactory(private val metaInfoClass: KClass) {
    protected abstract fun create(
        isEAP: Boolean,
        compilerBuildVersion: String,
        languageVersionString: String,
        apiVersionString: String,
        multiplatformEnable: Boolean,
        ownVersion: Int,
        coroutinesVersion: Int,
        multiplatformVersion: Int,
        metadataVersionArray: IntArray?,
        pluginClasspaths: String
    ): T

    fun create(args: CommonCompilerArguments): T {
        val languageVersion = args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST_STABLE

        return create(
            isEAP = !languageVersion.isStable,
            compilerBuildVersion = KotlinCompilerVersion.VERSION,
            languageVersionString = languageVersion.versionString,
            apiVersionString = args.apiVersion ?: languageVersion.versionString,
            multiplatformEnable = args.multiPlatform,
            ownVersion = OWN_VERSION,
            coroutinesVersion = COROUTINES_VERSION,
            multiplatformVersion = MULTIPLATFORM_VERSION,
            metadataVersionArray = args.metadataVersion?.let { BinaryVersion.parseVersionArray(it) },
            pluginClasspaths = PluginClasspaths(args.pluginClasspaths).serialize()
        )
    }

    fun serializeToString(args: CommonCompilerArguments): String =
        serializeToString(create(args))

    fun serializeToString(info: T): String =
        serializeToPlainText(info, metaInfoClass)

    fun deserializeFromString(str: String): T? =
        deserializeFromPlainText(str, metaInfoClass)

    companion object {
        const val OWN_VERSION: Int = 0
        const val COROUTINES_VERSION: Int = 0
        const val MULTIPLATFORM_VERSION: Int = 0
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy