Search in sources :

Example 1 with JavaTestConfigurationBase

use of com.intellij.execution.JavaTestConfigurationBase in project intellij-community by JetBrains.

the class TestDiscoveryExtension method processAvailableTraces.

private static void processAvailableTraces(RunConfigurationBase configuration) {
    final String tracesDirectory = getTracesDirectory(configuration);
    final TestDiscoveryIndex coverageIndex = TestDiscoveryIndex.getInstance(configuration.getProject());
    synchronized (ourTracesLock) {
        final File tracesDirectoryFile = new File(tracesDirectory);
        final File[] testMethodTraces = tracesDirectoryFile.listFiles((dir, name) -> name.endsWith(".tr"));
        if (testMethodTraces != null) {
            for (File testMethodTrace : testMethodTraces) {
                try {
                    coverageIndex.updateFromTestTrace(testMethodTrace, ((JavaTestConfigurationBase) configuration).getConfigurationModule().getModuleName(), ((JavaTestConfigurationBase) configuration).getFrameworkPrefix());
                    FileUtil.delete(testMethodTrace);
                } catch (IOException e) {
                    LOG.error("Can not load " + testMethodTrace, e);
                }
            }
            final String[] filesInTracedDirectories = tracesDirectoryFile.list();
            if (filesInTracedDirectories == null || filesInTracedDirectories.length == 0) {
                FileUtil.delete(tracesDirectoryFile);
            }
        }
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) JavaTestConfigurationBase(com.intellij.execution.JavaTestConfigurationBase)

Example 2 with JavaTestConfigurationBase

use of com.intellij.execution.JavaTestConfigurationBase in project intellij-community by JetBrains.

the class TestDiscoveryExtension method attachToProcess.

@Override
protected void attachToProcess(@NotNull final RunConfigurationBase configuration, @NotNull final ProcessHandler handler, @Nullable RunnerSettings runnerSettings) {
    if (runnerSettings == null && isApplicableFor(configuration)) {
        final String frameworkPrefix = ((JavaTestConfigurationBase) configuration).getFrameworkPrefix();
        final String moduleName = ((JavaTestConfigurationBase) configuration).getConfigurationModule().getModuleName();
        Disposable disposable = Disposer.newDisposable();
        final Alarm processTracesAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
        final MessageBusConnection connection = configuration.getProject().getMessageBus().connect();
        connection.subscribe(SMTRunnerEventsListener.TEST_STATUS, new SMTRunnerEventsAdapter() {

            private List<String> myCompletedMethodNames = new ArrayList<>();

            @Override
            public void onTestFinished(@NotNull SMTestProxy test) {
                final SMTestProxy.SMRootTestProxy root = test.getRoot();
                if ((root == null || root.getHandler() == handler)) {
                    final String fullTestName = test.getLocationUrl();
                    if (fullTestName != null && fullTestName.startsWith(JavaTestLocator.TEST_PROTOCOL)) {
                        myCompletedMethodNames.add(frameworkPrefix + fullTestName.substring(JavaTestLocator.TEST_PROTOCOL.length() + 3));
                        if (myCompletedMethodNames.size() > 50) {
                            final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
                            myCompletedMethodNames.clear();
                            processTracesAlarm.addRequest(() -> processAvailableTraces(fullTestNames, getTracesDirectory(configuration), moduleName, frameworkPrefix, TestDiscoveryIndex.getInstance(configuration.getProject())), 100);
                        }
                    }
                }
            }

            @Override
            public void onTestingFinished(@NotNull SMTestProxy.SMRootTestProxy testsRoot) {
                if (testsRoot.getHandler() == handler) {
                    processTracesAlarm.cancelAllRequests();
                    processTracesAlarm.addRequest(() -> {
                        processAvailableTraces(configuration);
                        Disposer.dispose(disposable);
                    }, 0);
                    connection.disconnect();
                }
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Alarm(com.intellij.util.Alarm) ArrayList(java.util.ArrayList) SMTRunnerEventsAdapter(com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter) JavaTestConfigurationBase(com.intellij.execution.JavaTestConfigurationBase)

Aggregations

JavaTestConfigurationBase (com.intellij.execution.JavaTestConfigurationBase)2 SMTRunnerEventsAdapter (com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter)1 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)1 Disposable (com.intellij.openapi.Disposable)1 Alarm (com.intellij.util.Alarm)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1