-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dc1cdbf
WIP SAVE
petertrr 305b0d6
Cleanup
petertrr bf0fca9
WIP SAVE
petertrr 127b187
Merge remote-tracking branch 'origin/main' into feature/base-core-cli
petertrr c3596f3
WIP SAVE CLI
petertrr 3b53b4a
WIP SAVE CLI
petertrr e1e676f
WIP SAVE CLI
petertrr 1e944f5
WIP SAVE CLI
petertrr 0a76d48
WIP SAVE CLI
petertrr cca3ad4
WIP SAVE CLI
petertrr 2dc50c0
WIP SAVE CLI
petertrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
save-cli/src/commonMain/kotlin/org/cqfn/save/cli/Config.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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
14
save-cli/src/commonMain/kotlin/org/cqfn/save/cli/SaveCliRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
save-core/src/commonMain/kotlin/org/cqfn/save/core/Save.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
save-core/src/commonMain/kotlin/org/cqfn/save/core/config/ReportType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
22 changes: 22 additions & 0 deletions
22
save-core/src/commonMain/kotlin/org/cqfn/save/core/config/SaveConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
11 changes: 11 additions & 0 deletions
11
save-core/src/commonMain/kotlin/org/cqfn/save/core/config/TestSuiteConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
11 changes: 11 additions & 0 deletions
11
save-core/src/commonMain/kotlin/org/cqfn/save/core/plugin/Plugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
plugins { | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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