Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize subprojects and command-line interface #3

Merged
merged 11 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 10 additions & 56 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,15 @@ import org.cqfn.save.buildutils.configureDiktat
import org.cqfn.save.buildutils.createDetektTask
import org.cqfn.save.buildutils.createDiktatTask
import org.cqfn.save.buildutils.installGitHooks
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

plugins {
kotlin("multiplatform") version Versions.kotlin
kotlin("plugin.serialization") version Versions.kotlin
kotlin("multiplatform") version Versions.kotlin apply false
id("com.github.ben-manes.versions") version "0.38.0"
id("com.cdsap.talaiot.plugin.base") version "1.4.2"
}

version = "0.1.0-SNAPSHOT"

repositories {
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx/")
}

kotlin {
jvm()
val os = getCurrentOperatingSystem()
val saveTarget = when {
os.isMacOsX -> macosX64("save")
os.isLinux -> linuxX64("save")
os.isWindows -> mingwX64("save")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}

saveTarget.apply {
binaries {
executable {
entryPoint = "org.cqfn"
}
}
}

sourceSets {
val saveMain by getting {
dependencies {
implementation("com.squareup.okio:okio-multiplatform:3.0.0-alpha.1")
implementation( "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1")
}
}
val saveTest by getting

val jvmMain by getting {
dependsOn(saveMain)
}

val jvmTest by getting {
dependsOn(saveTest)
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter-engine:5.0.0")
}
}
}
}

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}

allprojects {
repositories {
mavenCentral()
Expand All @@ -73,4 +21,10 @@ allprojects {
}
createDiktatTask()
createDetektTask()
installGitHooks()
installGitHooks()

talaiot {
publishers {
timelinePublisher = true
}
}
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
object Versions {
val kotlin = "1.4.31"
val junit = "5.7.1"
}
57 changes: 57 additions & 0 deletions save-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem

plugins {
kotlin("multiplatform")
}

repositories {
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx/")
}

kotlin {
jvm()
val os = getCurrentOperatingSystem()
val saveTarget = when {
os.isMacOsX -> macosX64("save")
os.isLinux -> linuxX64("save")
os.isWindows -> mingwX64("save")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}

configure(listOf(saveTarget)) {
binaries {
executable {
entryPoint = "org.cqfn.save.cli.main"
}
}
}

sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
languageSettings.useExperimentalAnnotation("okio.ExperimentalFileSystem")
}
val commonMain by getting {
dependencies {
implementation(project(":save-core"))
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.2")
}
}
val commonTest by getting

val jvmMain by getting

val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter-engine:${Versions.junit}")
}
}
}
}

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}
60 changes: 60 additions & 0 deletions save-cli/src/commonMain/kotlin/org/cqfn/save/cli/Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Utilities to work with SAVE config in CLI mode
*/

package org.cqfn.save.cli

import org.cqfn.save.core.config.ReportType
import org.cqfn.save.core.config.SaveConfig

import okio.Path.Companion.toPath

import kotlinx.cli.ArgParser
import kotlinx.cli.ArgType
import kotlinx.cli.default

/**
* @param args CLI args
* @return an instance of [SaveConfig]
*/
fun createConfigFromArgs(args: Array<String>): SaveConfig {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be will add some argument for a baseline? (while I haven't yet forgotten about that)
We should have a baseline functionality

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this and addressed other comments, please take a look

val parser = ArgParser("save")

val config by parser.option(
ArgType.String,
shortName = "c",
description = "Path to the root save config file",
).default("save.toml")

val debug by parser.option(
ArgType.Boolean,
shortName = "d",
description = "Turn on debug logging"
).default(false)

val quiet by parser.option(
ArgType.Boolean,
shortName = "q",
description = "Do not log anything"
).default(false)

val reportType by parser.option(
ArgType.Choice<ReportType>(),
shortName = "r",
).default(ReportType.JSON)

val baseline by parser.option(
ArgType.String,
shortName = "b",
description = "Path to the file with baseline data",
)

parser.parse(args)
return SaveConfig(
configPath = config.toPath(),
debug = debug,
quiet = quiet,
reportType = reportType,
baselinePath = baseline?.toPath()
)
}
14 changes: 14 additions & 0 deletions save-cli/src/commonMain/kotlin/org/cqfn/save/cli/SaveCliRunner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Main entry point for SAVE CLI execution
*/

package org.cqfn.save.cli

import org.cqfn.save.core.Save

fun main(args: Array<String>) {
val save = Save(
createConfigFromArgs(args)
)
save.performAnalysis()
}
51 changes: 51 additions & 0 deletions save-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem

plugins {
kotlin("multiplatform")
}

repositories {
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx/")
}

kotlin {
jvm()
val os = getCurrentOperatingSystem()
val saveTarget = when {
os.isMacOsX -> macosX64("save")
os.isLinux -> linuxX64("save")
os.isWindows -> mingwX64("save")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}

configure(listOf(saveTarget)) {
}

sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
languageSettings.useExperimentalAnnotation("okio.ExperimentalFileSystem")
}
val commonMain by getting {
dependencies {
api("com.squareup.okio:okio-multiplatform:3.0.0-alpha.1")
}
}
val commonTest by getting

val jvmMain by getting

val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter-engine:${Versions.junit}")
}
}
}
}

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}
30 changes: 30 additions & 0 deletions save-core/src/commonMain/kotlin/org/cqfn/save/core/Save.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.cqfn.save.core

import org.cqfn.save.core.config.SaveConfig
import org.cqfn.save.core.plugin.Plugin

import okio.FileSystem

/**
* @property saveConfig an instance of [SaveConfig]
*/
@Suppress("INLINE_CLASS_CAN_BE_USED") // todo: remove when there are >1 constructor parameters
class Save(
private val saveConfig: SaveConfig
) {
/**
* Main entrypoint for SAVE framework. Discovers plugins and calls their execution.
*/
fun performAnalysis() {
// get all toml configs in file system
val fs = FileSystem.SYSTEM
val configFileLines: List<String> = fs.read(saveConfig.configPath) {
generateSequence { readUtf8Line() }.toList()
}

val plugins: List<Plugin> = emptyList() // todo: discover plugins
plugins.forEach {
it.execute(configFileLines)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.cqfn.save.core.config

/**
* Possible types of output formats.
*/
enum class ReportType {
JSON, PLAIN, TOML, XML
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cqfn.save.core.config

import okio.ExperimentalFileSystem
import okio.Path

/**
* Configuration properties of save application, retrieved either from peoperties file
* or from CLI args.
* @property configPath path to the configuration file
* @property debug
* @property quiet
* @property reportType type of generated report with execution results
* @property baselinePath path to the file with baseline data
*/
@OptIn(ExperimentalFileSystem::class)
data class SaveConfig(
val configPath: Path,
val debug: Boolean,
val quiet: Boolean,
val reportType: ReportType,
val baselinePath: Path?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.cqfn.save.core.config

/**
* Configuration for a test suite, that is read from test suite configuration file (toml config)
* @property suiteName name of test suite
* @property description dsecription of test suite
*/
data class TestSuiteConfig(
val suiteName: String,
val description: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.cqfn.save.core.plugin

/**
* Plugin that can be injected into SAVE during execution. Plugins accept contents of configuration file and then perform some work.
*/
interface Plugin {
/**
* @param configFileLines contents of configuration file
*/
fun execute(configFileLines: List<String>)
}
6 changes: 6 additions & 0 deletions save-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins {
}

repositories {
mavenCentral()
}
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

rootProject.name = "save"
include("save-core")
include("save-cli")
include("save-plugins")