Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to new ExternalSystemNotificationExtension.customize() with externalProjectPath #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ class GradleBuildInvokerImpl @NonInjectable @VisibleForTesting internal construc
if (startBuildEventPosted) {
val title = "$executionName failed"
val dataContext: DataContext = BuildConsoleUtils.getDataContext(id, buildViewManager)
val failureResult: FailureResult = ExternalSystemUtil.createFailureResult(title, e, GRADLE_SYSTEM_ID, project, dataContext)
val failureResult: FailureResult = ExternalSystemUtil.createFailureResult(
title, e, GRADLE_SYSTEM_ID, project, request.rootProjectPath.absolutePath, dataContext
)
buildEventDispatcher.onEvent(id, FinishBuildEventImpl(id, null, System.currentTimeMillis(), "failed", failureResult))
}
super.onFailure(id, e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class GradleJvmNotificationExtension: GradleNotificationExtension() {
}
}

override fun customize(notificationData: NotificationData, project: Project, error: Throwable?) {
super.customize(notificationData, project, error)
override fun customize(notificationData: NotificationData, project: Project, externalProjectPath: String, error: Throwable?) {
super.customize(notificationData, project, externalProjectPath, error)
val expectedPrefix = GradleBundle.message("gradle.jvm.is.invalid")
if (notificationData.message.startsWith(expectedPrefix)) {
val ideSdks = IdeSdks.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.intellij.testFramework.replaceService
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker.Companion.getKnownIssuesCheckList
import org.junit.Test
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.anyString
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.any
import org.mockito.Mockito.spy
Expand Down Expand Up @@ -70,7 +71,7 @@ class DexDisabledIssueCheckerIntegrationTest: AndroidGradleTestCase() {
assertThat(result.invocations.firstOrNull()?.buildError).isNotNull()
// and that error generates the expected BuildIssue
val throwableCaptor = ArgumentCaptor.forClass(Throwable::class.java)
verify(spyNotificationManager).createNotification(any(), throwableCaptor.capture(), any(), eq(project), any())
verify(spyNotificationManager).createNotification(any(), throwableCaptor.capture(), any(), eq(project), anyString(), any())
val generatedExceptions = throwableCaptor.allValues
assertThat(generatedExceptions).hasSize(1)
assertThat(generatedExceptions[0]).isInstanceOf(BuildIssueException::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GradleJvmNotificationExtensionTest {
val gradleProjectRule = AndroidGradleProjectRule()

private val gradleJvmExtension = GradleJvmNotificationExtension()
private val externalProjectPath = gradleProjectRule.project.basePath.orEmpty()

@Before
fun setUp() {
Expand All @@ -70,7 +71,7 @@ class GradleJvmNotificationExtensionTest {
"<a href=\"${OpenProjectJdkLocationListener.ID}\">Change JDK location</a>\n"
assertThat(notificationData.registeredListenerIds).isEmpty()

gradleJvmExtension.customize(notificationData, gradleProjectRule.project, null)
gradleJvmExtension.customize(notificationData, gradleProjectRule.project, externalProjectPath, null)
assertThat(notificationData.message).isEqualTo(expectedMessage)
val newListeners = notificationData.registeredListenerIds
assertThat(newListeners).contains("${baseId()}.embedded")
Expand All @@ -90,7 +91,7 @@ class GradleJvmNotificationExtensionTest {
"<a href=\"${OpenProjectJdkLocationListener.ID}\">Change JDK location</a>\n"
assertThat(notificationData.registeredListenerIds).isEmpty()

gradleJvmExtension.customize(notificationData, gradleProjectRule.project, null)
gradleJvmExtension.customize(notificationData, gradleProjectRule.project, externalProjectPath, null)
assertThat(notificationData.message).isEqualTo(expectedMessage)
val newListeners = notificationData.registeredListenerIds
assertThat(newListeners).contains("${baseId()}.embedded")
Expand All @@ -113,7 +114,7 @@ class GradleJvmNotificationExtensionTest {
assertThat(notificationData.registeredListenerIds).hasSize(3)
val spyData = spy(notificationData)

gradleJvmExtension.customize(spyData, gradleProjectRule.project, null)
gradleJvmExtension.customize(spyData, gradleProjectRule.project, externalProjectPath, null)
// Should not add new quickfixes nor modify the message if they are already there
verify(spyData, never()).setListener(Mockito.any(), Mockito.any())
assertThat(notificationData.message).isEqualTo(originalMessage)
Expand All @@ -127,7 +128,7 @@ class GradleJvmNotificationExtensionTest {
assertThat(notificationData.registeredListenerIds).hasSize(0)
val spyData = spy(notificationData)

gradleJvmExtension.customize(spyData, gradleProjectRule.project, null)
gradleJvmExtension.customize(spyData, gradleProjectRule.project, externalProjectPath, null)
// Should not add new quickfixes nor modify the message if the error message does not start with "Invalid Gradle JDK..."
verify(spyData, never()).setListener(Mockito.any(), Mockito.any())
assertThat(notificationData.message).isEqualTo(originalMessage)
Expand All @@ -148,7 +149,7 @@ class GradleJvmNotificationExtensionTest {
val spyIdeSdks = spy(IdeSdks.getInstance())
Mockito.doReturn(invalidReason).whenever(spyIdeSdks).generateInvalidJdkReason(Mockito.any())
ApplicationManager.getApplication().replaceService(IdeSdks::class.java, spyIdeSdks, gradleProjectRule.fixture.projectDisposable)
gradleJvmExtension.customize(notificationData, gradleProjectRule.project, null)
gradleJvmExtension.customize(notificationData, gradleProjectRule.project, externalProjectPath, null)
assertThat(notificationData.message).isEqualTo(expectedMessage)
val newListeners = notificationData.registeredListenerIds
assertThat(newListeners).contains("${baseId()}.embedded")
Expand Down