diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemMessageEvent.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemMessageEvent.java new file mode 100644 index 000000000000..e40cb7fde971 --- /dev/null +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemMessageEvent.java @@ -0,0 +1,19 @@ +// Copyright 2000-2021 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 com.intellij.openapi.externalSystem.model.task.event; + +import org.jetbrains.annotations.Nullable; + +/** + * An event with textual description. + * @param + */ +public interface ExternalSystemMessageEvent extends ExternalSystemProgressEvent{ + + /** + * Textual description of event. + * + * @return arbitrary additional information about status update + */ + @Nullable + default String getDescription() { return null; } +} diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemMessageEventImpl.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemMessageEventImpl.java new file mode 100644 index 000000000000..8b43bb02ca59 --- /dev/null +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemMessageEventImpl.java @@ -0,0 +1,24 @@ +// Copyright 2000-2021 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 com.intellij.openapi.externalSystem.model.task.event; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ExternalSystemMessageEventImpl extends BaseExternalSystemProgressEvent + implements ExternalSystemMessageEvent { + private final String myDescription; + + public ExternalSystemMessageEventImpl(@NotNull String eventId, + @Nullable String parentEventId, + @NotNull T descriptor, + @Nullable String message) { + super(eventId, parentEventId, descriptor); + myDescription = message; + } + + @Nullable + @Override + public String getDescription() { + return myDescription; + } +} diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemStatusEvent.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemStatusEvent.java index d4602a1868b5..956ec5e77370 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemStatusEvent.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/ExternalSystemStatusEvent.java @@ -15,14 +15,12 @@ */ package com.intellij.openapi.externalSystem.model.task.event; -import org.jetbrains.annotations.Nullable; - /** * An event that informs about an interim results of the operation. * * @author Vladislav.Soroka */ -public interface ExternalSystemStatusEvent extends ExternalSystemProgressEvent { +public interface ExternalSystemStatusEvent extends ExternalSystemMessageEvent { /** * The amount of work already performed by the build operation. * @@ -43,12 +41,4 @@ public interface ExternalSystemStatusEvent extend * @return The measure used to express the amount of work. */ String getUnit(); - - /** - * Textual description of event. - * - * @return arbitrary additional information about status update - */ - @Nullable - default String getDescription() { return null; } } diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptor.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptor.java index da724b488c02..8e03b08e8bb6 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptor.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptor.java @@ -15,18 +15,12 @@ */ package com.intellij.openapi.externalSystem.model.task.event; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * @author Vladislav.Soroka */ public interface TestOperationDescriptor extends OperationDescriptor { - @Nullable - String getParentId(); - - @NotNull - String getId(); @Nullable String getSuiteName(); diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptorImpl.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptorImpl.java index bd6a15b4bd1c..5f78cec77879 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptorImpl.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/task/event/TestOperationDescriptorImpl.java @@ -16,7 +16,6 @@ package com.intellij.openapi.externalSystem.model.task.event; import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -25,38 +24,22 @@ import org.jetbrains.annotations.Nullable; public class TestOperationDescriptorImpl extends OperationDescriptorImpl implements TestOperationDescriptor { private static final long serialVersionUID = 1L; - private final String myId; - private final String myParentId; private final String mySuiteName; private final String myClassName; private final String myMethodName; - public TestOperationDescriptorImpl(@NotNull String id, - @Nullable String parentId, - @Nls String displayName, + public TestOperationDescriptorImpl(@Nls String displayName, long eventTime, String suiteName, String className, String methodName) { super(displayName, eventTime); - myId = id; - myParentId = parentId; mySuiteName = suiteName; myClassName = className; myMethodName = methodName; } - @Override - public @NotNull String getId() { - return myId; - } - - @Override - public @Nullable String getParentId() { - return myParentId; - } - @Nullable @Override public String getSuiteName() { diff --git a/plugins/gradle/java/src/execution/test/runner/events/AfterSuiteEvent.java b/plugins/gradle/java/src/execution/test/runner/events/AfterSuiteEvent.java index 1fd669f75e7f..f36b4db041dd 100644 --- a/plugins/gradle/java/src/execution/test/runner/events/AfterSuiteEvent.java +++ b/plugins/gradle/java/src/execution/test/runner/events/AfterSuiteEvent.java @@ -37,7 +37,7 @@ public class AfterSuiteEvent extends AbstractTestEvent { if (!(testEvent instanceof ExternalSystemFinishEvent)) { return; } - final String testId = testEvent.getDescriptor().getId(); + final String testId = testEvent.getEventId(); TestEventResult result = TestEventResult.fromOperationResult(((ExternalSystemFinishEvent)testEvent).getOperationResult()); doProcess(testId, result); diff --git a/plugins/gradle/java/src/execution/test/runner/events/AfterTestEvent.java b/plugins/gradle/java/src/execution/test/runner/events/AfterTestEvent.java index c448e6d35348..2c5f4372ec32 100644 --- a/plugins/gradle/java/src/execution/test/runner/events/AfterTestEvent.java +++ b/plugins/gradle/java/src/execution/test/runner/events/AfterTestEvent.java @@ -17,7 +17,6 @@ package org.jetbrains.plugins.gradle.execution.test.runner.events; import com.intellij.execution.testframework.sm.runner.SMTestProxy; import com.intellij.openapi.externalSystem.model.task.event.*; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ObjectUtils; @@ -41,7 +40,7 @@ public class AfterTestEvent extends AbstractTestEvent { if (!(testEvent instanceof ExternalSystemFinishEvent)) { return; } - final String testId = testEvent.getDescriptor().getId(); + final String testId = testEvent.getEventId(); final SMTestProxy testProxy = findTestProxy(testId); if (testProxy == null) return; diff --git a/plugins/gradle/java/src/execution/test/runner/events/BeforeSuiteEvent.java b/plugins/gradle/java/src/execution/test/runner/events/BeforeSuiteEvent.java index 2393aa86ea78..8bce0c30950a 100644 --- a/plugins/gradle/java/src/execution/test/runner/events/BeforeSuiteEvent.java +++ b/plugins/gradle/java/src/execution/test/runner/events/BeforeSuiteEvent.java @@ -6,6 +6,7 @@ import com.intellij.execution.testframework.sm.runner.SMTestProxy; import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEvent; import com.intellij.openapi.externalSystem.model.task.event.TestOperationDescriptor; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy; @@ -36,10 +37,9 @@ public class BeforeSuiteEvent extends AbstractTestEvent { @Override public void process(@NotNull ExternalSystemProgressEvent testEvent) { TestOperationDescriptor testDescriptor = testEvent.getDescriptor(); - final String testId = testDescriptor.getId(); - final String parentTestId = testDescriptor.getParentId(); - String methodName = testDescriptor.getMethodName(); - final String name = methodName != null ? methodName : testId; + final String testId = testEvent.getEventId(); + final String parentTestId = testEvent.getParentEventId(); + final String name = ObjectUtils.coalesce(testDescriptor.getDisplayName(), testDescriptor.getMethodName(), testId); final String fqClassName = testDescriptor.getClassName(); doProcess(testId, parentTestId, name, fqClassName); diff --git a/plugins/gradle/java/src/execution/test/runner/events/BeforeTestEvent.java b/plugins/gradle/java/src/execution/test/runner/events/BeforeTestEvent.java index 98187054548e..15d9e72e5b9e 100644 --- a/plugins/gradle/java/src/execution/test/runner/events/BeforeTestEvent.java +++ b/plugins/gradle/java/src/execution/test/runner/events/BeforeTestEvent.java @@ -5,6 +5,7 @@ import com.intellij.execution.testframework.sm.runner.SMTestProxy; import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEvent; import com.intellij.openapi.externalSystem.model.task.event.TestOperationDescriptor; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.ObjectUtils; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -35,10 +36,9 @@ public class BeforeTestEvent extends AbstractTestEvent { @Override public void process(@NotNull ExternalSystemProgressEvent testEvent) { TestOperationDescriptor testDescriptor = testEvent.getDescriptor(); - final String testId = testDescriptor.getId(); - final String parentTestId = testDescriptor.getParentId(); - String methodName = testDescriptor.getMethodName(); - final String name = methodName != null ? methodName : testId; + final String testId = testEvent.getEventId(); + final String parentTestId = testEvent.getParentEventId(); + final String name = ObjectUtils.coalesce(testDescriptor.getDisplayName(), testDescriptor.getMethodName(), testId); final String fqClassName = testDescriptor.getClassName(); doProcess(testId, parentTestId, name, fqClassName); diff --git a/plugins/gradle/java/src/execution/test/runner/events/OnOutputEvent.java b/plugins/gradle/java/src/execution/test/runner/events/OnOutputEvent.java index 99cd06c7eab5..f8822b471e7a 100644 --- a/plugins/gradle/java/src/execution/test/runner/events/OnOutputEvent.java +++ b/plugins/gradle/java/src/execution/test/runner/events/OnOutputEvent.java @@ -3,11 +3,11 @@ package org.jetbrains.plugins.gradle.execution.test.runner.events; import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.execution.testframework.sm.runner.SMTestProxy; +import com.intellij.execution.testframework.sm.runner.events.TestOutputEvent; +import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemMessageEvent; import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEvent; -import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemStatusEvent; import com.intellij.openapi.externalSystem.model.task.event.TestOperationDescriptor; import com.intellij.openapi.util.Key; -import com.intellij.execution.testframework.sm.runner.events.TestOutputEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestsExecutionConsole; @@ -35,25 +35,21 @@ public class OnOutputEvent extends AbstractTestEvent { @Override public void process(@NotNull ExternalSystemProgressEvent testEvent) { - if (!(testEvent instanceof ExternalSystemStatusEvent)) { + if (!(testEvent instanceof ExternalSystemMessageEvent)) { return; } TestOperationDescriptor testDescriptor = testEvent.getDescriptor(); - final String testId = testDescriptor.getId(); - String description = ((ExternalSystemStatusEvent)testEvent).getDescription(); - Key destination = ProcessOutputTypes.STDERR; - if (description.startsWith(OUT)) { - destination = ProcessOutputTypes.STDOUT; - description = description.substring(OUT.length()); + final String testId = testEvent.getEventId(); + final String description = ((ExternalSystemMessageEvent)testEvent).getDescription(); + + if (description == null) { + doProcess(testId, "", ProcessOutputTypes.STDERR); + } else if (description.startsWith(OUT)) { + doProcess(testId, description.substring(OUT.length()), ProcessOutputTypes.STDOUT); } else if (description.startsWith(ERR)) { - destination = ProcessOutputTypes.STDERR; - description = description.substring(ERR.length()); + doProcess(testId, description.substring(ERR.length()), ProcessOutputTypes.STDERR); } - - final String output = description; - - doProcess(testId, output, destination); } private void doProcess(String testId, String output, @NotNull Key type) { diff --git a/plugins/gradle/java/testSources/execution/test/GradleJavaTestEventsIntegrationTest.kt b/plugins/gradle/java/testSources/execution/test/GradleJavaTestEventsIntegrationTest.kt index dd485ebf6f07..22face303822 100644 --- a/plugins/gradle/java/testSources/execution/test/GradleJavaTestEventsIntegrationTest.kt +++ b/plugins/gradle/java/testSources/execution/test/GradleJavaTestEventsIntegrationTest.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.externalSystem.model.task.* import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent import com.intellij.openapi.externalSystem.model.task.event.TestOperationDescriptor import com.intellij.openapi.util.Pair +import com.intellij.openapi.util.registry.Registry import com.intellij.testFramework.RunAll import com.intellij.util.ThrowableRunnable import org.assertj.core.api.Assertions.assertThat @@ -21,8 +22,23 @@ import org.junit.Test open class GradleJavaTestEventsIntegrationTest: GradleImportingTestCase() { + override fun setUp() { + super.setUp() + if (testLauncherAPISupported()) { + Registry.get("gradle.testLauncherAPI.enabled").setValue(true) + } + } + + override fun tearDown() { + RunAll( + ThrowableRunnable { Registry.get("gradle.testLauncherAPI.enabled").setValue(false) }, + ThrowableRunnable { super.tearDown() } + ).run() + } + @Test fun test() { + val gradleSupportsJunitPlatform = isGradleNewerOrSameAs("4.6") createProjectSubFile("src/main/java/my/pack/AClass.java", "package my.pack;\n" + diff --git a/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunnerViewTest.kt b/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunnerViewTest.kt index bc65f35f2908..95ec278da64b 100644 --- a/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunnerViewTest.kt +++ b/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunnerViewTest.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMo import com.intellij.openapi.externalSystem.util.ExternalSystemUtil import com.intellij.openapi.project.Project import com.intellij.openapi.util.SystemInfo +import com.intellij.openapi.util.registry.Registry import com.intellij.testFramework.ExtensionTestUtil.maskExtensions import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.RunAll @@ -38,10 +39,12 @@ class GradleTestRunnerViewTest : GradleImportingTestCase() { super.setUp() buildViewTestFixture = BuildViewTestFixture(myProject) buildViewTestFixture.setUp() + Registry.get("gradle.testLauncherAPI.enabled").setValue(true) } override fun tearDown() { RunAll( + ThrowableRunnable { Registry.get("gradle.testLauncherAPI.enabled").setValue(false) }, ThrowableRunnable { if (::buildViewTestFixture.isInitialized) buildViewTestFixture.tearDown() }, ThrowableRunnable { super.tearDown() } ).run() diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleProgressListener.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleProgressListener.java index 5db784a737dd..81b95001bc28 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleProgressListener.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleProgressListener.java @@ -10,17 +10,16 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener; -import com.intellij.openapi.externalSystem.model.task.event.ExternalSystemBuildEvent; +import com.intellij.openapi.externalSystem.model.task.event.TestOperationDescriptor; +import com.intellij.openapi.externalSystem.model.task.event.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.externalSystem.model.task.event.TestOperationDescriptor; -import com.intellij.openapi.externalSystem.model.task.event.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.Navigatable; -import org.gradle.internal.impldep.com.google.gson.GsonBuilder; import com.intellij.util.containers.ContainerUtil; +import org.gradle.internal.impldep.com.google.gson.GsonBuilder; import org.gradle.tooling.ProgressEvent; import org.gradle.tooling.ProgressListener; import org.gradle.tooling.events.FinishEvent; @@ -109,10 +108,10 @@ public class GradleProgressListener implements ProgressListener, org.gradle.tool String message = prefix + outputEvent.getDescriptor().getMessage(); if (descriptor instanceof JvmTestOperationDescriptor) { final TestOperationDescriptor operationDescriptor = convertDescriptor(outputEvent, (JvmTestOperationDescriptor)descriptor); - ExternalSystemStatusEventImpl event = new ExternalSystemStatusEventImpl<>(eventId.id.toString(), - eventId.parentId.toString(), - operationDescriptor,0,0, "", - message); + ExternalSystemMessageEvent event = new ExternalSystemMessageEventImpl<>(eventId.id.toString(), + eventId.parentId.toString(), + operationDescriptor, + message); return new ExternalSystemTaskExecutionEvent(myTaskId, event); } @@ -173,7 +172,7 @@ public class GradleProgressListener implements ProgressListener, org.gradle.tool boolean parentIsTest = descriptor.getParent() instanceof org.gradle.tooling.events.test.TestOperationDescriptor; String parentId = parentIsTest ? descriptor.getParent().getDisplayName() : null; - return new TestOperationDescriptorImpl(id, parentId, descriptor.getDisplayName(), + return new TestOperationDescriptorImpl(descriptor.getDisplayName(), testProgressEvent.getEventTime(), descriptor.getSuiteName(), descriptor.getClassName(),