[Gradle] parse exception stacktrace info if present in the build script error output IDEA-209457

GitOrigin-RevId: 3eb6e615a0af4158ba942abc9ff088b88c46f104
This commit is contained in:
Vladislav.Soroka
2019-10-09 10:05:57 +00:00
committed by intellij-monorepo-bot
parent 6fbeea6cb6
commit e819ba58d4
5 changed files with 61 additions and 5 deletions
@@ -4,7 +4,6 @@ package org.jetbrains.plugins.gradle.importing
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.externalSystem.importing.ImportSpec
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager
import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl
import com.intellij.openapi.externalSystem.view.ExternalProjectsViewImpl
@@ -272,9 +271,7 @@ project(':string-utils') {
@Override
protected ImportSpec createImportSpec() {
ImportSpecBuilder importSpecBuilder = new ImportSpecBuilder(myProject, getExternalSystemId())
.use(ProgressExecutionMode.MODAL_SYNC)
.forceWhenUptodate();
ImportSpecBuilder importSpecBuilder = new ImportSpecBuilder(super.createImportSpec())
if (isPreview) {
importSpecBuilder.usePreviewMode()
}
@@ -68,6 +68,19 @@ class GradleBuildScriptErrorParser : BuildOutputParser {
nextLine == "* Try:" -> break@loop
}
}
var exception: StringBuilder? = null
while (true) {
val nextLine = reader.readLine() ?: break
if (nextLine == "* Exception is:") {
exception = StringBuilder(nextLine).appendln()
} else {
exception?.appendln(nextLine)
}
if (nextLine == "BUILD FAILED") break
}
exception?.also { description.appendln().append(it) }
// compilation errors should be added by the respective compiler output parser
if (reason == "Compilation failed; see the compiler error output for details" ||
reason == "Compilation error. See log for more details" ||
@@ -154,7 +154,6 @@ public class GradleExecutionHelper {
if (!settings.getArguments().contains("--debug")){
settings.withArgument("--info");
}
settings.withArgument("--stacktrace");
}
}
@@ -3,6 +3,8 @@ package org.jetbrains.plugins.gradle.importing;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.externalSystem.importing.ImportSpec;
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings;
import com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter;
@@ -225,6 +227,13 @@ public abstract class GradleImportingTestCase extends ExternalSystemImportingTes
super.importProject(config);
}
@Override
protected ImportSpec createImportSpec() {
ImportSpecBuilder importSpecBuilder = new ImportSpecBuilder(super.createImportSpec());
importSpecBuilder.withArguments("--stacktrace");
return importSpecBuilder.build();
}
@NotNull
protected String injectRepo(@NonNls @Language("Groovy") String config) {
config = "allprojects {\n" +
@@ -1,6 +1,9 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.importing
import com.intellij.openapi.externalSystem.importing.ImportSpec
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder
import com.intellij.openapi.util.io.FileUtil
import org.gradle.util.GradleVersion
import org.jetbrains.plugins.gradle.settings.GradleSystemSettings
import org.junit.Test
@@ -9,10 +12,28 @@ import org.junit.Test
open class GradleOutputParsersMessagesImportingTest : BuildViewMessagesImportingTestCase() {
val itemLinePrefix by lazy { if (currentGradleVersion < GradleVersion.version("4.8")) " " else "-" }
val isPerTaskOutputSupported by lazy { currentGradleVersion >= GradleVersion.version("4.7") }
private var enableStackTraceImportingOption = false
// do not inject repository
override fun injectRepo(config: String): String = config
override fun createImportSpec(): ImportSpec {
val baseImportSpec = super.createImportSpec()
val baseArguments = baseImportSpec.arguments
val importSpecBuilder = ImportSpecBuilder(baseImportSpec)
if (enableStackTraceImportingOption) {
if (baseArguments == null || !baseArguments.contains("--stacktrace")) {
importSpecBuilder.withArguments("${baseArguments} --stacktrace")
}
}
else {
if (baseArguments != null) {
importSpecBuilder.withArguments(baseArguments.replace("--stacktrace", ""))
}
}
return importSpecBuilder.build()
}
@Test
fun `test build script errors on Sync`() {
createSettingsFile("include 'api', 'impl' ")
@@ -270,4 +291,21 @@ open class GradleOutputParsersMessagesImportingTest : BuildViewMessagesImporting
" -build.gradle\n" +
" only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed")
}
@Test
fun `test build script errors with stacktrace info`() {
enableStackTraceImportingOption = true
importProject("apply plugin: 'java'foo")
assertSyncViewTreeEquals("-\n" +
" -failed\n" +
" -build.gradle\n" +
" Cannot get property 'foo' on null object")
val filePath = FileUtil.toSystemDependentName(myProjectConfig.path)
assertSyncViewSelectedNode("Cannot get property 'foo' on null object",
"Build file '$filePath' line: 1\n\n" +
"A problem occurred evaluating root project 'project'.\n" +
"> Cannot get property 'foo' on null object\n")
}
}