From 4d116556481af3b52baf434e4f8d5b45854a0cff Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 16:05:15 -0700 Subject: [PATCH 1/8] - Extracted out custom shell script task. --- app/build.gradle.kts | 20 +--------------- buildSrc/build.gradle.kts | 7 ++++++ .../src/main/kotlin/CreateShellScriptTask.kt | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/CreateShellScriptTask.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 166b1d2..6f9b7e6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -70,26 +70,8 @@ tasks.jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } -// Custom task to create a shell script wrapper compatible with bash and zsh -abstract class CreateShellScriptTask : DefaultTask() { - @get:OutputFile - abstract val outputFile: Property - - @TaskAction - fun createScript() { - outputFile.get().writeText( - """ - |#!/bin/sh - |DIR="$(cd "$(dirname "$0")" && pwd)" - |exec java -jar "${'$'}DIR/bounding-box.jar" "${'$'}@" - """.trimMargin() - ) - outputFile.get().setExecutable(true) - } -} - tasks.register("createShellScript") { - outputFile.set(layout.buildDirectory.file("libs/bounding-box").map { it.asFile }) + outputFile.set(layout.buildDirectory.file("libs/bounding-box")) } // Ensure the shell script is created after the JAR diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..b22ed73 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/CreateShellScriptTask.kt b/buildSrc/src/main/kotlin/CreateShellScriptTask.kt new file mode 100644 index 0000000..27d9480 --- /dev/null +++ b/buildSrc/src/main/kotlin/CreateShellScriptTask.kt @@ -0,0 +1,24 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import java.io.File + +abstract class CreateShellScriptTask : DefaultTask() { + @get:OutputFile + abstract val outputFile: RegularFileProperty + + @TaskAction + fun createScript() { + val file = outputFile.get().asFile + file.writeText( + """ + |#!/bin/sh + |DIR="$(cd "$(dirname "$0")" && pwd)" + |exec java -jar "${'$'}DIR/bounding-box.jar" "${'$'}@" + """.trimMargin() + ) + file.setExecutable(true) + println("Shell script created at: ${file.absolutePath}") + } +} \ No newline at end of file From 1a5421c9140bce5a2f8defb056f5056f15bf7273 Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 16:08:05 -0700 Subject: [PATCH 2/8] - workflow_dispatch --- .github/workflows/gradle.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c979517..28a89d2 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -7,6 +7,9 @@ on: pull_request: branches: [main] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + jobs: build: runs-on: ubuntu-latest From 377342a25e41ee3fef9a4c720de5a05bae6f6f7a Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 16:10:27 -0700 Subject: [PATCH 3/8] - on section --- .github/workflows/gradle.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 28a89d2..c4e741b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -3,9 +3,13 @@ name: BoundingBox CI on: push: - branches: [main] + branches: + - main + - extract_out_shellscript_task pull_request: - branches: [main] + branches: + - main + - extract_out_shellscript_task # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From 6b9152ee5c36ca0eff65b906607daa5342045aca Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 16:15:37 -0700 Subject: [PATCH 4/8] - Removed edits on section & worflow dispatch --- .github/workflows/gradle.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c4e741b..c979517 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -3,16 +3,9 @@ name: BoundingBox CI on: push: - branches: - - main - - extract_out_shellscript_task + branches: [main] pull_request: - branches: - - main - - extract_out_shellscript_task - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: + branches: [main] jobs: build: From 265360c2b5e210fe6bae6dc45b1ef6b0261a73e2 Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 16:21:25 -0700 Subject: [PATCH 5/8] - logger.lifecycle() --- .github/workflows/gradle.yml | 4 +++- buildSrc/src/main/kotlin/CreateShellScriptTask.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c979517..3f98826 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -3,7 +3,9 @@ name: BoundingBox CI on: push: - branches: [main] + branches: + - main + - extract_out_shellscript_task pull_request: branches: [main] diff --git a/buildSrc/src/main/kotlin/CreateShellScriptTask.kt b/buildSrc/src/main/kotlin/CreateShellScriptTask.kt index 27d9480..c9b8700 100644 --- a/buildSrc/src/main/kotlin/CreateShellScriptTask.kt +++ b/buildSrc/src/main/kotlin/CreateShellScriptTask.kt @@ -19,6 +19,6 @@ abstract class CreateShellScriptTask : DefaultTask() { """.trimMargin() ) file.setExecutable(true) - println("Shell script created at: ${file.absolutePath}") + logger.lifecycle("Shell script created at: ${file.absolutePath}") } } \ No newline at end of file From 4498aead1329acf8818defde5a74f34045e2138f Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 16:30:43 -0700 Subject: [PATCH 6/8] - Set to always run task by being never up to date --- app/build.gradle.kts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6f9b7e6..3f29e58 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,14 +1,3 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details on building Java & JVM projects, please refer - * to https://docs.gradle.org/8.14/userguide/building_java_projects.html in the Gradle documentation. - */ - -import org.gradle.api.tasks.TaskAction -import org.gradle.api.DefaultTask - plugins { // Apply the application plugin to add support for building a CLI application in Java. application @@ -72,6 +61,7 @@ tasks.jar { tasks.register("createShellScript") { outputFile.set(layout.buildDirectory.file("libs/bounding-box")) + outputs.upToDateWhen { false } } // Ensure the shell script is created after the JAR From 756b10332dfce04ed6a71a35647a991453aa6cce Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 17:00:09 -0700 Subject: [PATCH 7/8] - mustRunAfterTest() --- app/build.gradle.kts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3f29e58..599c0a7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -64,7 +64,10 @@ tasks.register("createShellScript") { outputs.upToDateWhen { false } } -// Ensure the shell script is created after the JAR +tasks.named("createShellScript") { + mustRunAfter("test") +} + tasks.build { dependsOn("createShellScript") } \ No newline at end of file From 5103e4270c3036bc12abae6328c555d54b33b371 Mon Sep 17 00:00:00 2001 From: unnsse Date: Wed, 7 May 2025 17:03:07 -0700 Subject: [PATCH 8/8] - Removed branch --- .github/workflows/gradle.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 3f98826..c979517 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -3,9 +3,7 @@ name: BoundingBox CI on: push: - branches: - - main - - extract_out_shellscript_task + branches: [main] pull_request: branches: [main]