/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/*
* IrisApi source resolution, applied by the root settings file:
*
* apply from: new File(settingsDir, 'gradle/irisapi-resolution.settings.gradle')
*
* IrisApi is a separate project with no published artifact, so Iris always compiles against a sibling
* checkout as a composite build. Core declares `com.volmit:iris-api` (what modules see) and
* `com.volmit:iris-host` (what loads and runs them); this substitutes them with the checkout's `api`
* and `host` projects.
*
* Behaviour:
* -PlocalIrisApiDirectory= explicit IrisApi checkout (relative paths resolve against the
* including build's settings directory).
* IRISAPI_DIR= same, via environment.
* otherwise walk up from settingsDir looking for an `api` directory
* that contains a settings script.
*
* When nothing is found the build fails here, naming where it looked, rather than later with an
* unresolvable dependency.
*
* The three modded adapter builds apply it too: core's dependencies on IrisApi must resolve in them, and the adapters
* read IrisApi types (ResourceId, BlockTurn).
*/
import java.io.File
boolean irisHasIrisApiSettings(File directory) {
if (directory == null) {
return false
}
new File(directory, 'settings.gradle.kts').exists() || new File(directory, 'settings.gradle').exists()
}
File irisResolveLocalIrisApiDirectory() {
String configuredPath = providers.gradleProperty('localIrisApiDirectory')
.orElse(providers.environmentVariable('IRISAPI_DIR'))
.orNull
if (configuredPath != null && !configuredPath.isBlank()) {
File configuredDirectory = new File(configuredPath)
if (!configuredDirectory.isAbsolute()) {
configuredDirectory = new File(settingsDir, configuredPath)
}
if (irisHasIrisApiSettings(configuredDirectory)) {
return configuredDirectory
}
throw new GradleException("IrisApi checkout ${configuredDirectory} has no settings script")
}
File currentDirectory = settingsDir
while (currentDirectory != null) {
File candidate = new File(currentDirectory, 'api')
if (irisHasIrisApiSettings(candidate)) {
return candidate
}
currentDirectory = currentDirectory.parentFile
}
throw new GradleException("No IrisApi checkout found in ${settingsDir} or its parent directories; "
+ "expected an `api` folder with a settings script, or pass -PlocalIrisApiDirectory= or IRISAPI_DIR")
}
includeBuild(irisResolveLocalIrisApiDirectory()) {
dependencySubstitution {
substitute(module('com.volmit:iris-api')).using(project(':api'))
substitute(module('com.volmit:iris-host')).using(project(':host'))
}
}