⁠
joseph burton: Minecraft new project wizard (#1933 )
* Forge creator almost working
* Store authors and website for next time the user uses the creator
* Don't allow for dialog submission before a latent step is finished
* Fabric mod creator
* Add modid.mixins.json to Forge project creator
* Start with Architectury creator
* Fix long-running tasks that need to run after one another
* Apply website in Forge creator
* Set the correct gradle version in the Forge project creator
* Architectury should be finished but it's not working, not sure why
* Add support for custom build systems via extension points
* Sponge project creator, first maven implementation
* Remove unsupported platforms from the readme
* Add missing platforms to readme
* Replace some silly code with less silly code
* Add Spigot and Paper creators
* Add Velocity creator
* Add BungeeCord and Waterfall creator
* Delete unused code
* ktlint format
* Apply the correct JDK version depending on the platform and version
* Fix license years after merge
* Improvements and fixes to JDK selector UI
* Fix architectury template
* Fix issues with Sponge creator
* Fix IncorrectOperationException in AbstractLatentStep
* Add option to create a git repo (which also creates a gitignore)
* UI improvements
* Add a message encouraging users to report outdated templates
* Add note to project wizard outdated form warning not to request new platforms
* Paper before Spigot
* Remove dependency on TemplateMakerFabric
* Reorganize creators into multiple files and repackage some things
* Improve documentation
* Improve ergonomics for build system properties, main class name, repository, issue tracker
* Limit Sponge API version to 8 and above in dropdown box
* Prevent class name from messing up when the project name contains dots
* Forge creator almost working
* Store authors and website for next time the user uses the creator
* Don't allow for dialog submission before a latent step is finished
* Fabric mod creator
* Add modid.mixins.json to Forge project creator
* Start with Architectury creator
* Fix long-running tasks that need to run after one another
* Apply website in Forge creator
* Set the correct gradle version in the Forge project creator
* Architectury should be finished but it's not working, not sure why
* Add support for custom build systems via extension points
* Sponge project creator, first maven implementation
* Remove unsupported platforms from the readme
* Add missing platforms to readme
* Replace some silly code with less silly code
* Add Spigot and Paper creators
* Add Velocity creator
* Add BungeeCord and Waterfall creator
* Delete unused code
* ktlint format
* Apply the correct JDK version depending on the platform and version
* Fix license years after merge
* Improvements and fixes to JDK selector UI
* Fix architectury template
* Fix issues with Sponge creator
* Fix IncorrectOperationException in AbstractLatentStep
* Add option to create a git repo (which also creates a gitignore)
* UI improvements
* Add a message encouraging users to report outdated templates
* Add note to project wizard outdated form warning not to request new platforms
* Paper before Spigot
* Remove dependency on TemplateMakerFabric
* Reorganize creators into multiple files and repackage some things
* Improve documentation
* Improve ergonomics for build system properties, main class name, repository, issue tracker
* Limit Sponge API version to 8 and above in dropdown box
* Prevent class name from messing up when the project name contains dots
- /*
- * Minecraft Dev for IntelliJ
- *
- * https://minecraftdev.org
- *
- * Copyright (c) 2023 minecraft-dev
- *
- * MIT License
- */
- package com.demonwav.mcdev.creator
- import com.demonwav.mcdev.creator.buildsystem.BuildSystem
- import com.demonwav.mcdev.creator.exception.ProjectCreatorException
- import com.demonwav.mcdev.util.invokeAndWait
- import com.demonwav.mcdev.util.invokeLater
- import com.demonwav.mcdev.util.virtualFileOrError
- import com.intellij.openapi.module.Module
- import com.intellij.openapi.progress.ProcessCanceledException
- import com.intellij.openapi.progress.ProgressIndicator
- import com.intellij.openapi.progress.ProgressManager
- import com.intellij.openapi.progress.Task
- import com.intellij.openapi.vfs.VfsUtil
- import java.nio.file.Path
- class MinecraftProjectCreator {
- var buildSystem: BuildSystem? = null
- var config: ProjectConfig? = null
- fun create(root: Path, module: Module) {
- val build = buildSystem ?: throw IllegalStateException("buildSystem not initialized")
- ProgressManager.getInstance().run(CreateTask(root, module, build))
- }
- class WorkLogStep(val config: Any) {
- private val steps = mutableListOf<Pair<Any, Int>>()
- private var currentStep: Pair<Any, Int>? = null
- fun printState(sb: StringBuilder) {
- sb.append(" ").appendLine(if (config is String) config else config.javaClass.name)
- for ((step, indent) in steps) {
- printStep(sb, step, " ", indent)
- }
- currentStep?.let { (step, indent) ->
- printStep(sb, step, " > ", indent)
- }
- }
- private fun printStep(sb: StringBuilder, step: Any, baseIndent: String, indent: Int) {
- repeat(indent) {
- sb.append(" ")
- }
- sb.append(baseIndent).appendLine(if (step is String) step else step.javaClass.name)
- }
- fun newCurrentStep(newStep: Any, indent: Int = 0) {
- finishCurrentStep()
- currentStep = newStep to indent
- }
- fun finishCurrentStep() {
- currentStep?.let { step ->
- steps += step
- }
- currentStep = null
- }
- companion object {
- var currentLog: WorkLogStep? = null
- }
- }
- private inner class CreateTask(
- private val root: Path,
- private val module: Module,
- private val build: BuildSystem
- ) : Task.Backgroundable(module.project, "Setting up project", false) {
- override fun shouldStartInBackground() = false
- override fun run(indicator: ProgressIndicator) {
- if (module.isDisposed || project.isDisposed) {
- return
- }
- val workLog = mutableListOf<WorkLogStep>()
- try {
- // Should be empty, just make sure IntelliJ knows that
- invokeAndWait {
- VfsUtil.markDirtyAndRefresh(false, true, true, root.virtualFileOrError)
- }
- val config = [email protected] ?: return
- build.configure(config, root)
- val log = newLog(config, workLog)
- if (!build.buildCreator(config, root, module).getSteps().run(indicator, log)) {
- return
- }
- config.type.type.performCreationSettingSetup(module.project)
- CreatorStep.runAllReformats()
- // Tell IntelliJ about everything we've done
- invokeLater {
- VfsUtil.markDirtyAndRefresh(false, true, true, root.virtualFileOrError)
- }
- } catch (e: Exception) {
- if (e is ProcessCanceledException || e.cause is ProcessCanceledException) {
- // Do not log PCE. The second condition is there because LaterInvocator wraps PCEs in RuntimeExceptions
- return
- }
- val workLogText = buildString {
- appendLine("Build steps completed:")
- for (workLogStep in workLog) {
- workLogStep.printState(this)
- }
- }
- throw ProjectCreatorException(workLogText, e)
- } finally {
- WorkLogStep.currentLog = null
- }
- }
- private fun Iterable<CreatorStep>.run(indicator: ProgressIndicator, workLog: WorkLogStep): Boolean {
- for (step in this) {
- if (module.isDisposed || project.isDisposed) {
- return false
- }
- workLog.newCurrentStep(step)
- step.runStep(indicator)
- }
- workLog.finishCurrentStep()
- return true
- }
- private fun newLog(obj: Any, workLog: MutableList<WorkLogStep>): WorkLogStep {
- val log = WorkLogStep(obj)
- WorkLogStep.currentLog = log
- workLog += log
- return log
- }
- }
- }