001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project;
043:
044: import java.io.IOException;
045: import java.io.Reader;
046: import java.io.StringReader;
047: import java.io.StringWriter;
048: import java.util.logging.Logger;
049: import junit.framework.Assert;
050: import org.netbeans.junit.NbTestCase;
051: import org.openide.ErrorManager;
052: import org.openide.windows.IOProvider;
053: import org.openide.windows.InputOutput;
054: import org.openide.windows.OutputListener;
055: import org.openide.windows.OutputWriter;
056:
057: /**
058: * @author Jaroslav Tulach
059: */
060: public class InputOutputProviderImpl extends IOProvider {
061:
062: static NbTestCase running;
063:
064: /** Creates a new instance of InputOutputProviderImpl */
065: public InputOutputProviderImpl() {
066: }
067:
068: public static void registerCase(NbTestCase r) {
069: running = r;
070: }
071:
072: public InputOutput getIO(String name, boolean newIO) {
073: return new IO(name);
074: }
075:
076: public OutputWriter getStdOut() {
077: Assert.assertNotNull("A test case must be registered", running);
078: return new OW("stdout");
079: }
080:
081: private static class OW extends OutputWriter {
082:
083: private Logger err;
084:
085: public OW(String prefix) {
086: super (new StringWriter());
087: err = Logger.getLogger("test.output." + prefix);
088: err.info("create output " + prefix);
089: }
090:
091: public void println(String s, OutputListener l)
092: throws IOException {
093: write("println: " + s + " listener: " + l);
094: flush();
095: }
096:
097: public void reset() throws IOException {
098: write("Internal reset");
099: flush();
100: }
101:
102: public void write(char[] buf, int off, int len) {
103: write(new String(buf, off, len));
104: }
105:
106: public void write(int c) {
107: write(String.valueOf((char) c));
108: }
109:
110: public void write(char[] buf) {
111: write(buf, 0, buf.length);
112: }
113:
114: public void write(String s, int off, int len) {
115: write(s.substring(off, off + len));
116: }
117:
118: public void write(String s) {
119: err.info(s);
120: }
121: }
122:
123: @SuppressWarnings("deprecation")
124: // for flushReader
125: private static class IO implements InputOutput {
126:
127: private OW w;
128: private boolean closed;
129:
130: public IO(String n) {
131: w = new OW(n);
132: w.write("Created IO named '" + n + "'");
133: w.flush();
134: }
135:
136: public OutputWriter getOut() {
137: return w;
138: }
139:
140: public Reader getIn() {
141: w.write("Creating reader");
142: return new StringReader("");
143: }
144:
145: public OutputWriter getErr() {
146: return w;
147: }
148:
149: public void closeInputOutput() {
150: w.write("closeInputOutput");
151: closed = true;
152: }
153:
154: public boolean isClosed() {
155: w.write("isClosed");
156: return closed;
157: }
158:
159: public void setOutputVisible(boolean value) {
160: w.write("setOutputVisible: " + value);
161: }
162:
163: public void setErrVisible(boolean value) {
164: w.write("setErrVisible: " + value);
165: }
166:
167: public void setInputVisible(boolean value) {
168: w.write("setInputVisible: " + value);
169: }
170:
171: public void select() {
172: w.write("select");
173: }
174:
175: public boolean isErrSeparated() {
176: return false;
177: }
178:
179: public void setErrSeparated(boolean value) {
180: }
181:
182: public boolean isFocusTaken() {
183: return false;
184: }
185:
186: public void setFocusTaken(boolean value) {
187: }
188:
189: public Reader flushReader() {
190: return getIn();
191: }
192:
193: }
194: }
|