Skip to content

Commit

Permalink
fail the build if no init scripts are available
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Zhdanov committed Apr 22, 2024
1 parent d4416f8 commit 19d83de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,21 @@ abstract class BuildCustomGradleDistributionTask @Inject constructor(
)
.use { zipFileSystem ->
config.initScriptsSourceDir.get().asFile.let { initScriptsSourceDir ->
val includeRootDir = distribution?.let {
File(initScriptsSourceDir, it)
} ?: initScriptsSourceDir
val initScripts = includeRootDir.listFiles()?.filter {
it.name.endsWith(".gradle") || it.name.endsWith(".gradle.kts")
} ?: emptyList()
if (initScripts.isEmpty()) {
throw IllegalStateException(
"can not generate custom distribution ${zip.name} - there must be at least one file to "
+ "include into its init.d, but directory ${initScriptsSourceDir.canonicalPath} is empty"
)
}
addToZip(
zip = zipFileSystem,
includeRootDir = distribution?.let {
File(initScriptsSourceDir, it)
} ?: initScriptsSourceDir,
includeRootDir = includeRootDir,
gradleVersion = gradleVersion,
pathsToExcludeFromContentExpansion = pathsToExcludeFromContentExpansion,
replacements = replacements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ class CustomGradleDistributionPluginTest {
private fun prepareGradleDistributionZip(projectRootDir: File) {
val downloadDir = File(projectRootDir, "build/gradle-download")
Files.createDirectories(downloadDir.toPath())
listOf("bin", "all").forEach {
val zip = File(downloadDir, "gradle-${GRADLE_VERSION}-${it}.zip")
for (type in DISTRIBUTION_TYPES) {
val zip = File(downloadDir, "gradle-${GRADLE_VERSION}-${type}.zip")
createGradleDistributionZip(zip)
}
}
Expand Down Expand Up @@ -593,8 +593,8 @@ class CustomGradleDistributionPluginTest {
const val GRADLE_VERSION = "8.3"
const val PROJECT_NAME = "my-project"
const val PROJECT_VERSION = "1.0"
const val DEFAULT_DISTRIBUTION_TYPE = "bin"
const val BUILT_DISTS_DIR = "build/gradle-dist"
val DISTRIBUTION_TYPES = setOf("bin", "all")

@field:TempDir(cleanup = CleanupMode.ON_SUCCESS)
lateinit var TESTS_ARTIFACTS_ROOT_DIR: Path
Expand Down

0 comments on commit 19d83de

Please sign in to comment.