-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tasks for better readability.
Add test coverage (wip).
- Loading branch information
Showing
18 changed files
with
1,333 additions
and
364 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Thu Dec 09 14:59:52 CET 2021 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
74 changes: 0 additions & 74 deletions
74
lib/klutter-tasks/src/main/kotlin/dev/buijs/klutter/tasks/BuildFlutterDebugAppTask.kt
This file was deleted.
Oops, something went wrong.
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
71 changes: 71 additions & 0 deletions
71
lib/klutter-tasks/src/main/kotlin/dev/buijs/klutter/tasks/CliExecutor.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,71 @@ | ||
package dev.buijs.klutter.tasks | ||
|
||
import dev.buijs.klutter.kore.KlutterException | ||
import java.io.File | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* Execute a CLI command. | ||
* | ||
*/ | ||
open class CliExecutor { | ||
|
||
/** | ||
* Execute a CLI command. | ||
*/ | ||
fun execute( | ||
/** | ||
* Folder from where to execute this command. | ||
*/ | ||
runFrom: File, | ||
|
||
/** | ||
* Maximum time in seconds to wait for the command to be executed. | ||
*/ | ||
timeout: Long? = null, | ||
|
||
/** | ||
* The command to be executed. | ||
*/ | ||
command: String, | ||
): String = command.execute( | ||
runFrom = runFrom, | ||
timeout = timeout, | ||
) | ||
|
||
open fun String.execute( | ||
/** | ||
* Folder from where to execute this command. | ||
*/ | ||
runFrom: File, | ||
|
||
/** | ||
* Maximum time in seconds to wait for the command to be executed. | ||
*/ | ||
timeout: Long? = null, | ||
): String { | ||
|
||
val process = ProcessBuilder() | ||
.command(split(" ")) | ||
.directory(runFrom) | ||
.start() | ||
|
||
if(timeout == null) { | ||
process.waitFor() | ||
} else { | ||
process.waitFor(timeout, TimeUnit.SECONDS) | ||
} | ||
|
||
if(process.exitValue() != 0) { | ||
throw KlutterException( | ||
"Failed to execute command: \n${ | ||
process.errorStream.reader().readText() | ||
}" | ||
) | ||
} | ||
|
||
return process.inputStream.readBytes().decodeToString() | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.