remove old test protocols

This commit is contained in:
Anna.Kozlova
2016-08-08 17:08:03 +02:00
parent c8ce38de47
commit 6bd2df48e2
137 changed files with 187 additions and 8672 deletions
@@ -23,6 +23,7 @@ import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.execution.testDiscovery.JavaAutoRunManager;
import com.intellij.execution.testframework.*;
import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction;
@@ -48,7 +49,6 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.psi.JavaPsiFacade;
@@ -122,12 +122,9 @@ public abstract class JavaTestFrameworkRunnableState<T extends
return module != null;
}
protected ExecutionResult startSMRunner(Executor executor) throws ExecutionException {
if (!isSmRunnerUsed()) {
return null;
}
getJavaParameters().getVMParametersList().addProperty("idea." + getFrameworkId() + ".sm_runner");
@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
final RunnerSettings runnerSettings = getRunnerSettings();
final SMTRunnerConsoleProperties testConsoleProperties = getConfiguration().createTestConsoleProperties(executor);
@@ -138,7 +135,7 @@ public abstract class JavaTestFrameworkRunnableState<T extends
Disposer.register(getConfiguration().getProject(), consoleView);
final OSProcessHandler handler = createHandler(executor);
consoleView.attachToProcess(handler);
final AbstractTestProxy root = viewer.getRoot();
if (root instanceof TestProxyRoot) {
@@ -180,10 +177,6 @@ public abstract class JavaTestFrameworkRunnableState<T extends
return result;
}
protected boolean isSmRunnerUsed() {
return Registry.is(getFrameworkId() + "_sm");
}
protected abstract void configureRTClasspath(JavaParameters javaParameters);
@Override
@@ -22,11 +22,13 @@ import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.*;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -131,7 +133,6 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
DumbService.getInstance(getProject()).runWhenSmart(() -> {
onFound();
finish();
startListening();
});
}
@@ -163,6 +164,4 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
}
}
}
protected void startListening() {}
}
@@ -15,8 +15,6 @@
*/
package com.intellij.rt.ant.execution;
import com.intellij.rt.execution.junit.segments.PacketWriter;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
@@ -15,8 +15,6 @@
*/
package com.intellij.rt.ant.execution;
import com.intellij.rt.execution.junit.segments.PacketWriter;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.input.InputHandler;
import org.apache.tools.ant.input.InputRequest;
@@ -0,0 +1,51 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.ant.execution;
public class Packet extends PacketWriter {
public static final char ourSpecialSymbol = '$';
public static final char[] ourSymbolsToEncode = new char[] {'\n', '\r', SegmentedStream.SPECIAL_SYMBOL};
public static final int CODE_LENGTH = 2;
public static String encode(String packet) {
StringBuffer buffer = new StringBuffer(packet.length());
for (int i = 0; i < packet.length(); i++) {
char chr = packet.charAt(i);
if (chr == ourSpecialSymbol) {
buffer.append(chr);
buffer.append(chr);
continue;
}
boolean appendChar = true;
for (int j = 0; j < ourSymbolsToEncode.length; j++) {
if (ourSymbolsToEncode[j] == chr) {
buffer.append(ourSpecialSymbol);
final String code = String.valueOf((int)chr);
for (int count = CODE_LENGTH - code.length(); count > 0; count--) {
buffer.append("0");
}
buffer.append(code);
appendChar = false;
break;
}
}
if (appendChar) {
buffer.append(chr);
}
}
return buffer.toString();
}
}
@@ -15,8 +15,6 @@
*/
package com.intellij.rt.ant.execution;
import com.intellij.rt.execution.junit.segments.PacketWriter;
/**
* @author dyoma
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
package com.intellij.rt.ant.execution;
public interface PacketProcessor {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
package com.intellij.rt.ant.execution;
public class PacketWriter {
private final StringBuffer myBody = new StringBuffer();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
package com.intellij.rt.ant.execution;
/**
* @noinspection HardCodedStringLiteral
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
package com.intellij.rt.ant.execution;
import java.io.IOException;
import java.io.OutputStream;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
package com.intellij.rt.ant.execution;
/**
* @noinspection HardCodedStringLiteral
@@ -15,9 +15,6 @@
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import junit.framework.ComparisonFailure;
import java.lang.reflect.Field;
@@ -27,17 +24,19 @@ import java.util.Map;
/**
* @noinspection HardCodedStringLiteral
*/
public class ComparisonDetailsExtractor extends ExceptionPacketFactory {
public class ComparisonDetailsExtractor {
private static Map EXPECTED = new HashMap();
private static Map ACTUAL = new HashMap();
protected String myActual = "";
protected String myExpected = "";
private final Throwable myAssertion;
static {
try {
init(ComparisonFailure.class);
init(org.junit.ComparisonFailure.class);
} catch (Throwable e) {}
}
catch (Throwable e) {
}
}
private static void init(Class exceptionClass) throws NoSuchFieldException {
@@ -51,20 +50,11 @@ public class ComparisonDetailsExtractor extends ExceptionPacketFactory {
}
public ComparisonDetailsExtractor(Throwable assertion, String expected, String actual) {
super(PoolOfTestStates.COMPARISON_FAILURE, assertion);
myAssertion = assertion;
myActual = actual;
myExpected = expected;
}
public static ExceptionPacketFactory create(Throwable assertion) {
try {
return create(assertion, getExpected(assertion), getActual(assertion));
}
catch (Throwable e) {
return new ExceptionPacketFactory(PoolOfTestStates.FAILED_INDEX, assertion);
}
}
public static String getActual(Throwable assertion) throws IllegalAccessException, NoSuchFieldException {
return get(assertion, ACTUAL, "fActual");
}
@@ -73,7 +63,8 @@ public class ComparisonDetailsExtractor extends ExceptionPacketFactory {
return get(assertion, EXPECTED, "fExpected");
}
private static String get(final Throwable assertion, final Map staticMap, final String fieldName) throws IllegalAccessException, NoSuchFieldException {
private static String get(final Throwable assertion, final Map staticMap, final String fieldName)
throws IllegalAccessException, NoSuchFieldException {
String actual;
if (assertion instanceof ComparisonFailure) {
actual = (String)((Field)staticMap.get(ComparisonFailure.class)).get(assertion);
@@ -88,20 +79,4 @@ public class ComparisonDetailsExtractor extends ExceptionPacketFactory {
}
return actual;
}
public static ExceptionPacketFactory create(Throwable assertion, final String expected, String actual) {
return new ComparisonDetailsExtractor(assertion, expected, actual);
}
public Packet createPacket(OutputObjectRegistry registry, Object test) {
Packet packet = super.createPacket(registry, test);
packet.
addLimitedString(wrap(myExpected)).
addLimitedString(wrap(myActual));
return packet;
}
private static String wrap(final String message) {
return message != null ? message : "null";
}
}
@@ -1,37 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
public class ExceptionPacketFactory implements PacketFactory {
private final Throwable myAssertion;
private int myState;
public ExceptionPacketFactory(int state, Throwable assertion) {
myState = state;
myAssertion = assertion;
}
public Packet createPacket(OutputObjectRegistry registry, Object test) {
return registry.createPacket().
setTestState(test, myState).
addThrowable(myAssertion);
}
protected void setState(int state) { myState = state; }
}
@@ -15,11 +15,9 @@
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
import junit.framework.ComparisonFailure;
public class FileComparisonFailure extends ComparisonFailure implements KnownException {
public class FileComparisonFailure extends ComparisonFailure {
private final String myExpected;
private final String myActual;
private final String myFilePath;
@@ -54,23 +52,4 @@ public class FileComparisonFailure extends ComparisonFailure implements KnownExc
public String getActual() {
return myActual;
}
public PacketFactory getPacketFactory() {
return new MyPacketFactory(this, myExpected, myActual, myFilePath);
}
private static class MyPacketFactory extends ComparisonDetailsExtractor {
private final String myFilePath;
MyPacketFactory(ComparisonFailure assertion, String expected, String actual, String filePath) {
super(assertion, expected, actual);
myFilePath = filePath;
}
public Packet createPacket(OutputObjectRegistry registry, Object test) {
Packet packet = super.createPacket(registry, test);
packet.addLimitedString(myFilePath);
return packet;
}
}
}
@@ -1,20 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
public interface KnownException {
PacketFactory getPacketFactory();
}
@@ -1,23 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
public interface PacketFactory {
Packet createPacket(OutputObjectRegistry registry, Object test);
}
@@ -1,123 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
import java.util.Collection;
import java.util.Hashtable;
public abstract class OutputObjectRegistry {
private final Hashtable myKnownKeys = new Hashtable();
private int myLastIndex = 0;
private PacketProcessor myMainTransport;
protected OutputObjectRegistry(PacketProcessor mainTransport, int lastIndex) {
myLastIndex = lastIndex;
myMainTransport = mainTransport;
}
public String referenceTo(Object test) {
if (containsKey(test)) return getKey(test);
return sendObject(test);
}
public String referenceTo(Object test, Collection packets) {
if (containsKey(test)) return getKey(test);
return sendObject(test, packets);
}
private boolean containsKey(Object test) {
return myKnownKeys.containsKey(createObjectWrapper(test));
}
private String getKey(Object test) {
return (String)myKnownKeys.get(createObjectWrapper(test));
}
private void putKey(Object test, String key) {
myKnownKeys.put(createObjectWrapper(test), key);
}
public void forget(Object test) {
myKnownKeys.remove(createObjectWrapper(test));
}
private String sendObject(Object test, Collection packets) {
final String key = String.valueOf(myLastIndex++);
putKey(test, key);
final Packet packet = createPacket();
packet.addString(PoolOfDelimiters.OBJECT_PREFIX).addReference(key);
addStringRepresentation(test, packet);
packet.addLong(getTestCont(test));
packet.addString(PoolOfDelimiters.REFERENCE_END_STR);
packets.add(packet);
return key;
}
public Packet createPacket() {
return new Packet(myMainTransport, this);
}
private String sendObject(Object test) {
final String key = String.valueOf(myLastIndex++);
putKey(test, key);
Packet packet = createPacket().addString(PoolOfDelimiters.OBJECT_PREFIX).addReference(key);
addStringRepresentation(test, packet);
packet.addLong(getTestCont(test));
packet.send();
return key;
}
protected abstract int getTestCont(Object test);
protected abstract void addStringRepresentation(Object test, Packet packet);
protected static void addTestClass(Packet packet, String className) {
packet.
addLimitedString(PoolOfTestTypes.TEST_CLASS).
addLimitedString(className);
}
protected void addUnknownTest(Packet packet, Object test) {
packet.
addLimitedString(PoolOfTestTypes.UNKNOWN).
addLong(getTestCont(test)).
addLimitedString(test.getClass().getName());
}
protected static void addAllInPackage(Packet packet, String name) {
packet.
addLimitedString(PoolOfTestTypes.ALL_IN_PACKAGE).
addLimitedString(name);
}
protected static void addTestMethod(Packet packet, String methodName, String className) {
packet.
addLimitedString(PoolOfTestTypes.TEST_METHOD).
addLimitedString(methodName).
addLimitedString(className);
}
public int getKnownObject(Object description) {
final Object o = getKey(description);
if (o instanceof String) {
return Integer.parseInt((String)o);
}
return 0;
}
protected Object createObjectWrapper(Object object) {
return object;
}
}
@@ -1,155 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
import junit.runner.BaseTestRunner;
import java.io.*;
import java.util.Collection;
import java.util.Vector;
public class Packet extends PacketWriter {
private final OutputObjectRegistry myRegistry;
private final PacketProcessor myTransport;
public static final char ourSpecialSymbol = '$';
public static final char[] ourSymbolsToEncode = new char[] {'\n', '\r', SegmentedStream.SPECIAL_SYMBOL};
public static final int CODE_LENGTH = 2;
public Packet(PacketProcessor transport, OutputObjectRegistry registry) {
myTransport = transport;
myRegistry = registry;
}
public Packet addObject(Object test) {
return addReference(myRegistry.referenceTo(test));
}
public Packet addObject(Object test, Collection packet) {
return addReference(myRegistry.referenceTo(test, packet));
}
public Packet addReference(String reference) {
appendString(reference + PoolOfDelimiters.REFERENCE_END);
return this;
}
public Packet switchInputTo(Object test) {
appendString(PoolOfDelimiters.INPUT_COSUMER);
return addObject(test);
}
public Packet addString(String string) {
appendString(string);
return this;
}
public void send() {
sendThrough(myTransport);
}
public Packet addLong(long integer) {
appendLong(integer);
return this;
}
public Packet setTestState(Object test, int state) {
return addString(PoolOfDelimiters.CHANGE_STATE).addObject(test).addLong(state);
}
public Packet addLimitedString(String message) {
appendLimitedString(message);
return this;
}
public Packet addThrowable(Throwable throwable) {
String filteredTrace;
try {
filteredTrace = BaseTestRunner.getFilteredTrace(throwable);
}
catch (Throwable e) {
filteredTrace = BaseTestRunner.getFilteredTrace(e);
}
String message;
try {
message = BaseTestRunner.getPreference("filterstack").equals("true") ? makeNewLinesCompatibleWithJUnit(throwableToString(throwable)) : throwableToString(throwable);
}
catch (Throwable e) {
message = throwableToString(e);
}
addLimitedString(message);
if (filteredTrace.startsWith(message))
filteredTrace = filteredTrace.substring(message.length());
addLimitedString(new TraceFilter(filteredTrace).execute());
return this;
}
private static String throwableToString(final Throwable throwable) {
final String tostring = throwable.toString();
return tostring == null ? throwable.getClass().getName() : tostring;
}
private static String makeNewLinesCompatibleWithJUnit(String string) {
try {
StringWriter buffer = new StringWriter();
PrintWriter writer = new PrintWriter(buffer);
BufferedReader reader = new BufferedReader(new StringReader(string));
String line;
while ((line = reader.readLine()) != null)
writer.println(line);
return buffer.getBuffer().toString();
} catch (IOException e) {return null;}
}
public static String encode(String packet) {
StringBuffer buffer = new StringBuffer(packet.length());
for (int i = 0; i < packet.length(); i++) {
char chr = packet.charAt(i);
if (chr == ourSpecialSymbol) {
buffer.append(chr);
buffer.append(chr);
continue;
}
boolean appendChar = true;
for (int j = 0; j < ourSymbolsToEncode.length; j++) {
if (ourSymbolsToEncode[j] == chr) {
buffer.append(ourSpecialSymbol);
final String code = String.valueOf((int)chr);
for (int count = CODE_LENGTH - code.length(); count > 0; count--) {
buffer.append("0");
}
buffer.append(code);
appendChar = false;
break;
}
}
if (appendChar) {
buffer.append(chr);
}
}
return buffer.toString();
}
public Packet addStrings(Vector vector) {
int size = vector.size();
addLong(size);
for (int i = 0; i < size; i++) {
addLimitedString((String)vector.elementAt(i));
}
return this;
}
}
@@ -1,27 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
/**
* @noinspection HardCodedStringLiteral
*/
public interface PoolOfTestTypes {
String TEST_METHOD = "TM";
String TEST_CLASS = "TC";
String ALL_IN_PACKAGE = "TN";
String UNKNOWN = "TU";
}
@@ -1,67 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.segments;
import java.io.*;
import java.util.Vector;
class TraceFilter {
private final String myTrace;
private final Vector myLines = new Vector();
public TraceFilter(String trace) {
myTrace = trace;
}
public String execute() {
try {
readLines();
} catch (IOException e) {
return myTrace;
}
int traceLastLine = firstJUnitLine(myLines.size() - 1, true);
if (traceLastLine < 0) return "";
int traceFirstLine = firstJUnitLine(traceLastLine, false);
StringWriter buffer = new StringWriter();
PrintWriter writer = new PrintWriter(buffer);
for (int i = 0; i < traceFirstLine; i++) writer.println(myLines.elementAt(i));
for (int i = traceLastLine; i < myLines.size(); i++) writer.println(myLines.elementAt(i));
writer.flush();
return buffer.toString();
}
private int firstJUnitLine(int startFrom, boolean searchForJUnitLines) {
for (int i = startFrom; i >= 0; i--) {
String line = (String) myLines.elementAt(i);
if (isIdeaJUnit(line) == searchForJUnitLines) return i;
}
return startFrom;
}
/**
* @noinspection HardCodedStringLiteral
*/
private boolean isIdeaJUnit(String line) {
return line.indexOf("com.intellij.rt") >= 0;
}
private void readLines() throws IOException {
BufferedReader reader = new BufferedReader(new StringReader(myTrace));
String line;
while ((line = reader.readLine()) != null) { myLines.addElement(line); }
reader.close();
}
}
@@ -1,29 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit.states;
public interface PoolOfTestStates {
int SKIPPED_INDEX = 0;
int COMPLETE_INDEX = 1;
int NOT_RUN_INDEX = 2;
int RUNNING_INDEX = 3;
int TERMINATED_INDEX = 4;
int IGNORED_INDEX = 5;
int FAILED_INDEX = 6;
int COMPARISON_FAILURE = 7;
int ERROR_INDEX = 8;
int PASSED_INDEX = COMPLETE_INDEX;
}
@@ -60,10 +60,8 @@ public abstract class ForkedByModuleSplitter {
bufferedReader.close();
}
long time = System.currentTimeMillis();
int result = startSplitting(args, configName, repeatCount);
myForkedDebuggerHelper.closeDebugSocket();
sendTime(time);
return result;
}
@@ -154,9 +152,6 @@ public abstract class ForkedByModuleSplitter {
String repeatCount, int result) throws Exception;
protected abstract String getStarterName();
protected void sendTime(long time) {}
protected void sendTree(Object rootDescription) {}
public static File createClasspathJarFile(Manifest manifest, String classpath) throws IOException {
final Attributes attributes = manifest.getMainAttributes();
@@ -39,7 +39,6 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
if (myRootDescription == null) {
return -1;
}
sendTree(myRootDescription);
if (myWorkingDirsPath == null || new File(myWorkingDirsPath).length() == 0) {
final String classpath = System.getProperty("java.class.path");
if (repeatCount != null && RepeatCount.getCount(repeatCount) != 0 && myForkMode.equals("repeat")) {
@@ -47,8 +47,8 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.rt.ant.execution.SegmentedOutputStream;
import com.intellij.rt.execution.junit.JUnitStarter;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import com.intellij.testFramework.MapDataContext;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.PsiTestUtil;
@@ -428,8 +428,6 @@ ui.no.bangs.and.whistles=false
comment.by.line.bulk.lines.trigger=100
junit_sm=true
testng_sm=true
show.flex.debug.design.view=false
diff.patience.alg=false
@@ -15,7 +15,6 @@
*/
package com.intellij.lang.ant.config.execution;
import com.intellij.execution.junit2.segments.OutputPacketProcessor;
import com.intellij.execution.testframework.Printable;
import com.intellij.execution.testframework.Printer;
import com.intellij.ide.CommonActionsManager;
@@ -32,6 +31,7 @@ import com.intellij.lang.ant.config.actions.*;
import com.intellij.lang.ant.config.impl.AntBuildFileImpl;
import com.intellij.lang.ant.config.impl.BuildFileProperty;
import com.intellij.lang.ant.config.impl.HelpID;
import com.intellij.lang.ant.segments.OutputPacketProcessor;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
@@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit;
package com.intellij.lang.ant.config.execution;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.junit2.segments.Extractor;
import com.intellij.execution.process.KillableColoredProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessTerminatedListener;
import com.intellij.lang.ant.segments.Extractor;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.io.BaseOutputReader;
import org.jetbrains.annotations.NotNull;
@@ -31,11 +31,11 @@ import java.io.Reader;
/**
* @author dyoma
*/
public class JUnitProcessHandler extends KillableColoredProcessHandler {
public class AntProcessHandler extends KillableColoredProcessHandler {
private final Extractor myOut;
private final Extractor myErr;
private JUnitProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
private AntProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
super(commandLine);
myOut = new Extractor(getProcess().getInputStream(), commandLine.getCharset());
@@ -72,8 +72,8 @@ public class JUnitProcessHandler extends KillableColoredProcessHandler {
}
@NotNull
public static JUnitProcessHandler runCommandLine(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
final JUnitProcessHandler processHandler = new JUnitProcessHandler(commandLine);
public static AntProcessHandler runCommandLine(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
final AntProcessHandler processHandler = new AntProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
@@ -20,8 +20,6 @@ import com.intellij.execution.CantRunException;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.CommandLineBuilder;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.junit.JUnitProcessHandler;
import com.intellij.execution.junit2.segments.OutputPacketProcessor;
import com.intellij.execution.process.*;
import com.intellij.execution.testframework.Printable;
import com.intellij.execution.testframework.Printer;
@@ -33,6 +31,7 @@ import com.intellij.lang.ant.config.AntBuildFileBase;
import com.intellij.lang.ant.config.AntBuildListener;
import com.intellij.lang.ant.config.AntBuildTarget;
import com.intellij.lang.ant.config.impl.BuildFileProperty;
import com.intellij.lang.ant.segments.OutputPacketProcessor;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -183,9 +182,9 @@ public final class ExecutionHandler {
final long startTime = System.currentTimeMillis();
LocalHistory.getInstance().putSystemLabel(project, AntBundle.message("ant.build.local.history.label", buildFile.getName()));
final JUnitProcessHandler handler;
final AntProcessHandler handler;
try {
handler = JUnitProcessHandler.runCommandLine(commandLine);
handler = AntProcessHandler.runCommandLine(commandLine);
}
catch (final ExecutionException e) {
ApplicationManager.getApplication().invokeLater(
@@ -199,7 +198,7 @@ public final class ExecutionHandler {
}
private static void processRunningAnt(final ProgressIndicator progress,
final JUnitProcessHandler handler,
final AntProcessHandler handler,
final AntBuildMessageView errorView,
final AntBuildFileBase buildFile,
final long startTime,
@@ -15,9 +15,9 @@
*/
package com.intellij.lang.ant.config.execution;
import com.intellij.execution.junit2.segments.SegmentReader;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.lang.ant.AntBundle;
import com.intellij.lang.ant.segments.SegmentReader;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ex.MessagesEx;
@@ -15,18 +15,17 @@
*/
package com.intellij.lang.ant.config.execution;
import com.intellij.execution.junit.JUnitProcessHandler;
import com.intellij.execution.junit2.segments.*;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.testframework.Printable;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.lang.ant.config.AntBuildFile;
import com.intellij.lang.ant.segments.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ex.MessagesEx;
import com.intellij.rt.ant.execution.IdeaAntLogger2;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
import com.intellij.rt.ant.execution.PacketProcessor;
import java.io.IOException;
@@ -87,7 +86,7 @@ final class OutputParser2 extends OutputParser implements PacketProcessor, Input
}
public static OutputParser attachParser(final Project myProject,
JUnitProcessHandler handler,
AntProcessHandler handler,
final AntBuildMessageView errorView,
final ProgressIndicator progress,
final AntBuildFile buildFile) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
public interface DeferredActionsQueue {
void addLast(Runnable runnable);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
import com.intellij.openapi.diagnostic.Logger;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
public interface DispatchListener {
void onStarted();
@@ -13,15 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
import com.intellij.execution.junit.SegmentedInputStreamReader;
import com.intellij.execution.junit2.SegmentedInputStream;
import com.intellij.execution.testframework.Printable;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
import com.intellij.rt.ant.execution.PacketProcessor;
import com.intellij.util.concurrency.SequentialTaskExecutor;
import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
import com.intellij.execution.ui.ConsoleViewContentType;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
import com.intellij.execution.testframework.Printable;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
import com.intellij.rt.ant.execution.PacketProcessor;
/**
* User: anna
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2;
package com.intellij.lang.ant.segments;
import gnu.trove.TIntArrayList;
import org.jetbrains.annotations.NonNls;
import java.io.IOException;
import java.io.Reader;
import org.jetbrains.annotations.NonNls;
/**
* @author dyoma
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
package com.intellij.lang.ant.segments;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import com.intellij.rt.ant.execution.PoolOfDelimiters;
import com.intellij.util.ArrayUtil;
import java.util.ArrayList;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2;
package com.intellij.lang.ant.segments;
import com.intellij.rt.execution.junit.segments.Packet;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
import com.intellij.rt.execution.junit.segments.SegmentedStream;
import com.intellij.rt.ant.execution.Packet;
import com.intellij.rt.ant.execution.PacketProcessor;
import com.intellij.rt.ant.execution.SegmentedStream;
import com.intellij.util.StringBuilderSpinAllocator;
import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit;
package com.intellij.lang.ant.segments;
import com.intellij.execution.junit2.SegmentedInputStream;
import java.io.IOException;
import java.io.Reader;
@@ -19,37 +19,23 @@ package com.intellij.execution.junit;
import com.intellij.execution.*;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.execution.configurations.RunnerSettings;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.junit.testDiscovery.TestBySource;
import com.intellij.execution.junit.testDiscovery.TestsByChanges;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.segments.DeferredActionsQueue;
import com.intellij.execution.junit2.segments.DeferredActionsQueueImpl;
import com.intellij.execution.junit2.segments.DispatchListener;
import com.intellij.execution.junit2.segments.Extractor;
import com.intellij.execution.junit2.ui.JUnitTreeConsoleView;
import com.intellij.execution.junit2.ui.TestsPacketsReceiver;
import com.intellij.execution.junit2.ui.actions.RerunFailedTestsAction;
import com.intellij.execution.junit2.ui.model.CompletionEvent;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.model.RootTestInfo;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.process.*;
import com.intellij.execution.process.KillableColoredProcessHandler;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessTerminatedListener;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.execution.testframework.*;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.execution.testframework.SearchForTestsTask;
import com.intellij.execution.testframework.SourceScope;
import com.intellij.execution.testframework.TestSearchScope;
import com.intellij.execution.util.JavaParametersUtil;
import com.intellij.execution.util.ProgramParametersUtil;
import com.intellij.junit5.JUnit5IdeaTestRunner;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
@@ -202,129 +188,6 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
return javaParameters;
}
@NotNull
@Override
public ExecutionResult execute(@NotNull final Executor executor, @NotNull final ProgramRunner runner) throws ExecutionException {
final ExecutionResult executionResult = startSMRunner(executor);
if (executionResult != null) {
return executionResult;
}
final JUnitProcessHandler handler = createJUnitHandler(executor);
final RunnerSettings runnerSettings = getRunnerSettings();
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
final TestProxy unboundOutputRoot = new TestProxy(new RootTestInfo());
final JUnitConsoleProperties consoleProperties = new JUnitConsoleProperties(getConfiguration(), executor);
final JUnitTreeConsoleView consoleView = new JUnitTreeConsoleView(consoleProperties, getEnvironment(), unboundOutputRoot);
Disposer.register(getConfiguration().getProject(), consoleView);
consoleView.initUI();
consoleView.attachToProcess(handler);
unboundOutputRoot.setPrinter(consoleView.getPrinter());
Disposer.register(consoleView, unboundOutputRoot);
final TestsPacketsReceiver packetsReceiver = new TestsPacketsReceiver(consoleView, unboundOutputRoot) {
@Override
public synchronized void notifyStart(TestProxy root) {
if (!isRunning()) return;
super.notifyStart(root);
unboundOutputRoot.addChild(root);
if (getConfiguration().isSaveOutputToFile()) {
unboundOutputRoot.setOutputFilePath(getConfiguration().getOutputFilePath());
}
final JUnitRunningModel model = getModel();
if (model != null) {
handler.getOut().setDispatchListener(model.getNotifier());
Disposer.register(model, new Disposable() {
@Override
public void dispose() {
handler.getOut().setDispatchListener(DispatchListener.DEAF);
}
});
consoleView.attachToModel(model);
}
}
};
Disposer.register(consoleView, packetsReceiver);
final DeferredActionsQueue queue = new DeferredActionsQueueImpl();
handler.getOut().setPacketDispatcher(packetsReceiver, queue);
handler.getErr().setPacketDispatcher(packetsReceiver, queue);
handler.addProcessListener(new ProcessAdapter() {
private boolean myStarted = false;
@Override
public void startNotified(ProcessEvent event) {
myStarted = true;
}
@Override
public void processTerminated(ProcessEvent event) {
handler.removeProcessListener(this);
deleteTempFiles();
final Runnable runnable = () -> {
unboundOutputRoot.flush();
packetsReceiver.checkTerminated();
final JUnitRunningModel model = packetsReceiver.getModel();
notifyByBalloon(model, myStarted, consoleProperties);
};
handler.getOut().addRequest(runnable, queue);
}
@Override
public void onTextAvailable(final ProcessEvent event, final Key outputType) {
final String text = event.getText();
final ConsoleViewContentType consoleViewType = ConsoleViewContentType.getConsoleViewType(outputType);
final Printable printable = new Printable() {
@Override
public void printOn(final Printer printer) {
printer.print(text, consoleViewType);
}
};
final Extractor extractor;
if (consoleViewType == ConsoleViewContentType.ERROR_OUTPUT ||
consoleViewType == ConsoleViewContentType.SYSTEM_OUTPUT) {
extractor = handler.getErr();
}
else {
extractor = handler.getOut();
}
extractor.getEventsDispatcher().processOutput(printable);
}
});
final RerunFailedTestsAction rerunFailedTestsAction = new RerunFailedTestsAction(consoleView, consoleProperties);
rerunFailedTestsAction.setModelProvider(() -> packetsReceiver.getModel());
final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
result.setRestartActions(rerunFailedTestsAction);
return result;
}
protected void notifyByBalloon(JUnitRunningModel model, boolean started, JUnitConsoleProperties consoleProperties) {
String comment;
if (model != null) {
final CompletionEvent done = model.getProgress().getDone();
comment = done != null ? done.getComment() : null;
}
else {
comment = null;
}
TestsUIUtil.notifyByBalloon(consoleProperties.getProject(), started, model != null ? model.getRoot() : null, consoleProperties, comment);
}
@NotNull
protected JUnitProcessHandler createJUnitHandler(Executor executor) throws ExecutionException {
appendForkInfo(executor);
final String repeatMode = getConfiguration().getRepeatMode();
if (!RepeatCount.ONCE.equals(repeatMode)) {
final int repeatCount = getConfiguration().getRepeatCount();
final String countString = RepeatCount.N.equals(repeatMode) && repeatCount > 0
? RepeatCount.getCountString(repeatCount)
: repeatMode;
getJavaParameters().getProgramParametersList().add(countString);
}
return JUnitProcessHandler.runCommandLine(createCommandLine());
}
@NotNull
protected OSProcessHandler createHandler(Executor executor) throws ExecutionException {
appendForkInfo(executor);
@@ -20,10 +20,7 @@ import com.intellij.execution.*;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.configurations.RuntimeConfigurationWarning;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.ResetConfigurationModuleAdapter;
import com.intellij.execution.testframework.SearchForTestsTask;
import com.intellij.execution.testframework.SourceScope;
import com.intellij.execution.testframework.TestSearchScope;
@@ -40,7 +37,6 @@ import com.intellij.psi.search.PackageScope;
import com.intellij.refactoring.listeners.RefactoringElementListener;
import com.intellij.util.Function;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -60,14 +56,6 @@ public class TestPackage extends TestObject {
return data.getScope().getSourceScope(getConfiguration());
}
@NotNull
@Override
protected JUnitProcessHandler createJUnitHandler(Executor executor) throws ExecutionException {
final JUnitProcessHandler handler = super.createJUnitHandler(executor);
createSearchingForTestsTask().attachTaskToProcess(handler);
return handler;
}
@Override
public SearchForTestsTask createSearchingForTestsTask() {
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
@@ -207,13 +195,6 @@ public class TestPackage extends TestObject {
}
}
@Override
protected void notifyByBalloon(JUnitRunningModel model, boolean started, final JUnitConsoleProperties consoleProperties) {
if (myFoundTests || !ResetConfigurationModuleAdapter.tryWithAnotherModule(getConfiguration(), consoleProperties.isDebug())) {
super.notifyByBalloon(model, started, consoleProperties);
}
}
@TestOnly
public File getWorkingDirsFile() {
return myWorkingDirsFile;
@@ -1,82 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Filter;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import java.util.*;
class FilterCache {
private final ArrayList<TestProxy> myList = new ArrayList<TestProxy>(4);
private final Set<TestProxy> mySet = new HashSet<TestProxy>();
private final Map<Filter, ArrayList<TestProxy>> myCache = new THashMap<Filter, ArrayList<TestProxy>>();
public TestProxy[] select(final Filter filter) {
final ArrayList<TestProxy> selected = selectImpl(filter);
return selected.toArray(new TestProxy[selected.size()]);
}
public List<TestProxy> getList() {
return myList;
}
public void resetCache() {
myCache.clear();
}
public List<TestProxy> getUnmodifiableList() {
return Collections.unmodifiableList(myList);
}
public void insert(TestProxy child, int idx) {
if (idx >= 0) {
myList.add(idx, child);
} else {
myList.add(child);
}
mySet.add(child);
resetCache();
}
public boolean contains(TestProxy test) {
return mySet.contains(test);
}
public AbstractTestProxy detect(final Filter filter) {
return filter.detectIn(myList);
}
public Iterator iterator() {
return myList.iterator();
}
private ArrayList<TestProxy> selectImpl(@NotNull final Filter filter) {
final ArrayList<TestProxy> result = myCache.get(filter);
if (result != null) return result;
final ArrayList<TestProxy> selected = new ArrayList<TestProxy>();
for (final TestProxy childTest : myList) {
if (filter.shouldAccept(childTest)) selected.add(childTest);
}
selected.trimToSize();
myCache.put(filter, selected);
return selected;
}
}
@@ -1,354 +0,0 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.events.*;
import com.intellij.execution.junit2.info.MethodLocation;
import com.intellij.execution.junit2.info.TestInfo;
import com.intellij.execution.junit2.states.ComparisonFailureState;
import com.intellij.execution.junit2.states.IgnoredState;
import com.intellij.execution.junit2.states.Statistics;
import com.intellij.execution.junit2.states.TestState;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Filter;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.stacktrace.DiffHyperlink;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.pom.Navigatable;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class TestProxy extends AbstractTestProxy {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.TestProxy");
private final TestInfo myInfo;
private TestState myState = TestState.DEFAULT;
private final TestProxyListenersNotifier myNotifier = new TestProxyListenersNotifier();
private Statistics myStatistics = new Statistics();
private TestEventsConsumer myEventsConsumer;
private int myPreviousMagnitude = -1;
private int myStateTimestamp = 0;
// private ArrayList myChildren = new ArrayList();
private final FilterCache myChildren = new FilterCache();
private TestProxy myParent = null;
public static final Filter NOT_LEAF = Filter.LEAF.not();
public TestProxy(@NotNull final TestInfo info) {
myInfo = info;
}
public String toString() {
return getInfo().getComment() + "." + getInfo().getName();
}
public TestState getState() {
return myState;
}
public void setState(final TestState state) {
if (myState != state) {
if (state.isFinal()) {
addLast(state);
} else {
fireOnNewPrintable(state);
}
if (myState != null) {
state.merge(myState, getParent());
}
myState = state;
fireStateChanged();
}
}
public void fireStateChanged() {
myStateTimestamp++;
pullEvent(new StateChangedEvent(this));
if (myParent != null)
myParent.onChanged(this);
myNotifier.onChanged(this);
}
public int getStateTimestamp() {
return myStateTimestamp;
}
public int getChildCount() {
return myChildren.getList().size();
}
public List<TestProxy> getChildren() {
return myChildren.getUnmodifiableList();
}
public TestProxy getParent() {
return myParent;
}
public Navigatable getDescriptor(@Nullable Location location, @NotNull TestConsoleProperties properties) {
return getState().getDescriptor(location);
}
public String getName() {
return getInfo().getName();
}
@Override
public boolean isConfig() {
return false;
}
public boolean isInProgress() {
return getState().isInProgress();
}
public boolean isDefect() {
return getState().isDefect();
}
public boolean shouldRun() {
return getInfo().shouldRun();
}
public int getMagnitude() {
return getState().getMagnitude();
}
public Location getLocation(@NotNull final Project project, @NotNull GlobalSearchScope searchScope) {
final Location location = getInfo().getLocation(project, searchScope);
if (location == null) {
return checkParentParameterized(project, searchScope);
} else {
Location parentLocation = getParent().getLocation(project, searchScope);
if (parentLocation instanceof PsiMemberParameterizedLocation) {
return new PsiMemberParameterizedLocation(project,
location.getPsiElement(),
location instanceof MethodLocation ? ((MethodLocation)location).getContainingClass() : null,
((PsiMemberParameterizedLocation)parentLocation).getParamSetName());
}
}
return location;
}
private Location checkParentParameterized(Project project, GlobalSearchScope searchScope) {
final TestProxy parent = getParent();
if (parent != null) {
final Location parentLocation = parent.getLocation(project, searchScope);
if (parentLocation != null) {
final PsiElement parentElement = parentLocation.getPsiElement();
if (parentElement instanceof PsiClass) {
return PsiMemberParameterizedLocation.getParameterizedLocation((PsiClass)parentElement, getInfo().getName());
}
}
}
return null;
}
public boolean isLeaf() {
return getChildCount() == 0;
}
@Override
public boolean isInterrupted() {
return getMagnitude() == PoolOfTestStates.TERMINATED_INDEX;
}
@Override
public boolean hasPassedTests() {
return isPassed();
}
@Override
public boolean isIgnored() {
return myState instanceof IgnoredState;
}
public boolean isPassed() {
return getMagnitude() <= PoolOfTestStates.PASSED_INDEX;
}
public void addChild(final TestProxy child) {
addChild(child, -1);
}
public void addChild(final TestProxy child, final int idx) {
if (myChildren.contains(child))
return;
if (child.getParent() != null)
return;//todo throw new RuntimeException("Test: "+child + " already has parent: " + child.getParent());
myChildren.insert(child, idx);
child.myParent = this;
addLast(child);
child.setPrinter(myPrinter);
pullEvent(new NewChildEvent(this, child));
getState().changeStateAfterAddingChildTo(this, child);
myNotifier.onChildAdded(this, child);
}
public void insertNextRunningChild(final TestProxy child) {
int idx = -1;
List<TestProxy> list = myChildren.getList();
for (int i = 0; i < list.size(); i++) {
TestProxy proxy = list.get(i);
if (!proxy.getState().isFinal()) {
idx = i;
break;
}
}
addChild(child, idx);
}
public TestInfo getInfo() {
return myInfo;
}
public void onChanged(final AbstractTestProxy test) {
myChildren.resetCache();
final int magnitude = test.getMagnitude();
getState().update();
if (myPreviousMagnitude < magnitude || getState().getMagnitude() <= magnitude) {
fireStateChanged();
myPreviousMagnitude = getState().getMagnitude();
}
}
public void onStatisticsChanged() {
myChildren.resetCache();
if (myParent != null)
myParent.onStatisticsChanged();
pullEvent(new StatisticsChanged(this));
myNotifier.onStatisticsChanged(this);
}
public void addListener(final TestProxyListener listener) {
myNotifier.addListener(listener);
}
public void setStatistics(final Statistics statistics) {
if (!myState.isFinal()) {
LOG.error(String.valueOf(myState.getMagnitude()));
}
myStatistics = statistics;
onStatisticsChanged();
}
public Statistics getStatisticsImpl() {
return myStatistics;
}
public boolean hasChildSuites() {
return myChildren.detect(NOT_LEAF) != null;
}
public Statistics getStatistics() {
return myState.getStatisticsFor(this);
}
public TestProxy[] selectChildren(final Filter filter) {
return myChildren.select(filter);
}
public void setEventsConsumer(final TestEventsConsumer eventsConsumer) {
myEventsConsumer = eventsConsumer;
}
private void pullEvent(final TestEvent event) {
if (myEventsConsumer != null) {
myEventsConsumer.onEvent(event);
return;
}
if (myParent != null)
myParent.pullEvent(event);
}
public List<TestProxy> getAllTests() {
return myState.getAllTestsOf(this);
}
public void collectAllTestsTo(final ArrayList<TestProxy> allTests) {
allTests.add(this);
for (Iterator iterator = myChildren.iterator(); iterator.hasNext();) {
final TestProxy testProxy = (TestProxy) iterator.next();
testProxy.collectAllTestsTo(allTests);
}
}
public TestProxy getCommonAncestor(final TestProxy test) {
if (test == null) return this;
if (test.isAncestorOf(this)) return test;
for (TestProxy parent = this; parent != null; parent = parent.getParent())
if (parent.isAncestorOf(test)) return parent;
return null;
}
public boolean isAncestorOf(final TestProxy test) {
if (test == null) return false;
for (TestProxy parent = test; parent != null; parent = parent.getParent())
if (parent == this) return true;
return false;
}
public AbstractTestProxy[] getPathFromRoot() {
final ArrayList<TestProxy> parents = new ArrayList<TestProxy>();
TestProxy test = this;
do {
parents.add(test);
} while ((test = test.getParent()) != null);
Collections.reverse(parents);
return parents.toArray(new TestProxy[parents.size()]);
}
@Override
public Long getDuration() {
return (long) getStatistics().getTime();
}
@Override
public boolean shouldSkipRootNodeForExport() {
return false;
}
@Override
@Nullable
public DiffHyperlink getDiffViewerProvider() {
if (myState instanceof ComparisonFailureState) {
return ((ComparisonFailureState)myState).getHyperlink();
}
for (TestProxy proxy : getChildren()) {
if (!proxy.isDefect()) continue;
final DiffHyperlink provider = proxy.getDiffViewerProvider();
if (provider != null) {
return provider;
}
}
return null;
}
}
@@ -1,27 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2;
import com.intellij.execution.testframework.AbstractTestProxy;
public interface TestProxyListener {
TestProxyListener[] EMPTY_ARRAY = new TestProxyListener[0];
void onChildAdded(AbstractTestProxy parent, AbstractTestProxy newChild);
void onChanged(AbstractTestProxy proxy);
void onStatisticsChanged(AbstractTestProxy testProxy);
}
@@ -1,61 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2;
import com.intellij.execution.testframework.AbstractTestProxy;
import java.util.ArrayList;
public class TestProxyListenersNotifier implements TestProxyListener {
private ArrayList<TestProxyListener> myListeners;
private TestProxyListener[] myCachedListeners;
public void addListener(final TestProxyListener listener) {
if (myListeners == null) myListeners = new ArrayList<TestProxyListener>();
if (myListeners.contains(listener)) return;
myListeners.add(listener);
myCachedListeners = null;
}
public void onChanged(final AbstractTestProxy test) {
final TestProxyListener[] listeners = getListeners();
for (int i = 0; i < listeners.length; i++)
listeners[i].onChanged(test);
}
public void onChildAdded(final AbstractTestProxy testProxy, final AbstractTestProxy child) {
final TestProxyListener[] listeners = getListeners();
for (int i = 0; i < listeners.length; i++)
listeners[i].onChildAdded(testProxy, child);
}
private TestProxyListener[] getListeners() {
if (myCachedListeners == null) {
final int size = myListeners != null ? myListeners.size() : 0;
myCachedListeners = size != 0 ? myListeners.toArray(new TestProxyListener[size]) : TestProxyListener.EMPTY_ARRAY;
}
return myCachedListeners;
}
public void onStatisticsChanged(final AbstractTestProxy test) {
final TestProxyListener[] listeners = getListeners();
for (int i = 0; i < listeners.length; i++) {
final TestProxyListener listener = listeners[i];
listener.onStatisticsChanged(test);
}
}
}
@@ -1,45 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.events;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.TestEvent;
public class NewChildEvent extends TestEvent {
private final TestProxy myChild;
public TestProxy getChild() {
return myChild;
}
public NewChildEvent(final TestProxy parent, final TestProxy child) {
super(parent);
myChild = child;
}
public boolean equals(final Object obj) {
return super.equals(obj) && ((NewChildEvent) obj).myChild == myChild;
}
public int hashCode() {
return super.hashCode() ^ myChild.hashCode();
}
public TestProxy getTestSubtree() {
return getSource();
}
}
@@ -1,33 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.events;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.testframework.AbstractTestProxy;
public class StateChangedEvent extends TestEvent {
public StateChangedEvent(final TestProxy test) {
super(test);
}
public AbstractTestProxy getTestSubtree() {
final TestProxy test = getSource();
final AbstractTestProxy parent = test.getParent();
return parent != null ? parent : test;
}
}
@@ -1,26 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.events;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.TestEvent;
public class StatisticsChanged extends TestEvent {
public StatisticsChanged(final TestProxy test) {
super(test);
}
}
@@ -1,47 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.events;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.testframework.AbstractTestProxy;
public class TestEvent {
private final TestProxy mySource;
public TestEvent(final TestProxy source) {
mySource = source;
}
public TestProxy getSource() {
return mySource;
}
public int hashCode() {
return mySource.hashCode();
}
public boolean equals(final Object obj) {
if (obj == null)
return false;
if (mySource != ((TestEvent) obj).mySource) return false;
return obj.getClass() == getClass();
}
public AbstractTestProxy getTestSubtree() {
return null;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.events;
public interface TestEventsConsumer {
void onEvent(TestEvent event);
}
@@ -1,44 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.Location;
import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
class AllInPackageInfo extends TestInfo {
private String myName;
public void readFrom(final ObjectReader reader) {
myName = reader.readLimitedString();
}
public String getComment() {
return "";
}
public String getName() {
return myName.length() > 0 ? myName : JUnitConfiguration.DEFAULT_PACKAGE_NAME;
}
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
return null;
}
}
@@ -1,58 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.Nullable;
public abstract class ClassBasedInfo extends TestInfo {
private final DisplayTestInfoExtractor myClassInfo;
private PsiClassLocator myClass;
private String myComment = null;
public ClassBasedInfo(final DisplayTestInfoExtractor classInfo) {
myClassInfo = classInfo;
}
protected void readClass(final ObjectReader reader) {
setClassName(reader.readLimitedString());
}
protected void setClassName(final String name) {
myClass = PsiClassLocator.fromQualifiedName(name);
myComment = null;
}
@Nullable
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
return myClass.getLocation(project, searchScope);
}
public String getComment() {
if (myComment == null) {
myComment = myClassInfo.getComment(myClass);
}
return myComment;
}
public String getName() {
return myClassInfo.getName(myClass);
}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.ExecutionBundle;
class DefaultTestInfo extends ClassBasedInfo {
public DefaultTestInfo() {
super(DisplayTestInfoExtractor.CLASS_FULL_NAME);
}
public void readFrom(final ObjectReader reader) {
reader.readInt(); //TODO remove test count from packet
readClass(reader);
}
public String getName() {
return ExecutionBundle.message("test.cases.count.message", getTestsCount());
}
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
public interface DisplayTestInfoExtractor {
String getComment(PsiClassLocator classLocator);
String getName(PsiClassLocator classLocator);
DisplayTestInfoExtractor FOR_CLASS = new DisplayTestInfoExtractor() {
public String getComment(final PsiClassLocator classLocator) {
return classLocator.getPackage();
}
public String getName(final PsiClassLocator classLocator) {
return classLocator.getName();
}
};
DisplayTestInfoExtractor CLASS_FULL_NAME = new DisplayTestInfoExtractor() {
public String getComment(final PsiClassLocator classLocator) {
return classLocator.getQualifiedName();
}
public String getName(final PsiClassLocator classLocator) {
return null;
}
};
}
@@ -1,60 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.JavaExecutionUtil;
import com.intellij.execution.Location;
import com.intellij.execution.PsiLocation;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
public class PsiClassLocator implements PsiLocator {
private final String myName;
private final String myPackage;
private PsiClassLocator(final String name, final String aPackage) {
myName = name;
myPackage = aPackage;
}
public static PsiClassLocator fromQualifiedName(final String name) {
final int lastDot = name.lastIndexOf('.');
if (lastDot == -1 || lastDot == name.length() || (name.endsWith("]") && name.contains("[")))
return new PsiClassLocator(name, "");
else
return new PsiClassLocator(name.substring(lastDot + 1), name.substring(0, lastDot));
}
public Location<PsiClass> getLocation(final Project project, GlobalSearchScope searchScope) {
final PsiClass psiClass = JavaExecutionUtil.findMainClass(project, getQualifiedName(), searchScope);
return psiClass != null ? new PsiLocation<PsiClass>(project, psiClass) : null;
}
public String getPackage() {
return myPackage;
}
public String getName() {
return myName;
}
public String getQualifiedName() {
return StringUtil.getQualifiedName(myPackage, myName);
}
}
@@ -1,25 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.Location;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
public interface PsiLocator {
Location getLocation(Project project, GlobalSearchScope searchScope);
}
@@ -1,63 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.MethodSignatureUtil;
import org.jetbrains.annotations.Nullable;
class TestCaseInfo extends ClassBasedInfo {
private String myMethod;
public TestCaseInfo() {
super(DisplayTestInfoExtractor.CLASS_FULL_NAME);
}
public void readFrom(final ObjectReader reader) {
myMethod = reader.readLimitedString();
readClass(reader);
}
public String getName() {
return myMethod;
}
@Nullable
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
final Location<PsiClass> classLocation = (Location<PsiClass>)super.getLocation(project, searchScope);
if (classLocation == null) return null;
String strippedMethodName = myMethod; //navigation to for parametr. methods
final int idx = myMethod.indexOf('[');
if (idx != -1) {
strippedMethodName = myMethod.substring(0, idx);
}
final PsiMethod method = MethodSignatureUtil.findMethodBySignature(classLocation.getPsiElement(),
MethodSignatureUtil.createMethodSignature(strippedMethodName, PsiType.EMPTY_ARRAY, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY), true);
if (method != null)
return new MethodLocation(project, method, classLocation);
return null;
}
public boolean shouldRun() {
return true;
}
}
@@ -1,29 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.junit2.segments.ObjectReader;
class TestClassInfo extends ClassBasedInfo {
public TestClassInfo() {
super(DisplayTestInfoExtractor.FOR_CLASS);
}
public void readFrom(final ObjectReader reader) {
readClass(reader);
}
}
@@ -1,71 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.rt.execution.junit.segments.PoolOfTestTypes;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public abstract class TestInfo implements PsiLocator {
public static final Map<String,Class> KNOWN_PSI_LOCATOR_CLASSES = new HashMap<String, Class>();
static {
KNOWN_PSI_LOCATOR_CLASSES.put(PoolOfTestTypes.TEST_METHOD, TestCaseInfo.class);
KNOWN_PSI_LOCATOR_CLASSES.put(PoolOfTestTypes.TEST_CLASS, TestClassInfo.class);
KNOWN_PSI_LOCATOR_CLASSES.put(PoolOfTestTypes.ALL_IN_PACKAGE, AllInPackageInfo.class);
}
@NotNull
public static TestInfo readInfoFrom(final ObjectReader reader) {
final String testType = reader.readLimitedString();
Class infoClass = KNOWN_PSI_LOCATOR_CLASSES.get(testType);
if (infoClass == null)
infoClass = DefaultTestInfo.class;
final TestInfo info;
try {
info = (TestInfo) infoClass.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
info.readFrom(reader);
info.setTestCount(reader.readInt());
return info;
}
private int myTestCount;
public boolean shouldRun() {
return false;
}
public int getTestsCount() {
return myTestCount;
}
public void setTestCount(final int testCount) {
myTestCount = testCount;
}
public abstract void readFrom(ObjectReader reader);
public abstract String getComment();
public abstract String getName();
}
@@ -1,52 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.info.TestInfo;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import com.intellij.util.containers.HashMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
public class InputObjectRegistry {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.segments.InputObjectRegistryImpl");
private final Map<String, TestProxy> myKnownObjects = new HashMap<String,TestProxy>();
public TestProxy getByKey(final String key) {
final TestProxy result = myKnownObjects.get(key);
if (result == null) {
LOG.error("Unknwon key: " + key);
LOG.info("Known keys:");
final ArrayList<String> knownKeys = new ArrayList<String>(myKnownObjects.keySet());
Collections.sort(knownKeys);
LOG.info(knownKeys.toString());
}
return result;
}
public void readPacketFrom(final ObjectReader reader) {
final String reference = reader.upTo(PoolOfDelimiters.REFERENCE_END);
if (myKnownObjects.containsKey(reference)) return;
final TestProxy test = new TestProxy(TestInfo.readInfoFrom(reader));
myKnownObjects.put(reference, test);
}
}
@@ -1,33 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
public class ObjectReader extends SegmentReader {
private final InputObjectRegistry myObjectRegistry;
public ObjectReader(final String packet, final int offset, final InputObjectRegistry registry) {
super(packet.substring(offset, packet.length()));
myObjectRegistry = registry;
}
public TestProxy readObject() {
return myObjectRegistry.getByKey(upTo(PoolOfDelimiters.REFERENCE_END));
}
}
@@ -1,52 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.testframework.stacktrace.DiffHyperlink;
import com.intellij.execution.ui.ConsoleViewContentType;
import org.jetbrains.annotations.NonNls;
public class ComparisonFailureState extends FaultyState {
private DiffHyperlink myHyperlink;
@NonNls
protected static final String EXPECTED_VALUE_MESSAGE_TEXT = "expected:<";
public void initializeFrom(final ObjectReader reader) {
super.initializeFrom(reader);
myHyperlink = JUnitDiffHyperlink.readFrom(reader);
}
protected void printExceptionHeader(final Printer printer, String message) {
final int columnIndex = message.indexOf(':');
if (columnIndex != -1) {
printer.print(message.substring(0, columnIndex + 1), ConsoleViewContentType.ERROR_OUTPUT);
message = message.substring(columnIndex + 1);
}
if (message.trim().length() > 0) {
final int generatedMessageStart = message.indexOf(EXPECTED_VALUE_MESSAGE_TEXT);
if (generatedMessageStart != -1) message = message.substring(0, generatedMessageStart);
printer.print(message, ConsoleViewContentType.ERROR_OUTPUT);
}
myHyperlink.printOn(printer);
}
public DiffHyperlink getHyperlink() {
return myHyperlink;
}
}
@@ -1,37 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
public class CumulativeStatistics extends Statistics {
private long myMemoryUsage = 0;
private boolean myIsEmpty = true;
public CumulativeStatistics() {
}
public void add(final Statistics statistics) {
myTime += statistics.getTime();
myMemoryUsage += statistics.getMemoryUsage();
if (myIsEmpty)
myBeforeMemory = statistics.getBeforeMemory();
myAfterMemory = statistics.getAfterMemory();
myIsEmpty = false;
}
public long getMemoryUsage() {
return myMemoryUsage;
}
}
@@ -1,106 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.Location;
import com.intellij.execution.PsiLocation;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.stacktrace.StackTraceLine;
import com.intellij.execution.testframework.CompositePrintable;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.diff.LineTokenizer;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class FaultyState extends ReadableState {
private List<String> myMessages;
private List<String> myStackTraces;
public void initializeFrom(final ObjectReader reader) {
myMessages = Collections.singletonList(reader.readLimitedString());
myStackTraces = Collections.singletonList(reader.readLimitedString());
}
public void printOn(final Printer printer) {
printer.print(CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
printer.mark();
for (int i = 0; i < myMessages.size(); i++) {
printExceptionHeader(printer, myMessages.get(i));
if (i < myStackTraces.size()) {
printer.print(myStackTraces.get(i) + CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
}
}
}
protected void printExceptionHeader(final Printer printer, final String message) {
printer.print(message, ConsoleViewContentType.ERROR_OUTPUT);
}
public boolean isDefect() {
return true;
}
@Override
public void merge(@NotNull TestState state, TestProxy parent) {
if (state instanceof FaultyState) {
while (parent != null) {
TestState parentState = parent.getState();
if (parentState instanceof SuiteState && !((SuiteState)parentState).isRunning()) {
parent.addLast(this);
} else {
break;
}
parent = parent.getParent();
}
}
}
public Navigatable getDescriptor(final Location<?> location) {
if (location == null) return super.getDescriptor(location);
//navigate to the first stack trace
final String[] stackTrace = new LineTokenizer(myStackTraces.get(0)).execute();
final PsiLocation<?> psiLocation = location.toPsiLocation();
final PsiClass containingClass = psiLocation.getParentElement(PsiClass.class);
if (containingClass == null) return super.getDescriptor(location);
String containingMethod = null;
for (Iterator<Location<PsiMethod>> iterator = psiLocation.getAncestors(PsiMethod.class, false); iterator.hasNext();) {
final PsiMethod psiMethod = iterator.next().getPsiElement();
if (containingClass.equals(psiMethod.getContainingClass())) containingMethod = psiMethod.getName();
}
if (containingMethod == null) return super.getDescriptor(location);
final String qualifiedName = containingClass.getQualifiedName();
StackTraceLine lastLine = null;
for (String aStackTrace : stackTrace) {
final StackTraceLine line = new StackTraceLine(containingClass.getProject(), aStackTrace);
if (containingMethod.equals(line.getMethodName()) && qualifiedName.equals(line.getClassName())) {
lastLine = line;
break;
}
}
return lastLine != null ?
lastLine.getOpenFileDescriptor(containingClass.getContainingFile().getVirtualFile()) :
super.getDescriptor(location);
}
}
@@ -1,51 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.CompositePrintable;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.ui.ConsoleViewContentType;
public class IgnoredState extends ReadableState {
private TestProxy myPeformedTest;
private String myIgnoredMessage;
private String myMessage;
private String myStackTrace;
public void initializeFrom(final ObjectReader reader) {
myPeformedTest = reader.readObject();
myIgnoredMessage = reader.readLimitedString();
myMessage = reader.readLimitedString();
myStackTrace = reader.readLimitedString();
}
public void printOn(final Printer printer) {
String parentName = myPeformedTest.getParent() == null ? myPeformedTest.getInfo().getComment() : myPeformedTest.getParent().toString();
String message = ExecutionBundle.message("junit.runing.info.ignored.console.message", parentName, myPeformedTest.getInfo().getName());
printer.print(message + (myIgnoredMessage.length() > 0 ? " (" + myIgnoredMessage + ")": "") + CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
if (myMessage.length() > 0) {
printer.print(myMessage + CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
}
if (myStackTrace.length() > 0) {
printer.print(myStackTrace + CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
}
}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.testframework.stacktrace.DiffHyperlink;
public class JUnitDiffHyperlink extends DiffHyperlink {
public JUnitDiffHyperlink(final String expected, final String actual, final String filePath) {
super(expected, actual, filePath);
}
public static DiffHyperlink readFrom(final ObjectReader reader) {
final String expected = reader.readLimitedString();
final String actual = reader.readLimitedString();
final String fileName = reader.isAtEnd() ? null : reader.readLimitedString();
return new JUnitDiffHyperlink(expected, actual, fileName);
}
}
@@ -1,48 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.testframework.Printer;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
public final class NotFailedState extends TestState {
private final boolean myIsFinal;
public NotFailedState(final int magnitude, final boolean aFinal) {
myMagnitude = magnitude;
myIsFinal = aFinal;
}
public int getMagnitude() {
return myMagnitude;
}
public boolean isFinal() {
return myIsFinal;
}
public void printOn(final Printer printer) {
}
public static NotFailedState createPassed() {
return new NotFailedState(PoolOfTestStates.PASSED_INDEX, true);
}
public static TestState createTerminated() {
return new NotFailedState(PoolOfTestStates.TERMINATED_INDEX, true);
}
}
@@ -1,36 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.junit2.segments.ObjectReader;
public abstract class ReadableState extends TestState {
public abstract void initializeFrom(ObjectReader reader);
public int getMagnitude() {
return myMagnitude;
}
public void setMagitude(final int magnitude) {
myMagnitude = magnitude;
}
public boolean isFinal() {
return true;
}
}
@@ -1,39 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.junit2.ui.Formatters;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.CompositePrintable;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.ui.ConsoleViewContentType;
public class SkippedState extends ReadableState {
private TestProxy myPeformedTest;
public void initializeFrom(final ObjectReader reader) {
myPeformedTest = reader.readObject();
}
public void printOn(final Printer printer) {
printer.print(Formatters.printTest(myPeformedTest) + ":" + CompositePrintable.NEW_LINE,
ConsoleViewContentType.SYSTEM_OUTPUT);
myPeformedTest.printOn(printer);
}
}
@@ -1,50 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.junit2.segments.ObjectReader;
public class Statistics {
public int myTime = 0;
protected long myBeforeMemory = 0;
protected long myAfterMemory = 0;
public Statistics(final ObjectReader reader) {
myTime = reader.readInt();
myBeforeMemory = reader.readLong();
myAfterMemory = reader.readLong();
}
public Statistics() {
}
public int getTime() {
return myTime;
}
public long getBeforeMemory() {
return myBeforeMemory;
}
public long getAfterMemory() {
return myAfterMemory;
}
public long getMemoryUsage() {
return myAfterMemory - myBeforeMemory;
}
}
@@ -1,175 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.TestProxyListener;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Printer;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SuiteState extends TestState {
private final TestProxy myTest;
private int myMaxMagnitude = PoolOfTestStates.NOT_RUN_INDEX;
private boolean myHasRunning;
private final StateCache myCache = new StateCache();
public SuiteState(final TestProxy test) {
myTest = test;
myTest.addListener(new TestProxyListener() {
public void onChildAdded(final AbstractTestProxy testProxy, final AbstractTestProxy newChild) {
if (newChild.getParent() == myTest) {
myCache.invalidate();
}
}
public void onChanged(final AbstractTestProxy test) {
if (test == myTest) myCache.invalidate();
}
public void onStatisticsChanged(final AbstractTestProxy test) {
if (test == myTest) myCache.invalidate();
}
});
}
public int getMagnitude() {
return myHasRunning ? PoolOfTestStates.RUNNING_INDEX : myMaxMagnitude;
}
public void update() {
myCache.invalidate();
}
public void printOn(final Printer printer) {
}
public boolean isFinal() {
return true;
}
public boolean isDefect() {
return getMagnitude() >= PoolOfTestStates.FAILED_INDEX;
}
public boolean isInProgress() {
return myCache.get(IS_IN_PROGRESS).booleanValue();
}
public Statistics getStatisticsFor(final TestProxy test) {
return myCache.get(GET_STATISTICS);
}
public List<TestProxy> getAllTestsOf(final TestProxy test) {
return myCache.get(ALL_TESTS);
}
public void changeStateAfterAddingChildTo(final TestProxy test, final TestProxy child) {
if (child.getState().getMagnitude() <= getMagnitude()) {
test.onStatisticsChanged();
return;
}
test.onChanged(test);
}
public void setRunning(boolean running) {
myHasRunning = running;
}
public boolean isRunning() {
return myHasRunning;
}
public void updateMagnitude(int magnitude) {
if (myMaxMagnitude == PoolOfTestStates.NOT_RUN_INDEX) {
myMaxMagnitude = magnitude;
} else if (myMaxMagnitude < magnitude) {
myMaxMagnitude = magnitude;
}
}
private static final CachedAcpect<List<TestProxy>> ALL_TESTS = new CachedAcpect<List<TestProxy>>() {
public List<TestProxy> calculate(final SuiteState state) {
final ArrayList<TestProxy> allTests = new ArrayList<TestProxy>();
state.myTest.collectAllTestsTo(allTests);
return allTests;
}
};
private static final CachedAcpect<Statistics> GET_STATISTICS = new CachedAcpect<Statistics>() {
public Statistics calculate(final SuiteState state) {
final CumulativeStatistics result = new CumulativeStatistics();
for (final TestProxy testCase : state.myTest.getChildren()) {
result.add(testCase.getStatistics());
}
return result;
}
};
private static final CachedAcpect<Boolean> IS_IN_PROGRESS = new CachedAcpect<Boolean>() {
public Boolean calculate(final SuiteState state) {
final List<TestProxy> children = state.myTest.getChildren();
for (int i = children.size() - 1; i >= 0; i--) {
if (children.get(i).isInProgress()) return Boolean.TRUE;
}
return Boolean.FALSE;
}
};
private static abstract class CachedAcpect<T> {
private static int ourNextInstanceIndex = 0;
private final int myId;
protected CachedAcpect() {
synchronized (CachedAcpect.class) {
myId = ourNextInstanceIndex;
ourNextInstanceIndex++;
}
}
public abstract T calculate(SuiteState state);
public int getId() {
return myId;
}
}
private class StateCache {
private final Object[] myValues = new Object[3];
public <T> T get(final CachedAcpect<T> aspect) {
final int id = aspect.getId();
T value = (T)myValues[id];
if (value == null) {
value = aspect.calculate(SuiteState.this);
myValues[id] = value;
}
return value;
}
public void invalidate() {
Arrays.fill(myValues, null);
}
}
}
@@ -1,75 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.testframework.Printable;
import com.intellij.ide.util.EditSourceUtil;
import com.intellij.pom.Navigatable;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public abstract class TestState implements Printable {
public static final TestState DEFAULT = new NotFailedState(PoolOfTestStates.NOT_RUN_INDEX, false);
public static final TestState RUNNING_STATE = new NotFailedState(PoolOfTestStates.RUNNING_INDEX, false);
protected int myMagnitude;
public List<TestProxy> getAllTestsOf(final TestProxy test) {
final ArrayList<TestProxy> allTests = new ArrayList<TestProxy>();
test.collectAllTestsTo(allTests);
return allTests;
}
public abstract int getMagnitude();
public abstract boolean isFinal();
public boolean isDefect() {
return false;
}
public boolean isInProgress() {
return !isFinal();
}
public Statistics getStatisticsFor(final TestProxy test) {
return test.getStatisticsImpl();
}
public void update() {
}
public void merge(@NotNull TestState state, TestProxy parent){}
public boolean isPassed() {
return getMagnitude() == PoolOfTestStates.PASSED_INDEX;
}
public Navigatable getDescriptor(final Location<?> location) {
if (location != null) return EditSourceUtil.getDescriptor(location.getPsiElement());
return null;
}
public void changeStateAfterAddingChildTo(final TestProxy test, final TestProxy child) {
test.setState(new SuiteState(test));
}
}
@@ -1,30 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.states;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Filter;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
public class TestStateUpdater {
public static final Filter RUNNING = new Filter() {
public boolean shouldAccept(final AbstractTestProxy test) {
return test.getMagnitude() == PoolOfTestStates.RUNNING_INDEX;
}
};
public static final Filter RUNNING_LEAF = RUNNING.and(Filter.LEAF);
}
@@ -1,54 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.states.CumulativeStatistics;
import com.intellij.execution.junit2.states.Statistics;
import com.intellij.openapi.util.text.StringUtil;
class ActualStatistics implements TestStatistics {
private final CumulativeStatistics myStatistics = new CumulativeStatistics();
private String myPrefix = "";
public ActualStatistics(final Statistics statistics) {
myStatistics.add(statistics);
}
public void setRunning() {
myPrefix = TestStatistics.RUNNING_SUITE_PREFIX;
}
public String getTime() {
return myPrefix + StringUtil.formatDuration(myStatistics.getTime());
}
public String getMemoryUsageDelta() {
return showMemory(myStatistics.getMemoryUsage());
}
public String getBeforeMemory() {
return showMemory(myStatistics.getBeforeMemory());
}
public String getAfterMemory() {
return showMemory(myStatistics.getAfterMemory());
}
private String showMemory(final long memoryUsage) {
return myPrefix + Formatters.printFullKBMemory(memoryUsage);
}
}
@@ -1,218 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.ui.actions.JUnitToolbarPanel;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.testframework.PoolOfTestIcons;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.testframework.TestTreeView;
import com.intellij.execution.testframework.ToolbarPanel;
import com.intellij.execution.testframework.ui.TestResultsPanel;
import com.intellij.execution.testframework.ui.TestStatusLine;
import com.intellij.execution.testframework.ui.TestsOutputConsolePrinter;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.Alarm;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
public class ConsolePanel extends TestResultsPanel {
@NonNls private static final String PROPORTION_PROPERTY = "test_tree_console_proprtion";
private static final float DEFAULT_PROPORTION = 0.2f;
private JUnitStatusLine myStatusLine;
private StatisticsPanel myStatisticsPanel;
private TestTreeView myTreeView;
private TestsOutputConsolePrinter myPrinter;
private StartingProgress myStartingProgress;
public ConsolePanel(final JComponent console,
final TestsOutputConsolePrinter printer,
final JUnitConsoleProperties properties,
AnAction[] consoleActions) {
super(console, consoleActions, properties, PROPORTION_PROPERTY, DEFAULT_PROPORTION);
myPrinter = printer;
}
@Override
public void initUI() {
super.initUI();
myStartingProgress = new StartingProgress(myTreeView);
}
@Override
protected ToolbarPanel createToolbarPanel() {
return new JUnitToolbarPanel(myProperties, this);
}
@Override
protected TestStatusLine createStatusLine() {
myStatusLine = new JUnitStatusLine();
return myStatusLine;
}
@Override
protected JComponent createTestTreeView() {
myTreeView = new JUnitTestTreeView();
return myTreeView;
}
public void onProcessStarted(final ProcessHandler process) {
myStatusLine.onProcessStarted(process);
if (myStartingProgress == null) return;
myStartingProgress.start(process);
}
public void setModel(final JUnitRunningModel model) {
stopStartingProgress();
final TestTreeView treeView = model.getTreeView();
treeView.setLargeModel(true);
setLeftComponent(treeView);
myToolbarPanel.setModel(model);
myStatusLine.setModel(model);
model.addListener(new JUnitAdapter() {
@Override
public void onTestSelected(final TestProxy test) {
if (myPrinter != null) myPrinter.updateOnTestSelected(test);
}
});
myStatisticsPanel.attachTo(model);
}
private void stopStartingProgress() {
if (myStartingProgress != null) myStartingProgress.doStop();
myStartingProgress = null;
}
public TestTreeView getTreeView() {
return myTreeView;
}
public Printer getPrinter() {
return myPrinter;
}
@Override
public void dispose() {
stopStartingProgress();
myPrinter = null;
}
private static class StartingProgress implements Runnable {
private final Alarm myAlarm = new Alarm();
private final Tree myTree;
private final DefaultTreeModel myModel;
private final DefaultMutableTreeNode myRootNode = new DefaultMutableTreeNode();
private boolean myStarted = false;
private boolean myStopped = false;
private final SimpleColoredComponent myStartingLabel;
private ProcessHandler myProcess;
private long myStartedAt = System.currentTimeMillis();
private final ProcessAdapter myProcessListener = new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
ApplicationManager.getApplication().invokeLater(() -> doStop());
}
};
public StartingProgress(final Tree tree) {
myTree = tree;
myModel = new DefaultTreeModel(myRootNode);
myTree.setModel(myModel);
myStartingLabel = new SimpleColoredComponent();
myTree.setPaintBusy(true);
//myStartingLabel.setBackground(UIManager.getColor("Tree.background"));
myTree.setCellRenderer(new TreeCellRenderer() {
@NotNull
@Override
public Component getTreeCellRendererComponent(@NotNull final JTree tree, final Object value,
final boolean selected, final boolean expanded,
final boolean leaf, final int row, final boolean hasFocus) {
myStartingLabel.clear();
myStartingLabel.setIcon(PoolOfTestIcons.LOADING_ICON);
myStartingLabel.append(getProgressText(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
if (!myStarted) postRepaint();
return myStartingLabel;
}
});
myTree.addPropertyChangeListener(JTree.TREE_MODEL_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(@NotNull final PropertyChangeEvent evt) {
myTree.removePropertyChangeListener(JTree.TREE_MODEL_PROPERTY, this);
doStop();
}
});
}
private void doStop() {
myStopped = true;
myTree.setPaintBusy(false);
myModel.nodeChanged(myRootNode);
myAlarm.cancelAllRequests();
if (myProcess != null) myProcess.removeProcessListener(myProcessListener);
myProcess = null;
}
@Override
public void run() {
myModel.nodeChanged(myRootNode);
postRepaint();
}
private void postRepaint() {
if (myStopped) return;
myStarted = true;
myAlarm.cancelAllRequests();
myAlarm.addRequest(this, 300, ModalityState.NON_MODAL);
}
public void start(final ProcessHandler process) {
if (process.isProcessTerminated()) return;
myProcess = process;
myStartedAt = System.currentTimeMillis();
process.addProcessListener(myProcessListener);
}
private String getProgressText() {
if (myStopped) return ExecutionBundle.message("test.not.started.progress.text");
final long millis = System.currentTimeMillis() - myStartedAt;
final String phaseName = myProcess == null ? ExecutionBundle.message("starting.jvm.progress.text") : ExecutionBundle.message("instantiating.tests.progress.text");
return phaseName + Formatters.printMinSec(millis);
}
}
}
@@ -1,110 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.info.TestInfo;
import com.intellij.execution.junit2.states.TestState;
import com.intellij.execution.ExecutionBundle;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import java.text.NumberFormat;
public class Formatters {
public static String printTest(final TestProxy test) {
if (test == null || test.getInfo() == null)
return "";
final TestInfo info = test.getInfo();
return info.getName() + sensibleCommentFor(test);
}
public static String printMemory(final long memory) {
final String string = printMemoryUnsigned(memory);
return memory > 0 ? "+" + string : string;
}
public static String printMemoryUnsigned(final long memory) {
return ExecutionBundle.message("junit.runing.info.memory.available.kb.message", NumberFormat.getInstance().format((double)memory/1024.0));
}
public static TestStatistics statisticsFor(final TestProxy test) {
if (test == null)
return TestStatistics.ABCENT;
final TestState state = test.getState();
final int magnitude = state.getMagnitude();
if (magnitude == PoolOfTestStates.NOT_RUN_INDEX)
return TestStatistics.NOT_RUN;
if (test.isLeaf())
return state.isFinal() ?
actualInfo(test) :
TestStatistics.RUNNING;
final ActualStatistics actualStatistics = actualInfo(test);
if (state.isInProgress())
actualStatistics.setRunning();
return actualStatistics;
}
private static ActualStatistics actualInfo(final TestProxy test) {
return new ActualStatistics(test.getStatistics());
}
private static boolean isCommentSensible(final TestProxy testProxy) {
final TestInfo info = testProxy.getInfo();
if (info.getComment().length() == 0)
return false;
final TestProxy parent = testProxy.getParent();
return parent == null || !fullLabelOf(parent.getInfo()).equals(info.getComment());
}
private static String fullLabelOf(final TestInfo info) {
return info.getComment() + "." + info.getName();
}
public static String sensibleCommentFor(final TestProxy testProxy) {
final String sensibleComment;
if (isCommentSensible(testProxy)) {
sensibleComment = " (" + testProxy.getInfo().getComment() + ")";
}
else {
sensibleComment = "";
}
return sensibleComment;
}
public static String printMemoryMega(final long memory) {
final double unit = 1024*1024;
return ExecutionBundle.message("junit.runing.info.memory.available.mb.message", NumberFormat.getInstance().format((double)memory/unit));
}
public static String printFullKBMemory(final long memory) {
return ExecutionBundle.message("memory.available.message", NumberFormat.getInstance().format(memory / 1024));
}
public static String printMinSec(final long millis) {
final long seconds = millis / 1000;
if (seconds == 0) return "";
final long min = seconds / 60;
final long sec = seconds % 60;
return min + ":" + formatInt(sec, 2);
}
public static String formatInt(final long value, final int minDigits) {
String strValue = Long.toString(value);
for (int i = strValue.length(); i < minDigits; i++) strValue = "0" + strValue;
return strValue;
}
}
@@ -1,171 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.NewChildEvent;
import com.intellij.execution.junit2.events.StateChangedEvent;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.ui.model.CompletionEvent;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.model.StateEvent;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.ui.TestStatusLine;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.util.ColorProgressBar;
import com.intellij.ui.SimpleColoredComponent;
class JUnitStatusLine extends TestStatusLine {
private final StateInfo myStateInfo = new StateInfo();
private boolean myTestsBuilt = false;
JUnitStatusLine() {
super();
}
public void setModel(final JUnitRunningModel model) {
myTestsBuilt = true;
myProgressBar.setForeground(ColorProgressBar.GREEN);
model.addListener(new TestProgressListener(model.getProgress()));
}
public void onProcessStarted(final ProcessHandler process) {
if (myTestsBuilt) return;
process.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
process.removeProcessListener(this);
ApplicationManager.getApplication().invokeLater(() -> {
myStateInfo.setTerminated(myState);
if (!myTestsBuilt && myProgressBar.getValue() == 0) {
setStatusColor(ColorProgressBar.RED);
setFraction(1.0);
myState.append(ExecutionBundle.message("junit.running.info.failed.to.start.error.message"));
}
});
}
});
}
private static class StateInfo {
private int myTotal = 0;
private int myCompleted = 0;
private int myDefects = 0;
private String myCurrentTestName = "";
private StateEvent myDoneEvent;
private boolean myTerminated = false;
public void setDone(final StateEvent event) {
myDoneEvent = event;
}
public void updateCounters(final TestProgress progress) {
myTotal = progress.getMaximum();
myCompleted = progress.getValue();
myDefects = progress.countDefects();
final TestProxy currentTest = progress.getCurrentTest();
myCurrentTestName = currentTest == null ? "" : Formatters.printTest(currentTest);
}
public double getCompletedPercents() {
return (double)myCompleted/(double)myTotal;
}
public void updateLabel(final SimpleColoredComponent label) {
label.clear();
final StringBuilder buffer = new StringBuilder();
if (myDoneEvent != null && myTerminated) {
String termMessage = generateTermMessage(getTestCount(0));
buffer.append(termMessage);
final String comment = myDoneEvent.getComment();
if (comment.length() > 0) {
buffer.append(" (").append(comment).append(")");
}
} else {
buffer.append(ExecutionBundle.message("junit.running.info.status.running.number.with.name", getTestCount(myDoneEvent != null ? 0 : 1), myCurrentTestName));
}
label.append(buffer.toString());
}
private String getTestCount(int offset) {
String testCount;
if (myDefects > 0)
testCount = ExecutionBundle.message("junit.running.info.status.completed.from.total.failed", myCompleted + offset, myTotal, myDefects); // += " Failed: " + myDefects + " ";
else
testCount = ExecutionBundle.message("junit.running.info.status.completed.from.total", myCompleted + offset, myTotal); // myCompleted + " of " + myTotal
return testCount;
}
private String generateTermMessage(final String testCount) {
switch(myDoneEvent.getType()) {
case DONE: return ExecutionBundle.message("junit.running.info.status.done.count", testCount);
default: return ExecutionBundle.message("junit.running.info.status.terminated.count", testCount);
}
}
public void setTerminated(SimpleColoredComponent stateLabel) {
myTerminated = true;
updateLabel(stateLabel);
}
}
private class TestProgressListener extends JUnitAdapter {
private TestProgress myProgress;
public TestProgressListener(final TestProgress progress) {
myProgress = progress;
}
@Override
public void onRunnerStateChanged(final StateEvent event) {
if (!event.isRunning()) {
final CompletionEvent completionEvent = (CompletionEvent) event;
myStateInfo.setDone(completionEvent);
myProgress.setDone(completionEvent);
if (completionEvent.isTerminated() && !myProgress.hasDefects()) {
setStatusColor(ColorProgressBar.YELLOW);
}
updateCounters();
}
}
@Override
public void onTestChanged(final TestEvent event) {
if (event instanceof StateChangedEvent || event instanceof NewChildEvent)
updateCounters();
}
@Override
public void doDispose() {
myProgress = null;
}
private void updateCounters() {
myStateInfo.updateCounters(myProgress);
setFraction(myStateInfo.getCompletedPercents());
if (myProgress.hasDefects()) {
setStatusColor(ColorProgressBar.RED);
}
myStateInfo.updateLabel(myState);
}
}
}
@@ -1,44 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.TestTreeView;
import org.jetbrains.annotations.NotNull;
import javax.swing.tree.TreePath;
public class JUnitTestTreeView extends TestTreeView {
protected TreeTestRenderer getRenderer(TestConsoleProperties properties) {
return new TreeTestRenderer(properties);
}
public TestProxy getSelectedTest(@NotNull final TreePath selectionPath) {
return TestProxyClient.from(selectionPath.getLastPathComponent());
}
public String convertValueToText(final Object value,
final boolean selected,
final boolean expanded,
final boolean leaf,
final int row,
final boolean hasFocus) {
return Formatters.printTest(TestProxyClient.from(value));
}
}
@@ -1,70 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.model.TreeCollapser;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView;
import com.intellij.execution.testframework.ui.TestResultsPanel;
import org.jetbrains.annotations.NotNull;
public class JUnitTreeConsoleView extends BaseTestsOutputConsoleView {
private ConsolePanel myConsolePanel;
private final JUnitConsoleProperties myProperties;
private final ExecutionEnvironment myEnvironment;
public JUnitTreeConsoleView(final JUnitConsoleProperties properties,
final ExecutionEnvironment environment,
final AbstractTestProxy unboundOutputRoot) {
super(properties, unboundOutputRoot);
myProperties = properties;
myEnvironment = environment;
}
@Override
protected TestResultsPanel createTestResultsPanel() {
myConsolePanel = new ConsolePanel(getConsole().getComponent(), getPrinter(), myProperties,
getConsole().createConsoleActions());
return myConsolePanel;
}
@Override
public void attachToProcess(final ProcessHandler processHandler) {
super.attachToProcess(processHandler);
myConsolePanel.onProcessStarted(processHandler);
}
@Override
public void dispose() {
super.dispose();
myConsolePanel = null;
}
public void attachToModel(@NotNull JUnitRunningModel model) {
if (myConsolePanel != null) {
myConsolePanel.getTreeView().attachToModel(model);
model.attachToTree(myConsolePanel.getTreeView());
myConsolePanel.setModel(model);
model.onUIBuilt();
new TreeCollapser().setModel(model);
}
}
}
@@ -1,143 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.testframework.actions.TestContext;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.testframework.TestsUIUtil;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.ui.*;
import com.intellij.ui.table.BaseTableView;
import com.intellij.ui.table.TableView;
import com.intellij.util.EditSourceOnDoubleClickHandler;
import com.intellij.util.config.Storage;
import com.intellij.util.ui.ListTableModel;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
class StatisticsPanel extends JPanel implements DataProvider{
private final MyJUnitListener myListener = new MyJUnitListener();
private TestProxy myCurrentTest = null;
private StatisticsTable myChildInfo = null;
// private TestCaseStatistics myTestCaseInfo = new TestCaseStatistics(TestColumnInfo.COLUMN_NAMES);
private JUnitRunningModel myModel;
private final TableView myTable;
private final Storage.PropertiesComponentStorage myStorage = new Storage.PropertiesComponentStorage("junit_statistics_table_columns");
private SimpleColoredComponent myTotalLabel;
private SimpleColoredComponent myTimeLabel;
public StatisticsPanel() {
super(new BorderLayout(0, 0));
myChildInfo = new StatisticsTable(TestColumnInfo.COLUMN_NAMES);
myTable = new TableView(myChildInfo) {
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
return new TestTableRenderer(TestColumnInfo.COLUMN_NAMES);
}
};
EditSourceOnDoubleClickHandler.install(myTable);
PopupHandler.installPopupHandler(myTable,
IdeActions.GROUP_TESTSTATISTICS_POPUP,
ActionPlaces.TESTSTATISTICS_VIEW_POPUP);
// add(myTestCaseInfo, BorderLayout.NORTH);
add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER);
final JPanel eastPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
myTotalLabel = new SimpleColoredComponent();
eastPanel.add(myTotalLabel);
myTimeLabel = new SimpleColoredComponent();
eastPanel.add(myTimeLabel);
add(eastPanel, BorderLayout.SOUTH);
}
private void updateStatistics() {
myTable.setVisible(true);
// myTestCaseInfo.setVisible(false);
TestProxy proxy = myCurrentTest != null ? myCurrentTest : myModel.getRoot();
if (proxy.isLeaf() && proxy.getParent() != null) {
proxy = proxy.getParent();
}
myChildInfo.updateStatistics(proxy);
myTotalLabel.clear();
myTotalLabel.append(TestsUIUtil.getTestSummary(proxy), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
myTimeLabel.clear();
myTimeLabel.append("Total time: " + Formatters.statisticsFor(proxy).getTime(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
final int idx = myChildInfo.getIndexOf(myCurrentTest);
if (idx >= 0) TableUtil.selectRows(myTable, new int[]{myTable.convertRowIndexToView(idx)});
TableUtil.scrollSelectionToVisible(myTable);
}
public void attachTo(final JUnitRunningModel model) {
myModel = model;
myModel.addListener(myListener);
myChildInfo.setModel(model);
BaseTableView.restore(myStorage, myTable);
}
public Object getData(final String dataId) {
if (myModel == null) return null;
final int selectedRow = myTable.getSelectedRow();
final TestProxy selectedTest = selectedRow == -1 ? null : myChildInfo.getTestAt(myTable.convertRowIndexToModel(selectedRow));
if (TestContext.DATA_KEY.is(dataId)) {
return new TestContext(myModel, selectedTest);
}
return TestsUIUtil.getData(selectedTest, dataId, myModel);
}
private class MyJUnitListener extends JUnitAdapter {
public void onTestChanged(final TestEvent event) {
if (!StatisticsPanel.this.isShowing()) return;
final TestProxy source = event.getSource();
if (myCurrentTest == source || myCurrentTest == null && source == myModel.getRoot()) {
updateStatistics();
}
}
public void onTestSelected(final TestProxy test) {
if (!StatisticsPanel.this.isShowing()) return;
if (myCurrentTest == test)
return;
if (test == null) {
myTable.setVisible(false);
return;
}
myCurrentTest = test;
updateStatistics();
}
public void doDispose() {
BaseTableView.store(myStorage, myTable);
myTable.setModelAndUpdateColumns(new ListTableModel(TestColumnInfo.COLUMN_NAMES));
myModel = null;
myChildInfo = null;
myCurrentTest = null;
}
}
}
@@ -1,98 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.testframework.Filter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import java.util.ArrayList;
import java.util.Arrays;
public class StatisticsTable extends ListTableModel<TestProxy> {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.ui.StatisticsTable");
private TestProxy myTest;
private JUnitRunningModel myModel;
public StatisticsTable(final ColumnInfo[] columnNames) {
super(columnNames);
}
public void setModel(final JUnitRunningModel model) {
myModel = model;
setTest(myModel.getRoot());
}
public void onSelectionChanged(final TestProxy test) {
setTest(test);
}
private void setTest(final TestProxy test) {
if (myTest == test) return;
updateStatistics(test);
}
private void changeTableData() {
if (myTest == null) {
resetTests();
return;
}
setItems(new ArrayList<TestProxy>(Arrays.asList(myTest.selectChildren(Filter.NO_FILTER))));
}
private void resetTests() {
setItems(new ArrayList<TestProxy>());
}
public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) {
LOG.error("value: " + aValue + " row: " + rowIndex + " column: " + columnIndex);
}
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
return false;
}
// TODO: move out of the table
private Object testProperty(final int columnIndex) {
if (columnIndex == 0)
return ExecutionBundle.message("junit.runing.info.total.label");
return getAspectOf(columnIndex, myTest);
}
public TestProxy getTestAt(final int rowIndex) {
if (rowIndex < 0 || rowIndex > getItems().size())
return null;
return getItems().get(rowIndex);
}
public int getIndexOf(final Object test) {
for (int i = 0; i < getItems().size(); i++) {
final Object child = getItems().get(i);
if (child == test) return i;
}
return -1;
}
public void updateStatistics(TestProxy currentTest) {
myTest = currentTest;
changeTableData();
}
}
@@ -1,290 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.states.Statistics;
import com.intellij.execution.junit2.states.TestState;
import com.intellij.execution.testframework.Filter;
import com.intellij.execution.testframework.TestsUIUtil;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import com.intellij.ui.*;
import com.intellij.util.ui.ColumnInfo;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.Comparator;
import java.util.List;
public abstract class TestColumnInfo extends ColumnInfo implements Comparator {
public TestColumnInfo(final String name) {
super(name);
}
public Object valueOf(final Object object) {
return valueOfTest((TestProxy)object);
}
public Comparator getComparator() {
return this;
}
protected abstract String valueOfTest(TestProxy test);
private static abstract class StatisticsColumn extends TestColumnInfo {
public StatisticsColumn(final String name) {
super(name);
}
public final int compare(final Object o1, final Object o2) {
final long a2 = getAspect(getTestStatistics(o2));
final long a1 = getAspect(getTestStatistics(o1));
return a2 > a1 ? 1 : a1 > a2 ? -1 : 0;
}
private static Statistics getTestStatistics(final Object o1) {
return ((TestProxy) o1).getStatistics();
}
public TableCellRenderer getRenderer(final Object o) {
return new RightAlignedRenderer();
}
protected abstract long getAspect(Statistics statistics);
}
private static final ColumnInfo TEST = new TestColumnInfo(ExecutionBundle.message("junit.runing.info.test.column.name")) {
public String valueOfTest(final TestProxy test) {
return Formatters.printTest(test);
}
public TableCellRenderer getRenderer(final Object o) {
return new TestInfoRenderer();
}
public int compare(final Object o1, final Object o2) {
return getTestName(o1).compareTo(getTestName(o2));
}
private String getTestName(final Object o1) {
return ((TestProxy)o1).getInfo().getName();
}
};
private static final ColumnInfo TIME = new StatisticsColumn(ExecutionBundle.message("junit.runing.info.time.elapsed.column.name")){
public String valueOfTest(final TestProxy test) {
return Formatters.statisticsFor(test).getTime();
}
public long getAspect(final Statistics statistics) {
return statistics.getTime();
}
};
private static final ColumnInfo MEMORY_DELTA = new StatisticsColumn(ExecutionBundle.message("junit.runing.info.usage.delta.column.name")){
public String valueOfTest(final TestProxy test) {
return Formatters.statisticsFor(test).getMemoryUsageDelta();
}
public long getAspect(final Statistics statistics) {
return statistics.getMemoryUsage();
}
};
private static final ColumnInfo BEFORE_MEMORY = new StatisticsColumn(ExecutionBundle.message("junit.runing.info.usage.before.column.name")){
public String valueOfTest(final TestProxy test) {
return Formatters.statisticsFor(test).getBeforeMemory();
}
public long getAspect(final Statistics statistics) {
return statistics.getBeforeMemory();
}
};
private static final ColumnInfo AFTER_MEMORY = new StatisticsColumn(ExecutionBundle.message("junit.runing.info.usage.after.column.name")){
public String valueOfTest(final TestProxy test) {
return Formatters.statisticsFor(test).getAfterMemory();
}
public long getAspect(final Statistics statistics) {
return statistics.getAfterMemory();
}
};
private static final ColumnInfo CHILDREN_STATES = new TestColumnInfo(ExecutionBundle.message("junit.runing.info.results.column.name")) {
protected String valueOfTest(final TestProxy test) {
return "";
}
public int compare(final Object o1, final Object o2) {
return defectCount(o1) - defectCount(o2);
}
private int defectCount(final Object o1) {
final TestProxy test = (TestProxy)o1;
return test.selectChildren(Filter.DEFECT).length;
}
public TableCellRenderer getRenderer(final Object o) {
return new CountDefectsRenderer();
}
};
public static final ColumnInfo[] COLUMN_NAMES = new ColumnInfo[]{TEST, TIME, MEMORY_DELTA, BEFORE_MEMORY, AFTER_MEMORY, CHILDREN_STATES};
private static TestProxy getTestAtRow(final JTable table, final int row) {
final StatisticsTable tableModel = (StatisticsTable)table.getModel();
return tableModel.getTestAt(table.convertRowIndexToModel(row));
}
private static class TestInfoRenderer extends ColoredTableCellRenderer {
protected void customizeCellRenderer(final JTable table, final Object value, final boolean selected, final boolean hasFocus, final int row, final int column) {
TestRenderer.renderTest(getTestAtRow(table, row), this);
}
}
private static class RightAlignedRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(final JTable table, final Object value,
final boolean isSelected, final boolean hasFocus, final int row, final int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setHorizontalAlignment(JLabel.RIGHT);
return this;
}
}
private static class CountDefectsRenderer extends JPanel implements TableCellRenderer {
private static final SimpleTextAttributes RUNNING_COLOR = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.BLACK);
private static final SimpleTextAttributes DEFECT_ATTRIBUTE = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, JBColor.RED);
private final SimpleColoredRenderer myCounters = new SimpleColoredRenderer();
private final SimpleColoredRenderer myProgressIndicator = new SimpleColoredRenderer();
private final TableCellState myCellState = new TableCellState();
private static final SimpleTextAttributes TERMINATED_ATTRIBUTE = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD,
JBColor.ORANGE);
public CountDefectsRenderer() {
super(new BorderLayout());
add(myProgressIndicator, BorderLayout.WEST);
add(myCounters, BorderLayout.EAST);
}
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
myCellState.collectState(table, isSelected, hasFocus, row, column);
myCellState.updateRenderer(this);
updateSubcomponent(myCounters);
updateSubcomponent(myProgressIndicator);
customizeCellRenderer(table, row);
return this;
}
private void updateSubcomponent(final SimpleColoredRenderer subRenderer) {
subRenderer.clear();
subRenderer.setCellState(myCellState);
myCellState.updateRenderer(subRenderer);
subRenderer.setBorder(null);
}
private void customizeCellRenderer(final JTable table, final int row) {
final StatisticsTable model = (StatisticsTable)table.getModel();
final TestProxy test = model.getTestAt(table.convertRowIndexToModel(row));
if (test == null) {
return;
}
if (test.getChildCount() == 0) {
customizeTestCase(test);
}
else {
customizeTestSuite(test);
}
}
private void customizeTestSuite(final TestProxy test) {
int running = 0;
int passed = 0;
int errors = 0;
int failed = 0;
int ignored = 0;
final TestState suiteState = test.getState();
final List testCases = test.getAllTests();
for (final Object testCase : testCases) {
final TestProxy child = (TestProxy)testCase;
if (!child.isLeaf()) continue;
final TestState state = child.getState();
if (state.isInProgress()) {
running++;
}
else if (state.isPassed()) {
passed++;
}
else if (state.getMagnitude() == PoolOfTestStates.ERROR_INDEX) {
errors++;
}
else if (state.getMagnitude() == PoolOfTestStates.IGNORED_INDEX) {
ignored++;
}
else {
failed++;
}
}
if (running > 0) {
myProgressIndicator.append(ExecutionBundle.message("junit.runing.info.left.to.run.count.tree.node", running), RUNNING_COLOR);
}
String separator = "";
if (failed > 0) {
myCounters.append(ExecutionBundle.message("junit.runing.info.failed.count.message", failed), DEFECT_ATTRIBUTE);
separator = " ";
}
if (errors > 0) {
myCounters.append(separator + ExecutionBundle.message("junit.runing.info.errors.count.message", errors), DEFECT_ATTRIBUTE);
separator = " ";
}
if (ignored> 0) {
myCounters.append(separator + ExecutionBundle.message("junit.runing.info.ignored.count.message", ignored), TERMINATED_ATTRIBUTE);
separator = " ";
}
if (passed > 0) {
final Color color = suiteState.isPassed() ? TestsUIUtil.PASSED_COLOR : Color.BLACK;
myCounters.append(separator + ExecutionBundle.message("junit.runing.info.passed.count.message", passed), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, color));
}
}
private void customizeTestCase(final TestProxy test) {
final TestState state = test.getState();
if (state.isInProgress()) {
myCounters.append(ExecutionBundle.message("junit.runing.info.running.label"), RUNNING_COLOR);
}
else if (state.isPassed()) {
myCounters
.append(ExecutionBundle.message("junit.runing.info.passed.label"), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, TestsUIUtil.PASSED_COLOR));
}
else if (state.getMagnitude() == PoolOfTestStates.ERROR_INDEX) {
myCounters.append(ExecutionBundle.message("junit.runing.info.error.tree.node"), DEFECT_ATTRIBUTE);
}
else if (state.getMagnitude() == PoolOfTestStates.TERMINATED_INDEX) {
myCounters.append(ExecutionBundle.message("junit.runing.info.terminated.label"), TERMINATED_ATTRIBUTE);
}
else if (state.getMagnitude() == PoolOfTestStates.IGNORED_INDEX) {
myCounters.append(ExecutionBundle.message("junit.runing.info.ignored.label"), TERMINATED_ATTRIBUTE);
}
else {
myCounters.append(ExecutionBundle.message("junit.runing.info.assertion.tree.node"), DEFECT_ATTRIBUTE);
}
}
}
}
@@ -1,147 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.NewChildEvent;
import com.intellij.execution.junit2.events.StateChangedEvent;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.ui.model.CompletionEvent;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Filter;
import com.intellij.execution.testframework.TestsUIUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
public class TestProgress extends DefaultBoundedRangeModel implements Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.ui.TestProgress");
private int myProblemsCounter = 0;
private TestProxy myCurrentState = null;
private final MyJUnitListener myListener = new MyJUnitListener();
private int myMissingChildren;
private Project myProject;
public static final Filter TEST_CASE = new Filter() {
public boolean shouldAccept(final AbstractTestProxy test) {
return test.shouldRun();
}
};
private CompletionEvent myDone;
public TestProgress() {
super(0, 0, 0, 0);
}
public TestProgress(final JUnitRunningModel model) {
this();
setModel(model);
}
public void setModel(final JUnitRunningModel model) {
myMissingChildren = 0;
myProject = model.getProject();
final int knownTestCases = TEST_CASE.select(model.getRoot().getAllTests()).size();
final int declaredTestCases = model.getRoot().getInfo().getTestsCount();
if (declaredTestCases > knownTestCases)
myMissingChildren = declaredTestCases - knownTestCases;
setMaximum(knownTestCases + myMissingChildren);
model.addListener(myListener);
}
public int countDefects() {
return myProblemsCounter;
}
public boolean hasDefects() {
return countDefects() > 0;
}
public TestProxy getCurrentTest() {
return myCurrentState;
}
private void setCurrentState(final TestProxy currentState) {
myCurrentState = currentState;
fireStateChanged();
}
public CompletionEvent getDone() {
return myDone;
}
public void setDone(CompletionEvent done) {
myDone = done;
}
private class MyJUnitListener extends JUnitAdapter {
public void onTestChanged(final TestEvent event) {
if (event instanceof StateChangedEvent)
onChanged((StateChangedEvent) event);
if (event instanceof NewChildEvent)
onChildAdded((NewChildEvent) event);
}
public void onChanged(final StateChangedEvent event) {
final TestProxy test = event.getSource();
if (!test.isLeaf())
return;
final int stateMagnitude = test.getState().getMagnitude();
if (test.getState().isFinal()) {
if (!test.getInfo().shouldRun())
newTestAppeared();
if (getValue() >= getMaximum()) {
@NonNls final String message = "State changed: " +test + " state: " + stateMagnitude +
" Max: " + getMaximum() + " Value: "+ getValue();
LOG.error(message);
}
if (test.getState().isDefect())
myProblemsCounter++;
setValue(getValue() + 1);
}
setCurrentState(stateMagnitude == PoolOfTestStates.RUNNING_INDEX ? test : null);
}
public void onChildAdded(final NewChildEvent event) {
if (event.getChild().getInfo().shouldRun())
newTestAppeared();
}
private void newTestAppeared() {
if (myMissingChildren == 0)
setMaximum(getMaximum() + 1);
else
myMissingChildren--;
}
}
@Override
public void setValue(int n) {
super.setValue(n);
TestsUIUtil.showIconProgress(myProject, n, getMaximum(), myProblemsCounter, false);
}
public void dispose() {
TestsUIUtil.clearIconProgress(myProject);
}
}
@@ -1,43 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.ide.util.treeView.NodeDescriptor;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
public class TestProxyClient {
public static TestProxy from(final Object object) {
if (object instanceof DefaultMutableTreeNode) {
final Object userObject = ((DefaultMutableTreeNode)object).getUserObject();
if (userObject instanceof NodeDescriptor) {
final Object element = ((NodeDescriptor)userObject).getElement();
if (element instanceof TestProxy) {
return (TestProxy)element;
}
}
}
return null;
}
public static TestProxy from(final TreePath path) {
if (path == null) return null;
return from(path.getLastPathComponent());
}
}
@@ -1,73 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.info.TestInfo;
import com.intellij.execution.junit2.ui.model.SpecialNode;
import com.intellij.execution.testframework.PoolOfTestIcons;
import com.intellij.execution.testframework.TestsUIUtil;
import com.intellij.execution.testframework.ui.TestsProgressAnimator;
import com.intellij.icons.AllIcons;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.containers.HashMap;
import javax.swing.*;
import java.util.Map;
class TestRenderer {
private static final Map<Integer,Icon> ourIcons = new HashMap<Integer, Icon>();
public static Icon getIconFor(final TestProxy testProxy, final boolean isPaused) {
final int magnitude = testProxy.getState().getMagnitude();
if (magnitude == PoolOfTestStates.RUNNING_INDEX)
return isPaused ? AllIcons.RunConfigurations.TestPaused : TestsProgressAnimator.getCurrentFrame();
else
return ourIcons.get(new Integer(magnitude));
}
private static SimpleTextAttributes getSpecialAttributes() {
return new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, TestsUIUtil.PASSED_COLOR);
}
static {
mapIcon(PoolOfTestStates.SKIPPED_INDEX, PoolOfTestIcons.SKIPPED_ICON);
mapIcon(PoolOfTestStates.NOT_RUN_INDEX, PoolOfTestIcons.NOT_RAN);
mapIcon(PoolOfTestStates.PASSED_INDEX, PoolOfTestIcons.PASSED_ICON);
mapIcon(PoolOfTestStates.TERMINATED_INDEX, PoolOfTestIcons.TERMINATED_ICON);
mapIcon(PoolOfTestStates.FAILED_INDEX, PoolOfTestIcons.FAILED_ICON);
mapIcon(PoolOfTestStates.COMPARISON_FAILURE, PoolOfTestIcons.FAILED_ICON);
mapIcon(PoolOfTestStates.ERROR_INDEX, PoolOfTestIcons.ERROR_ICON);
mapIcon(PoolOfTestStates.IGNORED_INDEX, PoolOfTestIcons.IGNORED_ICON);
}
private static void mapIcon(final int index, final Icon icon) {
ourIcons.put(new Integer(index), icon);
}
public static void renderTest(final TestProxy test, final SimpleColoredComponent renderer) {
final TestInfo info = test.getInfo();
if (test instanceof SpecialNode) {
renderer.append(info.getName(), getSpecialAttributes());
} else {
renderer.append(info.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
renderer.append(Formatters.sensibleCommentFor(test), SimpleTextAttributes.GRAY_ATTRIBUTES);
}
}
}
@@ -1,62 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import org.jetbrains.annotations.NonNls;
public interface TestStatistics {
@NonNls String RUNNING_SUITE_PREFIX = "RUNNING: ";
TestStatistics ABCENT = new NoStatistics("NO SELECTION");
TestStatistics NOT_RUN = new NoStatistics("NOT RUN");
TestStatistics RUNNING = new NoStatistics("RUNNING");
String getTime();
String getMemoryUsageDelta();
String getBeforeMemory();
String getAfterMemory();
static class NoStatistics implements TestStatistics {
private final String myMessage;
public NoStatistics(@NonNls final String message) {
myMessage = "<" + message + ">";
}
public String getTime() {
return myMessage;
}
public String getMemoryUsageDelta() {
return myMessage;
}
public String getBeforeMemory() {
return myMessage;
}
public String getAfterMemory() {
return myMessage;
}
public String toString() {
return myMessage;
}
}
}
@@ -1,46 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.util.ui.ColumnInfo;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
class TestTableRenderer implements TableCellRenderer {
private final TableCellRenderer[] myRenderers;
private final TableCellRenderer myLeftTopRenderer = new DefaultTableCellRenderer();
public TestTableRenderer(final ColumnInfo[] columns) {
myRenderers = new TableCellRenderer[columns.length];
for (int i = 0; i < columns.length; i++) {
final ColumnInfo column = columns[i];
myRenderers[i] = column.getRenderer(null);
}
}
public Component getTableCellRendererComponent(final JTable table, final Object value,
final boolean isSelected, final boolean hasFocus,
final int row, final int column) {
final int modelColumn = table.convertColumnIndexToModel(column);
final TableCellRenderer renderer = myRenderers[modelColumn];
return renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}
@@ -1,363 +0,0 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* User: anna
* Date: 11-Dec-2009
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.info.ClassBasedInfo;
import com.intellij.execution.junit2.info.DisplayTestInfoExtractor;
import com.intellij.execution.junit2.segments.InputObjectRegistry;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.execution.junit2.segments.OutputPacketProcessor;
import com.intellij.execution.junit2.states.*;
import com.intellij.execution.junit2.ui.model.CompletionEvent;
import com.intellij.execution.junit2.ui.model.JUnitListenersNotifier;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Printable;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import com.intellij.util.containers.HashMap;
import gnu.trove.TIntObjectHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class TestsPacketsReceiver implements OutputPacketProcessor, Disposable {
private static final TIntObjectHashMap<StateChanger> STATE_CLASSES = new TIntObjectHashMap<StateChanger>();
private Map<String, TestProxy> myKnownDynamicParents;
private final TestProxy myUnboundOutput;
static {
mapClass(PoolOfTestStates.RUNNING_INDEX, new RunningStateSetter());
mapClass(PoolOfTestStates.COMPLETE_INDEX, new TestCompleter());
mapClass(PoolOfTestStates.FAILED_INDEX, new StateReader(FaultyState.class));
mapClass(PoolOfTestStates.ERROR_INDEX, new StateReader(FaultyState.class));
mapClass(PoolOfTestStates.IGNORED_INDEX, new StateReader(IgnoredState.class));
mapClass(PoolOfTestStates.SKIPPED_INDEX, new StateReader(SkippedState.class));
mapClass(PoolOfTestStates.COMPARISON_FAILURE, new StateReader(ComparisonFailureState.class));
}
public static void mapClass(final int magnitude, @NotNull StateChanger factory) {
factory.setMagnitude(magnitude);
STATE_CLASSES.put(magnitude, factory);
}
private final InputObjectRegistry myObjectRegistry;
private final Set<TestProxy> myCurrentTests = new HashSet<TestProxy>();
private boolean myIsTerminated = false;
private JUnitRunningModel myModel;
private final JUnitConsoleProperties myConsoleProperties;
public TestsPacketsReceiver(@NotNull JUnitTreeConsoleView consoleView, @NotNull TestProxy unboundOutput) {
myUnboundOutput = unboundOutput;
myObjectRegistry = new InputObjectRegistry();
myConsoleProperties = (JUnitConsoleProperties)consoleView.getProperties();
}
@Override
public void processPacket(final String packet) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (packet.startsWith(PoolOfDelimiters.TREE_PREFIX)) {
notifyStart(readNode(new ObjectReader(packet, PoolOfDelimiters.TREE_PREFIX.length(), myObjectRegistry)));
}
else if (packet.startsWith(PoolOfDelimiters.INPUT_COSUMER)) {
notifyTestStart(new ObjectReader(packet, PoolOfDelimiters.INPUT_COSUMER.length(), myObjectRegistry));
}
else if (packet.startsWith(PoolOfDelimiters.CHANGE_STATE)) {
notifyTestResult(new ObjectReader(packet, PoolOfDelimiters.CHANGE_STATE.length(), myObjectRegistry));
}
else if (packet.startsWith(PoolOfDelimiters.TESTS_DONE)) {
notifyFinish(new ObjectReader(packet, PoolOfDelimiters.TESTS_DONE.length(), myObjectRegistry));
}
else if (packet.startsWith(PoolOfDelimiters.OBJECT_PREFIX)) {
myObjectRegistry.readPacketFrom(new ObjectReader(packet, PoolOfDelimiters.OBJECT_PREFIX.length(), myObjectRegistry));
}
}
@Override
public void processOutput(Printable printable) {
synchronized (myCurrentTests) {
if (myCurrentTests.isEmpty()) {
myUnboundOutput.addLast(printable);
} else {
for (TestProxy currentTest : myCurrentTests) {
currentTest.addLast(printable);
}
}
}
}
public synchronized void notifyStart(TestProxy root) {
myModel = new JUnitRunningModel(root, myConsoleProperties);
Disposer.register(this, myModel);
}
private static TestProxy readNode(final ObjectReader reader) {
final TestProxy node = reader.readObject();
final int childCount = reader.readInt();
for (int i = 0; i < childCount; i++) {
node.addChild(readNode(reader));
}
return node;
}
public void notifyTestStart(ObjectReader reader) {
final TestProxy testProxy = reader.readObject();
final JUnitRunningModel model = getModel();
if (model != null && testProxy.getParent() == null && model.getRoot() != testProxy) {
getDynamicParent(model, testProxy).addChild(testProxy);
}
}
private TestProxy getDynamicParent(JUnitRunningModel model, final TestProxy currentTest) {
if (myKnownDynamicParents == null) {
myKnownDynamicParents = new HashMap<String, TestProxy>();
}
final String parentClass = currentTest.getInfo().getComment();
TestProxy dynamicParent = myKnownDynamicParents.get(parentClass);
if (dynamicParent == null) {
final TestProxy root = findParent(parentClass, model.getRoot());
if (root != null) {
dynamicParent = root;
}
else {
dynamicParent = new TestProxy(new ClassBasedInfo(DisplayTestInfoExtractor.FOR_CLASS) {
{
setClassName(parentClass);
}
@Override
public void readFrom(ObjectReader reader) {
}
});
model.getRoot().addChild(dynamicParent);
}
myKnownDynamicParents.put(parentClass, dynamicParent);
}
return dynamicParent;
}
private static TestProxy findParent(String parentClass, TestProxy root) {
if (isAccepted(root, parentClass)) {
return root;
}
for (TestProxy proxy : root.getChildren()) {
if (isAccepted(proxy, parentClass)) {
return proxy;
}
}
return null;
}
private static boolean isAccepted(TestProxy root, String parentClass) {
return Comparing.strEqual(parentClass, StringUtil.getQualifiedName(root.getInfo().getComment(), root.getName()));
}
public void notifyTestResult(ObjectReader reader) {
final TestProxy testProxy = reader.readObject();
if (testProxy.getParent() == null) { //model.getRoot() == testProxy
getDynamicParent(myModel, testProxy).insertNextRunningChild(testProxy);
}
final int state = reader.readInt();
final StateChanger stateChanger = STATE_CLASSES.get(state);
stateChanger.changeStateOf(testProxy, reader);
synchronized (myCurrentTests) {
if (stateChanger instanceof RunningStateSetter) {
myCurrentTests.add(testProxy);
}
else {
myCurrentTests.remove(testProxy);
}
}
}
public void notifyFinish(ObjectReader reader) {
myIsTerminated = true;
synchronized (myCurrentTests) {
myCurrentTests.clear();
}
final JUnitRunningModel model = getModel();
if (model != null) {
model.getNotifier().fireRunnerStateChanged(new CompletionEvent(true, reader.readInt()));
terminateStillRunning(model);
}
}
public synchronized boolean isRunning() {
return !myIsTerminated;
}
public synchronized void setTerminated(boolean terminated) {
myIsTerminated = terminated;
}
@Nullable
public JUnitRunningModel getModel() {
return myModel;
}
@Override
public void dispose() {
myModel = null;
}
public void checkTerminated() {
if (isRunning()) {
final JUnitRunningModel model = getModel();
if (model != null) {
final JUnitListenersNotifier notifier = model.getNotifier();
if (notifier != null) {
notifier.fireRunnerStateChanged(new CompletionEvent(false, -1));
terminateStillRunning(model);
}
}
setTerminated(true);
}
}
private void terminateStillRunning(@NotNull JUnitRunningModel model) {
if (model.getRoot() != null) {
final List<AbstractTestProxy> runningTests = TestStateUpdater.RUNNING_LEAF.select(myModel.getRoot().getAllTests());
for (final AbstractTestProxy runningTest : runningTests) {
final TestProxy testProxy = (TestProxy)runningTest;
final TestState terminated = NotFailedState.createTerminated();
testProxy.setState(terminated);
TestProxy parent = testProxy.getParent();
while (parent != null) {
parent.setState(terminated);
parent = parent.getParent();
}
}
}
}
private abstract static class StateChanger {
static final Logger LOG = Logger.getInstance("#" + StateChanger.class.getName());
abstract void changeStateOf(TestProxy testProxy, ObjectReader reader);
void setMagnitude(final int magnitude) {
}
static void complete(TestProxy testProxy) {
final int magnitude = testProxy.getState().getMagnitude();
TestProxy parent = testProxy.getParent();
TestProxy child = testProxy;
while (parent != null) {
final List<TestProxy> children = parent.getChildren();
final TestState parentState = parent.getState();
if (parentState instanceof SuiteState) {
if (!child.isInProgress() && child.equals(children.get(children.size() - 1))) {
((SuiteState)parentState).setRunning(false);
parent.fireStateChanged();
parent.flush();
}
((SuiteState)parentState).updateMagnitude(magnitude);
}
child = parent;
parent = parent.getParent();
}
}
}
private static class RunningStateSetter extends StateChanger {
@Override
public void changeStateOf(final TestProxy testProxy, final ObjectReader reader) {
testProxy.setState(TestState.RUNNING_STATE);
TestProxy parent = testProxy.getParent();
while (parent != null) {
final TestState state = parent.getState();
if (state instanceof SuiteState) {
((SuiteState)state).setRunning(true);
}
parent = parent.getParent();
}
}
}
private static class StateReader extends StateChanger {
private final Class<? extends ReadableState> myStateClass;
private int myInstanceMagnitude;
public StateReader(final Class<? extends ReadableState> stateClass) {
myStateClass = stateClass;
}
@Override
public void changeStateOf(final TestProxy testProxy, final ObjectReader reader) {
final ReadableState state;
try {
state = myStateClass.newInstance();
}
catch (Exception e) {
LOG.error(e);
return;
}
state.setMagitude(myInstanceMagnitude);
state.initializeFrom(reader);
testProxy.setState(state);
complete(testProxy);
}
@Override
public void setMagnitude(final int magnitude) {
myInstanceMagnitude = magnitude;
}
}
private static class TestCompleter extends StateChanger {
@Override
public void changeStateOf(final TestProxy testProxy, final ObjectReader reader) {
TestState state = testProxy.getState();
if (!testProxy.getState().isFinal()) {
state = NotFailedState.createPassed();
}
testProxy.setState(state);
testProxy.setStatistics(new Statistics(reader));
complete(testProxy);
}
}
}
@@ -1,51 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import javax.swing.*;
class TreeTestRenderer extends ColoredTreeCellRenderer {
private final TestConsoleProperties myProperties;
public TreeTestRenderer(final TestConsoleProperties properties) {
myProperties = properties;
}
public void customizeCellRenderer(
final JTree tree,
final Object value,
final boolean selected,
final boolean expanded,
final boolean leaf,
final int row,
final boolean hasFocus
) {
final TestProxy testProxy = TestProxyClient.from(value);
if (testProxy != null) {
TestRenderer.renderTest(testProxy, this);
setIcon(TestRenderer.getIconFor(testProxy, myProperties.isPaused()));
} else {
append(ExecutionBundle.message("junit.runing.info.loading.tree.node.text"), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
}
}
@@ -1,74 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.actions;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.model.StateEvent;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.testframework.*;
import com.intellij.execution.testframework.actions.ScrollToTestSourceAction;
import com.intellij.openapi.project.Project;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiClass;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
public class JUnitToolbarPanel extends ToolbarPanel {
@NonNls protected static final String TEST_SUITE_CLASS_NAME = "junit.framework.TestSuite";
public JUnitToolbarPanel(final TestConsoleProperties properties,
final JComponent parentComponent) {
super(properties, parentComponent);
}
public void setModel(final TestFrameworkRunningModel model) {
super.setModel(model);
final JUnitRunningModel jUnitModel = (JUnitRunningModel)model;
jUnitModel.addListener(new JUnitAdapter() {
public void onRunnerStateChanged(final StateEvent event) {
if (event.isRunning() || !JUnitConsoleProperties.SELECT_FIRST_DEFECT.value(jUnitModel.getProperties()))
return;
final AbstractTestProxy firstDefect = Filter.DEFECTIVE_LEAF.detectIn(jUnitModel.getRoot().getAllTests());
if (firstDefect != null) jUnitModel.selectAndNotify(firstDefect);
}
});
RunningTestTracker.install(jUnitModel);
jUnitModel.addListener(new LvcsLabeler(jUnitModel));
jUnitModel.addListener(new JUnitAdapter() {
public void onTestSelected(final TestProxy test) {
if (test == null) return;
final Project project = jUnitModel.getProject();
if (!ScrollToTestSourceAction.isScrollEnabled(model)) return;
final Location location = test.getInfo().getLocation(project, jUnitModel.getProperties().getScope());
if (location != null) {
final PsiClass aClass = PsiTreeUtil.getParentOfType(location.getPsiElement(), PsiClass.class, false);
if (aClass != null && JUnitToolbarPanel.TEST_SUITE_CLASS_NAME.equals(aClass.getQualifiedName())) return;
}
final Navigatable descriptor = TestsUIUtil.getOpenFileDescriptor(test, model);
if (descriptor != null && descriptor.canNavigate()) {
descriptor.navigate(false);
}
}
});
}
}
@@ -1,55 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.actions;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.junit2.ui.model.CompletionEvent;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.StateEvent;
import com.intellij.execution.testframework.LvcsHelper;
import com.intellij.execution.testframework.TestFrameworkRunningModel;
public class LvcsLabeler extends JUnitAdapter {
private final TestFrameworkRunningModel myModel;
public LvcsLabeler(final TestFrameworkRunningModel model) {
myModel = model;
}
public void onRunnerStateChanged(final StateEvent event) {
if (!(event instanceof CompletionEvent)) {
return;
}
final boolean areTestsFailed = myModel.getRoot().isDefect();
final CompletionEvent completion = (CompletionEvent)event;
final RunProfile configuration = myModel.getProperties().getConfiguration();
if (configuration == null) {
return;
}
if (testsTerminatedAndNotFailed(completion, areTestsFailed)) return;
if (completion.isNormalExit()) {
LvcsHelper.addLabel(myModel);
}
}
private static boolean testsTerminatedAndNotFailed(final CompletionEvent completion, final boolean areTestsPassed) {
return !completion.isNormalExit() && areTestsPassed;
}
}
@@ -1,128 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.actions;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.StateChangedEvent;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.ui.model.JUnitAdapter;
import com.intellij.execution.junit2.ui.model.JUnitRunningModel;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.TestFrameworkPropertyListener;
import com.intellij.execution.testframework.TrackRunningTestUtil;
import com.intellij.execution.testframework.actions.TestFrameworkActions;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pass;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import javax.swing.*;
class RunningTestTracker extends JUnitAdapter implements TestFrameworkPropertyListener<Boolean> {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.ui.actions.TrackRunningTestAction");
private final JUnitRunningModel myModel;
private TrackingPolicy myTrackingPolicy;
private TestProxy myLastRan = null;
private TestProxy myLastSelected = null;
private RunningTestTracker(final JUnitRunningModel model) {
myModel = model;
final JTree tree = myModel.getTree();
TrackRunningTestUtil.installStopListeners(tree, myModel, new Pass<AbstractTestProxy>() {
@Override
public void pass(AbstractTestProxy testProxy) {
myLastSelected = (TestProxy)testProxy;
}
});
choosePolicy();
}
public void onChanged(final Boolean value) {
choosePolicy();
myTrackingPolicy.apply();
}
public void onTestChanged(final TestEvent event) {
if (event instanceof StateChangedEvent) {
final TestProxy proxy = event.getSource();
final boolean isRunning = isRunningState(proxy);
if (isRunning) {
if (proxy.isLeaf()) {
myLastRan = proxy;
}
if (myLastSelected == proxy) {
myLastSelected = null;
}
}
else if (proxy == myLastRan) {
myLastRan = null;
}
myTrackingPolicy.applyTo(proxy);
}
}
public static void install(final JUnitRunningModel model) {
final RunningTestTracker testTracker = new RunningTestTracker(model);
model.addListener(testTracker);
TestFrameworkActions.addPropertyListener(JUnitConsoleProperties.TRACK_RUNNING_TEST, testTracker, model, false);
}
private static boolean isRunningState(final TestProxy test) {
return test.getState().getMagnitude() == PoolOfTestStates.RUNNING_INDEX;
}
private abstract static class TrackingPolicy {
protected abstract void applyTo(TestProxy test);
protected abstract void apply();
}
private void choosePolicy() {
final boolean shouldTrack = JUnitConsoleProperties.TRACK_RUNNING_TEST.value(myModel.getProperties());
myTrackingPolicy = shouldTrack ? TRACK_RUNNING : DONT_TRACK;
}
private static final TrackingPolicy DONT_TRACK = new TrackingPolicy() {
protected void applyTo(final TestProxy test) {}
protected void apply() {}
};
private final TrackingPolicy TRACK_RUNNING = new TrackingPolicy() {
protected void applyTo(final TestProxy test) {
LOG.assertTrue(myModel != null);
selectLastTest();
if (!test.isLeaf() && test.getState().isPassed())
myModel.collapse(test);
}
protected void apply() {
LOG.assertTrue(myModel != null);
selectLastTest();
}
private void selectLastTest() {
if (myLastRan != null && isRunningState(myLastRan)) {
if (myLastSelected == null) {
myModel.selectTest(myLastRan);
}
else {
myModel.expandTest(myLastRan);
}
}
}
};
}
@@ -1,41 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.openapi.util.text.StringUtil;
public class CompletionEvent extends StateEvent {
private final boolean myNormalExit;
public CompletionEvent(final boolean normalExit, final long time) {
super(normalExit ? TerminatedType.DONE: TerminatedType.TERNINATED,
time >= 0 ? "in " + StringUtil.formatDuration(time) : "");
myNormalExit = normalExit;
}
public boolean isRunning() {
return false;
}
public boolean isNormalExit() {
return myNormalExit;
}
public boolean isTerminated() {
return !myNormalExit;
}
}
@@ -1,45 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.execution.ExecutionBundle;
class Flag {
private final Logger myLogger;
private boolean myValue;
public Flag(final Logger logger, final boolean value) {
myLogger = logger;
myValue = value;
}
public void setValue(final boolean value) {
myValue = value;
// StringWriter out = new StringWriter();
// new Exception(String.valueOf(value)).printStackTrace(new PrintWriter(out));
// myLastAccess = out.toString();
}
public void assertValue(final boolean expected) {
myLogger.assertTrue(expected == myValue, "first time");
}
public boolean getValue() {
return myValue;
}
}
@@ -1,44 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.TestProxy;
import java.util.List;
public abstract class JUnitAdapter implements JUnitListener {
public void onTestSelected(final TestProxy test) {
}
public final void onDispose(final JUnitRunningModel model) {
model.removeListener(this);
doDispose();
}
protected void doDispose() {}
public void onTestChanged(final TestEvent event) {
}
public void onRunnerStateChanged(final StateEvent event) {
}
public void onEventsDispatched(final List<TestEvent> events) {
}
}
@@ -1,30 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.TestProxy;
import java.util.List;
public interface JUnitListener {
void onTestSelected(TestProxy test);
void onDispose(JUnitRunningModel model);
void onTestChanged(TestEvent event);
void onRunnerStateChanged(StateEvent event);
void onEventsDispatched(List<TestEvent> events);
}
@@ -1,162 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.events.TestEventsConsumer;
import com.intellij.execution.junit2.segments.DispatchListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.Alarm;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class JUnitListenersNotifier implements TestEventsConsumer, DispatchListener, Runnable {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.ui.model.JUnitListenersNotifier");
private final ArrayList<JUnitListener> myListeners = new ArrayList<JUnitListener>();
private final ArrayList<TestEvent> myEventsQueue = new ArrayList<TestEvent>();
private final Flag myCollectingEvents = new Flag(LOG, true);
private final Alarm myAlarm = new Alarm();
private final boolean myDeferEvents;
// public static TimeMeasurer MEASURER = new TimeMeasurer();
// private static final String ON_TEST_SELECTED = "TestSelected";
// private static final String DISPATCH_SINGLES = "Dispatch single events";
// private static final String PACKET_DISPATCH = "DispatchPacket";
// private static final String ON_EVENT = "onEvent";
public JUnitListenersNotifier(final boolean deferEvents) {
myDeferEvents = deferEvents;
// MEASURER.reset();
}
public JUnitListenersNotifier() {
this(!ApplicationManager.getApplication().isUnitTestMode());
}
public void fireTestSelected(final TestProxy test) {
// MEASURER.start(ON_TEST_SELECTED);
final JUnitListener[] listeners = getListeners();
for (final JUnitListener listener : listeners) {
listener.onTestSelected(test);
}
// MEASURER.stop(ON_TEST_SELECTED);
}
public void fireDisposed(final JUnitRunningModel model) {
final JUnitListener[] listeners = getListeners();
for (final JUnitListener listener : listeners) {
listener.onDispose(model);
}
}
private void dispatchTestEvent(final TestEvent event) {
final JUnitListener[] listeners = getListeners();
for (final JUnitListener listener : listeners) {
listener.onTestChanged(event);
}
}
public void fireRunnerStateChanged(final StateEvent event) {
// if (!event.isRunning()) MEASURER.printAll();
final JUnitListener[] listeners = getListeners();
for (final JUnitListener listener : listeners) {
listener.onRunnerStateChanged(event);
}
if (!myCollectingEvents.getValue()) {
myAlarm.cancelAllRequests();
dispatchAllEvents();
}
}
public void fireEventsDispatched(final List<TestEvent> events) {
// MEASURER.start(PACKET_DISPATCH);
final JUnitListener[] listeners = getListeners();
for (final JUnitListener listener : listeners) {
listener.onEventsDispatched(events);
}
// MEASURER.stop(PACKET_DISPATCH);
}
private JUnitListener[] getListeners() {
return myListeners.toArray(new JUnitListener[myListeners.size()]);
}
public void addListener(@NotNull JUnitListener listener) {
myListeners.add(listener);
}
public void removeListener(final JUnitListener listener) {
myListeners.remove(listener);
}
public void onEvent(final TestEvent event) {
// MEASURER.start(ON_EVENT);
if (myEventsQueue.isEmpty() && myDeferEvents) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(this, 400);
}
myEventsQueue.add(event);
// MEASURER.stop(ON_EVENT);
}
public void onStarted() {
myCollectingEvents.assertValue(false);
myCollectingEvents.setValue(true);
}
public void onFinished() {
myCollectingEvents.assertValue(true);
myCollectingEvents.setValue(false);
if (!myDeferEvents)
run();
}
public void run() {
myCollectingEvents.assertValue(false);
dispatchAllEvents();
}
private void dispatchAllEvents() {
//long start = System.currentTimeMillis();
final List<TestEvent> filteredEvents = removeDuplicates(myEventsQueue);
myEventsQueue.clear();
// MEASURER.start(DISPATCH_SINGLES);
for (final TestEvent event : filteredEvents) {
dispatchTestEvent(event);
}
// MEASURER.stop(DISPATCH_SINGLES);
fireEventsDispatched(filteredEvents);
//System.out.println("duration = " + (System.currentTimeMillis() - start));
}
private static <T> List<T> removeDuplicates(final List<T> list) {
final ArrayList<T> result = new ArrayList<T>(list.size());
final Set<T> collected = new HashSet<T>();
for (T t : list) {
if (collected.contains(t)) continue;
collected.add(t);
result.add(t);
}
return result;
}
}
@@ -1,232 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.execution.junit2.TestProxy;
import com.intellij.execution.junit2.events.StateChangedEvent;
import com.intellij.execution.junit2.events.TestEvent;
import com.intellij.execution.junit2.ui.TestProgress;
import com.intellij.execution.junit2.ui.TestProxyClient;
import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.Filter;
import com.intellij.execution.testframework.TestFrameworkRunningModel;
import com.intellij.execution.testframework.TestTreeView;
import com.intellij.execution.testframework.ui.TestsProgressAnimator;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import com.intellij.util.ui.tree.TreeUtil;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
public class JUnitRunningModel implements TestFrameworkRunningModel {
private final TestProgress myProgress;
private final TestProxy myRoot;
private final JUnitConsoleProperties myProperties;
private final MyTreeSelectionListener myTreeListener = new MyTreeSelectionListener();
private JTree myTreeView;
private TestTreeBuilder myTreeBuilder;
private final JUnitListenersNotifier myNotifier = new JUnitListenersNotifier();
private TestsProgressAnimator myAnimator;
public JUnitRunningModel(final TestProxy root, final JUnitConsoleProperties properties) {
myRoot = root;
myProperties = properties;
myRoot.setEventsConsumer(myNotifier);
myProgress = new TestProgress(this);
Disposer.register(this, myProgress);
Disposer.register(this, myTreeListener);
Disposer.register(this, new Disposable() {
public void dispose() {
myNotifier.fireDisposed(JUnitRunningModel.this);
}
});
}
public TestTreeBuilder getTreeBuilder() {
return myTreeBuilder;
}
public void attachToTree(final TestTreeView treeView) {
myTreeBuilder = new TestTreeBuilder(treeView, this, myProperties);
Disposer.register(this, myTreeBuilder);
myAnimator = new TestsProgressAnimator(myTreeBuilder);
addListener(new JUnitAdapter() {
public void onTestChanged(final TestEvent event) {
if (event instanceof StateChangedEvent) {
final TestProxy test = event.getSource();
if (test.isLeaf() && test.getState().getMagnitude() == PoolOfTestStates.RUNNING_INDEX) {
myAnimator.setCurrentTestCase(test);
}
}
}
public void onRunnerStateChanged(final StateEvent event) {
if (!event.isRunning()) {
myAnimator.stopMovie();
}
}
public void doDispose() {
dispose();
}
});
myTreeView = treeView;
selectTest(getRoot());
myTreeListener.install();
}
public JTree getTree() {
return myTreeView;
}
public void dispose() {
}
public TestTreeView getTreeView() {
return (TestTreeView) myTreeBuilder.getTree();
}
public boolean hasTestSuites() {
return myRoot.hasChildSuites();
}
public TestProgress getProgress() {
return myProgress;
}
public TestProxy getRoot() {
return myRoot;
}
public void selectAndNotify(final AbstractTestProxy testProxy) {
selectTest((TestProxy)testProxy);
myNotifier.fireTestSelected((TestProxy)testProxy);
}
public Project getProject() {
return myProperties.getProject();
}
public JUnitConsoleProperties getProperties() { return myProperties; }
public void selectTest(final TestProxy test) {
if (test == null) return;
myTreeBuilder.select(test, null);
}
public void expandTest(final TestProxy test) {
if (test == null) return;
myTreeBuilder.expand(test, null);
}
public void collapse(final TestProxy test) {
if (test == getRoot())
return;
final TreePath path = pathToTest(test, false);
if (path == null) return;
myTreeView.collapsePath(path);
}
public JUnitListenersNotifier getNotifier() {
return myNotifier;
}
public void setFilter(final Filter filter) {
final TestTreeStructure treeStructure = getStructure();
treeStructure.setFilter(filter);
myTreeBuilder.updateFromRoot();
}
public boolean isRunning() {
return myRoot.isInProgress();
}
private TestTreeStructure getStructure() {
return (TestTreeStructure)myTreeBuilder.getTreeStructure();
}
public void addListener(final JUnitListener listener) {
myNotifier.addListener(listener);
}
public void removeListener(final JUnitListener listener) {
myNotifier.removeListener(listener);
}
public void onUIBuilt() {
//myNotifier.fireTestSelected(myRoot);
}
private TreePath pathToTest(final TestProxy test, final boolean expandIfCollapsed) {
final TestTreeBuilder treeBuilder = getTreeBuilder();
DefaultMutableTreeNode node = treeBuilder.getNodeForElement(test);
if (node == null && !expandIfCollapsed)
return null;
node = treeBuilder.ensureTestVisible(test);
if (node == null)
return null;
return TreeUtil.getPath((TreeNode) myTreeView.getModel().getRoot(), node);
}
public JUnitConfiguration getConfiguration() {
return (JUnitConfiguration)myProperties.getConfiguration();
}
private class MyTreeSelectionListener extends FocusAdapter implements TreeSelectionListener, Disposable {
public void valueChanged(final TreeSelectionEvent e) {
final TestProxy test = TestProxyClient.from(e.getPath());
myNotifier.fireTestSelected(test);
}
public void focusGained(final FocusEvent e) {
ApplicationManager.getApplication().invokeLater(() -> {
if (!myTreeBuilder.isDisposed()) {
myNotifier.fireTestSelected((TestProxy)getTreeView().getSelectedTest());
}
});
}
public void install() {
myTreeView.addTreeSelectionListener(this);
myTreeView.addFocusListener(this);
}
public void dispose() {
if (myTreeView != null) {
myTreeView.removeTreeSelectionListener(this);
myTreeView.removeFocusListener(this);
}
}
}
}
@@ -1,55 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.ui.model;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.info.TestInfo;
import com.intellij.execution.junit2.segments.ObjectReader;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
/**
* User: anna
* Date: Jul 21, 2010
*/
public class RootTestInfo extends TestInfo {
private String myName = SpecialNode.TESTS_IN_PROGRESS;
public String getComment() {
return "";
}
public String getName() { return myName; }
public void setName(final String name) { myName = name; }
public boolean shouldRun() {
return false;
}
public int getTestsCount() {
return 0;
}
@Override
public void readFrom(ObjectReader reader) {
}
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More