Skip to content

Commit

Permalink
Merge branch 'dev' into 2021.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Aug 24, 2021
2 parents 72d138b + 5999273 commit 802ae84
Show file tree
Hide file tree
Showing 50 changed files with 712 additions and 81 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin.code.style=official
ideaVersion = 2021.1
ideaVersionName = 2021.1

coreVersion = 1.5.13
coreVersion = 1.5.14
downloadIdeaSources = true

pluginTomlVersion = 0.2.144.3766-211
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Minecraft Development for IntelliJ
</tr>
</table>

Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.5.13-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.5.14-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
----------------------

<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/creator/BuildSystemWizardStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BuildSystemWizardStep(private val creator: MinecraftProjectCreator) : Modu
override fun getComponent() = panel

override fun updateStep() {
val previousBuildSystem = buildSystemBox.selectedItem
buildSystemBox.removeAllItems()
buildSystemBox.isEnabled = true

Expand All @@ -46,12 +47,18 @@ class BuildSystemWizardStep(private val creator: MinecraftProjectCreator) : Modu
buildSystemBox.addItem(type)
}

buildSystemBox.selectedIndex = 0
if (buildSystemBox.itemCount == 1) {
buildSystemBox.isEnabled = false
return
}

if (previousBuildSystem != null) {
buildSystemBox.selectedItem = previousBuildSystem
return
}

buildSystemBox.selectedIndex = 0

// We prefer Gradle, so if it's included, choose it
// If Gradle is not included, luck of the draw
if (creator.configs.any { it.preferredBuildSystem == BuildSystemType.GRADLE }) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/creator/MinecraftModuleBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import java.nio.file.Files
Expand Down Expand Up @@ -103,7 +104,7 @@ class MinecraftModuleBuilder : JavaModuleBuilder() {
wizardContext: WizardContext,
modulesProvider: ModulesProvider
): Array<ModuleWizardStep> {
return arrayOf(
val baseSteps = arrayOf(
BuildSystemWizardStep(creator),
BukkitProjectSettingsWizard(creator),
SpongeProjectSettingsWizard(creator),
Expand All @@ -113,6 +114,10 @@ class MinecraftModuleBuilder : JavaModuleBuilder() {
VelocityProjectSettingsWizard(creator),
BungeeCordProjectSettingsWizard(creator)
)
if (Registry.`is`("mcdev.wizard.finalizer")) {
return baseSteps + ProjectSetupFinalizerWizardStep(creator, wizardContext)
}
return baseSteps
}

override fun getCustomOptionsStep(context: WizardContext?, parentDisposable: Disposable?) =
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/creator/MinecraftProjectCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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
Expand Down Expand Up @@ -159,6 +160,10 @@ class MinecraftProjectCreator {
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) {
Expand Down
21 changes: 19 additions & 2 deletions src/main/kotlin/creator/PlatformVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,46 @@ import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.util.ProxyHttpConnectionFactory
import com.demonwav.mcdev.util.fromJson
import com.google.gson.Gson
import com.intellij.openapi.diagnostic.Attachment
import com.intellij.openapi.diagnostic.Logger
import java.io.IOException
import javax.swing.JComboBox

private const val cloudflareBaseUrl = "https://minecraftdev.org/versions/"
private const val githubBaseUrl = "https://raw.githubusercontent.com/minecraft-dev/minecraftdev.org/master/versions/"

val PLATFORM_VERSION_LOGGER = Logger.getInstance("MDev.PlatformVersion")

fun getVersionSelector(type: PlatformType): PlatformVersion {
val versionJson = type.versionJson ?: throw UnsupportedOperationException("Incorrect platform type: $type")
return getVersionJson(versionJson)
}

inline fun <reified T : Any> getVersionJson(path: String): T {
val text = getText(path)
return Gson().fromJson(text)
try {
return Gson().fromJson(text)
} catch (e: Exception) {
val attachment = Attachment("JSON Document", text)
attachment.isIncluded = true
PLATFORM_VERSION_LOGGER.error("Failed to parse JSON document from '$path'", e, attachment)
throw e
}
}

fun getText(path: String): String {
return try {
// attempt cloudflare
doCall(cloudflareBaseUrl + path)
} catch (e: IOException) {
PLATFORM_VERSION_LOGGER.warn("Failed to reach cloudflare URL ${cloudflareBaseUrl + path}", e)
// if that fails, attempt github
doCall(githubBaseUrl + path)
try {
doCall(githubBaseUrl + path)
} catch (e: IOException) {
PLATFORM_VERSION_LOGGER.warn("Failed to reach fallback GitHub URL ${githubBaseUrl + path}", e)
throw e
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/creator/ProjectConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package com.demonwav.mcdev.creator
import com.demonwav.mcdev.creator.buildsystem.BuildSystemType
import com.demonwav.mcdev.platform.PlatformType
import com.intellij.util.containers.isNullOrEmpty
import com.intellij.util.lang.JavaVersion

private val bracketRegex = Regex("[\\[\\]]")
private val commaRegex = Regex("\\s*,\\s*")
Expand All @@ -37,6 +38,8 @@ abstract class ProjectConfig {
var description: String? = null
fun hasDescription() = description?.isNotBlank() == true

abstract val javaVersion: JavaVersion

protected fun commaSplit(string: String): List<String> {
return if (!string.isBlank()) {
string.trim().replace(bracketRegex, "").split(commaRegex).toList()
Expand Down
Loading

0 comments on commit 802ae84

Please sign in to comment.