User: joe Date: 16 Nov 26 02:40 Revision: 2fb0e13166664fb22ad7a2951e718be185100cdb Summary: Merge branch '2026.2' into 2026.3 # Conflicts: # buildSrc/src/main/kotlin/mcdev-publishing.gradle.kts # gradle/libs.versions.toml # src/main/kotlin/creator/custom/CreatorCredentials.kt # src/main/kotlin/util/McdevReflection.kt TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=10799&personal=false Index: gradle.properties =================================================================== --- gradle.properties (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ gradle.properties (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -25,9 +25,6 @@ coreVersion = 1.9.1 -# Silences a build-time warning because we are bundling our own kotlin library -kotlin.stdlib.default.dependency = false - org.gradle.parallel=true org.gradle.caching=true Index: gradle/libs.versions.toml =================================================================== --- gradle/libs.versions.toml (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ gradle/libs.versions.toml (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -5,11 +5,10 @@ coroutines = "1.11.0" junit = "6.0.3" asm = "9.9.1" -fuel = "2.3.1" licenser = "0.7.5" changelog = "2.5.0" # https://github.com/JetBrains/intellij-platform-gradle-plugin -intellij-plugin = "2.19.0" +intellij-plugin = "2.20.1" # https://central.sonatype.com/artifact/org.jetbrains.intellij/plugin-repository-rest-client intellij-plugin-repository-rest-client = "2.0.51" # https://www.jetbrains.com/intellij-repository/snapshots or https://www.jetbrains.com/intellij-repository/releases/ @@ -39,7 +38,7 @@ coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" } -mappingIo = "net.fabricmc:mapping-io:0.8.0" +mappingIo = "net.fabricmc:mapping-io:0.9.2" mixinExtras-expressions = "io.github.llamalad7:mixinextras-expressions:0.0.6" jgraphx = "com.github.vlsi.mxgraph:jgraphx:4.2.2" @@ -62,9 +61,6 @@ gson = "com.google.code.gson:gson:2.13.2" jspecify = "org.jspecify:jspecify:1.0.0" -fuel = { module = "com.github.kittinunf.fuel:fuel", version.ref = "fuel" } -fuel-coroutines = { module = "com.github.kittinunf.fuel:fuel-coroutines", version.ref = "fuel" } - sentry = "io.sentry:sentry:8.37.1" # Testing @@ -80,9 +76,11 @@ junit-vintage = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit" } junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit" } +# Shaded, so its Jetty and Jackson can't clash with the IDE's +wiremock = "org.wiremock:wiremock-standalone:3.13.2" + mixinExtras-common = "io.github.llamalad7:mixinextras-common:0.5.3" [bundles] coroutines = ["coroutines-swing"] asm = ["asm", "asm-tree", "asm-analysis", "asm-util"] -fuel = ["fuel", "fuel-coroutines"] Index: src/main/kotlin/creator/custom/CreatorCredentials.kt =================================================================== --- src/main/kotlin/creator/custom/CreatorCredentials.kt (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ src/main/kotlin/creator/custom/CreatorCredentials.kt (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -24,8 +24,6 @@ import com.demonwav.mcdev.creator.custom.providers.RemoteTemplateProvider.RemoteAuthType import com.demonwav.mcdev.util.McdevReflection import com.demonwav.mcdev.util.McdevReflection.invokeUnwrap -import com.github.kittinunf.fuel.core.Request -import com.github.kittinunf.fuel.core.extensions.authentication import com.intellij.collaboration.auth.AccountManager import com.intellij.collaboration.auth.ServerAccount import com.intellij.collaboration.auth.findAccountOrNull @@ -36,6 +34,7 @@ import git4idea.remote.GitHttpAuthDataProvider import git4idea.remote.hosting.http.SilentHostedGitHttpAuthDataProviderBase import java.nio.file.Path +import java.util.Base64 import java.util.Properties import javax.xml.parsers.DocumentBuilderFactory import javax.xml.xpath.XPathFactory @@ -66,21 +65,29 @@ return PasswordSafe.instance[credAttrs] } - suspend fun configureAuthorization( - request: Request, + fun basicAuthHeader(username: String, password: String): Map { + val token = Base64.getEncoder().encodeToString("$username:$password".toByteArray(Charsets.UTF_8)) + return mapOf("Authorization" to "Basic $token") + } + + /** + * Returns the headers that authenticate a request to [url] with the given [authType], or an empty map if no + * credentials are stored for it. + */ + suspend fun authorizationHeaders( url: String, authType: RemoteAuthType, credentials: String - ): Request { + ): Map { when (authType) { - RemoteAuthType.NONE -> return request + RemoteAuthType.NONE -> return emptyMap() RemoteAuthType.BASIC -> { val creds = getCredentials(url, credentials) val username = creds?.userName val password = creds?.getPasswordAsString() if (username != null && password != null) { - return request.authentication().basic(username, password) + return basicAuthHeader(username, password) } } @@ -88,14 +95,14 @@ val creds = getCredentials(url, null) val password = creds?.getPasswordAsString() if (password != null) { - return request.authentication().bearer(password) + return mapOf("Authorization" to "Bearer $password") } } RemoteAuthType.GIT_HTTP -> { val creds = findGitHttpAuthBearerToken(credentials) if (creds != null) { - return request.authentication().basic(creds.first, creds.second) + return basicAuthHeader(creds.first, creds.second) } } @@ -104,12 +111,12 @@ val username = creds?.userName val password = creds?.getPasswordAsString() if (username != null && password != null) { - return request.header(username, password) + return mapOf(username to password) } } } - return request + return emptyMap() } fun SilentHostedGitHttpAuthDataProviderBase<*, *>.getProviderId(): String = @@ -151,6 +158,11 @@ return account.name to token } + fun findMavenRepoAuthHeaders(url: String): Map { + val (username, password) = findMavenRepoCredentials(url) ?: return emptyMap() + return basicAuthHeader(username, password) + } + fun findMavenRepoCredentials(url: String): Pair? { val repoData = MinecraftSettings.instance.creatorMavenRepos.find { url.startsWith(it.url) } if (repoData == null) { Index: src/main/kotlin/creator/custom/npm/NpmEnvironment.kt =================================================================== --- src/main/kotlin/creator/custom/npm/NpmEnvironment.kt (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ src/main/kotlin/creator/custom/npm/NpmEnvironment.kt (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -21,7 +21,7 @@ package com.demonwav.mcdev.creator.custom.npm import com.demonwav.mcdev.asset.MCDevBundle -import com.demonwav.mcdev.update.PluginUtil +import com.demonwav.mcdev.util.McdevHttp import com.intellij.ide.util.PropertiesComponent import com.intellij.execution.ExecutionException import com.intellij.execution.configurations.GeneralCommandLine @@ -37,8 +37,6 @@ import com.intellij.openapi.util.io.NioFiles import com.intellij.openapi.util.text.StringUtil import com.intellij.util.io.DigestUtil -import com.intellij.util.io.HttpRequests -import com.intellij.util.io.URLUtil import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.createDirectories @@ -81,7 +79,6 @@ private val mutex = Mutex() private const val CUSTOM_NPM_PATH_KEY = "mcdev.creator.npm.path" - private const val REGISTRY_URL = "https://registry.npmjs.org" val directory: Path get() = PathManager.getSystemDir().resolve("mcdev-npm") @@ -108,11 +105,7 @@ * Fetches information about who published the given version (or dist-tag) of a package from the npm registry. */ fun fetchPackageInfo(source: NpmPackageSource.Registry): NpmPackageInfo { - // Scoped packages need their slash to be escaped - val url = "$REGISTRY_URL/${source.name.replace("/", "%2F")}/${URLUtil.encodeURIComponent(source.version)}" - val text = HttpRequests.request(url) - .userAgent(PluginUtil.useragent) - .readString() + val text = McdevHttp.request(NpmRegistry.packageUrl(source.name, source.version)).readString() val json = Json.parseToJsonElement(text).jsonObject fun JsonElement?.personName(): String? = when (this) { Index: src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt =================================================================== --- src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -27,14 +27,9 @@ import com.demonwav.mcdev.creator.custom.CreatorCredentials.getProviderId import com.demonwav.mcdev.creator.custom.TemplateDescriptor import com.demonwav.mcdev.creator.modalityState -import com.demonwav.mcdev.creator.selectProxy -import com.demonwav.mcdev.update.PluginUtil import com.demonwav.mcdev.util.capitalize +import com.demonwav.mcdev.util.McdevHttp import com.demonwav.mcdev.util.refreshSync -import com.github.kittinunf.fuel.core.FuelManager -import com.github.kittinunf.fuel.coroutines.awaitByteArrayResult -import com.github.kittinunf.result.getOrNull -import com.github.kittinunf.result.onError import com.intellij.ide.util.projectWizard.WizardContext import com.intellij.openapi.application.PathManager import com.intellij.openapi.diagnostic.ControlFlowException @@ -68,6 +63,7 @@ import kotlin.io.path.absolutePathString import kotlin.io.path.exists import kotlin.io.path.writeBytes +import kotlinx.coroutines.CancellationException open class RemoteTemplateProvider : TemplateProvider { @@ -103,23 +99,26 @@ val repoUrl = replaceVariables(originalRepoUrl, TemplateDescriptor.LATEST_FORMAT_VERSION) - val manager = FuelManager() - manager.proxy = selectProxy(repoUrl) - var request = manager.get(repoUrl) - .header("Accept", "application/octet-stream") - .header("User-Agent", PluginUtil.useragent) - .timeout(10000) + val headers = if (credentials.isNotBlank()) { + CreatorCredentials.authorizationHeaders(originalRepoUrl, authType, credentials) + } else { + emptyMap() + } - if (credentials.isNotBlank()) { - request = CreatorCredentials.configureAuthorization(request, originalRepoUrl, authType, credentials) + val data = try { + McdevHttp.get(repoUrl, headers) { + accept("application/octet-stream").connectTimeout(10000) + }.connect { + readBytes(null) - } + } + } catch (e: Exception) { + if (e is CancellationException || e is ControlFlowException) { + throw e + } + thisLogger().warn("Could not fetch remote templates repository update at $repoUrl", e) + return false + } - val result = request.awaitByteArrayResult() - - val data = result.onError { - thisLogger().warn("Could not fetch remote templates repository update at $repoUrl", it) - }.getOrNull() ?: return false - try { val zipPath = RemoteTemplateRepo.getDestinationZip(repoName) zipPath.parent.createDirectories() Index: src/main/kotlin/update/PluginUpdater.kt =================================================================== --- src/main/kotlin/update/PluginUpdater.kt (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ src/main/kotlin/update/PluginUpdater.kt (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -20,6 +20,7 @@ package com.demonwav.mcdev.update +import com.demonwav.mcdev.util.McdevHttp import com.demonwav.mcdev.util.McdevReflection import com.demonwav.mcdev.util.forEachNotNull import com.demonwav.mcdev.util.invokeLater @@ -37,7 +38,6 @@ import com.intellij.openapi.updateSettings.impl.PluginDownloader import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.SystemInfo -import com.intellij.util.io.HttpRequests import java.io.IOException import java.net.URLEncoder import org.jdom.Element @@ -72,7 +72,7 @@ "https://plugins.jetbrains.com/plugins/list?pluginId=8327&build=" + "$buildNumber&pluginVersion=$currentVersion&os=$os" - val responseDoc = HttpRequests.request(url).connect { request -> + val responseDoc = McdevHttp.request(url).connect { request -> try { return@connect JDOMUtil.load(request.inputStream) } catch (e: JDOMException) { Index: src/main/kotlin/util/McdevReflection.kt =================================================================== --- src/main/kotlin/util/McdevReflection.kt (revision d411ca468686825a93f9f26853f73f451cf5c237) +++ src/main/kotlin/util/McdevReflection.kt (revision 2fb0e13166664fb22ad7a2951e718be185100cdb) @@ -22,12 +22,14 @@ import com.intellij.codeInsight.generation.ClassMember import com.intellij.codeInsight.generation.GenerateMembersHandlerBase +import com.intellij.codeInspection.LocalQuickFix import com.intellij.collaboration.auth.AccountManager import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.openapi.updateSettings.impl.PluginDownloader import com.intellij.psi.PsiClass import git4idea.remote.hosting.http.SilentHostedGitHttpAuthDataProviderBase +import java.lang.reflect.Constructor import java.lang.reflect.Field import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method @@ -66,6 +68,14 @@ ) @JvmStatic + val CLASS_MARKDOWN_DOCUMENTATION_COMMENTS_MIGRATION_FIX: Class<*> = + Class.forName("com.siyeh.ig.migration.MarkdownDocumentationCommentsMigrationInspection\$MarkdownDocumentationCommentsMigrationFix") + + @JvmStatic + val CONSTRUCTOR_MARKDOWN_DOCUMENTATION_COMMENTS_MIGRATION_FIX: Constructor = + CLASS_MARKDOWN_DOCUMENTATION_COMMENTS_MIGRATION_FIX.getDeclaredConstructorEx() + + @JvmStatic val FIELD_PLUGIN_DOWNLOADER_MY_FILE: Field = PluginDownloader::class.java.getDeclaredFieldEx("myFile", Path::class.java) @@ -102,6 +112,18 @@ } /** + * Like [Class.getDeclaredConstructor], but makes the constructor accessible. + */ + private inline fun Class<*>.getDeclaredConstructorEx(vararg params: Class<*>): Constructor { + check(T::class.java.isAssignableFrom(this)) { + "Class ${this.name} is not a subclass of ${T::class.java.name}" + } + val constructor = this.asSubclass(T::class.java).getDeclaredConstructor(*params) + constructor.isAccessible = true + return constructor + } + + /** * Like [Class.getDeclaredMethod], but makes the method accessible and checks that it has the expected [returnType]. */ private fun Class<*>.getDeclaredMethodEx(name: String, returnType: Class<*>, vararg params: Class<*>): Method { @@ -114,6 +136,18 @@ } /** + * Like [Constructor.newInstance], but rethrows the exception thrown by the invoked constructor rather than wrapping + * it in an [InvocationTargetException]. + */ + fun Constructor.newInstanceUnwrap(vararg args: Any?): T { + try { + return newInstance(*args) + } catch (e: InvocationTargetException) { + throw e.cause ?: e + } + } + + /** * Like [Method.invoke], but rethrows the exception thrown by the invoked method rather than wrapping it in an * [InvocationTargetException]. */