Skip to content

Commit

Permalink
Setup quality baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed Jul 29, 2019
1 parent a28a1a4 commit 609f661
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 45 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: java
matrix:
include:
- os: linux
jdk: openjdk8
- os: linux
jdk: openjdk11
install: true
script:
- ./gradlew build detekt publishToMavenLocal
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# ksh

[![build status](https://travis-ci.org/arturbosch/ksh.svg?branch=master)](https://travis-ci.org/arturbosch/ksh)
[![CodeFactor](https://www.codefactor.io/repository/github/arturbosch/ksh/badge)](https://www.codefactor.io/repository/github/arturbosch/ksh)
[ ![Download](https://api.bintray.com/packages/arturbosch/generic/ksh/images/download.svg) ](https://bintray.com/arturbosch/generic/ksh/_latestVersion)

A framework to build shell-like applications
Expand Down
22 changes: 22 additions & 0 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" ?>
<SmellBaseline>
<Blacklist></Blacklist>
<Whitelist>
<ID>ComplexMethod:DefaultParameterResolver.kt$DefaultParameterResolver$override fun evaluate(methodTarget: MethodTarget, input: InputLine): List&lt;Any?&gt;</ID>
<ID>ComplexMethod:Help.kt$Help$@ShellMethod(help = "Prints this help message.") fun main( @ShellOption(["", "--command"], defaultValue = "") command: String ): String</ID>
<ID>ComplexMethod:Help.kt$Help$private fun forSpecificCommand(command: ShellClass, methodTarget: MethodTarget): String</ID>
<ID>EmptyFunctionBlock:ShellClass.kt$ShellClass${}</ID>
<ID>LongMethod:DefaultParameterResolver.kt$DefaultParameterResolver$override fun evaluate(methodTarget: MethodTarget, input: InputLine): List&lt;Any?&gt;</ID>
<ID>LongParameterList:TestCommands.kt$Conversions$( @ShellOption(["-i"]) aInt: Int, @ShellOption(["-f"]) aFloat: Float, @ShellOption(["-b"]) aBool: Boolean, @ShellOption(["-d"]) aDouble: Double, @ShellOption(["-s"]) aString: String, @ShellOption(["-file"]) aFile: File )</ID>
<ID>MagicNumber:AliasesResolver.kt$AliasesResolver$100</ID>
<ID>MatchingDeclarationName:Main.kt$io.gitlab.arturbosch.ksh.Main.kt</ID>
<ID>MatchingDeclarationName:TestContext.kt$io.gitlab.arturbosch.ksh.test.TestContext.kt</ID>
<ID>MaxLineLength:ContextExtensions.kt$container.get&lt;Debugging&gt;() .log { "Invoking '${target.methodTarget.name}' on '${target.shellClass.javaClass.simpleName}' with args='${target.arguments}'" }</ID>
<ID>MaximumLineLength:</ID>
<ID>NoUnusedImports:</ID>
<ID>SpreadOperator:DefaultMethodTarget.kt$DefaultMethodTarget$(command, *arguments.toTypedArray())</ID>
<ID>SpreadOperator:MethodTarget.kt$MethodTarget$(command, *arguments.toTypedArray())</ID>
<ID>TooGenericExceptionCaught:Bootstrap.kt$Bootstrap$e: RuntimeException</ID>
<ID>TooManyFunctions:Reflection.kt$io.gitlab.arturbosch.ksh.defaults.Reflection.kt</ID>
</Whitelist>
</SmellBaseline>
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ buildscript {
}

plugins {
id "com.github.johnrengelman.shadow" version "5.0.0"
id "com.github.johnrengelman.shadow" version "5.1.0"
id 'com.github.ben-manes.versions' version '0.21.0'
id "com.jfrog.bintray" version "1.8.1"
id "org.sonarqube" version "2.7"
id "io.gitlab.arturbosch.detekt" version "1.0.0-RC14"
id "com.jfrog.bintray" version "1.8.4"
id "org.sonarqube" version "2.7.1"
id "io.gitlab.arturbosch.detekt" version "1.0.0-RC16"
}

repositories {
jcenter()
}

dependencies {
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion"
}

detekt {
input = files(rootProject.rootDir)
buildUponDefaultConfig = true
failFast = true
baseline = file("$rootDir/baseline.xml")
}

allprojects {
Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
kshVersion=0.4.0
kutilsVersion=0.6.0
kotlinVersion=1.3.31
jlineVersion=3.11.0
kutilsVersion=0.6.4
kotlinVersion=1.3.41
jlineVersion=3.12.1
jcommanderVersion=1.72
metainfVersion=1.7
junitVersion=4.12
assertkVersion=0.10
assertkVersion=0.19
detektVersion=1.0.0-RC16
systemProp.sonar.host.url=http://localhost:9000
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.gitlab.arturbosch.ksh.aliases

import assertk.assert
import assertk.assertThat
import assertk.assertions.isEqualTo
import io.gitlab.arturbosch.ksh.NoopContainer
import io.gitlab.arturbosch.ksh.api.SimpleInputLine
Expand All @@ -13,7 +13,7 @@ class AliasesResolverProviderTest {
fun `resolves aliases`() {
val resolver = AliasesResolverProvider().provide(NoopContainer())
val transformed = resolver.transform(SimpleInputLine("hello"))
assert(transformed.words()).isEqualTo(listOf("help", "hello"))
assertThat(transformed.words()).isEqualTo(listOf("help", "hello"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import io.gitlab.arturbosch.ksh.api.ShellClass
import io.gitlab.arturbosch.ksh.api.ShellMethod
import io.gitlab.arturbosch.ksh.api.ShellOption
import io.gitlab.arturbosch.ksh.interpret
import io.gitlab.arturbosch.kutils.Path
import io.gitlab.arturbosch.kutils.consume
import io.gitlab.arturbosch.kutils.path
import io.gitlab.arturbosch.kutils.process
import java.io.IOException
import kotlin.properties.Delegates
Expand All @@ -34,7 +34,7 @@ class Script : ShellClass {
): String = try {
val (out, err, status) =
process(
command.split(" "), path(workDir ?: ".").toFile()
command.split(" "), Path(workDir ?: ".").toFile()
).consume()
(if (status == 0) out else err).joinToString(sep)
} catch (ioe: IOException) {
Expand All @@ -45,7 +45,7 @@ class Script : ShellClass {
fun file(
@ShellOption(["", "--script"], help = "Path to a ksh script") scriptName: String
) = try {
context.interpret(path(scriptName))
context.interpret(Path(scriptName))
} catch (ioe: IOException) {
throw IllegalArgumentException("Error executing script 'command'.", ioe)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.gitlab.arturbosch.ksh.commands

import assertk.assertThat
import assertk.assertions.isEqualTo
import io.gitlab.arturbosch.ksh.test.TestShellBuilder
import io.gitlab.arturbosch.ksh.test.get
Expand Down Expand Up @@ -30,6 +31,6 @@ internal class ScriptTest {
""".trimIndent()

assertk.assert(actual).isEqualTo(expected)
assertThat(actual).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.gitlab.arturbosch.ksh.converters

import assertk.assertions.each
import assertk.assertThat
import assertk.assertions.isInstanceOf
import io.gitlab.arturbosch.ksh.NoopContainer
import io.gitlab.arturbosch.ksh.defaults.DefaultConversions
import io.gitlab.arturbosch.ksh.defaults.providers.DefaultConvertersProvider
Expand All @@ -21,12 +22,13 @@ class ConverterTest {
fun defaultConvertersWork() {
val conversions = DefaultConversions(DefaultConvertersProvider().provide(NoopContainer()))

assertk.assert {
ConverterTest::class.java.getDeclaredMethod("parameters", Path::class.java, File::class.java)
.parameters
.map { it to associateBy(it) }
.map { conversions.convert(it.first, it.second) }
}.returnedValue { each { checkNotNull(it.actual)::class in setOf(Path::class, File::class) } }
val (first, second) = ConverterTest::class.java.getDeclaredMethod("parameters", Path::class.java, File::class.java)
.parameters
.map { it to associateBy(it) }
.map { conversions.convert(it.first, it.second) }

assertThat(first!!).isInstanceOf(Path::class)
assertThat(second!!).isInstanceOf(File::class)
}

private fun associateBy(it: Parameter): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.gitlab.arturbosch.ksh.defaults

import assertk.assertThat
import assertk.assertions.containsAll
import io.gitlab.arturbosch.ksh.Conversions
import io.gitlab.arturbosch.ksh.Hello
Expand Down Expand Up @@ -34,48 +35,48 @@ class DefaultCompleterTest {
@Test
fun `completion of all shell classes if nothing is entered`() {
val candidates = completer.complete("")
assertk.assert(candidates).containsAll("hello", "conversions")
assertThat(candidates).containsAll("hello", "conversions")
}

@Test
fun `completion of hello command when only word is hel`() {
val candidates = completer.complete("hel")
assertk.assert(candidates).containsAll("hello")
assertThat(candidates).containsAll("hello")
}

@Test
fun `completion of sub commands of hello are shown`() {
val candidates = completer.complete("hello ")
assertk.assert(candidates).containsAll("say", "count", "invalid")
assertThat(candidates).containsAll("say", "count", "invalid")
}

@Test
fun `completion of main command's (hello) only option is shown as second word indicates an option`() {
val candidates = completer.complete("hello --")
assertk.assert(candidates).containsAll("--name", "-n")
assertThat(candidates).containsAll("--name", "-n")
}

@Test
fun `completion of sub commands options when third word is empty`() {
val candidates = completer.complete("hello count ")
assertk.assert(candidates).containsAll("--name", "-n", "--times")
assertThat(candidates).containsAll("--name", "-n", "--times")
}

@Test
fun `completion of sub commands options when third word indicates an option`() {
val candidates = completer.complete("hello count -")
assertk.assert(candidates).containsAll("--name", "-n", "--times")
assertThat(candidates).containsAll("--name", "-n", "--times")
}

@Test
fun `completion of sub commands options when third word indicates a long option`() {
val candidates = completer.complete("hello count --")
assertk.assert(candidates).containsAll("--name", "--times")
assertThat(candidates).containsAll("--name", "--times")
}

@Test
fun `completion of sub commands option 'times'`() {
val candidates = completer.complete("hello count --tim")
assertk.assert(candidates).containsAll("--times")
assertThat(candidates).containsAll("--times")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.gitlab.arturbosch.ksh.defaults

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isIn
import assertk.assertions.isInstanceOf
Expand All @@ -20,77 +21,77 @@ class DefaultResolverTest {
@Test
fun resolveMainWithOneOptionIdLessParameter() {
val target = resolver.evaluate("hello Artur")
assertk.assert(target).isEqualTo("Hello Artur!")
assertThat(target).isEqualTo("Hello Artur!")
}

@Test
fun resolveMainWithOneParameter() {
val target = resolver.evaluate("hello --name Artur")
assertk.assert(target).isEqualTo("Hello Artur!")
assertThat(target).isEqualTo("Hello Artur!")
}

@Test
fun resolveMainWithOneDefaultParameter() {
val target = resolver.evaluate("hello")
assertk.assert(target).isEqualTo("Hello World!")
assertThat(target).isEqualTo("Hello World!")
}

@Test
fun resolveMethodWithOneParameter() {
val target = resolver.evaluate("hello say --name Artur")
assertk.assert(target).isEqualTo("Hello Artur!")
assertThat(target).isEqualTo("Hello Artur!")
}

@Test
fun resolveMethodWithOneDefaultParameter() {
val target = resolver.evaluate("hello say")
assertk.assert(target).isEqualTo("Hello OMG!")
assertThat(target).isEqualTo("Hello OMG!")
}

@Test
fun resolveMethodWithTwoParametersAndDefaults() {
val target = resolver.evaluate("hello count")
assertk.assert(target).isEqualTo("Hello OMGOMGOMG")
assertThat(target).isEqualTo("Hello OMGOMGOMG")
}

@Test
fun resolveMethodWithTwoParametersOneDefault() {
val target = resolver.evaluate("hello count --name Artur")
assertk.assert(target).isEqualTo("Hello ArturArturArtur")
assertThat(target).isEqualTo("Hello ArturArturArtur")
}

@Test
fun resolveMethodWithTwoParametersNoDefaults() {
val target = resolver.evaluate("hello count --name Artur --times 1")
assertk.assert(target).isEqualTo("Hello Artur")
assertThat(target).isEqualTo("Hello Artur")
}

@Test
fun resolveClassWithCustomIdAndMethodWithAllConversionsAndRandomParameters() {
val command = "conversions -file /home/test -i 5 -b -f 2.0f -d 5.0 -s bla"
val target = resolver.evaluate(command)
assertk.assert(target).isEqualTo("5 2.0 true 5.0 bla /home/test")
assertThat(target).isEqualTo("5 2.0 true 5.0 bla /home/test")
}

@Test
fun resolveTwoUnnamedParameters() {
val target = resolver.evaluate("hello invalid Artur 25")
assertk.assert(target).isEqualTo("Hello Artur - 25")
assertThat(target).isEqualTo("Hello Artur - 25")
}

@Test
fun resolvesPathParameters() {
val target = resolver.evaluate("conversions path this/is/a/path")
assertk.assert(target!!).isInstanceOf(Path::class)
assertThat(target!!).isInstanceOf(Path::class)
}

@Test
fun resolvesToDefaultMainOnEmptyInput() {
assertk.assert(resolver.evaluate("double")).isEqualTo("first")
assertThat(resolver.evaluate("double")).isEqualTo("first")
}

@Test
fun resolvedToAnyIfMainIsSpecifiedMoreThanOneTime() {
assertk.assert(resolver.evaluate("double main")).isIn("first", "second")
assertThat(resolver.evaluate("double main")).isIn("first", "second")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.gitlab.arturbosch.ksh.defaults

import assertk.assertThat
import assertk.assertions.isEqualTo
import io.gitlab.arturbosch.ksh.Gradle
import io.gitlab.arturbosch.ksh.test.testResolver
Expand All @@ -15,6 +16,6 @@ class FixedResolverBugsTest {
@Test
fun `should skip non flag words after arity is resolved`() {
val target = resolver.evaluate("gradle module testy -wd /bla/bla -g a.b.c")
assertk.assert(target).isEqualTo("")
assertThat(target).isEqualTo("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ class SettingsProvider : ShellSettingsProvider {
}
}
}

0 comments on commit 609f661

Please sign in to comment.