mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 23:40:37 -05:00
Fix dependency resolution for plugins in buildSrc
This commit is contained in:
@@ -24,7 +24,6 @@ fun ProjectConnection.getBuildModel(config: Config, path: String): DefaultBuild
|
||||
if (config.gradleArgs != null) addArguments(config.gradleArgs)
|
||||
if (path.isNotEmpty()) addArguments("--project-dir=$path")
|
||||
if (!config.quiet) {
|
||||
setColorOutput(true)
|
||||
setStandardOutput(System.err)
|
||||
setStandardError(System.err)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.github.ajalt.clikt.parameters.options.default
|
||||
import com.github.ajalt.clikt.parameters.options.flag
|
||||
import com.github.ajalt.clikt.parameters.options.multiple
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.options.split
|
||||
import com.github.ajalt.clikt.parameters.options.validate
|
||||
import com.github.ajalt.clikt.parameters.types.file
|
||||
import com.squareup.moshi.Moshi
|
||||
@@ -55,7 +54,7 @@ class Main : CliktCommand(
|
||||
private val includes: List<File> by option("--include", "-i",
|
||||
metavar = "DIR",
|
||||
help = "Add an additional project to include")
|
||||
.file(exists = true, fileOkay = false, folderOkay = true, readable = true)
|
||||
.file(mustExist = true, canBeFile = false, canBeDir = true, mustBeReadable = true)
|
||||
.multiple()
|
||||
.validate { files ->
|
||||
val failures = files.filterNot { it.isProjectRoot() }
|
||||
@@ -79,12 +78,12 @@ class Main : CliktCommand(
|
||||
}
|
||||
}
|
||||
|
||||
private val outDir: File? by option("--out-dir", "-o",
|
||||
val outDir: File? by option("--out-dir", "-o",
|
||||
metavar = "DIR",
|
||||
help = "Path to write generated files (default: PROJECT-DIR)")
|
||||
.file(fileOkay = false, folderOkay = true)
|
||||
.file(canBeFile = false, canBeDir = true)
|
||||
|
||||
private val envFile: String by option("--env", "-e",
|
||||
val envFile: String by option("--env", "-e",
|
||||
metavar = "FILENAME",
|
||||
help = "Prefix for environment files (.json and .nix)")
|
||||
.default("gradle-env")
|
||||
@@ -105,8 +104,11 @@ class Main : CliktCommand(
|
||||
}
|
||||
}
|
||||
|
||||
// Visible for testing
|
||||
lateinit var config: Config
|
||||
|
||||
override fun run() {
|
||||
val config = Config(
|
||||
config = Config(
|
||||
gradleVersion,
|
||||
gradleArgs,
|
||||
configurations,
|
||||
|
||||
19
app/src/test/kotlin/org/nixos/gradle2nix/BuildSrcTest.kt
Normal file
19
app/src/test/kotlin/org/nixos/gradle2nix/BuildSrcTest.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import strikt.api.expectThat
|
||||
import strikt.assertions.containsKey
|
||||
|
||||
object BuildSrcTest : Spek({
|
||||
fixture("buildsrc/plugin-in-buildsrc/kotlin")
|
||||
val fixture: Fixture by memoized()
|
||||
|
||||
describe("project with plugin in buildSrc") {
|
||||
fixture.run()
|
||||
|
||||
it("should include buildSrc in gradle env", timeout = 0) {
|
||||
expectThat(fixture.env()).containsKey("buildSrc")
|
||||
}
|
||||
}
|
||||
})
|
||||
57
app/src/test/kotlin/org/nixos/gradle2nix/TestUtil.kt
Normal file
57
app/src/test/kotlin/org/nixos/gradle2nix/TestUtil.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import okio.buffer
|
||||
import okio.source
|
||||
import org.spekframework.spek2.dsl.Root
|
||||
import strikt.api.expectThat
|
||||
import strikt.assertions.exists
|
||||
import strikt.assertions.isNotNull
|
||||
import strikt.assertions.toPath
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
private val moshi = Moshi.Builder().build()
|
||||
|
||||
class Fixture(val project: Path) {
|
||||
private val app = Main()
|
||||
|
||||
fun run(vararg args: String) {
|
||||
app.main(args.toList() + project.toString())
|
||||
}
|
||||
|
||||
fun env(): Map<String, NixGradleEnv> {
|
||||
val file = (app.outDir ?: project.toFile()).resolve("${app.envFile}.json")
|
||||
expectThat(file).toPath().exists()
|
||||
val env = file.source().buffer().use { source ->
|
||||
moshi
|
||||
.adapter<Map<String, NixGradleEnv>>(
|
||||
Types.newParameterizedType(Map::class.java, String::class.java, NixGradleEnv::class.java)
|
||||
).fromJson(source)
|
||||
}
|
||||
expectThat(env).isNotNull()
|
||||
return env!!
|
||||
}
|
||||
}
|
||||
|
||||
fun Root.fixture(name: String) {
|
||||
val fixture by memoized(
|
||||
factory = {
|
||||
val url = checkNotNull(Thread.currentThread().contextClassLoader.getResource(name)?.toURI()) {
|
||||
"$name: No test fixture found"
|
||||
}
|
||||
val fixtureRoot = Paths.get(url)
|
||||
val dest = createTempDir("gradle2nix").toPath()
|
||||
val src = checkNotNull(fixtureRoot.takeIf { Files.exists(it) }) {
|
||||
"$name: Test fixture not found: $fixtureRoot"
|
||||
}
|
||||
src.toFile().copyRecursively(dest.toFile())
|
||||
Fixture(dest)
|
||||
},
|
||||
destructor = {
|
||||
it.project.toFile().deleteRecursively()
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user