mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
zip collected discovery index
This commit is contained in:
+1
-1
@@ -198,7 +198,7 @@ public class TestDiscoveryExtension extends RunConfigurationExtension {
|
||||
discoveryIndex.updateFromTestTrace(testMethodTrace, moduleName, frameworkPrefix);
|
||||
FileUtil.delete(testMethodTrace);
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (Throwable e) {
|
||||
LOG.error("Can not load " + testMethodTrace, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,17 +18,22 @@ package com.intellij;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestListener;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* Used in TestAll to collect data in command line
|
||||
@@ -87,26 +92,27 @@ public class InternalTestDiscoveryListener implements TestListener, Closeable {
|
||||
myCompletedMethodNames.add("j" + className + "." + methodName);
|
||||
|
||||
if (myCompletedMethodNames.size() > 50) {
|
||||
flushCurrentTraces();
|
||||
final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
|
||||
myCompletedMethodNames.clear();
|
||||
myProcessTracesAlarm.addRequest(() -> {
|
||||
flushCurrentTraces(fullTestNames);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void flushCurrentTraces() {
|
||||
final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
|
||||
myCompletedMethodNames.clear();
|
||||
myProcessTracesAlarm.addRequest(() -> {
|
||||
System.out.println("Start compacting to index");
|
||||
try {
|
||||
final Object index = getIndex();
|
||||
final Method method = Class.forName("com.intellij.execution.testDiscovery.TestDiscoveryExtension")
|
||||
.getMethod("processAvailableTraces", fullTestNames.getClass(), myTracesDirectory.getClass(), String.class, String.class, myDiscoveryIndexClass);
|
||||
method.invoke(null, fullTestNames, myTracesDirectory, myModuleName, "j", index);
|
||||
System.out.println("Compacting done.");
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 100);
|
||||
protected void flushCurrentTraces(final String[] fullTestNames) {
|
||||
System.out.println("Start compacting to index");
|
||||
try {
|
||||
final Object index = getIndex();
|
||||
final Method method = Class.forName("com.intellij.execution.testDiscovery.TestDiscoveryExtension")
|
||||
.getMethod("processAvailableTraces", fullTestNames.getClass(), myTracesDirectory.getClass(), String.class, String.class,
|
||||
myDiscoveryIndexClass);
|
||||
method.invoke(null, fullTestNames, myTracesDirectory, myModuleName, "j", index);
|
||||
System.out.println("Compacting done.");
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMethodName(Test test) {
|
||||
@@ -140,10 +146,34 @@ public class InternalTestDiscoveryListener implements TestListener, Closeable {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
myProcessTracesAlarm.cancelAllRequests();
|
||||
final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
|
||||
myCompletedMethodNames.clear();
|
||||
flushCurrentTraces(fullTestNames);
|
||||
zipOutput(myTracesDirectory);
|
||||
myProcessTracesAlarm.addRequest(() -> {
|
||||
flushCurrentTraces();
|
||||
Disposer.dispose(myProcessTracesAlarm);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
private static void zipOutput(String tracesDirectory) {
|
||||
final File[] files = new File(tracesDirectory).listFiles();
|
||||
if (files == null) {
|
||||
System.out.println("No traces found.");
|
||||
return;
|
||||
}
|
||||
System.out.println("Preparing zip.");
|
||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(tracesDirectory + File.separator + "out.zip"))) {
|
||||
for (File file : files) {
|
||||
ZipUtil.addFileToZip(zipOutputStream, file, "/" + file.getName(), null, null);
|
||||
}
|
||||
System.out.println("Zip prepared.");
|
||||
|
||||
for (File file : files) {
|
||||
FileUtil.delete(file);
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user