diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt index 814320b..26db8ad 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt @@ -35,12 +35,17 @@ import io.papermc.paperweight.util.constants.* import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.logging.Logging import org.gradle.api.tasks.Delete import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.bundling.Zip import org.gradle.kotlin.dsl.* class PaperweightCore : Plugin { + companion object { + private val logger = Logging.getLogger(PaperweightCore::class.java) + } + override fun apply(target: Project) { checkJavaVersion() Git.checkForGit() @@ -58,7 +63,7 @@ class PaperweightCore : Plugin { // Make sure the submodules are initialized, since there are files there // which are required for configuration - target.layout.initSubmodules() + target.layout.maybeInitSubmodules(target.offlineMode(), logger) target.configurations.create(PARAM_MAPPINGS_CONFIG) target.configurations.create(REMAPPER_CONFIG) diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/GeneralTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/GeneralTasks.kt index 08a0189..2177141 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/GeneralTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/GeneralTasks.kt @@ -40,7 +40,9 @@ open class GeneralTasks( ) : InitialTasks(project) { // Configuration won't necessarily always run, so do it as the first task when it's needed as well - val initSubmodules by tasks.registering() + val initSubmodules by tasks.registering { + offlineMode.set(project.offlineMode()) + } val buildDataInfo: Provider = project.contents(extension.craftBukkit.buildDataInfo) { gson.fromJson(it) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/InitSubmodules.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/InitSubmodules.kt index e0f7918..c43bf8e 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/InitSubmodules.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/InitSubmodules.kt @@ -26,17 +26,27 @@ import io.papermc.paperweight.util.* import javax.inject.Inject import org.gradle.api.DefaultTask import org.gradle.api.file.ProjectLayout +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.UntrackedTask +@Suppress("LeakingThis") @UntrackedTask(because = "Git tracks the state") abstract class InitSubmodules : DefaultTask() { @get:Inject abstract val layout: ProjectLayout + @get:Input + abstract val offlineMode: Property + + init { + offlineMode.convention(false) + } + @TaskAction fun run() { - layout.initSubmodules() + layout.maybeInitSubmodules(offlineMode.get(), logger) } } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt index 77a1c6a..1ca2034 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt @@ -60,6 +60,7 @@ import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty import org.gradle.api.invocation.Gradle import org.gradle.api.logging.LogLevel +import org.gradle.api.logging.Logger import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.provider.Property import org.gradle.api.provider.Provider @@ -94,11 +95,23 @@ val ProjectLayout.cache: Path get() = projectDirectory.dir(".gradle/$CACHE_PATH").path fun ProjectLayout.cacheDir(path: String) = projectDirectory.dir(".gradle/$CACHE_PATH").dir(path) + +fun ProjectLayout.maybeInitSubmodules(offline: Boolean, logger: Logger) { + if (offline) { + Git.checkForGit() + logger.lifecycle("Offline mode enabled, not initializing submodules. This may cause problems if submodules are not already initialized.") + } else { + initSubmodules() + } +} + fun ProjectLayout.initSubmodules() { Git.checkForGit() Git(projectDirectory.path)("submodule", "update", "--init").executeOut() } +fun Project.offlineMode(): Boolean = gradle.startParameter.isOffline + fun Provider.fileExists(project: Project): Provider { return flatMap { project.provider { it.takeIf { f -> f.path.exists() } } } }