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

com.github.mvysny.kaributesting.v10.VaadinVersion.kt Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package com.github.mvysny.kaributesting.v10

import com.vaadin.flow.server.Version
import elemental.json.JsonObject

data class SemanticVersion(val major: Int, val minor: Int, val bugfix: Int) : Comparable {
    override fun compareTo(other: SemanticVersion): Int =
            compareValuesBy(this, other, { it.major }, { it.minor }, { it.bugfix })

    override fun toString() = "$major.$minor.$bugfix"
}

object VaadinMeta {
    /**
     * Vaadin Flow `flow-server.jar` version: for example 1.2.0 for Vaadin 12
     */
    val flowVersion: SemanticVersion get() = SemanticVersion(Version.getMajorVersion(), Version.getMinorVersion(), Version.getRevision())

    /**
     * Guesses Vaadin version from [flowVersion]. Returns one of 11, 12, 13 or 14.
     */
    val version: Int get() = when {
        flowVersion < SemanticVersion(1, 2, 0) -> 11
        flowVersion < SemanticVersion(1, 3, 0) -> 12
        flowVersion < SemanticVersion(2, 0, 0) -> 13
        else -> 14
    }

    val flowBuildInfo: JsonObject? get() = Thread.currentThread().contextClassLoader
            .getResource("META-INF/VAADIN/config/flow-build-info.json")
            ?.readJson()

    val isCompatibilityMode: Boolean get() = flowBuildInfo?.getBoolean("compatibilityMode") ?: true
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy