mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-15 11:12:59 +07:00
idea_rt -> community/java/java-runtime
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class FormPreviewFrame {
|
||||
private JComponent myComponent;
|
||||
private static final ResourceBundle ourBundle = ResourceBundle.getBundle("RuntimeBundle");
|
||||
|
||||
// Note: this class should not be obfuscated
|
||||
|
||||
public static void main(String[] args) {
|
||||
FormPreviewFrame f = new FormPreviewFrame();
|
||||
|
||||
JFrame frame = new JFrame(ourBundle.getString("form.preview.title"));
|
||||
frame.setContentPane(f.myComponent);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// Add menu bar
|
||||
final JMenuBar menuBar = new JMenuBar();
|
||||
frame.setJMenuBar(menuBar);
|
||||
|
||||
final JMenu menuFile = new JMenu(ourBundle.getString("form.menu.preview"));
|
||||
menuFile.setMnemonic(ourBundle.getString("form.menu.preview.mnemonic").charAt(0));
|
||||
menuFile.add(new JMenuItem(new MyPackAction(frame)));
|
||||
menuFile.add(new JMenuItem(new MyExitAction()));
|
||||
menuBar.add(menuFile);
|
||||
|
||||
final JMenu viewMenu = new JMenu(ourBundle.getString("form.menu.laf"));
|
||||
viewMenu.setMnemonic(ourBundle.getString("form.menu.laf.mnemonic").charAt(0));
|
||||
menuBar.add(viewMenu);
|
||||
|
||||
final UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
|
||||
for(int i = 0; i < lafs.length; i++){
|
||||
viewMenu.add(new MySetLafAction(frame, lafs[i]));
|
||||
}
|
||||
|
||||
frame.pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
frame.setLocation((screenSize.width - frame.getWidth())/2, (screenSize.height - frame.getHeight())/2);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static final class MyExitAction extends AbstractAction{
|
||||
public MyExitAction() {
|
||||
super(ourBundle.getString("form.menu.file.exit"));
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MyPackAction extends AbstractAction{
|
||||
private final JFrame myFrame;
|
||||
|
||||
public MyPackAction(final JFrame frame) {
|
||||
super(ourBundle.getString("form.menu.view.pack"));
|
||||
myFrame = frame;
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
myFrame.pack();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MySetLafAction extends AbstractAction{
|
||||
private final JFrame myFrame;
|
||||
private final UIManager.LookAndFeelInfo myInfo;
|
||||
|
||||
public MySetLafAction(final JFrame frame, final UIManager.LookAndFeelInfo info) {
|
||||
super(info.getName());
|
||||
myFrame = frame;
|
||||
myInfo = info;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
UIManager.setLookAndFeel(myInfo.getClassName());
|
||||
SwingUtilities.updateComponentTreeUI(myFrame);
|
||||
Dimension prefSize = myFrame.getPreferredSize();
|
||||
if(prefSize.width > myFrame.getWidth() || prefSize.height > myFrame.getHeight()){
|
||||
myFrame.pack();
|
||||
}
|
||||
}
|
||||
catch(Exception exc){
|
||||
JOptionPane.showMessageDialog(
|
||||
myFrame,
|
||||
MessageFormat.format(ourBundle.getString("error.cannot.change.look.feel"), new Object[] {exc.getMessage()}),
|
||||
ourBundle.getString("error.title"),
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
form.preview.title=Form Preview
|
||||
form.menu.preview=Preview
|
||||
form.menu.preview.mnemonic=P
|
||||
form.menu.file.exit=Exit
|
||||
form.menu.laf=Look and Feel
|
||||
form.menu.laf.mnemonic=L
|
||||
form.menu.view.pack=Pack
|
||||
error.cannot.change.look.feel=Cannot change LookAndFeel.\nReason: {0}
|
||||
error.title=Error
|
||||
junit.runner.error=Error: {0}
|
||||
junit.class.not.found=Class not found: "{0}"
|
||||
junit.cannot.instantiate.tests=Cannot instantiate test(s): {0}
|
||||
junit.class.not.derived={0} is not derived from TestCase. Do not provide method name.
|
||||
junit.suite.must.be.static=''{0}.suite()'' method must be static
|
||||
junit.failed.to.invoke.suite=Failed to invoke suite(): {0}
|
||||
junit.method.not.found=Method ''{0}'' not found
|
||||
tests.found.in.package={0} test {0, choice, 1#class|2#classes} found in package ''{1}''
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.intellij.rt.ant.execution;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class AntMain2 {
|
||||
public static final int MSG_VERBOSE = 3;
|
||||
public static final int MSG_ERR = 0;
|
||||
public static final int MSG_WARN = 1;
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
IdeaAntLogger2.guardStreams();
|
||||
|
||||
// first try to use the new way of launching ant
|
||||
try {
|
||||
final Class antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher");
|
||||
//noinspection HardCodedStringLiteral
|
||||
antLauncher.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
|
||||
return;
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
// ignore and try older variant
|
||||
}
|
||||
|
||||
final Class antMain = Class.forName("org.apache.tools.ant.Main");
|
||||
//noinspection HardCodedStringLiteral
|
||||
antMain.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
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;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public final class IdeaAntLogger2 extends DefaultLogger {
|
||||
static SegmentedOutputStream ourOut;
|
||||
static SegmentedOutputStream ourErr;
|
||||
public static final char MESSAGE_CONTENT = 'M';
|
||||
public static final char EXCEPTION_CONTENT = 'X';
|
||||
public static final char INPUT_REQUEST = 'I';
|
||||
public static final char BUILD_END = 'b';
|
||||
public static final char BUILD = 'B';
|
||||
public static final char TARGET = 'G';
|
||||
public static final char TARGET_END = 'g';
|
||||
public static final char TASK = 'T';
|
||||
public static final char TASK_END = 't';
|
||||
public static final char MESSAGE = 'M';
|
||||
public static final char ERROR = 'E';
|
||||
public static final char EXCEPTION = 'X';
|
||||
public static final char EXCEPTION_LINE_SEPARATOR = 0;
|
||||
|
||||
/**
|
||||
* @noinspection HardCodedStringLiteral
|
||||
*/
|
||||
public static final String OUTPUT_PREFIX = "IDEA_ANT_INTEGRATION";
|
||||
|
||||
private final Priority myMessagePriority = new MessagePriority();
|
||||
private final Priority myTargetPriority = new StatePriority(Project.MSG_INFO);
|
||||
private final Priority myTaskPriority = new StatePriority(Project.MSG_INFO);
|
||||
private final Priority myAlwaysSend = new Priority() {
|
||||
public void setPriority(int level) {}
|
||||
|
||||
protected boolean shouldSend(int priority) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public IdeaAntLogger2() {
|
||||
guardStreams();
|
||||
}
|
||||
|
||||
public synchronized void setMessageOutputLevel(int level) {
|
||||
super.setMessageOutputLevel(level);
|
||||
myMessagePriority.setPriority(level);
|
||||
myTargetPriority.setPriority(level);
|
||||
myTaskPriority.setPriority(level);
|
||||
myAlwaysSend.setPriority(level);
|
||||
}
|
||||
|
||||
public synchronized void buildStarted(BuildEvent event) {
|
||||
myAlwaysSend.sendMessage(BUILD, event.getPriority(), "");
|
||||
}
|
||||
|
||||
public synchronized void buildFinished(BuildEvent event) {
|
||||
myAlwaysSend.sendMessage(BUILD_END, event.getPriority(), event.getException());
|
||||
}
|
||||
|
||||
public synchronized void targetStarted(BuildEvent event) {
|
||||
myTargetPriority.sendMessage(TARGET, event.getPriority(), event.getTarget().getName());
|
||||
}
|
||||
|
||||
public synchronized void targetFinished(BuildEvent event) {
|
||||
sendException(event);
|
||||
myTargetPriority.sendMessage(TARGET_END, event.getPriority(), event.getException());
|
||||
}
|
||||
|
||||
public synchronized void taskStarted(BuildEvent event) {
|
||||
myTaskPriority.sendMessage(TASK, event.getPriority(), event.getTask().getTaskName());
|
||||
}
|
||||
|
||||
public synchronized void taskFinished(BuildEvent event) {
|
||||
sendException(event);
|
||||
myTaskPriority.sendMessage(TASK_END, event.getPriority(), event.getException());
|
||||
}
|
||||
|
||||
public synchronized void messageLogged(BuildEvent event) {
|
||||
if (sendException(event)) return;
|
||||
int priority = event.getPriority();
|
||||
String message = event.getMessage();
|
||||
if (priority == Project.MSG_ERR)
|
||||
myMessagePriority.sendMessage(ERROR, priority, message);
|
||||
else
|
||||
myMessagePriority.sendMessage(MESSAGE, priority, message);
|
||||
}
|
||||
|
||||
private boolean sendException(BuildEvent event) {
|
||||
Throwable exception = event.getException();
|
||||
if (exception != null) {
|
||||
myAlwaysSend.sendMessage(EXCEPTION, event.getPriority(), exception);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void guardStreams() {
|
||||
if (ourErr != null && ourOut != null) return;
|
||||
PrintStream out = System.out;
|
||||
PrintStream err = System.err;
|
||||
ourOut = new SegmentedOutputStream(out);
|
||||
ourErr = new SegmentedOutputStream(err);
|
||||
System.setOut(new PrintStream(ourOut));
|
||||
System.setErr(new PrintStream(ourErr));
|
||||
ourOut.sendStart();
|
||||
ourErr.sendStart();
|
||||
}
|
||||
|
||||
private void send(PacketWriter packet) {
|
||||
packet.sendThrough(ourOut);
|
||||
packet.sendThrough(ourErr);
|
||||
}
|
||||
|
||||
private PacketWriter createPacket(char id, int priority) {
|
||||
PacketWriter packet = PacketFactory.ourInstance.createPacket(id);
|
||||
packet.appendLong(priority);
|
||||
return packet;
|
||||
}
|
||||
|
||||
private abstract class Priority {
|
||||
protected void peformSendMessage(char id, int priority, String text) {
|
||||
PacketWriter packet = createPacket(id, priority);
|
||||
packet.appendChar(MESSAGE_CONTENT);
|
||||
packet.appendLimitedString(text);
|
||||
send(packet);
|
||||
}
|
||||
|
||||
protected void peformSendMessage(char id, int priority, Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
PacketWriter packet = createPacket(id, priority);
|
||||
StringWriter stackTrace = new StringWriter();
|
||||
throwable.printStackTrace(new PrintWriter(stackTrace));
|
||||
packet.appendChar(EXCEPTION_CONTENT);
|
||||
packet.appendLimitedString(stackTrace.toString());
|
||||
send(packet);
|
||||
} else {
|
||||
peformSendMessage(id, priority, "");
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(char id, int priority, String text) {
|
||||
if (shouldSend(priority)) peformSendMessage(id, priority, text);
|
||||
}
|
||||
|
||||
public void sendMessage(char id, int priority, Throwable throwable) {
|
||||
if (shouldSend(priority)) peformSendMessage(id, priority, throwable);
|
||||
}
|
||||
|
||||
public abstract void setPriority(int level);
|
||||
protected abstract boolean shouldSend(int priority);
|
||||
}
|
||||
|
||||
private class MessagePriority extends Priority {
|
||||
private int myPriority = Project.MSG_ERR;
|
||||
|
||||
public void setPriority(int level) {
|
||||
myPriority = level;
|
||||
}
|
||||
|
||||
protected boolean shouldSend(int priority) {
|
||||
return priority <= myPriority;
|
||||
}
|
||||
}
|
||||
|
||||
private class StatePriority extends Priority {
|
||||
private boolean myEnabled = true;
|
||||
private final int myMinLevel;
|
||||
|
||||
public StatePriority(int minLevel) {
|
||||
myMinLevel = minLevel;
|
||||
}
|
||||
|
||||
public void setPriority(int level) {
|
||||
myEnabled = myMinLevel <= level;
|
||||
}
|
||||
|
||||
protected boolean shouldSend(int priority) {
|
||||
return myEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
import org.apache.tools.ant.input.MultipleChoiceInputRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* @author dyoma
|
||||
*/
|
||||
public class IdeaInputHandler implements InputHandler {
|
||||
public void handleInput(InputRequest request) throws BuildException {
|
||||
String prompt = request.getPrompt();
|
||||
if (prompt == null) throw new BuildException("Prompt is null");
|
||||
SegmentedOutputStream out = IdeaAntLogger2.ourOut;
|
||||
SegmentedOutputStream err = IdeaAntLogger2.ourErr;
|
||||
if (out == null || err == null)
|
||||
throw new BuildException("Selected InputHandler should be used by Intellij IDEA");
|
||||
PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
|
||||
packet.appendLimitedString(prompt);
|
||||
if (request instanceof MultipleChoiceInputRequest) {
|
||||
Vector choices = ((MultipleChoiceInputRequest)request).getChoices();
|
||||
if (choices != null && choices.size() > 0) {
|
||||
int count = choices.size();
|
||||
packet.appendLong(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
packet.appendLimitedString((String)choices.elementAt(i));
|
||||
} else packet.appendLong(0);
|
||||
} else packet.appendLong(0);
|
||||
packet.sendThrough(out);
|
||||
packet.sendThrough(err);
|
||||
try {
|
||||
byte[] replayLength = readBytes(4);
|
||||
int length = ((int)replayLength[0] << 24) | ((int)replayLength[1] << 16) | ((int)replayLength[2] << 8) | replayLength[3];
|
||||
byte[] replay = readBytes(length);
|
||||
String input = new String(replay);
|
||||
request.setInput(input);
|
||||
if (!request.isInputValid()) throw new BuildException("Invalid input: " + input);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] readBytes(int count) throws IOException {
|
||||
byte[] replayLength = new byte[count];
|
||||
int read = System.in.read(replayLength);
|
||||
if (read != count) throw new IOException("End of input stream");
|
||||
return replayLength;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.intellij.rt.ant.execution;
|
||||
|
||||
import com.intellij.rt.execution.junit.segments.PacketWriter;
|
||||
|
||||
/**
|
||||
* @author dyoma
|
||||
*/
|
||||
class PacketFactory {
|
||||
private int myLastMessageId = -1;
|
||||
public static final PacketFactory ourInstance = new PacketFactory();
|
||||
|
||||
public synchronized PacketWriter createPacket(char id) {
|
||||
PacketWriter writer = new PacketWriter();
|
||||
myLastMessageId++;
|
||||
writer.appendLong(myLastMessageId);
|
||||
writer.appendChar(id);
|
||||
return writer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright 2000-2005 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.compiler;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* MUST BE COMPILED WITH JDK 1.1 IN ORDER TO SUPPORT JAVAC LAUNCHING FOR ALL JDKs
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: Oct 10, 2005
|
||||
*/
|
||||
public class JavacResourcesReader {
|
||||
public static final String MSG_PATTERNS_START = "__patterns_start";
|
||||
public static final String MSG_PATTERNS_END = "__patterns_end";
|
||||
public static final String MSG_PARSING_STARTED = "MSG_PARSING_STARTED";
|
||||
public static final String MSG_PARSING_COMPLETED = "MSG_PARSING_COMPLETED";
|
||||
public static final String MSG_LOADING = "MSG_LOADING";
|
||||
public static final String MSG_CHECKING = "MSG_CHECKING";
|
||||
public static final String MSG_WROTE = "MSG_WROTE";
|
||||
public static final String MSG_WARNING = "MSG_WARNING";
|
||||
public static final String MSG_NOTE = "MSG_NOTE";
|
||||
public static final String MSG_STATISTICS = "MSG_STATISTICS";
|
||||
public static final String MSG_IGNORED = "MSG_IGNORED";
|
||||
|
||||
private static final String[] BUNDLE_NAMES = new String[] {
|
||||
"com.sun.tools.javac.resources.compiler", // v1.5
|
||||
"com.sun.tools.javac.v8.resources.compiler", // v1.3-1.4
|
||||
"sun.tools.javac.resources.javac" // v1.1-1.2
|
||||
};
|
||||
|
||||
private static final BundleKey[] MSG_NAME_KEY_PAIRS = new BundleKey[] {
|
||||
new BundleKey(MSG_PARSING_STARTED, "compiler.misc.verbose.parsing.started"),
|
||||
new BundleKey(MSG_PARSING_COMPLETED, "compiler.misc.verbose.parsing.done"),
|
||||
new BundleKey(MSG_PARSING_COMPLETED, "benv.parsed_in"), // jdk 1.1-1.2
|
||||
new BundleKey(MSG_LOADING, "compiler.misc.verbose.loading"),
|
||||
new BundleKey(MSG_LOADING, "benv.loaded_in"), // jdk 1.1-1.2
|
||||
new BundleKey(MSG_CHECKING, "compiler.misc.verbose.checking.attribution"),
|
||||
new BundleKey(MSG_WROTE,"compiler.misc.verbose.wrote.file"),
|
||||
new BundleKey(MSG_WROTE,"main.wrote"), // jdk 1.1-1.2
|
||||
new BundleKey(MSG_WARNING,"compiler.warn.warning"),
|
||||
new BundleKey(MSG_NOTE,new String[] {"compiler.note.note", "compiler.note.deprecated.filename"}), // jdk 1.5
|
||||
new BundleKey(MSG_NOTE,new String[] {"compiler.note.note", "compiler.note.deprecated.plural"}), // jdk 1.5
|
||||
new BundleKey(MSG_NOTE,new String[] {"compiler.note.note", "compiler.note.deprecated.recompile"}), // jdk 1.5
|
||||
new BundleKey(MSG_NOTE,new String[] {"compiler.note.note", "compiler.note.unchecked.filename"}), // jdk 1.5
|
||||
new BundleKey(MSG_NOTE,new String[] {"compiler.note.note", "compiler.note.unchecked.plural"}), // jdk 1.5
|
||||
new BundleKey(MSG_NOTE,new String[] {"compiler.note.note", "compiler.note.unchecked.recompile"}), // jdk 1.5
|
||||
new BundleKey(MSG_STATISTICS,"compiler.misc.count.error"),
|
||||
new BundleKey(MSG_STATISTICS,"compiler.misc.count.error.plural"),
|
||||
new BundleKey(MSG_STATISTICS,"compiler.misc.count.warn"),
|
||||
new BundleKey(MSG_STATISTICS,"compiler.misc.count.warn.plural"),
|
||||
new BundleKey(MSG_STATISTICS,"main.errors"), //jdk 1.1 - 1.2
|
||||
new BundleKey(MSG_STATISTICS,"main.warnings"), //jdk 1.1 - 1.2
|
||||
new BundleKey(MSG_STATISTICS,"main.1error"), //jdk 1.1 - 1.2
|
||||
new BundleKey(MSG_STATISTICS,"main.1warning"), //jdk 1.1 - 1.2
|
||||
new IgnoredWarningBundleKey("compiler.warn.dir.path.element.not.found"), //jdk 1.5
|
||||
new IgnoredWarningBundleKey("compiler.warn.path.element.not.found"), //jdk 1.5
|
||||
};
|
||||
|
||||
public static final String CATEGORY_VALUE_DIVIDER = "=";
|
||||
|
||||
public static void main(String[] args) {
|
||||
dumpPatterns();
|
||||
}
|
||||
|
||||
// for debug purposes
|
||||
/*
|
||||
public static void printPatterns() {
|
||||
final ResourceBundle messagesBundle = getMessagesBundle();
|
||||
if (messagesBundle == null) {
|
||||
System.out.println("No bundles found");
|
||||
return;
|
||||
}
|
||||
final Enumeration keys = messagesBundle.getKeys();
|
||||
while (keys.hasMoreElements()) {
|
||||
final Object key = keys.nextElement();
|
||||
System.out.println(key + "->" + messagesBundle.getObject((String)key));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static boolean dumpPatterns() {
|
||||
final ResourceBundle messagesBundle = getMessagesBundle();
|
||||
if (messagesBundle == null) {
|
||||
return false;
|
||||
}
|
||||
System.err.println(MSG_PATTERNS_START);
|
||||
for (int idx = 0; idx < MSG_NAME_KEY_PAIRS.length; idx++) {
|
||||
BundleKey bundleKey = MSG_NAME_KEY_PAIRS[idx];
|
||||
try {
|
||||
System.err.println(bundleKey.category + CATEGORY_VALUE_DIVIDER + bundleKey.getCategoryValue(messagesBundle));
|
||||
}
|
||||
catch (MissingResourceException ignored) {
|
||||
}
|
||||
}
|
||||
System.err.println(MSG_PATTERNS_END);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ResourceBundle getMessagesBundle() {
|
||||
for (int i = 0; i < BUNDLE_NAMES.length; i++) {
|
||||
try {
|
||||
return ResourceBundle.getBundle(BUNDLE_NAMES[i]);
|
||||
}
|
||||
catch (MissingResourceException ignored) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class BundleKey {
|
||||
public final String category;
|
||||
public final String[] keys;
|
||||
|
||||
public BundleKey(final String category, final String key) {
|
||||
this(category, new String[] {key});
|
||||
}
|
||||
|
||||
public BundleKey(final String category, final String[] composite) {
|
||||
this.category = category;
|
||||
this.keys = composite;
|
||||
}
|
||||
|
||||
public String getCategoryValue(ResourceBundle messagesBundle) {
|
||||
if (keys.length == 1) {
|
||||
return messagesBundle.getString(keys[0]);
|
||||
}
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
for (int idx = 0; idx < keys.length; idx++) {
|
||||
buf.append(messagesBundle.getString(keys[idx]));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static class IgnoredWarningBundleKey extends BundleKey {
|
||||
public IgnoredWarningBundleKey(final String messageKey) {
|
||||
super(JavacResourcesReader.MSG_IGNORED, new String[]{"compiler.warn.warning", messageKey});
|
||||
}
|
||||
|
||||
public String getCategoryValue(ResourceBundle messagesBundle) {
|
||||
return messagesBundle.getString(keys[0]) + MessageFormat.format(messagesBundle.getString(keys[1]), new Object[] {""});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.intellij.rt.compiler;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* MUST BE COMPILED WITH JDK 1.1 IN ORDER TO SUPPORT JAVAC LAUNCHING FOR ALL JDKs
|
||||
*/
|
||||
public class JavacRunner {
|
||||
|
||||
/**
|
||||
* @param args - params
|
||||
* 0. jdk version string
|
||||
* 1. javac main class
|
||||
* 2. javac parameters
|
||||
*/
|
||||
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, IOException {
|
||||
|
||||
if (!JavacResourcesReader.dumpPatterns()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String versionString = args[0];
|
||||
final Class aClass = Class.forName(args[1]);
|
||||
//noinspection HardCodedStringLiteral
|
||||
final Method mainMethod = aClass.getMethod("main", new Class[] {String[].class});
|
||||
String[] newArgs;
|
||||
if (versionString.indexOf("1.1") > -1) {
|
||||
// expand the file
|
||||
final Vector arguments = new Vector();
|
||||
boolean isClasspath = false;
|
||||
for (int idx = 3; idx < args.length; idx++) {
|
||||
final String arg = args[idx];
|
||||
if (arg.startsWith("@") && !isClasspath) {
|
||||
String path = arg.substring(1);
|
||||
addFilesToCompile(arguments, path);
|
||||
}
|
||||
else {
|
||||
isClasspath = "-classpath".equals(arg) || "-cp".equals(arg) || "-bootclasspath".equals(arg);
|
||||
arguments.addElement(arg);
|
||||
}
|
||||
}
|
||||
newArgs = new String[arguments.size()];
|
||||
for (int idx = 0; idx < newArgs.length; idx++) {
|
||||
newArgs[idx] = (String)arguments.elementAt(idx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newArgs = new String[args.length - 2];
|
||||
System.arraycopy(args, 2, newArgs, 0, newArgs.length);
|
||||
}
|
||||
expandClasspath(newArgs);
|
||||
mainMethod.invoke(null, new Object[] {newArgs});
|
||||
}
|
||||
|
||||
private static void addFilesToCompile(Vector arguments, String path) throws IOException {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(new File(path)));
|
||||
for (String filePath = reader.readLine(); filePath != null; filePath = reader.readLine()) {
|
||||
arguments.addElement(filePath.replace('/', File.separatorChar));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void expandClasspath(String[] args) throws IOException {
|
||||
for (int idx = 0; idx < args.length; idx++) {
|
||||
final String arg = args[idx];
|
||||
//noinspection HardCodedStringLiteral
|
||||
if ("-classpath".equals(arg) || "-cp".equals(arg) || "-bootclasspath".equals(arg)) {
|
||||
final String cpValue = args[idx + 1];
|
||||
if (cpValue.startsWith("@")) {
|
||||
args[idx + 1] = readClasspath(cpValue.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String readClasspath(String filePath) throws IOException {
|
||||
final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(filePath))));
|
||||
try {
|
||||
return readString(in);
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static String readString(DataInput stream) throws IOException {
|
||||
int length = stream.readInt();
|
||||
if (length == -1) return null;
|
||||
|
||||
char[] chars = new char[length];
|
||||
byte[] bytes = new byte[length*2];
|
||||
stream.readFully(bytes);
|
||||
|
||||
for (int i = 0, i2 = 0; i < length; i++, i2+=2) {
|
||||
chars[i] = (char)((bytes[i2] << 8) + (bytes[i2 + 1] & 0xFF));
|
||||
}
|
||||
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @author: Eugene Zhuravlev
|
||||
* Date: Sep 16, 2002
|
||||
* Time: 10:56:58 PM
|
||||
*/
|
||||
package com.intellij.rt.debugger;
|
||||
|
||||
public class BatchEvaluatorServer {
|
||||
Object[] myObjects;
|
||||
|
||||
public Object[] evaluate(Object[] objects) {
|
||||
myObjects = objects;
|
||||
Object[] result = new Object[objects.length];
|
||||
for (int idx = 0; idx < objects.length; idx++) {
|
||||
try {
|
||||
result[idx] = objects[idx].toString();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
result[idx] = e;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 12-Aug-2008
|
||||
*/
|
||||
package com.intellij.rt.execution;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandLineWrapper {
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
|
||||
IllegalAccessException, IOException, InstantiationException {
|
||||
|
||||
final List urls = new ArrayList();
|
||||
final File file = new File(args[0]);
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
try {
|
||||
while(reader.ready()) {
|
||||
urls.add(new File(reader.readLine()).toURI().toURL());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
file.delete();
|
||||
String progClass = args[1];
|
||||
String[] progArgs = new String[args.length - 2];
|
||||
System.arraycopy(args, 2, progArgs, 0, progArgs.length);
|
||||
ClassLoader loader = new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]), null);
|
||||
final String classloader = System.getProperty("java.system.class.loader");
|
||||
if (classloader != null) {
|
||||
try {
|
||||
loader = (ClassLoader)Class.forName(classloader).getConstructor(new Class[]{ClassLoader.class}).newInstance(new Object[]{loader});
|
||||
}
|
||||
catch (Exception e) {
|
||||
//leave URL class loader
|
||||
}
|
||||
}
|
||||
Class mainClass = loader.loadClass(progClass);
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
Class mainArgType = (new String[0]).getClass();
|
||||
Method main = mainClass.getMethod("main", new Class[]{mainArgType});
|
||||
ensureAccess(main);
|
||||
main.invoke(null, new Object[]{progArgs});
|
||||
}
|
||||
|
||||
private static void ensureAccess(Object reflectionObject) {
|
||||
// need to call setAccessible here in order to be able to launch package-local classes
|
||||
// calling setAccessible() via reflection because the method is missing from java version 1.1.x
|
||||
final Class aClass = reflectionObject.getClass();
|
||||
try {
|
||||
final Method setAccessibleMethod = aClass.getMethod("setAccessible", new Class[] {boolean.class});
|
||||
setAccessibleMethod.invoke(reflectionObject, new Object[] {Boolean.TRUE});
|
||||
}
|
||||
catch (Exception e) {
|
||||
// the method not found
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.intellij.rt.execution.application;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
* @noinspection HardCodedStringLiteral
|
||||
*/
|
||||
public class AppMain {
|
||||
private static final String PROPERTY_PORT_NUMBER = "idea.launcher.port";
|
||||
private static final String PROPERTY_BINPATH = "idea.launcher.bin.path";
|
||||
|
||||
private static native void triggerControlBreak();
|
||||
|
||||
static {
|
||||
String binPath = System.getProperty(PROPERTY_BINPATH) + File.separator;
|
||||
final String osName = System.getProperty("os.name").toLowerCase();
|
||||
String libPath = null;
|
||||
if (osName.startsWith("windows")) {
|
||||
libPath = binPath + "breakgen.dll";
|
||||
} else if (osName.startsWith("linux")) {
|
||||
if (System.getProperty("os.name").toLowerCase().equals("amd64")) {
|
||||
libPath = binPath + "libbreakgen64.so";
|
||||
} else {
|
||||
libPath = binPath + "libbreakgen.so";
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (libPath != null) {
|
||||
System.load(libPath);
|
||||
}
|
||||
}
|
||||
catch (UnsatisfiedLinkError e) {
|
||||
//Do nothing, unknown os or some other error => no ctrl-break is available
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
|
||||
final int portNumber = Integer.getInteger(PROPERTY_PORT_NUMBER).intValue();
|
||||
Thread t = new Thread(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
ServerSocket socket = new ServerSocket(portNumber);
|
||||
Socket client = socket.accept();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
||||
while (true) {
|
||||
String msg = reader.readLine();
|
||||
|
||||
if ("TERM".equals(msg)){
|
||||
return;
|
||||
}
|
||||
else if ("BREAK".equals(msg)) {
|
||||
triggerControlBreak();
|
||||
}
|
||||
else if ("STOP".equals(msg)) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
return;
|
||||
} catch (SecurityException se) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, "Monitor Ctrl-Break");
|
||||
try {
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
} catch (Exception e) {}
|
||||
|
||||
String mainClass = args[0];
|
||||
String[] parms = new String[args.length - 1];
|
||||
for (int j = 1; j < args.length; j++) {
|
||||
parms[j - 1] = args[j];
|
||||
}
|
||||
Method m = Class.forName(mainClass).getMethod("main", new Class[]{parms.getClass()});
|
||||
try {
|
||||
ensureAccess(m);
|
||||
m.invoke(null, new Object[]{parms});
|
||||
} catch (InvocationTargetException ite) {
|
||||
throw ite.getTargetException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureAccess(Object reflectionObject) {
|
||||
// need to call setAccessible here in order to be able to launch package-local classes
|
||||
// calling setAccessible() via reflection because the method is missing from java version 1.1.x
|
||||
final Class aClass = reflectionObject.getClass();
|
||||
try {
|
||||
final Method setAccessibleMethod = aClass.getMethod("setAccessible", new Class[] {boolean.class});
|
||||
setAccessibleMethod.invoke(reflectionObject, new Object[] {Boolean.TRUE});
|
||||
}
|
||||
catch (Exception e) {
|
||||
// the method not found
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.intellij.rt.execution.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class MainAppClassLoader extends URLClassLoader {
|
||||
/**
|
||||
* @noinspection HardCodedStringLiteral
|
||||
*/
|
||||
private static final String USER_CLASSPATH = "idea.user.classpath";
|
||||
private final Class myAppMainClass;
|
||||
|
||||
private static URL[] makeUrls() {
|
||||
List classpath = new ArrayList();
|
||||
try {
|
||||
String userClassPath = System.getProperty(USER_CLASSPATH, "");
|
||||
StringTokenizer tokenizer = new StringTokenizer(userClassPath, File.pathSeparator, false);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String pathItem = tokenizer.nextToken();
|
||||
classpath.add(new File(pathItem).toURL());
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (URL[]) classpath.toArray(new URL[classpath.size()]);
|
||||
}
|
||||
|
||||
public MainAppClassLoader(ClassLoader loader) {
|
||||
super(makeUrls(), null);
|
||||
myAppMainClass = AppMain.class;
|
||||
}
|
||||
|
||||
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
if (name.equals(myAppMainClass.getName())) {
|
||||
return myAppMainClass;
|
||||
}
|
||||
return super.loadClass(name, resolve);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.intellij.rt.execution.junit;
|
||||
|
||||
import com.intellij.rt.execution.junit.segments.OutputObjectRegistryEx;
|
||||
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(OutputObjectRegistryEx registry, Object test) {
|
||||
return registry.createPacket().
|
||||
setTestState(test, myState).
|
||||
addThrowable(myAssertion);
|
||||
}
|
||||
|
||||
protected void setState(int state) { myState = state; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.intellij.rt.execution.junit;
|
||||
|
||||
import com.intellij.rt.execution.junit.segments.OutputObjectRegistryEx;
|
||||
import com.intellij.rt.execution.junit.segments.Packet;
|
||||
|
||||
public interface PacketFactory {
|
||||
Packet createPacket(OutputObjectRegistryEx registry, Object test);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class EchoOutputStream extends OutputStream {
|
||||
private final OutputStream myOut;
|
||||
private final OutputStream myEcho;
|
||||
|
||||
public EchoOutputStream(OutputStream out, OutputStream echo) {
|
||||
myOut = out;
|
||||
myEcho = echo;
|
||||
}
|
||||
|
||||
public synchronized void write(int b) throws IOException {
|
||||
myOut.write(b);
|
||||
myEcho.write(b);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
public interface OutputObjectRegistry {
|
||||
|
||||
String referenceTo(Object object);
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
public abstract class OutputObjectRegistryEx implements OutputObjectRegistry, PacketFactory {
|
||||
private final Hashtable myKnownKeys = new Hashtable();
|
||||
private int myLastIndex = 0;
|
||||
private PacketProcessor myMainTransport;
|
||||
private PacketProcessor myAuxilaryTransport;
|
||||
|
||||
public OutputObjectRegistryEx(PacketProcessor transport) {
|
||||
myMainTransport = transport;
|
||||
}
|
||||
|
||||
public OutputObjectRegistryEx(PacketProcessor mainTransport, PacketProcessor auxilaryTransport) {
|
||||
this(mainTransport);
|
||||
myAuxilaryTransport = auxilaryTransport;
|
||||
}
|
||||
|
||||
public String referenceTo(Object test) {
|
||||
if (myKnownKeys.containsKey(test))
|
||||
return (String) myKnownKeys.get(test);
|
||||
return sendObject(test);
|
||||
}
|
||||
|
||||
public Packet createPacket() {
|
||||
return new Packet(myMainTransport, this);
|
||||
}
|
||||
|
||||
private String sendObject(Object test) {
|
||||
String key = String.valueOf(myLastIndex++);
|
||||
myKnownKeys.put(test, key);
|
||||
Packet packet = createPacket().addString(PoolOfDelimiters.OBJECT_PREFIX).addReference(key);
|
||||
addStringRepresentation(test, packet);
|
||||
packet.addLong(getTestCont(test));
|
||||
sendViaAllTransports(packet);
|
||||
return key;
|
||||
}
|
||||
|
||||
protected abstract int getTestCont(Object test);
|
||||
protected abstract void addStringRepresentation(Object test, Packet packet);
|
||||
|
||||
private void sendViaAllTransports(Packet packet) {
|
||||
packet.send();
|
||||
if (myAuxilaryTransport != null)
|
||||
packet.sendThrough(myAuxilaryTransport);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 void forget(Object test) {
|
||||
myKnownKeys.remove(test);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
import junit.runner.BaseTestRunner;
|
||||
|
||||
import java.io.*;
|
||||
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 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 = BaseTestRunner.getFilteredTrace(throwable);
|
||||
String message = BaseTestRunner.getPreference("filterstack").equals("true") ? makeNewLinesCompatibleWithJUnit(throwableToString(throwable)) : throwableToString(throwable);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
public interface PacketFactory {
|
||||
Packet createPacket();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
public interface PacketProcessor {
|
||||
|
||||
void processPacket(String packet);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
/**
|
||||
* @author MYakovlev
|
||||
* Date: Feb 27, 2003
|
||||
* Time: 10:48:55 AM
|
||||
*/
|
||||
public class PacketProcessors{
|
||||
public static final PacketProcessor DEAF = new PacketProcessor() {
|
||||
public void processPacket(String packet) {
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
public class PacketWriter {
|
||||
private final StringBuffer myBody = new StringBuffer();
|
||||
|
||||
public void appendString(String string) {
|
||||
myBody.append(string);
|
||||
}
|
||||
|
||||
public void appendLong(long integer) {
|
||||
myBody.append(integer);
|
||||
myBody.append(PoolOfDelimiters.INTEGER_DELIMITER);
|
||||
}
|
||||
|
||||
public void appendLimitedString(String message) {
|
||||
if (message == null)
|
||||
appendLimitedString("");
|
||||
else {
|
||||
appendLong(message.length());
|
||||
appendString(message);
|
||||
}
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return myBody.toString();
|
||||
}
|
||||
|
||||
public void sendThrough(PacketProcessor transport) {
|
||||
transport.processPacket(getString());
|
||||
}
|
||||
|
||||
public void appendChar(char aChar) {
|
||||
myBody.append(aChar);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
/**
|
||||
* @noinspection HardCodedStringLiteral
|
||||
*/
|
||||
public interface PoolOfDelimiters {
|
||||
char REFERENCE_END = ':';
|
||||
char INTEGER_DELIMITER = ' ';
|
||||
|
||||
String OBJECT_PREFIX = "O";
|
||||
String TREE_PREFIX = "T";
|
||||
String INPUT_COSUMER = "I";
|
||||
String CHANGE_STATE = "S";
|
||||
String TESTS_DONE = "D";
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
/**
|
||||
* @noinspection HardCodedStringLiteral
|
||||
*/
|
||||
public interface PoolOfKnownObjects {
|
||||
String DEFAULT_INPUT_CONSUMER = "K1";
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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";
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class SegmentedOutputStream extends OutputStream implements PacketProcessor {
|
||||
private final PrintStream myPrintStream;
|
||||
private boolean myStarted = false;
|
||||
|
||||
public SegmentedOutputStream(PrintStream transportStream) {
|
||||
myPrintStream = transportStream;
|
||||
try {
|
||||
flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void write(int b) throws IOException {
|
||||
if (b == SegmentedStream.SPECIAL_SYMBOL && myStarted) writeNext(b);
|
||||
writeNext(b);
|
||||
flush();
|
||||
}
|
||||
|
||||
public synchronized void write(byte[] b, int off, int len) throws IOException {
|
||||
super.write(b, off, len);
|
||||
}
|
||||
|
||||
public synchronized void flush() throws IOException {
|
||||
myPrintStream.flush();
|
||||
}
|
||||
|
||||
public synchronized void close() throws IOException {
|
||||
myPrintStream.close();
|
||||
}
|
||||
|
||||
private void writeNext(int b) {
|
||||
myPrintStream.write(b);
|
||||
}
|
||||
|
||||
public synchronized void processPacket(String packet) {
|
||||
if (!myStarted)
|
||||
sendStart();
|
||||
writeNext(SegmentedStream.MARKER_PREFIX);
|
||||
String encodedPacket = Packet.encode(packet);
|
||||
writeNext(String.valueOf(encodedPacket.length())+SegmentedStream.LENGTH_DELIMITER+encodedPacket);
|
||||
}
|
||||
|
||||
private void writeNext(String string) {
|
||||
try {
|
||||
myPrintStream.write(string.getBytes());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendStart() {
|
||||
writeNext(SegmentedStream.STARTUP_MESSAGE);
|
||||
myStarted = true;
|
||||
}
|
||||
|
||||
public void beNotStarted() {
|
||||
myStarted = false;
|
||||
}
|
||||
|
||||
public static interface PrintStreamProvider {
|
||||
OutputStream getOutputStream();
|
||||
}
|
||||
|
||||
public static class SimplePrintStreamProvider implements PrintStreamProvider {
|
||||
private final PrintStream myPrintStream;
|
||||
|
||||
public SimplePrintStreamProvider(PrintStream printStream) {
|
||||
myPrintStream = printStream;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
return myPrintStream;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.intellij.rt.execution.junit.segments;
|
||||
|
||||
/**
|
||||
* @noinspection HardCodedStringLiteral
|
||||
*/
|
||||
public interface SegmentedStream {
|
||||
char SPECIAL_SYMBOL = '/';
|
||||
String SPECIAL_SYMBOL_STRING = String.valueOf(SPECIAL_SYMBOL);
|
||||
String MARKER_PREFIX = SPECIAL_SYMBOL_STRING + "M";
|
||||
String LENGTH_DELIMITER = " ";
|
||||
String STARTUP_MESSAGE = "@#IJIDEA#JUnitSupport#@";
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user