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);
}
}
}
}
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();
}
}
});
}
}
Aggregations