Skip to content

Commit 19d83de

Browse files
author
Denis Zhdanov
committed
fail the build if no init scripts are available
1 parent d4416f8 commit 19d83de

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/main/kotlin/tech/harmonysoft/oss/gradle/dist/BuildCustomGradleDistributionTask.kt

+13-3
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,21 @@ abstract class BuildCustomGradleDistributionTask @Inject constructor(
371371
)
372372
.use { zipFileSystem ->
373373
config.initScriptsSourceDir.get().asFile.let { initScriptsSourceDir ->
374+
val includeRootDir = distribution?.let {
375+
File(initScriptsSourceDir, it)
376+
} ?: initScriptsSourceDir
377+
val initScripts = includeRootDir.listFiles()?.filter {
378+
it.name.endsWith(".gradle") || it.name.endsWith(".gradle.kts")
379+
} ?: emptyList()
380+
if (initScripts.isEmpty()) {
381+
throw IllegalStateException(
382+
"can not generate custom distribution ${zip.name} - there must be at least one file to "
383+
+ "include into its init.d, but directory ${initScriptsSourceDir.canonicalPath} is empty"
384+
)
385+
}
374386
addToZip(
375387
zip = zipFileSystem,
376-
includeRootDir = distribution?.let {
377-
File(initScriptsSourceDir, it)
378-
} ?: initScriptsSourceDir,
388+
includeRootDir = includeRootDir,
379389
gradleVersion = gradleVersion,
380390
pathsToExcludeFromContentExpansion = pathsToExcludeFromContentExpansion,
381391
replacements = replacements

src/test/kotlin/tech/harmonysoft/oss/gradle/dist/CustomGradleDistributionPluginTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ class CustomGradleDistributionPluginTest {
446446
private fun prepareGradleDistributionZip(projectRootDir: File) {
447447
val downloadDir = File(projectRootDir, "build/gradle-download")
448448
Files.createDirectories(downloadDir.toPath())
449-
listOf("bin", "all").forEach {
450-
val zip = File(downloadDir, "gradle-${GRADLE_VERSION}-${it}.zip")
449+
for (type in DISTRIBUTION_TYPES) {
450+
val zip = File(downloadDir, "gradle-${GRADLE_VERSION}-${type}.zip")
451451
createGradleDistributionZip(zip)
452452
}
453453
}
@@ -593,8 +593,8 @@ class CustomGradleDistributionPluginTest {
593593
const val GRADLE_VERSION = "8.3"
594594
const val PROJECT_NAME = "my-project"
595595
const val PROJECT_VERSION = "1.0"
596-
const val DEFAULT_DISTRIBUTION_TYPE = "bin"
597596
const val BUILT_DISTS_DIR = "build/gradle-dist"
597+
val DISTRIBUTION_TYPES = setOf("bin", "all")
598598

599599
@field:TempDir(cleanup = CleanupMode.ON_SUCCESS)
600600
lateinit var TESTS_ARTIFACTS_ROOT_DIR: Path

0 commit comments

Comments
 (0)