diff --git a/build.gradle b/build.gradle index aaf7902..85b502b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,23 +6,18 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" } } -apply plugin: 'idea' apply plugin: 'org.jetbrains.kotlin.jvm' -apply plugin: 'org.jetbrains.kotlin.plugin.serialization' -apply plugin: 'maven-publish' apply plugin: 'java-test-fixtures' - +apply plugin: 'maven-publish' group = 'io.provs' -version = '0.8.8-SNAPSHOT' +version = '0.8.8' repositories { mavenCentral() - jcenter() } test { @@ -53,10 +48,9 @@ java { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0" // JVM dependency implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - implementation group: 'com.hierynomus', name: 'sshj', version: '0.30.0' + implementation group: 'com.hierynomus', name: 'sshj', version: '0.31.0' api "org.slf4j:slf4j-api:1.7.30" api "ch.qos.logback:logback-classic:1.2.3" @@ -79,6 +73,7 @@ task fatJar(type: Jar) { with jar } +//create a single Jar with all dependencies excl. Kotlin libs without version-number but with suffix "latest" task fatJarLatest(type: Jar) { doFirst { from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } @@ -114,7 +109,6 @@ task uberJar(type: Jar) { archiveClassifier = 'uber' } - //create a single Jar with all dependencies incl. Kotlin libs - as ...-latest task uberJarLatest(type: Jar) { @@ -162,6 +156,8 @@ publishing { header(HttpHeaderAuthentication) } } + } else { + mavenLocal() } } } \ No newline at end of file diff --git a/src/main/kotlin/io/provs/Prov.kt b/src/main/kotlin/io/provs/Prov.kt index 63eb8f1..1cf7fe5 100644 --- a/src/main/kotlin/io/provs/Prov.kt +++ b/src/main/kotlin/io/provs/Prov.kt @@ -148,9 +148,9 @@ open class Prov protected constructor(private val processor: Processor, val name /** * Executes command cmd and returns true in case of success else false. - * The success resp. failure does not count into the overall success. + * The success resp. failure is not evaluated, i.e. it is not taken into account for the overall success. */ - fun check(cmd: String, dir: String? = null): Boolean { + fun chk(cmd: String, dir: String? = null): Boolean { return cmdNoEval(cmd, dir).success } diff --git a/src/main/kotlin/io/provs/Utils.kt b/src/main/kotlin/io/provs/Utils.kt index cc2e6ef..e5b475e 100644 --- a/src/main/kotlin/io/provs/Utils.kt +++ b/src/main/kotlin/io/provs/Utils.kt @@ -5,6 +5,7 @@ import io.provs.processors.ContainerStartMode import io.provs.processors.ContainerUbuntuHostProcessor import io.provs.processors.RemoteProcessor import java.io.File +import java.net.InetAddress /** * Returns the name of the calling function but excluding some functions of the prov framework @@ -71,7 +72,10 @@ fun local(): Prov { */ @Suppress("unused") // used by other libraries resp. KotlinScript fun remote(host: String, remoteUser: String, password: Secret? = null, platform: String? = null): Prov { - return Prov.newInstance(RemoteProcessor(host, remoteUser, password), platform) + require(host.isNotEmpty(), { "Host must not be empty." }) + require(remoteUser.isNotEmpty(), { "Remote user must not be empty." }) + + return Prov.newInstance(RemoteProcessor(InetAddress.getByName(host), remoteUser, password), platform) } diff --git a/src/main/kotlin/io/provs/processors/RemoteUbuntuProcessor.kt b/src/main/kotlin/io/provs/processors/RemoteUbuntuProcessor.kt index 0e93cfe..72bc930 100644 --- a/src/main/kotlin/io/provs/processors/RemoteUbuntuProcessor.kt +++ b/src/main/kotlin/io/provs/processors/RemoteUbuntuProcessor.kt @@ -13,10 +13,11 @@ import java.io.BufferedReader import java.io.File import java.io.IOException import java.io.InputStreamReader +import java.net.InetAddress import java.util.concurrent.TimeUnit -class RemoteProcessor(ip: String, user: String, password: Secret? = null) : Processor { +class RemoteProcessor(ip: InetAddress, user: String, password: Secret? = null) : Processor { companion object { @Suppress("JAVA_CLASS_ON_COMPANION") diff --git a/src/test/kotlin/io/provs/ProvTest.kt b/src/test/kotlin/io/provs/ProvTest.kt index 4a092ae..e44ac62 100644 --- a/src/test/kotlin/io/provs/ProvTest.kt +++ b/src/test/kotlin/io/provs/ProvTest.kt @@ -344,7 +344,7 @@ internal class ProvTest { @Test fun check_returnsTrue() { // when - val res = local().check("echo 123") + val res = local().chk("echo 123") // then assertTrue(res) @@ -353,7 +353,7 @@ internal class ProvTest { @Test fun check_returnsFalse() { // when - val res = local().check("cmddoesnotexist") + val res = local().chk("cmddoesnotexist") // then assertFalse(res) diff --git a/src/test/kotlin/io/provs/UtilsKtTest.kt b/src/test/kotlin/io/provs/UtilsKtTest.kt new file mode 100644 index 0000000..005a968 --- /dev/null +++ b/src/test/kotlin/io/provs/UtilsKtTest.kt @@ -0,0 +1,49 @@ +package io.provs + +import io.provs.test.defaultTestContainer +import io.provs.test.tags.ContainerTest +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import java.net.UnknownHostException + +internal class UtilsKtTest { + + @Test + fun test_getCallingMethodName() { + // when + val s = getCallingMethodName() + + // then + assertEquals("test_getCallingMethodName", s) + } + + @Test + @ContainerTest + fun runCmdInContainer() { + // when + val res = defaultTestContainer().cmd("echo something") + + // then + assertTrue(res.success) + } + + @Test + fun remote_emptyHost() { + assertThrows(IllegalArgumentException::class.java, + { remote("", "user") }) + } + + @Test + fun remote_invalidHost() { + assertThrows( + UnknownHostException::class.java, + { remote("invalid_host", "user") }) + } + + @Test + @Disabled // run manually after having updated user + fun test_remote() { + assertTrue(remote("127.0.0.1", "user").cmd("echo sth").success) + } +} \ No newline at end of file diff --git a/src/test/kotlin/io/provs/UtilsTest.kt b/src/test/kotlin/io/provs/UtilsTest.kt deleted file mode 100644 index c0aa9b1..0000000 --- a/src/test/kotlin/io/provs/UtilsTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.provs - -import io.provs.test.defaultTestContainer -import io.provs.test.tags.ContainerTest -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test - -internal class UtilsTest { - - @Test - fun test_getCallingMethodName() { - // when - val s = getCallingMethodName() - - // then - Assertions.assertEquals("test_getCallingMethodName", s) - } - - @Test - @ContainerTest - fun test_docker() { - // when - val res = defaultTestContainer().cmd("echo something") - - // then - Assertions.assertEquals(true, res.success) - } -} \ No newline at end of file