diff --git a/.github/workflows/deploy_maven_central.yml b/.github/workflows/deploy_maven_central.yml
index 5d780c4..dbd1030 100644
--- a/.github/workflows/deploy_maven_central.yml
+++ b/.github/workflows/deploy_maven_central.yml
@@ -16,17 +16,26 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
- java-version: '11'
+ java-version: '17'
distribution: 'temurin'
+ - name: Make gradlew executable
+ run: chmod +x ./gradlew
- name: Validate Gradle wrapper
- uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
+ uses: gradle/wrapper-validation-action@v1
+ - name: Restore gradle.properties
+ env:
+ GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
+ GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
+ run: |
+ echo "$GPG_PRIVATE_KEY" | base64 -d > kutil/sec.pem
+ echo "signing.keyId=ED76201E" >> ./gradle.properties
+ echo "signing.password=${GPG_PASSPHRASE}" >> ./gradle.properties
+ echo "signing.secretKeyRingFile=sec.pem" >> ./gradle.properties
- name: Publish package
- uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
+ uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
-# gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
-# MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
####
diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml
new file mode 100644
index 0000000..bdeea3a
--- /dev/null
+++ b/.github/workflows/test_on_push.yml
@@ -0,0 +1,29 @@
+name: run test
+
+on:
+ push:
+ workflow_dispatch:
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+ - name: Set up Java
+ uses: actions/setup-java@v3
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ - name: Make gradlew executable
+ run: chmod +x ./gradlew
+ - name: Validate Gradle wrapper
+ uses: gradle/wrapper-validation-action@v1
+ - name: run test
+ uses: gradle/gradle-build-action@v2
+ with:
+ arguments: allTests
+ env:
+ MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
+ MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
+####
diff --git a/.gitignore b/.gitignore
index d5121c1..d2296a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,7 +18,6 @@ out/
*.ctxt
# Package Files #
-*.jar
*.war
*.nar
*.ear
@@ -127,4 +126,4 @@ run/
/.idea/
/log1/
/log/
-/api/build/
+/*/build/
diff --git a/README.md b/README.md
index ade46bd..2ad836f 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
## About
-* javaのutility
+* kotlinのutility
## Use
@@ -11,7 +11,7 @@
net.kigawa.kutil
kutil
- 2.2.1
+ 3.0.0
......
@@ -19,12 +19,12 @@
## Requirement
-* java
+* kotlin
## Author
* kigawa
- * kigawa.8390@gmail.com
+ * contact@kigawa.net
# Making
diff --git a/api/build.gradle.kts b/api/build.gradle.kts
index f27b0ef..c4d5f94 100644
--- a/api/build.gradle.kts
+++ b/api/build.gradle.kts
@@ -3,4 +3,5 @@ plugins {
}
dependencies {
-}
+ commonMainImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
+}
\ No newline at end of file
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Func.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Func.kt
new file mode 100644
index 0000000..1602f37
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Func.kt
@@ -0,0 +1,10 @@
+package net.kigawa.kutil.kutil.api
+
+import kotlinx.coroutines.channels.Channel
+
+
+suspend inline fun Channel.forEach(func: (T) -> Unit) {
+ for (item in this) {
+ func(item)
+ }
+}
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Kutil.java b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Kutil.java
deleted file mode 100644
index c14441b..0000000
--- a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Kutil.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package net.kigawa.kutil.kutil.api;
-
-/**
- * utilities for java
- */
-@SuppressWarnings("unused")
-public class Kutil {
-
-}
\ No newline at end of file
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Kutil.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Kutil.kt
new file mode 100644
index 0000000..898ea92
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Kutil.kt
@@ -0,0 +1,56 @@
+@file:Suppress("unused")
+
+package net.kigawa.kutil.kutil.api
+
+import net.kigawa.kutil.kutil.api.io.KuCloseable
+import net.kigawa.kutil.kutil.api.io.SuspendCloseable
+import kotlin.contracts.ExperimentalContracts
+import kotlin.contracts.InvocationKind
+import kotlin.contracts.contract
+
+@Suppress("unused")
+object Kutil {
+ fun fillStr(src: String, size: Int, fillChar: Char = ' '): String {
+ val sb = StringBuilder(size)
+ for (i in 0 until size) {
+ sb.append(src.getOrNull(i) ?: fillChar)
+ }
+ return sb.toString()
+ }
+
+}
+
+@OptIn(ExperimentalContracts::class)
+inline fun T.tryCatch(
+ block: (self: T) -> R,
+): R {
+ contract {
+ callsInPlace(block, InvocationKind.EXACTLY_ONCE)
+ }
+ try {
+ return block(this)
+ } catch (e: Throwable) {
+ throw e
+ } finally {
+ close()
+ }
+}
+
+@OptIn(ExperimentalContracts::class)
+suspend inline fun T.tryCatchSuspend(
+ block: (self: T) -> R,
+): R {
+ contract {
+ callsInPlace(block, InvocationKind.EXACTLY_ONCE)
+ }
+ try {
+ return block(this)
+ } catch (e: Throwable) {
+ throw e
+ } finally {
+ when (this) {
+ is SuspendCloseable -> suspendClose()
+ else -> close()
+ }
+ }
+}
\ No newline at end of file
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilArray.java b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilArray.java
deleted file mode 100644
index 812dc88..0000000
--- a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilArray.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package net.kigawa.kutil.kutil.api;
-
-import java.util.*;
-import java.util.stream.*;
-
-/**
- * utilities about array
- */
-@SuppressWarnings("unused")
-public class KutilArray
-{
-
- /**
- * test obj contain in array
- *
- * @param array array to test
- * @param obj obj to test
- * @param source class type
- * @param test class type
- * @return return true when contain
- */
- public static boolean contain(S[] array, T obj)
- {
- return Arrays.asList(array).contains(obj);
- }
-
- /**
- * creat set from array
- *
- * @param ts base array
- * @param class type
- * @return created set
- */
- public static Set toSet(T[] ts)
- {
- return Arrays.stream(ts).collect(Collectors.toSet());
- }
-
-}
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilArray.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilArray.kt
new file mode 100644
index 0000000..2dad4e0
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilArray.kt
@@ -0,0 +1,7 @@
+package net.kigawa.kutil.kutil.api
+
+/**
+ * utilities about array
+ */
+@Suppress("unused", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
+expect object KutilArray
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilFile.java b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilFile.java
deleted file mode 100644
index c540950..0000000
--- a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilFile.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package net.kigawa.kutil.kutil.api;
-
-import java.io.File;
-import java.nio.file.Paths;
-
-/**
- * utilities about file
- */
-@SuppressWarnings("unused")
-public class KutilFile {
-
- /**
- * get child file from current
- *
- * @param path child file names
- * @return child file
- */
- public static File getRelativeFile(String... path) {
- return getFile(Paths.get("").toAbsolutePath().toFile(), path);
- }
-
- /**
- * get child file
- *
- * @param parent parent file
- * @param path child file names
- * @return child file
- */
- public static File getFile(File parent, String... path) {
- File file = parent;
- for (String name : path) {
- file = new File(file, name);
- }
- return file;
- }
-
- /**
- * get current file as absolute
- *
- * @return current dir
- */
- public static File getAbsolutFile() {
- return Paths.get("").toAbsolutePath().toFile();
- }
-}
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilFile.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilFile.kt
new file mode 100644
index 0000000..620700e
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilFile.kt
@@ -0,0 +1,9 @@
+package net.kigawa.kutil.kutil.api
+
+/**
+ * utilities about file
+ */
+@Suppress("unused", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
+expect object KutilFile {
+
+}
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilPlatform.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilPlatform.kt
new file mode 100644
index 0000000..424190c
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/KutilPlatform.kt
@@ -0,0 +1,7 @@
+package net.kigawa.kutil.kutil.api
+
+@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
+expect object KutilPlatform {
+ fun getSystemProperty(name: String): String
+ fun getEnv(name: String): String?
+}
\ No newline at end of file
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Option.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Option.kt
new file mode 100644
index 0000000..1820708
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/Option.kt
@@ -0,0 +1,10 @@
+package net.kigawa.kutil.kutil.api
+
+ @Suppress("unused")
+interface Option {
+ val name: String
+ val optName: String
+ val shortName: String?
+ val description: String
+ val defaultValue: String
+}
\ No newline at end of file
diff --git a/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/OptionStore.kt b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/OptionStore.kt
new file mode 100644
index 0000000..5fee200
--- /dev/null
+++ b/api/src/commonMain/kotlin/net/kigawa/kutil/kutil/api/OptionStore.kt
@@ -0,0 +1,16 @@
+package net.kigawa.kutil.kutil.api
+
+@Suppress("unused")
+class OptionStore {
+ private val options = mutableMapOf