mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gradle] Code review cleanup IDEA-232317 IJ-MR-5829
* Get rid of test operation descriptor IDs (use ProgressEvent ids instead). * Add separate Event for test output - ExternalSystemMessageEvent GitOrigin-RevId: 6df07e4f576c516c8a7b539f006ed9638f7f2506
This commit is contained in:
committed by
intellij-monorepo-bot
parent
981d02ff85
commit
3042bfaaba
+19
@@ -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 <T>
|
||||
*/
|
||||
public interface ExternalSystemMessageEvent<T extends OperationDescriptor> extends ExternalSystemProgressEvent<T>{
|
||||
|
||||
/**
|
||||
* Textual description of event.
|
||||
*
|
||||
* @return arbitrary additional information about status update
|
||||
*/
|
||||
@Nullable
|
||||
default String getDescription() { return null; }
|
||||
}
|
||||
+24
@@ -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<T extends OperationDescriptor> extends BaseExternalSystemProgressEvent<T>
|
||||
implements ExternalSystemMessageEvent<T> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
+1
-11
@@ -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<T extends OperationDescriptor> extends ExternalSystemProgressEvent<T> {
|
||||
public interface ExternalSystemStatusEvent<T extends OperationDescriptor> extends ExternalSystemMessageEvent<T> {
|
||||
/**
|
||||
* The amount of work already performed by the build operation.
|
||||
*
|
||||
@@ -43,12 +41,4 @@ public interface ExternalSystemStatusEvent<T extends OperationDescriptor> 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; }
|
||||
}
|
||||
|
||||
-6
@@ -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();
|
||||
|
||||
+1
-18
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<? extends TestOperationDescriptor> 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);
|
||||
|
||||
@@ -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<? extends TestOperationDescriptor> 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);
|
||||
|
||||
@@ -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<? extends TestOperationDescriptor> 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) {
|
||||
|
||||
@@ -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" +
|
||||
|
||||
@@ -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()
|
||||
|
||||
+8
-9
@@ -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<TestOperationDescriptor> event = new ExternalSystemStatusEventImpl<>(eventId.id.toString(),
|
||||
eventId.parentId.toString(),
|
||||
operationDescriptor,0,0, "",
|
||||
message);
|
||||
ExternalSystemMessageEvent<TestOperationDescriptor> 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(),
|
||||
|
||||
Reference in New Issue
Block a user