Skip to content

Commit

Permalink
Merge branch '2023.1' into 2023.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 8, 2023
2 parents c4785a0 + d78fb0f commit 51bf6c5
Show file tree
Hide file tree
Showing 35 changed files with 111 additions and 602 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask

plugins {
kotlin("jvm") version "1.8.0"
kotlin("jvm") version "1.9.0"
java
mcdev
groovy
idea
id("org.jetbrains.intellij") version "1.14.1"
id("org.jetbrains.intellij") version "1.15.0"
id("org.cadixdev.licenser")
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
}
Expand Down Expand Up @@ -282,7 +282,7 @@ license {

exclude("com/demonwav/mcdev/platform/mixin/invalidInjectorMethodSignature/*.java")

tasks {
this.tasks {
register("gradle") {
files.from(
fileTree(project.projectDir) {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 10 additions & 6 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,26 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/creator/creator-utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ fun FixedAssetsNewProjectWizardStep.addLicense(project: Project) {
addTemplates(project, "LICENSE" to "${license.id}.txt")
}

fun splitPackage(text: String): Pair<String, String> {
fun splitPackage(text: String): Pair<String?, String> {
val index = text.lastIndexOf('.')
if (index == -1) {
return null to text
}

val className = text.substring(index + 1)
val packageName = text.substring(0, index)
return packageName to className
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import java.nio.file.Path
abstract class FixedAssetsNewProjectWizardStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep(parent) {
lateinit var outputDirectory: String
private val assets = arrayListOf<FixedGeneratorAsset>()
val templateProperties = hashMapOf<String, Any>()
val templateProperties = hashMapOf<String, Any?>()
private val filesToOpen = hashSetOf<String>()

fun addAssets(vararg assets: Any) = addAssets(assets.toList())
Expand All @@ -66,9 +66,9 @@ abstract class FixedAssetsNewProjectWizardStep(parent: NewProjectWizardStep) : A
}
}

fun addTemplateProperties(vararg properties: Pair<String, Any>) = addTemplateProperties(properties.toMap())
fun addTemplateProperties(vararg properties: Pair<String, Any?>) = addTemplateProperties(properties.toMap())

fun addTemplateProperties(properties: Map<String, Any>) = templateProperties.putAll(properties)
fun addTemplateProperties(properties: Map<String, Any?>) = templateProperties.putAll(properties)

fun addFilesToOpen(vararg relativeCanonicalPaths: String) = addFilesToOpen(relativeCanonicalPaths.toList())

Expand Down
17 changes: 10 additions & 7 deletions src/main/kotlin/platform/forge/creator/asset-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class ForgeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningA
override fun setupAssets(project: Project) {
val mcVersion = data.getUserData(ForgeVersionChainStep.MC_VERSION_KEY) ?: return
val forgeVersion = data.getUserData(ForgeVersionChainStep.FORGE_VERSION_KEY) ?: return
val (mainPackageName, mainClassName) = splitPackage(data.getUserData(MainClassStep.KEY) ?: return)
val mainClass = data.getUserData(MainClassStep.KEY) ?: return
val (mainPackageName, mainClassName) = splitPackage(mainClass)
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()
val modName = data.getUserData(AbstractModNameStep.KEY) ?: return
val license = data.getUserData(LicenseStep.KEY) ?: return
Expand Down Expand Up @@ -108,12 +109,12 @@ class ForgeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningA
mcVersion >= MinecraftVersions.MC1_19 -> MinecraftTemplates.FG3_1_19_MAIN_CLASS_TEMPLATE
mcVersion >= MinecraftVersions.MC1_18 -> MinecraftTemplates.FG3_1_18_MAIN_CLASS_TEMPLATE
mcVersion >= MinecraftVersions.MC1_17 -> MinecraftTemplates.FG3_1_17_MAIN_CLASS_TEMPLATE
else -> MinecraftTemplates.FG3_MAIN_CLASS_TEMPLATE
else -> MinecraftTemplates.FG3_1_16_MAIN_CLASS_TEMPLATE
}

assets.addTemplates(
project,
"src/main/java/${mainPackageName.replace('.', '/')}/$mainClassName.java" to mainClassTemplate,
"src/main/java/${mainClass.replace('.', '/')}.java" to mainClassTemplate,
"src/main/resources/pack.mcmeta" to MinecraftTemplates.PACK_MCMETA_TEMPLATE,
"src/main/resources/META-INF/mods.toml" to MinecraftTemplates.MODS_TOML_TEMPLATE,
)
Expand All @@ -124,10 +125,12 @@ class ForgeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningA
}

if (configTemplate != null) {
assets.addTemplates(
project,
"src/main/java/${mainPackageName.replace('.', '/')}/Config.java" to configTemplate,
)
val configPath = if (mainPackageName != null) {
"src/main/java/${mainPackageName.replace('.', '/')}/Config.java"
} else {
"src/main/java/Config.java"
}
assets.addTemplates(project, configPath to configTemplate)
}

assets.addLicense(project)
Expand Down
11 changes: 0 additions & 11 deletions src/main/kotlin/platform/forge/creator/gradle-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.demonwav.mcdev.creator.step.LicenseStep
import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep
import com.demonwav.mcdev.creator.step.UseMixinsStep
import com.demonwav.mcdev.util.MinecraftTemplates
import com.demonwav.mcdev.util.MinecraftVersions
import com.demonwav.mcdev.util.SemanticVersion
import com.intellij.ide.wizard.NewProjectWizardStep
import com.intellij.openapi.application.WriteAction
Expand Down Expand Up @@ -95,9 +94,6 @@ class ForgeGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs
assets.addTemplateProperties(
"MOD_NAME" to modName,
"MC_VERSION" to mcVersion,
"MCP_CHANNEL" to "official",
"MCP_VERSION" to mcVersion,
"MCP_MC_VERSION" to mcVersion,
"MC_NEXT_VERSION" to mcNextVersion,
"FORGE_VERSION" to forgeVersion,
"FORGE_SPEC_VERSION" to forgeVersion.parts[0].versionString,
Expand All @@ -122,13 +118,6 @@ class ForgeGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs
assets.addTemplateProperties("GAME_TEST_FRAMEWORK" to "true")
}

if (mcVersion <= MinecraftVersions.MC1_16_5) {
assets.addTemplateProperties(
"MCP_CHANNEL" to "snapshot",
"MCP_VERSION" to "20210309",
)
}

assets.addTemplates(
project,
"build.gradle" to MinecraftTemplates.FG3_BUILD_GRADLE_TEMPLATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.intellij.openapi.application.runWriteActionAndWait
import com.intellij.openapi.externalSystem.task.TaskCallback
import com.intellij.openapi.roots.LibraryOrderEntry
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.util.ActionCallback
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiJavaFile
Expand Down Expand Up @@ -103,6 +104,10 @@ class FabricLoomDecompileSourceProvider : AttachSourcesProvider {
val library = libraryEntry.library
if (library != null) {
runWriteActionAndWait {
if (library is LibraryEx && library.isDisposed) {
return@runWriteActionAndWait
}

val model = library.modifiableModel
model.addRoot("jar://$sourcePath!/", OrderRootType.SOURCES)
model.commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.demonwav.mcdev.platform.mixin.reference.MixinSelector
import com.demonwav.mcdev.util.constantValue
import com.demonwav.mcdev.util.createLiteralExpression
import com.demonwav.mcdev.util.descriptor
import com.demonwav.mcdev.util.ifNotBlank
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
Expand Down Expand Up @@ -60,7 +61,7 @@ class ConstantInjectionPoint : InjectionPoint<PsiElement>() {
val longValue = args["longValue"]?.toLongOrNull()
val doubleValue = args["doubleValue"]?.toDoubleOrNull()
val stringValue = args["stringValue"]
val classValue = args["classValue"]?.let { Type.getObjectType(it.replace('.', '/')) }
val classValue = args["classValue"]?.ifNotBlank { Type.getObjectType(it.replace('.', '/')) }
val count =
nullValue.toInt() +
(intValue != null).toInt() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiMethodReferenceExpression
import com.intellij.psi.PsiReturnStatement
import com.intellij.psi.PsiTypes
import com.intellij.psi.controlFlow.AnalysisCanceledException
import com.intellij.psi.controlFlow.ControlFlowUtil
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.AbstractInsnNode
Expand Down Expand Up @@ -113,7 +114,12 @@ abstract class AbstractReturnInjectionPoint(private val tailOnly: Boolean) : Inj
}

val rBrace = codeBlockToAnalyze.rBrace ?: return
val controlFlow = HighlightControlFlowUtil.getControlFlowNoConstantEvaluate(codeBlockToAnalyze)
val controlFlow = try {
HighlightControlFlowUtil.getControlFlowNoConstantEvaluate(codeBlockToAnalyze)
} catch (e: AnalysisCanceledException) {
return
}

if (ControlFlowUtil.canCompleteNormally(controlFlow, 0, controlFlow.size)) {
if (tailOnly) {
result.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.intellij.icons.AllIcons
import com.intellij.ide.util.SuperMethodWarningUtil
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.ComponentValidator
Expand Down Expand Up @@ -299,21 +300,27 @@ private class RenameWithInheritanceFix(
if (isMethod) {
val method = startElement as? PsiMethod ?: return
if (editor != null) {
SuperMethodWarningUtil.checkSuperMethod(method, { md ->
RenameProcessor(project, md, newName, false, false).run()
true
}, editor)
DumbService.getInstance(project).smartInvokeLater {
SuperMethodWarningUtil.checkSuperMethod(method, { md ->
RenameProcessor(project, md, newName, false, false).run()
true
}, editor)
}
} else {
val superMethod = method.findDeepestSuperMethods().firstOrNull()
for (md in listOfNotNull(superMethod, method)) {
RenameProcessor(project, md, newName, false, false).run()
DumbService.getInstance(project).smartInvokeLater {
val superMethod = method.findDeepestSuperMethods().firstOrNull()
for (md in listOfNotNull(superMethod, method)) {
RenameProcessor(project, md, newName, false, false).run()
}
}
}
} else {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) {
return
}
RenameProcessor(project, startElement, newName, false, false).run()
DumbService.getInstance(project).smartInvokeLater {
RenameProcessor(project, startElement, newName, false, false).run()
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/platform/sponge/creator/asset-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ class SpongeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunning

override fun setupAssets(project: Project) {
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()
val (packageName, className) = splitPackage(data.getUserData(MainClassStep.KEY) ?: return)
val mainClass = data.getUserData(MainClassStep.KEY) ?: return
val (packageName, className) = splitPackage(mainClass)

assets.addTemplateProperties(
"PLUGIN_ID" to buildSystemProps.artifactId,
"PACKAGE" to packageName,
"CLASS_NAME" to className,
)
val mainClassFile = "src/main/java/${packageName.replace('.', '/')}/$className.java"
val mainClassFile = "src/main/java/${mainClass.replace('.', '/')}.java"
assets.addTemplates(
project,
mainClassFile to MinecraftTemplates.SPONGE8_MAIN_CLASS_TEMPLATE,
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/platform/velocity/creator/gradle-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class VelocityGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin
"PACKAGE" to mainPackage,
)

val buildConstantsJava = "src/main/templates/${mainPackage.replace('.', '/')}/BuildConstants.java"
val buildConstantsJava = if (mainPackage != null) {
"src/main/templates/${mainPackage.replace('.', '/')}/BuildConstants.java"
} else {
"src/main/templates/BuildConstants.java"
}
assets.addTemplates(
project,
"build.gradle" to MinecraftTemplates.VELOCITY_BUILD_GRADLE_TEMPLATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ class ModsTomlValidationInspection : LocalInspectionTool() {
"modId" -> {
val value = keyValue.value ?: return
val modId = value.stringValue() ?: return
if (!ForgeConstants.MOD_ID_REGEX.matches(modId)) {
if (modId != "\"" && !ForgeConstants.MOD_ID_REGEX.matches(modId)) {
val endOffset = if (value.text.endsWith('"')) modId.length + 1 else modId.length
holder.registerProblem(value, TextRange(1, endOffset), "Mod ID is invalid")
}
}
"displayTest" -> {
val value = keyValue.value ?: return
val test = value.stringValue() ?: return
if (test !in ForgeConstants.DISPLAY_TESTS) {
if (test != "\"" && test !in ForgeConstants.DISPLAY_TESTS) {
val endOffset = if (value.text.endsWith('"')) test.length + 1 else test.length
holder.registerProblem(value, TextRange(1, endOffset), "DisplayTest $test does not exist")
}
Expand All @@ -96,15 +96,15 @@ class ModsTomlValidationInspection : LocalInspectionTool() {
"side" -> {
val value = keyValue.value ?: return
val side = value.stringValue() ?: return
if (side !in ForgeConstants.DEPENDENCY_SIDES) {
if (side != "\"" && side !in ForgeConstants.DEPENDENCY_SIDES) {
val endOffset = if (value.text.endsWith('"')) side.length + 1 else side.length
holder.registerProblem(value, TextRange(1, endOffset), "Side $side does not exist")
}
}
"ordering" -> {
val value = keyValue.value ?: return
val order = value.stringValue() ?: return
if (order !in ForgeConstants.DEPENDENCY_ORDER) {
if (order != "\"" && order !in ForgeConstants.DEPENDENCY_ORDER) {
val endOffset = if (value.text.endsWith('"')) order.length + 1 else order.length
holder.registerProblem(value, TextRange(1, endOffset), "Order $order does not exist")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferen
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.util.ProcessingContext
import kotlin.math.max
import org.jetbrains.jps.model.java.JavaResourceRootType
import org.jetbrains.uast.UAnnotation
import org.jetbrains.uast.evaluateString
Expand Down Expand Up @@ -126,7 +127,7 @@ object ModsTomlModIdReferenceProvider : PsiReferenceProvider() {
}

class ModsTomlModIdReference(element: TomlValue) :
PsiReferenceBase<TomlValue>(element, TextRange(1, element.textLength - 1)) {
PsiReferenceBase<TomlValue>(element, TextRange(1, max(element.textLength - 1, 1))) {

val modId: String? = element.stringValue()

Expand Down
Loading

0 comments on commit 51bf6c5

Please sign in to comment.