mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 23:40:37 -05:00
Resolve and apply settings buildscript dependencies
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import dev.minutest.Tests
|
||||
import dev.minutest.experimental.FOCUS
|
||||
import dev.minutest.experimental.minus
|
||||
import dev.minutest.junit.JUnit5Minutests
|
||||
import dev.minutest.rootContext
|
||||
import strikt.api.expectThat
|
||||
import strikt.assertions.contains
|
||||
import strikt.assertions.containsExactly
|
||||
|
||||
class PluginTest : JUnit5Minutests {
|
||||
@Tests
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import dev.minutest.Tests
|
||||
import dev.minutest.junit.JUnit5Minutests
|
||||
import dev.minutest.rootContext
|
||||
import strikt.api.expectThat
|
||||
import strikt.assertions.containsExactly
|
||||
|
||||
class SettingsTest : JUnit5Minutests {
|
||||
@Tests
|
||||
fun tests() = rootContext("settings tests") {
|
||||
withRepository("m2") {
|
||||
withFixture("settings/buildscript") {
|
||||
test("resolves settings plugin in buildscript classpath") {
|
||||
expectThat(build()) {
|
||||
get("settings dependencies") { settingsDependencies }.ids
|
||||
.containsExactly(
|
||||
"org.apache:test:1.0.0@jar",
|
||||
"org.apache:test:1.0.0@pom"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,29 +168,27 @@ fun ContextBuilder<*>.withRepository(
|
||||
fun ContextBuilder<*>.withFixture(
|
||||
name: String,
|
||||
block: TestContextBuilder<*, ProjectFixture>.() -> Unit
|
||||
) {
|
||||
derivedContext<TestFixture>(name) {
|
||||
val url = checkNotNull(Thread.currentThread().contextClassLoader.getResource(name)?.toURI()) {
|
||||
"$name: No test fixture found"
|
||||
}
|
||||
val fixtureRoot = Paths.get(url).toFile().absoluteFile
|
||||
) = derivedContext<TestFixture>(name) {
|
||||
val url = checkNotNull(Thread.currentThread().contextClassLoader.getResource(name)?.toURI()) {
|
||||
"$name: No test fixture found"
|
||||
}
|
||||
val fixtureRoot = Paths.get(url).toFile().absoluteFile
|
||||
|
||||
deriveFixture {
|
||||
TestFixture(name, fixtureRoot)
|
||||
}
|
||||
deriveFixture {
|
||||
TestFixture(name, fixtureRoot)
|
||||
}
|
||||
|
||||
val testRoots = fixtureRoot.listFiles()!!
|
||||
.filter { it.isDirectory }
|
||||
.map { it.absoluteFile }
|
||||
.toList()
|
||||
val testRoots = fixtureRoot.listFiles()!!
|
||||
.filter { it.isDirectory }
|
||||
.map { it.absoluteFile }
|
||||
.toList()
|
||||
|
||||
testRoots.forEach { testRoot ->
|
||||
derivedContext<ProjectFixture>(testRoot.name) {
|
||||
deriveFixture { ProjectFixture(this, testRoot) }
|
||||
before { copy() }
|
||||
after { close() }
|
||||
block()
|
||||
}
|
||||
testRoots.forEach { testRoot ->
|
||||
derivedContext<ProjectFixture>(testRoot.name) {
|
||||
deriveFixture { ProjectFixture(this, testRoot) }
|
||||
before { copy() }
|
||||
after { close() }
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ import org.gradle.util.GradleVersion
|
||||
enum class ConfigurationScope {
|
||||
BUILDSCRIPT,
|
||||
PLUGIN,
|
||||
PROJECT
|
||||
PROJECT,
|
||||
SETTINGS
|
||||
}
|
||||
|
||||
internal class ConfigurationResolverFactory(
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.ProjectDependency
|
||||
import org.gradle.api.internal.GradleInternal
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.tasks.TaskContainer
|
||||
import org.gradle.api.tasks.wrapper.Wrapper
|
||||
@@ -85,6 +86,7 @@ private fun Project.buildModel(
|
||||
modelProperties: ModelProperties,
|
||||
pluginRequests: List<PluginRequest>
|
||||
): DefaultBuild {
|
||||
val settingsDependencies = settingsDependencies()
|
||||
val plugins = buildPlugins(pluginRequests)
|
||||
|
||||
val subprojects = if (modelProperties.subprojects.isEmpty()) {
|
||||
@@ -99,6 +101,7 @@ private fun Project.buildModel(
|
||||
|
||||
return DefaultBuild(
|
||||
gradle = buildGradle(),
|
||||
settingsDependencies = settingsDependencies,
|
||||
pluginDependencies = plugins,
|
||||
rootProject = buildProject(modelProperties.configurations, subprojects, plugins),
|
||||
includedBuilds = includedBuilds()
|
||||
@@ -126,6 +129,31 @@ private fun Project.buildGradle(): DefaultGradle =
|
||||
)
|
||||
}
|
||||
|
||||
private fun Project.settingsDependencies(): List<DefaultArtifact> {
|
||||
val buildscript = (gradle as GradleInternal).settings.buildscript
|
||||
|
||||
val resolverFactory = ConfigurationResolverFactory(this, ConfigurationScope.SETTINGS, buildscript.repositories)
|
||||
val resolver = resolverFactory.create(buildscript.dependencies)
|
||||
|
||||
logger.lifecycle(" Settings script")
|
||||
|
||||
val dependencies = buildscript.configurations
|
||||
.flatMap(resolver::resolve)
|
||||
.distinct()
|
||||
.sorted()
|
||||
|
||||
if (resolver.unresolved.isNotEmpty()) {
|
||||
logger.warn(buildString {
|
||||
append(" Failed to resolve settings script dependencies:\n")
|
||||
for (id in resolver.unresolved) {
|
||||
append(" - $id\n")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return dependencies
|
||||
}
|
||||
|
||||
private fun Project.buildPlugins(pluginRequests: List<PluginRequest>): List<DefaultArtifact> {
|
||||
return objects.newInstance<PluginResolver>(this).resolve(pluginRequests).distinct().sorted()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user