mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract coverage plugin
This commit is contained in:
@@ -70,4 +70,12 @@ public abstract class RunConfigurationExtension {
|
||||
public abstract void readExternal(ModuleBasedConfiguration runConfiguration, Element element) throws InvalidDataException;
|
||||
|
||||
public abstract void writeExternal(ModuleBasedConfiguration runConfiguration, Element element) throws WriteExternalException;
|
||||
|
||||
public abstract <T extends ModuleBasedConfiguration & RunJavaConfiguration> void patchConfiguration(T runJavaConfiguration);
|
||||
|
||||
public static <T extends ModuleBasedConfiguration & RunJavaConfiguration> void patchCreatedConfiguration(T configuration) {
|
||||
for (RunConfigurationExtension extension : Extensions.getExtensions(EP_NAME)) {
|
||||
extension.patchConfiguration(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.execution;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface RunJavaConfiguration {
|
||||
int VM_PARAMETERS_PROPERTY = 0;
|
||||
@@ -19,4 +20,11 @@ public interface RunJavaConfiguration {
|
||||
String getAlternativeJrePath();
|
||||
|
||||
void setAlternativeJrePath(String ALTERNATIVE_JRE_PATH);
|
||||
|
||||
@Nullable
|
||||
String getRunClass();
|
||||
|
||||
@Nullable
|
||||
String getPackage();
|
||||
|
||||
}
|
||||
|
||||
+11
@@ -156,6 +156,17 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getRunClass() {
|
||||
return MAIN_CLASS_NAME;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getPackage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isAlternativeJrePathEnabled() {
|
||||
return ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
}
|
||||
|
||||
+2
@@ -2,6 +2,7 @@ package com.intellij.execution.application;
|
||||
|
||||
import com.intellij.execution.JavaExecutionUtil;
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.RunConfigurationExtension;
|
||||
import com.intellij.execution.actions.ConfigurationContext;
|
||||
import com.intellij.execution.configurations.ConfigurationUtil;
|
||||
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
|
||||
@@ -53,6 +54,7 @@ public class ApplicationConfigurationProducer extends JavaRuntimeConfigurationPr
|
||||
configuration.MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(aClass);
|
||||
configuration.setName(configuration.getGeneratedName());
|
||||
setupConfigurationModule(context, configuration);
|
||||
RunConfigurationExtension.patchCreatedConfiguration(configuration);
|
||||
copyStepsBeforeRun(project, configuration);
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="idea_rt" />
|
||||
<orderEntry type="module" module-name="coverage" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.intellij.junit3;
|
||||
|
||||
import com.intellij.junit.IDEAJUnitCoverageListener;
|
||||
import com.intellij.rt.execution.junit.DeafStream;
|
||||
import com.intellij.rt.execution.junit.IdeaTestRunner;
|
||||
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
|
||||
@@ -11,15 +10,19 @@ import junit.framework.TestResult;
|
||||
import junit.textui.ResultPrinter;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
private TestListener myTestsListener;
|
||||
private JUnit3OutputObjectRegistry myRegistry;
|
||||
private ArrayList<String> myListeners;
|
||||
|
||||
public JUnit3IdeaTestRunner() {
|
||||
super(DeafStream.DEAF_PRINT_STREAM);
|
||||
}
|
||||
|
||||
public int startRunnerWithArgs(String[] args) {
|
||||
public int startRunnerWithArgs(String[] args, ArrayList<String> listeners) {
|
||||
myListeners = listeners;
|
||||
try {
|
||||
Test suite = TestRunnerUtil.getTestSuite(this, args);
|
||||
TestResult result = doRun(suite);
|
||||
@@ -52,9 +55,8 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
TestResult testResult = super.createTestResult();
|
||||
testResult.addListener(myTestsListener);
|
||||
try {
|
||||
final TestListener listener = IDEAJUnitCoverageListener.class.newInstance().getTestListener();
|
||||
if (listener != null) {
|
||||
testResult.addListener(listener);
|
||||
for (String listener : myListeners) {
|
||||
testResult.addListener((TestListener)Class.forName(listener).newInstance());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.intellij.junit4;
|
||||
|
||||
import com.intellij.junit.IDEAJUnitCoverageListener;
|
||||
import com.intellij.rt.execution.junit.DeafStream;
|
||||
import com.intellij.rt.execution.junit.IdeaTestRunner;
|
||||
import com.intellij.rt.execution.junit.segments.OutputObjectRegistryEx;
|
||||
@@ -42,7 +41,7 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
packet.send();
|
||||
}
|
||||
|
||||
public int startRunnerWithArgs(String[] args) {
|
||||
public int startRunnerWithArgs(String[] args, ArrayList<String> listeners) {
|
||||
try {
|
||||
final JUnitCore runner = new JUnitCore();
|
||||
|
||||
@@ -65,16 +64,9 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
}
|
||||
|
||||
runner.addListener(myTestsListener);
|
||||
try {
|
||||
final RunListener listener = IDEAJUnitCoverageListener.class.newInstance().getRunListener();
|
||||
if (listener != null) {
|
||||
runner.addListener(listener);
|
||||
}
|
||||
for (String listener : listeners) {
|
||||
runner.addListener((RunListener)Class.forName(listener).newInstance());
|
||||
}
|
||||
catch (Exception e) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
Result result = runner.run(request/*.sortWith(new Comparator() {
|
||||
public int compare(Object d1, Object d2) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 31-Aug-2009
|
||||
*/
|
||||
package com.intellij.rt.execution.junit;
|
||||
|
||||
import junit.framework.TestListener;
|
||||
import org.junit.runner.notification.RunListener;
|
||||
|
||||
public abstract class IDEAJUnitListener extends RunListener implements TestListener {
|
||||
public static final String EP_NAME = "com.intellij.junitListener";
|
||||
}
|
||||
@@ -6,8 +6,10 @@ package com.intellij.rt.execution.junit;
|
||||
|
||||
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface IdeaTestRunner {
|
||||
int startRunnerWithArgs(String[] args);
|
||||
int startRunnerWithArgs(String[] args, ArrayList<String> listeners);
|
||||
|
||||
void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr);
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.intellij.rt.execution.junit;
|
||||
|
||||
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
import com.intellij.junit3.JUnit3IdeaTestRunner;
|
||||
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Before rename or move
|
||||
@@ -25,7 +27,9 @@ public class JUnitStarter {
|
||||
String arg = args[i];
|
||||
argList.addElement(arg);
|
||||
}
|
||||
boolean isJUnit4 = removeVersionParameters(argList);
|
||||
|
||||
final ArrayList<String> listeners = new ArrayList<String>();
|
||||
boolean isJUnit4 = processParameters(argList, listeners);
|
||||
|
||||
if (!canWorkWithJUnitVersion(err, isJUnit4)) {
|
||||
err.flush();
|
||||
@@ -38,11 +42,11 @@ public class JUnitStarter {
|
||||
|
||||
String[] array = new String[argList.size()];
|
||||
argList.copyInto(array);
|
||||
int exitCode = prepareStreamsAndStart(array, isJUnit4, out, err);
|
||||
int exitCode = prepareStreamsAndStart(array, isJUnit4, listeners, out, err);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
private static boolean removeVersionParameters(Vector args) {
|
||||
private static boolean processParameters(Vector args, final List<String> listeners) {
|
||||
boolean isJunit4 = false;
|
||||
Vector result = new Vector(args.size());
|
||||
for (int i = 0; i < args.size(); i++) {
|
||||
@@ -54,7 +58,21 @@ public class JUnitStarter {
|
||||
isJunit4 = true;
|
||||
}
|
||||
else {
|
||||
if (arg.startsWith("@")) {
|
||||
if (arg.startsWith("@@")) {
|
||||
if (new File(arg.substring(2)).exists()) {
|
||||
try {
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(arg.substring(2)));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
listeners.add(line);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
} else if (arg.startsWith("@")) {
|
||||
while(new File(arg.substring(1)).length() == 0); //wait for test cases
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(arg.substring(1)));
|
||||
@@ -119,7 +137,8 @@ public class JUnitStarter {
|
||||
new TestRunner().setPrinter(new JUnit3IdeaTestRunner.MockResultPrinter());
|
||||
}
|
||||
|
||||
private static int prepareStreamsAndStart(String[] args, final boolean isJUnit4, SegmentedOutputStream out, SegmentedOutputStream err) {
|
||||
private static int prepareStreamsAndStart(String[] args, final boolean isJUnit4, ArrayList<String> listeners, SegmentedOutputStream out,
|
||||
SegmentedOutputStream err) {
|
||||
PrintStream oldOut = System.out;
|
||||
PrintStream oldErr = System.err;
|
||||
int result;
|
||||
@@ -128,7 +147,7 @@ public class JUnitStarter {
|
||||
System.setErr(new PrintStream(err));
|
||||
IdeaTestRunner testRunner = (IdeaTestRunner)getAgentClass(isJUnit4).newInstance();
|
||||
testRunner.setStreams(out, err);
|
||||
result = testRunner.startRunnerWithArgs(args);
|
||||
result = testRunner.startRunnerWithArgs(args, listeners);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
|
||||
+4
@@ -126,4 +126,8 @@ public class SnapShooterConfigurationExtension extends RunConfigurationExtension
|
||||
public void writeExternal(ModuleBasedConfiguration runConfiguration, Element element) throws WriteExternalException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends ModuleBasedConfiguration & RunJavaConfiguration> void patchConfiguration(T runJavaConfiguration) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user