Skip to content

Commit 0157923

Browse files
committed
Merge branch '2020.3' into 2021.1
2 parents a32734e + 21f7830 commit 0157923

File tree

18 files changed

+276
-220
lines changed

18 files changed

+276
-220
lines changed

build.gradle.kts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ plugins {
1818
mcdev
1919
groovy
2020
idea
21-
id("org.jetbrains.intellij") version "0.7.3"
21+
id("org.jetbrains.intellij") version "1.0"
2222
id("org.cadixdev.licenser") version "0.6.0"
2323
id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
2424
}
@@ -97,25 +97,25 @@ dependencies {
9797

9898
intellij {
9999
// IntelliJ IDEA dependency
100-
version = ideaVersion
100+
version.set(ideaVersion)
101101
// Bundled plugin dependencies
102-
setPlugins(
102+
plugins.addAll(
103103
"java",
104104
"maven",
105105
"gradle",
106106
"Groovy",
107+
"org.toml.lang:$pluginTomlVersion",
107108
// needed dependencies for unit tests
108109
"properties",
109-
"junit",
110-
"org.toml.lang:$pluginTomlVersion"
110+
"junit"
111111
)
112112

113-
pluginName = "Minecraft Development"
114-
updateSinceUntilBuild = true
113+
pluginName.set("Minecraft Development")
114+
updateSinceUntilBuild.set(true)
115115

116-
downloadSources = downloadIdeaSources.toBoolean()
116+
downloadSources.set(downloadIdeaSources.toBoolean())
117117

118-
sandboxDirectory = layout.projectDirectory.dir(".sandbox")
118+
sandboxDir.set(layout.projectDirectory.dir(".sandbox").toString())
119119
}
120120

121121
tasks.publishPlugin {
@@ -124,13 +124,13 @@ tasks.publishPlugin {
124124
project.version = "${project.version}-$buildNumber"
125125
}
126126
properties["mcdev.deploy.token"]?.let { deployToken ->
127-
token(deployToken)
127+
token.set(deployToken.toString())
128128
}
129-
channels(properties["mcdev.deploy.channel"] ?: "Stable")
129+
channels.add(properties["mcdev.deploy.channel"]?.toString() ?: "Stable")
130130
}
131131

132132
tasks.runPluginVerifier {
133-
ideVersions(listOf("IC-2020.1.3", "IC-2020.1.4"))
133+
ideVersions.addAll("IC-2020.1.3", "IC-2020.1.4")
134134
}
135135

136136
java {
@@ -200,7 +200,7 @@ tasks.test {
200200
idea {
201201
module {
202202
generatedSourceDirs.add(file("gen"))
203-
excludeDirs.add(file(intellij.sandboxDirectory))
203+
excludeDirs.add(file(intellij.sandboxDir.get()))
204204
}
205205
}
206206

src/main/kotlin/creator/CreatorStep.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ interface CreatorStep {
6767

6868
// Reformat the code to match their code style
6969
runReadAction {
70+
if (project.isDisposed) {
71+
return@runReadAction
72+
}
7073
PsiManager.getInstance(project).findFile(vFile)?.let {
7174
scheduledReformats += it.createSmartPointer()
7275
}

src/main/kotlin/creator/buildsystem/gradle/gradle-steps.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ fun setupGradleFiles(dir: Path, givenFiles: GradleFiles<String>): GradleFiles<Pa
129129
givenFiles.gradleProperties?.let { dir.resolve("gradle.properties") },
130130
givenFiles.settingsGradle?.let { dir.resolve("settings.gradle") }
131131
).apply {
132+
Files.deleteIfExists(buildGradle)
132133
Files.createFile(buildGradle)
133-
gradleProperties?.let { Files.createFile(it) }
134-
settingsGradle?.let { Files.createFile(it) }
134+
gradleProperties?.let { Files.deleteIfExists(it); Files.createFile(it) }
135+
settingsGradle?.let { Files.deleteIfExists(it); Files.createFile(it) }
135136
}
136137
}
137138

src/main/kotlin/creator/buildsystem/maven/maven-steps.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ class BasicMavenStep(
5959
Files.createDirectories(rootDirectory)
6060

6161
runWriteTask {
62+
if (project.isDisposed) {
63+
return@runWriteTask
64+
}
6265
val pomPsi = PsiFileFactory.getInstance(project).createFileFromText(XMLLanguage.INSTANCE, pomText)
6366
?: return@runWriteTask
6467

6568
pomPsi.name = "pom.xml"
6669

6770
val pomXmlPsi = pomPsi as XmlFile
6871
pomPsi.runWriteAction {
72+
if (project.isDisposed) {
73+
return@runWriteAction
74+
}
6975
val manager = DomManager.getDomManager(project)
7076
val mavenProjectXml = manager.getFileElement(pomXmlPsi, MavenDomProjectModel::class.java)?.rootElement
7177
?: return@runWriteAction
@@ -190,7 +196,7 @@ class BasicMavenFinalizerStep(
190196
val vPomFile = pomFile.virtualFile ?: throw IllegalStateException("Could not find file: $pomFile")
191197

192198
// Force Maven to setup the project
193-
invokeLater {
199+
invokeLater(project.disposed) {
194200
val manager = MavenProjectsManager.getInstance(project)
195201
manager.addManagedFilesOrUnignore(listOf(vPomFile))
196202
manager.importingSettings.isDownloadDocsAutomatically = true

src/main/kotlin/errorreporter/AnonymousFeedback.kt

Lines changed: 49 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import com.demonwav.mcdev.util.fromJson
1616
import com.google.gson.Gson
1717
import com.intellij.ide.plugins.PluginManagerCore
1818
import com.intellij.openapi.diagnostic.Attachment
19+
import com.intellij.openapi.util.text.StringUtil
1920
import java.net.HttpURLConnection
2021
import java.nio.ByteBuffer
2122
import java.nio.charset.CodingErrorAction
23+
import org.apache.commons.httpclient.HttpStatus
2224
import org.apache.commons.io.IOUtils
2325
import org.apache.http.HttpHeaders
2426
import org.apache.http.entity.ContentType
@@ -65,12 +67,8 @@ object AnonymousFeedback {
6567
errorMessage = "no error"
6668
}
6769

68-
var stackTrace = body.remove("error.stacktrace")
69-
stackTrace = if (stackTrace.isNullOrEmpty()) {
70-
"no stacktrace"
71-
} else {
72-
linkStacktrace(stackTrace)
73-
}
70+
val rawStackTrace = body.remove("error.raw_stacktrace")?.takeIf { it.isNotBlank() } ?: "no stacktrace"
71+
val stackTrace = body.remove("error.stacktrace")?.takeIf { it.isNotBlank() } ?: "no stacktrace"
7472

7573
val sb = StringBuilder()
7674

@@ -84,13 +82,20 @@ object AnonymousFeedback {
8482
sb.append("</table></td><td><table>\n")
8583
}
8684
val (key, value) = entry
87-
sb.append("<tr><td><b>").append(key).append("</b></td><td><code>").append(value).append(
88-
"</code></td></tr>\n"
89-
)
85+
sb.append("<tr><td><b>")
86+
.append(key)
87+
.append("</b></td><td><code>")
88+
.append(value)
89+
.append("</code></td></tr>\n")
9090
}
9191
sb.append("</table></td></tr></table>\n")
9292

93-
sb.append("\n<pre>\n").append(stackTrace).append("\n</pre>\n")
93+
sb.append("\n<pre><code>").append(stackTrace).append("</code></pre>\n")
94+
95+
sb.append("\n<details><summary>Original stack trace</summary>\n\n```\n")
96+
.append(rawStackTrace)
97+
.append("\n```\n</details>\n")
98+
9499
sb.append("\n```\n").append(errorMessage).append("\n```\n")
95100

96101
if (attachments.isNotEmpty()) {
@@ -149,11 +154,16 @@ object AnonymousFeedback {
149154
val numberRegex = Regex("\\d+")
150155
val newLineRegex = Regex("[\r\n]+")
151156

152-
val stack = envDetails["error.stacktrace"]?.replace(numberRegex, "") ?: return null
157+
val stack = envDetails["error.raw_stacktrace"]?.replace(numberRegex, "") ?: return null
153158

154-
val stackMcdevParts = stack.lineSequence()
159+
val ourMcdevParts = stack.lineSequence()
155160
.filter { line -> line.startsWith(packagePrefix) }
156-
.joinToString("\n")
161+
.map { it.trim() }
162+
.toList()
163+
164+
if (ourMcdevParts.isEmpty()) {
165+
return null
166+
}
157167

158168
val predicate = fun(map: Map<*, *>): Boolean {
159169
val body = (map["body"] as? String ?: return false)
@@ -167,23 +177,36 @@ object AnonymousFeedback {
167177

168178
val first = body.indexOf("\n```\n", startIndex = 0) + 5
169179
val second = body.indexOf("\n```\n", startIndex = first)
180+
if (first == 4 || second == -1) {
181+
return false
182+
}
183+
170184
val stackText = body.substring(first, second)
171185

172-
val mcdevParts = stackText.lineSequence()
186+
val theirMcdevParts = stackText.lineSequence()
173187
.filter { line -> line.startsWith(packagePrefix) }
174-
.joinToString("\n")
188+
.map { it.trim() }
189+
.toList()
175190

176-
return stackMcdevParts == mcdevParts
191+
return ourMcdevParts == theirMcdevParts
177192
}
178193

179194
// Look first for an open issue, then for a closed issue if one isn't found
180195
val block = getAllIssues(openIssueUrl, factory)?.firstOrNull(predicate)
181-
?: getAllIssues(closedIssueUrl, factory)?.firstOrNull(predicate)
196+
?: getAllIssues(closedIssueUrl, factory, limit = 300)?.firstOrNull(predicate)
182197
?: return null
183198
return (block["number"] as Double).toInt()
184199
}
185200

186-
private fun getAllIssues(url: String, factory: HttpConnectionFactory): List<Map<*, *>>? {
201+
private fun getMcdevStackElementLines(stack: String, numberRegex: Regex, linkRegex: Regex): List<String> {
202+
return stack.lineSequence()
203+
.mapNotNull { line -> linkRegex.matchEntire(line)?.groups?.get("content")?.value }
204+
.map { line -> StringUtil.unescapeXmlEntities(line) }
205+
.map { line -> line.replace(numberRegex, "") }
206+
.toList()
207+
}
208+
209+
private fun getAllIssues(url: String, factory: HttpConnectionFactory, limit: Int = -1): List<Map<*, *>>? {
187210
var useAuthed = false
188211

189212
var next: String? = url
@@ -197,13 +220,13 @@ object AnonymousFeedback {
197220

198221
connection.connect()
199222

200-
if (connection.responseCode == 403 && !useAuthed) {
223+
if (connection.responseCode == HttpStatus.SC_FORBIDDEN && !useAuthed) {
201224
useAuthed = true
202225
next = replaceWithAuth(next)
203226
continue
204227
}
205228

206-
if (connection.responseCode != 200) {
229+
if (connection.responseCode != HttpStatus.SC_OK) {
207230
return null
208231
}
209232

@@ -216,6 +239,10 @@ object AnonymousFeedback {
216239
val response = Gson().fromJson<List<Map<*, *>>>(data)
217240
list.addAll(response)
218241

242+
if (limit > 0 && list.size >= limit) {
243+
return list
244+
}
245+
219246
val link = connection.getHeaderField("Link")
220247

221248
next = getNextLink(link, useAuthed)
@@ -277,7 +304,7 @@ object AnonymousFeedback {
277304
}
278305

279306
val responseCode = connection.responseCode
280-
if (responseCode != 201) {
307+
if (responseCode != HttpStatus.SC_CREATED) {
281308
throw RuntimeException("Expected HTTP_CREATED (201), obtained $responseCode instead.")
282309
}
283310

@@ -287,7 +314,7 @@ object AnonymousFeedback {
287314
}
288315
connection.disconnect()
289316

290-
return Gson().fromJson<Map<*, *>>(body)
317+
return Gson().fromJson(body)
291318
}
292319

293320
private fun getConnection(factory: HttpConnectionFactory, url: String): HttpURLConnection {
@@ -300,74 +327,6 @@ object AnonymousFeedback {
300327
return connection
301328
}
302329

303-
private fun linkStacktrace(stacktrace: String): String {
304-
val versionRegex = Regex("""(?<intellijVersion>\d{4}\.\d)-(?<pluginVersion>\d+\.\d+\.\d+)""")
305-
306-
val version = PluginUtil.pluginVersion
307-
val match = versionRegex.matchEntire(version) ?: return stacktrace
308-
309-
val intellijVersion = match.groups["intellijVersion"]?.value ?: return stacktrace
310-
val pluginVersion = match.groups["pluginVersion"]?.value ?: return stacktrace
311-
312-
val tag = "$pluginVersion-$intellijVersion"
313-
314-
// v stack element text v
315-
// at com.demonwav.mcdev.facet.MinecraftFacet.shouldShowPluginIcon(MinecraftFacet.kt:185)
316-
// prefix ^ class path ^ ^ file name ^ ^ ^ line number
317-
val stackElementRegex = Regex(
318-
"""(?<prefix>\s+at\s+)""" +
319-
"""(?<stackElementText>""" +
320-
"""(?<className>com\.demonwav\.mcdev(?:\.\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}*)+)""" +
321-
"""(?:\.\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}*|<(?:cl)?init>)""" +
322-
"""\((?<fileName>.*\.\w+):(?<lineNumber>\d+)\)""" +
323-
""")\s*"""
324-
)
325-
326-
val baseTagUrl = "https://github.com/minecraft-dev/MinecraftDev/blob/$tag/src/main/kotlin/"
327-
328-
val sb = StringBuilder(stacktrace.length * 2)
329-
330-
for (line in stacktrace.lineSequence()) {
331-
val lineMatch = stackElementRegex.matchEntire(line)
332-
if (lineMatch == null) {
333-
sb.append(line).append('\n')
334-
continue
335-
}
336-
337-
val prefix = lineMatch.groups["prefix"]?.value
338-
val className = lineMatch.groups["className"]?.value
339-
val fileName = lineMatch.groups["fileName"]?.value
340-
val lineNumber = lineMatch.groups["lineNumber"]?.value
341-
val stackElementText = lineMatch.groups["stackElementText"]?.value
342-
343-
if (prefix == null || className == null || fileName == null ||
344-
lineNumber == null || stackElementText == null
345-
) {
346-
sb.append(line).append('\n')
347-
continue
348-
}
349-
350-
val path = className.substringAfter("com.demonwav.mcdev.")
351-
.substringBeforeLast('.')
352-
.replace('.', '/')
353-
sb.apply {
354-
append(prefix)
355-
append("<a href=\"")
356-
append(baseTagUrl)
357-
append(path)
358-
append('/')
359-
append(fileName)
360-
append("#L")
361-
append(lineNumber)
362-
append("\">")
363-
append(stackElementText)
364-
append("</a>\n")
365-
}
366-
}
367-
368-
return sb.toString()
369-
}
370-
371330
private val userAgent by lazy {
372331
var agent = "Minecraft Development IntelliJ IDEA plugin"
373332

src/main/kotlin/errorreporter/AnonymousFeedbackTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class AnonymousFeedbackTask(
3030
indicator.isIndeterminate = true
3131

3232
try {
33-
val (url, token, isDuplicate) =
34-
AnonymousFeedback.sendFeedback(ProxyHttpConnectionFactory, params, attachments)
33+
val factory = ProxyHttpConnectionFactory
34+
val (url, token, isDuplicate) = AnonymousFeedback.sendFeedback(factory, params, attachments)
3535

3636
callback(url, token, isDuplicate)
3737
} catch (e: Exception) {

src/main/kotlin/errorreporter/ErrorBean.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)