⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
root = true

[*.{kt,kts}]
max_line_length=120
ij_kotlin_imports_layout=*
indent_size = 4
indent_style = space
max_line_length = 120
ij_kotlin_imports_layout = *
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
insert_final_newline = true
12 changes: 7 additions & 5 deletions src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CreatorTemplateProcessor(

val factory = Consumer<Panel> { panel ->
val label = descriptor.translatedLabel
if (descriptor.collapsible == false) {
val group = if (descriptor.collapsible == false) {
panel.group(label) {
for (childFactory in childrenUiFactories) {
childFactory.accept(this@group)
Expand All @@ -190,7 +190,11 @@ class CreatorTemplateProcessor(
}

group.expanded = descriptor.default as? Boolean ?: false
group
}

val isVisible = CreatorProperty.setupVisibleProperty(context.graph, context.properties, reporter, descriptor.visible)
group.visibleIf(isVisible)
}

val order = descriptor.order ?: 0
Expand All @@ -201,10 +205,8 @@ class CreatorTemplateProcessor(
reporter.fatal("Duplicate property name ${descriptor.name}")
}

val prop = CreatorPropertyFactory.createFromType(descriptor.type, descriptor, context)
if (prop == null) {
reporter.fatal("Unknown template property type ${descriptor.type}")
}
val prop = CreatorPropertyFactory.createFromType(descriptor.type, descriptor, context, reporter)
?: reporter.fatal("Unknown template property type ${descriptor.type}")

prop.setupProperty(reporter)

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/creator/custom/TemplateDescriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class TemplateDescriptor(

companion object {

const val FORMAT_VERSION = 1
const val FORMAT_VERSION = 2
}
}

Expand All @@ -56,6 +56,7 @@ data class TemplatePropertyDescriptor(
val groupProperties: List<TemplatePropertyDescriptor>? = null,
val remember: Any? = null,
val visible: Any? = null,
val forceValue: Any? = null,
val editable: Boolean? = null,
val collapsible: Boolean? = null,
val warning: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2025 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* 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 Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.creator.custom.derivation

import com.demonwav.mcdev.creator.custom.PropertyDerivation
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
import com.demonwav.mcdev.creator.custom.types.CreatorProperty
import com.demonwav.mcdev.util.MinecraftVersions
import com.demonwav.mcdev.util.SemanticVersion

class ExtractPaperApiVersionPropertyDerivation : ExtractVersionMajorMinorPropertyDerivation() {

override fun derive(parentValues: List<Any?>): Any? {
val from = parentValues[0] as SemanticVersion
if (from >= MinecraftVersions.MC1_20_5) {
return from
}

return super.derive(parentValues);
}

companion object : PropertyDerivationFactory {

override fun create(
reporter: TemplateValidationReporter,
parents: List<CreatorProperty<*>?>?,
derivation: PropertyDerivation
): PreparedDerivation? {
if (parents.isNullOrEmpty()) {
reporter.error("Expected a parent")
return null
}

if (!parents[0]!!.acceptsType(SemanticVersion::class.java)) {
reporter.error("First parent must produce a semantic version")
return null
}

return ExtractPaperApiVersionPropertyDerivation()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
import com.demonwav.mcdev.creator.custom.types.CreatorProperty
import com.demonwav.mcdev.util.SemanticVersion

class ExtractVersionMajorMinorPropertyDerivation : PreparedDerivation {
open class ExtractVersionMajorMinorPropertyDerivation : PreparedDerivation {

override fun derive(parentValues: List<Any?>): Any? {
val from = parentValues[0] as SemanticVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.demonwav.mcdev.creator.custom.finalizers

import com.intellij.execution.RunManager
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.openapi.project.Project
import org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType
import org.jetbrains.plugins.gradle.service.execution.GradleRunConfiguration

class AddGradleRunConfigFinalizer : AddRunConfigFinalizer {

override val executablesName: String = "tasks"

override suspend fun execute(
context: WizardContext,
project: Project,
properties: Map<String, Any>,
templateProperties: Map<String, Any?>
) {
val tasks = properties.executables
val projectDir = context.projectFileDirectory

val gradleType = GradleExternalTaskConfigurationType.getInstance()

val runManager = RunManager.getInstance(project)
val runConfigName = properties["name"] as String

val runConfiguration = GradleRunConfiguration(project, gradleType.factory, runConfigName)

runConfiguration.settings.externalProjectPath = projectDir
runConfiguration.settings.executionName = runConfigName
runConfiguration.settings.taskNames = tasks

val settings = runManager.createConfiguration(runConfiguration, gradleType.factory)
settings.isActivateToolWindowBeforeRun = true
settings.storeInLocalWorkspace()

runManager.addConfiguration(settings)

if (properties["select"] == true || runManager.selectedConfiguration == null) {
runManager.selectedConfiguration = settings
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.demonwav.mcdev.creator.custom.finalizers

import com.intellij.execution.RunManager
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.openapi.project.Project
import org.jetbrains.idea.maven.execution.MavenRunConfigurationType
import org.jetbrains.idea.maven.execution.MavenRunnerParameters
import org.jetbrains.idea.maven.execution.MavenRunnerSettings

class AddMavenRunConfigFinalizer : AddRunConfigFinalizer {

override val executablesName: String = "goals"

override suspend fun execute(
context: WizardContext,
project: Project,
properties: Map<String, Any>,
templateProperties: Map<String, Any?>
) {
val goals = properties.executables
val projectDir = context.projectFileDirectory

val params = MavenRunnerParameters().also {
it.goals = goals
it.workingDirPath = projectDir
}
val settings = MavenRunConfigurationType.createRunnerAndConfigurationSettings(null, null, params, project)

settings.name = properties["name"] as String
settings.isActivateToolWindowBeforeRun = true
settings.storeInLocalWorkspace()

val runManager = RunManager.getInstance(project)

runManager.addConfiguration(settings)

if (properties["select"] == true || runManager.selectedConfiguration == null) {
runManager.selectedConfiguration = settings
}
}
}
28 changes: 28 additions & 0 deletions src/main/kotlin/creator/custom/finalizers/AddRunConfigFinalizer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.demonwav.mcdev.creator.custom.finalizers

import com.demonwav.mcdev.creator.custom.TemplateValidationReporter

interface AddRunConfigFinalizer : CreatorFinalizer {

val executablesName: String
val Map<String, Any>.executables: List<String>
@Suppress("UNCHECKED_CAST")
get() = this[executablesName] as List<String>

override fun validate(
reporter: TemplateValidationReporter,
properties: Map<String, Any>
) {
@Suppress("UNCHECKED_CAST")
val executables = properties[executablesName] as? List<String>
if (executables == null) {
reporter.warn("Missing list of '$executables' to execute")
}

@Suppress("UNCHECKED_CAST")
val name = properties["name"] as? String
if (name == null) {
reporter.warn("Missing task name")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@
package com.demonwav.mcdev.creator.custom.finalizers

import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.openapi.application.EDT
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import org.jetbrains.plugins.gradle.service.project.open.canLinkAndRefreshGradleProject
import org.jetbrains.plugins.gradle.service.project.open.linkAndSyncGradleProject

Expand All @@ -33,13 +40,40 @@ class ImportGradleProjectFinalizer : CreatorFinalizer {
project: Project,
properties: Map<String, Any>,
templateProperties: Map<String, Any?>
) {
) = coroutineScope {
val projectDir = context.projectFileDirectory
val canLink = canLinkAndRefreshGradleProject(projectDir, project, showValidationDialog = false)
thisLogger().info("canLink = $canLink projectDir = $projectDir")

if (canLink) {
linkAndSyncGradleProject(project, projectDir)
val link = async {
linkAndSyncGradleProject(project, projectDir)
}

openBuildToolWindow(project)

link.await()

thisLogger().info("Linking done")
}
}
}

suspend fun openBuildToolWindow(project: Project) = coroutineScope {
runCatching {
// Try to open the tool window after starting the sync.
// Having the tool window open will provide better context to the user about what's going on.
// The Build tool window isn't registered until a build is running, so we can't just open the tool window
// like normal here, we have to wait until after the build starts.
val manager = ToolWindowManager.getInstance(project)
for (i in 0 until 5) {
delay(250)
manager.getToolWindow("Build")?.let {
withContext(Dispatchers.EDT) {
it.show()
}
break
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
import java.nio.file.Path
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import org.jetbrains.idea.maven.buildtool.MavenSyncSpec
import org.jetbrains.idea.maven.project.MavenProjectsManager

Expand All @@ -35,15 +37,22 @@ class ImportMavenProjectFinalizer : CreatorFinalizer {
project: Project,
properties: Map<String, Any>,
templateProperties: Map<String, Any?>
) {
) = coroutineScope {
val projectDir = context.projectFileDirectory
val pomFile = VfsUtil.findFile(Path.of(projectDir).resolve("pom.xml"), true)
?: return
?: return@coroutineScope

thisLogger().info("Invoking import on EDT pomFile = ${pomFile.path}")
val projectsManager = MavenProjectsManager.getInstance(project)
projectsManager.addManagedFiles(listOf(pomFile))
projectsManager.updateAllMavenProjects(MavenSyncSpec.incremental("ImportMavenProjectFinalizer", false))

val import = async {
projectsManager.updateAllMavenProjects(MavenSyncSpec.incremental("ImportMavenProjectFinalizer", false))
}

openBuildToolWindow(project)

import.await()

thisLogger().info("Import finished")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RunGradleTasksFinalizer : CreatorFinalizer {
val projectDir = context.projectDirectory

thisLogger().info("tasks = $tasks projectDir = $projectDir")
runGradleTaskAndWait(project, projectDir) { settings ->
runGradleTaskAndWait(project, projectDir, toolWindow = true) { settings ->
settings.taskNames = tasks
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/creator/custom/model/StringList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ data class StringList(val values: List<String>) : List<String> by values {
@JvmOverloads
fun toString(separator: String, prefix: String = "", postfix: String = ""): String =
values.joinToString(separator, prefix, postfix)

fun toStringQuoted(): String =
values.joinToString(", ", transform = { '"' + it + '"' })
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.demonwav.mcdev.creator.custom.types

import com.demonwav.mcdev.asset.MCDevBundle
import com.demonwav.mcdev.asset.MCDevBundle.invoke
import com.demonwav.mcdev.creator.collectMavenVersions
import com.demonwav.mcdev.creator.custom.BuiltinValidations
import com.demonwav.mcdev.creator.custom.CreatorContext
Expand Down
Loading