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

2019.2 compatibility #1545

Merged
merged 16 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove reflection from OutputToGeneralTestEventsConverters
Only 2019.2 is now supported, so no need for complicated backwards
compatibility.
  • Loading branch information
KronicDeth committed Aug 15, 2019
commit f16d0945879ebbb31dd68a88035f4a3c3ddf14ba
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,17 @@

import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.sm.runner.OutputLineSplitter;
import com.intellij.execution.testframework.sm.runner.OutputEventSplitter;
import com.intellij.execution.testframework.sm.runner.OutputToGeneralTestEventsConverter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
import org.elixir_lang.mix.runner.Status;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MixOutputToGeneralTestEventsConverter extends OutputToGeneralTestEventsConverter {
private static final Logger LOGGER = Logger.getInstance(MixOutputToGeneralTestEventsConverter.class);
@NotNull
private static final Method SUPER_PROCESS_CONSISTENT_TEXT_METHOD;

static {
try {
SUPER_PROCESS_CONSISTENT_TEXT_METHOD = OutputToGeneralTestEventsConverter.class.getDeclaredMethod(
"processConsistentText",
String.class,
Key.class,
boolean.class
);
// counter `private` in IntelliJ IDEA prior to 2016.2
SUPER_PROCESS_CONSISTENT_TEXT_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

@NotNull
private OutputLineSplitter splitter;
private OutputEventSplitter splitter;
@Nullable
private Status stderrStatus = null;
@Nullable
Expand All @@ -43,23 +21,14 @@ public class MixOutputToGeneralTestEventsConverter extends OutputToGeneralTestEv
MixOutputToGeneralTestEventsConverter(@NotNull String testFrameworkName, @NotNull TestConsoleProperties consoleProperties) {
super(testFrameworkName, consoleProperties);

splitter = new OutputLineSplitter(consoleProperties.isEditable()) {
splitter = new OutputEventSplitter(consoleProperties.isEditable()) {
@Override
protected void onLineAvailable(@NotNull String text, @NotNull Key outputType, boolean tcLikeFakeOutput) {
subProcessConsistentText(text, outputType, tcLikeFakeOutput);
public void onTextAvailable(@NotNull String text, @NotNull Key outputType) {
processConsistentText(text, outputType);
}
};
}

/**
* Flashes the rest of stdout text buffer after output has been stopped
*/
@Override
public void flushBufferBeforeTerminating() {
super.flushBufferBeforeTerminating();
processStatuses();
}

@Override
public void flushBufferOnProcessTermination(int code) {
super.flushBufferOnProcessTermination(code);
Expand All @@ -73,7 +42,7 @@ public void process(String text, Key outputType) {

private void processStatus(@NotNull Status status, @NotNull Key outputType) {
for (String text : status.toTeamCityMessageList()) {
superProcessConsistentText(text, outputType, false);
super.processConsistentText(text, outputType);
}
}

Expand All @@ -89,7 +58,8 @@ private void processStatuses() {
}
}

private void subProcessConsistentText(@NotNull String text, @NotNull Key outputType, boolean tcLikeFakeOutput) {
@Override
public void processConsistentText(@NotNull String text, @NotNull Key outputType) {
if (outputType == ProcessOutputTypes.STDERR) {
if (stderrStatus != null) {
if (text.startsWith(" ")) {
Expand All @@ -98,13 +68,13 @@ private void subProcessConsistentText(@NotNull String text, @NotNull Key outputT
processStatus(stderrStatus, outputType);
stderrStatus = null;
} else {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
super.processConsistentText(text, outputType);
}
} else {
stderrStatus = Status.fromStderrLine(text);

if (stderrStatus == null) {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
super.processConsistentText(text, outputType);
}
}
} else if (outputType == ProcessOutputTypes.STDOUT) {
Expand All @@ -119,19 +89,11 @@ private void subProcessConsistentText(@NotNull String text, @NotNull Key outputT
stdoutStatus = Status.fromStdoutLine(text);

if (stdoutStatus == null) {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
super.processConsistentText(text, outputType);
}
}
} else {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
}
}

private void superProcessConsistentText(@NotNull String text, @NotNull Key outputType, boolean tcLikeFakeOutput) {
try {
SUPER_PROCESS_CONSISTENT_TEXT_METHOD.invoke(this, text, outputType, tcLikeFakeOutput);
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.error(e);
super.processConsistentText(text, outputType);
}
}
}
48 changes: 2 additions & 46 deletions src/org/elixir_lang/espec/State.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import com.intellij.execution.process.ColoredProcessHandler
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.testframework.TestConsoleProperties
import com.intellij.execution.testframework.autotest.ToggleAutoTestAction
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil
import com.intellij.execution.ui.ConsoleView
import org.elixir_lang.console.ElixirConsoleUtil
import org.elixir_lang.mix.State
import java.lang.reflect.InvocationTargetException

private const val TEST_FRAMEWORK_NAME = "ESpec"

Expand All @@ -28,54 +25,13 @@ class State(environment: ExecutionEnvironment, private val configuration: Config
return ColoredProcessHandler(process, commandLine.commandLineString)
}

/**
* Unifies the interface for `SMTestRunnerConnectionUtil.createAndAttachConsole` between 141 and later releases
*/
private fun createAndAttachConsole(testFrameworkName: String,
processHandler: ProcessHandler,
consoleProperties: TestConsoleProperties): ConsoleView? {
val klass = SMTestRunnerConnectionUtil::class.java
var consoleView: ConsoleView? = null

try {
val createAndAttachConsole = klass.getMethod("createAndAttachConsole", String::class.java, ProcessHandler::class.java, TestConsoleProperties::class.java)

try {
consoleView = createAndAttachConsole.invoke(null, testFrameworkName, processHandler, consoleProperties) as ConsoleView
} catch (e: IllegalAccessException) {
LOGGER.error(e)
} catch (e: InvocationTargetException) {
LOGGER.error(e)
}

} catch (noSuchCreateAndAttachConsole3Method: NoSuchMethodException) {
try {
val createAndAttachConsole = klass.getMethod("createAndAttachConsole", String::class.java, ProcessHandler::class.java, TestConsoleProperties::class.java, ExecutionEnvironment::class.java)

try {
consoleView = createAndAttachConsole.invoke(null, testFrameworkName, processHandler, consoleProperties, environment) as ConsoleView
} catch (e: IllegalAccessException) {
LOGGER.error(e)
} catch (e: InvocationTargetException) {
LOGGER.error(e)
}

} catch (noSuchCreateAndAttachConsole4Method: NoSuchMethodException) {
noSuchCreateAndAttachConsole4Method.printStackTrace()
}

}

return consoleView
}

@Throws(ExecutionException::class)
override fun execute(executor: Executor, runner: ProgramRunner<*>): ExecutionResult {
val processHandler = startProcess()

val properties = TestConsoleProperties(configuration, TEST_FRAMEWORK_NAME, executor)
val console = createAndAttachConsole(TEST_FRAMEWORK_NAME, processHandler, properties)
ElixirConsoleUtil.attachFilters(configuration.project, console!!)
val console = SMTestRunnerConnectionUtil.createAndAttachConsole(TEST_FRAMEWORK_NAME, processHandler, properties)
ElixirConsoleUtil.attachFilters(configuration.project, console)

val executionResult = DefaultExecutionResult(console, processHandler, *createActions(console, processHandler))
executionResult.setRestartActions(ToggleAutoTestAction())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,16 @@

import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.sm.runner.OutputLineSplitter;
import com.intellij.execution.testframework.sm.runner.OutputEventSplitter;
import com.intellij.execution.testframework.sm.runner.OutputToGeneralTestEventsConverter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
import org.elixir_lang.mix.runner.Status;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MixOutputToGeneralTestEventsConverter extends OutputToGeneralTestEventsConverter {
private static final Logger LOGGER = Logger.getInstance(MixOutputToGeneralTestEventsConverter.class);
@NotNull
private static final Method SUPER_PROCESS_CONSISTENT_TEXT_METHOD;

static {
try {
SUPER_PROCESS_CONSISTENT_TEXT_METHOD = OutputToGeneralTestEventsConverter.class.getDeclaredMethod(
"processConsistentText",
String.class,
Key.class,
boolean.class
);
// counter `private` in IntelliJ IDEA prior to 2016.2
SUPER_PROCESS_CONSISTENT_TEXT_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

@NotNull
private OutputLineSplitter splitter;
private OutputEventSplitter splitter;
@Nullable
private Status stderrStatus = null;
@Nullable
Expand All @@ -43,10 +20,10 @@ public class MixOutputToGeneralTestEventsConverter extends OutputToGeneralTestEv
MixOutputToGeneralTestEventsConverter(@NotNull String testFrameworkName, @NotNull TestConsoleProperties consoleProperties) {
super(testFrameworkName, consoleProperties);

splitter = new OutputLineSplitter(consoleProperties.isEditable()) {
splitter = new OutputEventSplitter(consoleProperties.isEditable()) {
@Override
protected void onLineAvailable(@NotNull String text, @NotNull Key outputType, boolean tcLikeFakeOutput) {
subProcessConsistentText(text, outputType, tcLikeFakeOutput);
public void onTextAvailable(@NotNull String text, @NotNull Key outputType) {
processConsistentText(text, outputType);
}
};
}
Expand All @@ -73,7 +50,7 @@ public void process(String text, Key outputType) {

private void processStatus(@NotNull Status status, @NotNull Key outputType) {
for (String text : status.toTeamCityMessageList()) {
superProcessConsistentText(text, outputType, false);
super.processConsistentText(text, outputType);
}
}

Expand All @@ -89,7 +66,8 @@ private void processStatuses() {
}
}

private void subProcessConsistentText(@NotNull String text, @NotNull Key outputType, boolean tcLikeFakeOutput) {
@Override
public void processConsistentText(@NotNull String text, @NotNull Key outputType) {
if (outputType == ProcessOutputTypes.STDERR) {
if (stderrStatus != null) {
if (text.startsWith(" ")) {
Expand All @@ -98,13 +76,13 @@ private void subProcessConsistentText(@NotNull String text, @NotNull Key outputT
processStatus(stderrStatus, outputType);
stderrStatus = null;
} else {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
super.processConsistentText(text, outputType);
}
} else {
stderrStatus = Status.fromStderrLine(text);

if (stderrStatus == null) {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
super.processConsistentText(text, outputType);
}
}
} else if (outputType == ProcessOutputTypes.STDOUT) {
Expand All @@ -119,19 +97,11 @@ private void subProcessConsistentText(@NotNull String text, @NotNull Key outputT
stdoutStatus = Status.fromStdoutLine(text);

if (stdoutStatus == null) {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
super.processConsistentText(text, outputType);
}
}
} else {
superProcessConsistentText(text, outputType, tcLikeFakeOutput);
}
}

private void superProcessConsistentText(@NotNull String text, @NotNull Key outputType, boolean tcLikeFakeOutput) {
try {
SUPER_PROCESS_CONSISTENT_TEXT_METHOD.invoke(this, text, outputType, tcLikeFakeOutput);
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.error(e);
super.processConsistentText(text, outputType);
}
}
}
48 changes: 2 additions & 46 deletions src/org/elixir_lang/exunit/State.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import com.intellij.execution.process.ColoredProcessHandler
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.testframework.TestConsoleProperties
import com.intellij.execution.testframework.autotest.ToggleAutoTestAction
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil
import com.intellij.execution.ui.ConsoleView
import org.elixir_lang.console.ElixirConsoleUtil
import org.elixir_lang.mix.State
import java.lang.reflect.InvocationTargetException

private const val TEST_FRAMEWORK_NAME = "ExUnit"

Expand All @@ -28,54 +25,13 @@ class State(environment: ExecutionEnvironment, private val configuration: Config
return ColoredProcessHandler(process, commandLine.commandLineString)
}

/**
* Unifies the interface for `SMTestRunnerConnectionUtil.createAndAttachConsole` between 141 and later releases
*/
private fun createAndAttachConsole(testFrameworkName: String,
processHandler: ProcessHandler,
consoleProperties: TestConsoleProperties): ConsoleView? {
val klass = SMTestRunnerConnectionUtil::class.java
var consoleView: ConsoleView? = null

try {
val createAndAttachConsole = klass.getMethod("createAndAttachConsole", String::class.java, ProcessHandler::class.java, TestConsoleProperties::class.java)

try {
consoleView = createAndAttachConsole.invoke(null, testFrameworkName, processHandler, consoleProperties) as ConsoleView
} catch (e: IllegalAccessException) {
LOGGER.error(e)
} catch (e: InvocationTargetException) {
LOGGER.error(e)
}

} catch (noSuchCreateAndAttachConsole3Method: NoSuchMethodException) {
try {
val createAndAttachConsole = klass.getMethod("createAndAttachConsole", String::class.java, ProcessHandler::class.java, TestConsoleProperties::class.java, ExecutionEnvironment::class.java)

try {
consoleView = createAndAttachConsole.invoke(null, testFrameworkName, processHandler, consoleProperties, environment) as ConsoleView
} catch (e: IllegalAccessException) {
LOGGER.error(e)
} catch (e: InvocationTargetException) {
LOGGER.error(e)
}

} catch (noSuchCreateAndAttachConsole4Method: NoSuchMethodException) {
noSuchCreateAndAttachConsole4Method.printStackTrace()
}

}

return consoleView
}

@Throws(ExecutionException::class)
override fun execute(executor: Executor, runner: ProgramRunner<*>): ExecutionResult {
val processHandler = startProcess()

val properties = TestConsoleProperties(configuration, TEST_FRAMEWORK_NAME, executor)
val console = createAndAttachConsole(TEST_FRAMEWORK_NAME, processHandler, properties)
ElixirConsoleUtil.attachFilters(configuration.project, console!!)
val console = SMTestRunnerConnectionUtil.createAndAttachConsole(TEST_FRAMEWORK_NAME, processHandler, properties)
ElixirConsoleUtil.attachFilters(configuration.project, console)

val executionResult = DefaultExecutionResult(console, processHandler, *createActions(console, processHandler))
executionResult.setRestartActions(ToggleAutoTestAction())
Expand Down