You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/06/11 18:07:22 UTC

svn commit: r783826 [2/2] - in /felix/trunk/gogo: ./ src/ src/aQute/ src/aQute/cpeg/ src/aQute/osgi/ src/aQute/osgi/launcher/ src/aQute/shell/ src/aQute/shell/console/ src/aQute/shell/equinox/ src/aQute/shell/lang/ src/aQute/shell/osgi/ src/aQute/shell...

Added: felix/trunk/gogo/src/aQute/shell/stdio/StdioConsole.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/shell/stdio/StdioConsole.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/shell/stdio/StdioConsole.java (added)
+++ felix/trunk/gogo/src/aQute/shell/stdio/StdioConsole.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.shell.stdio;
+
+import org.osgi.service.command.*;
+import org.osgi.service.component.*;
+
+import aQute.shell.console.*;
+
+public class StdioConsole extends Thread {
+    final Console console = new Console();
+
+    public StdioConsole() {
+        super("StdioConsole");
+    }
+    protected void activate(ComponentContext context) {
+        start();
+    }
+
+    protected void deactivate(ComponentContext context) {
+        console.close();
+        interrupt();
+    }
+
+    public void setProcessor(CommandProcessor processor ) {
+        console.setSession(processor.createSession(System.in,System.out,System.err));
+    }
+    
+    public void run() {
+        console.run();
+    }
+}
+

Added: felix/trunk/gogo/src/aQute/shell/telnet/Handler.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/shell/telnet/Handler.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/shell/telnet/Handler.java (added)
+++ felix/trunk/gogo/src/aQute/shell/telnet/Handler.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.shell.telnet;
+
+import java.io.*;
+import java.net.*;
+
+import org.osgi.service.command.*;
+
+import aQute.shell.console.*;
+
+public class Handler extends Thread {
+	TelnetShell		master;
+	Socket			socket;
+	CommandSession	session;
+	Console			console;
+	
+	public Handler(TelnetShell master, CommandSession session, Socket socket)
+			throws IOException {
+		this.master = master;
+		this.socket = socket;
+		this.session = session;
+	}
+
+	public void run() {
+		try {
+			console = new Console();
+			console.setSession(session);
+			console.run();
+		} finally {
+			close();
+			master.handlers.remove(this);
+		}
+	}
+
+	public void close() {
+		session.close();
+		try {
+			socket.close();
+		} catch (IOException e) {
+			// Ignore, this is close
+		}
+	}
+
+}

Added: felix/trunk/gogo/src/aQute/shell/telnet/TelnetShell.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/shell/telnet/TelnetShell.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/shell/telnet/TelnetShell.java (added)
+++ felix/trunk/gogo/src/aQute/shell/telnet/TelnetShell.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.shell.telnet;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+import org.osgi.service.command.*;
+import org.osgi.service.component.*;
+
+public class TelnetShell extends Thread {
+    boolean          quit;
+    CommandProcessor processor;
+    ServerSocket     server;
+    int              port     = 2019;
+    List<Handler>    handlers = new ArrayList<Handler>();
+
+    protected void activate(ComponentContext context) {
+        String s = (String) context.getProperties().get("port");
+        if (s != null)
+            port = Integer.parseInt(s);
+        System.out.println("Telnet Listener at port " + port);
+        start();
+    }
+
+    protected void deactivate(ComponentContext ctx) throws Exception {
+        try {
+            quit = true;
+            server.close();
+            interrupt();
+        } catch (Exception e) {
+            // Ignore
+        }
+    }
+
+    public void run() {
+        int delay = 0;
+        try {
+            while (!quit)
+                try {
+                    server = new ServerSocket(port);
+                    delay = 5;
+                    while (!quit) {
+                        Socket socket = server.accept();
+                        CommandSession session = processor.createSession(socket
+                                .getInputStream(), new PrintStream(socket
+                                .getOutputStream()), System.err);
+                        Handler handler = new Handler(this, session, socket);
+                        handlers.add(handler);
+                        handler.start();
+                    }
+                } catch (BindException be) {
+                    delay += 5;
+                    System.err.println("Can not bind to port " + port);
+                    try {
+                        Thread.sleep(delay * 1000);
+                    } catch (InterruptedException e) {
+                        // who cares?
+                    }
+                } catch (Exception e) {
+                    if (!quit)
+                        e.printStackTrace();
+                } finally {
+                    try {
+                        server.close();
+                        Thread.sleep(2000);
+                    } catch (Exception ie) {
+                        //
+                    }
+                }
+
+        } finally {
+            try {
+                if (server != null)
+                    server.close();
+            } catch (IOException e) {
+                //
+            }
+            for (Handler handler : handlers)
+                handler.close();
+        }
+    }
+
+    public void setProcessor(CommandProcessor processor) {
+        this.processor = processor;
+    }
+}

Added: felix/trunk/gogo/src/aQute/threadio/Marker.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/threadio/Marker.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/threadio/Marker.java (added)
+++ felix/trunk/gogo/src/aQute/threadio/Marker.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.threadio;
+
+import java.io.*;
+
+public class Marker {
+    Marker previous;
+    InputStream in;
+    PrintStream out;
+    PrintStream err;
+    ThreadIOImpl parent;
+    
+    public Marker(ThreadIOImpl parent, InputStream in, PrintStream out,
+            PrintStream err, Marker previous) {
+        this.previous = previous;
+        this.parent = parent;
+        this.in = in;
+        this.out=out;
+        this.err=err;
+    }
+
+    Marker activate() {
+        parent.in.setStream(in);
+        parent.out.setStream(out);
+        parent.err.setStream(err);
+        return previous;
+    }
+}

Added: felix/trunk/gogo/src/aQute/threadio/ThreadIOImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/threadio/ThreadIOImpl.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/threadio/ThreadIOImpl.java (added)
+++ felix/trunk/gogo/src/aQute/threadio/ThreadIOImpl.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.threadio;
+
+import java.io.*;
+
+import org.osgi.service.component.*;
+import org.osgi.service.threadio.*;
+
+public class ThreadIOImpl implements ThreadIO {
+	ThreadPrintStream err = new ThreadPrintStream(System.err);
+	ThreadPrintStream out = new ThreadPrintStream(System.out);
+	ThreadInputStream in = new ThreadInputStream(System.in);
+    ThreadLocal<Marker> current = new ThreadLocal<Marker>();
+	
+	protected void activate(ComponentContext context) {
+		start();
+	}
+
+	protected void deactivate() {
+	    stop();
+	}
+	
+	public void stop() {
+		System.setErr(err.dflt);
+		System.setOut(out.dflt);
+		System.setIn(in.dflt);
+	}
+
+	public void start() {
+		if ( System.out instanceof ThreadPrintStream )
+			throw new IllegalStateException("Thread Print Stream already set");
+		System.setOut(out);
+		System.setIn(in);
+        System.setErr(err);
+	}
+	
+	public void close() {
+	    Marker top = this.current.get();
+	    if ( top == null )
+	        throw new IllegalStateException("No thread io active");
+
+	    Marker previous = top.previous;
+	    if (previous==null) {
+	        in.end();
+	        out.end();
+	        err.end();
+	    } else {
+            this.current.set(previous);
+    	    previous.activate();
+	    }
+	}
+
+	public void setStreams(InputStream in, PrintStream out, PrintStream err) {
+        assert in != null;
+        assert out != null;
+        assert err != null;
+        Marker marker = new Marker(this,in,out,err, current.get());
+	    this.current.set(marker);
+	    marker.activate();
+	}
+}

Added: felix/trunk/gogo/src/aQute/threadio/ThreadInputStream.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/threadio/ThreadInputStream.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/threadio/ThreadInputStream.java (added)
+++ felix/trunk/gogo/src/aQute/threadio/ThreadInputStream.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.threadio;
+
+import java.io.*;
+
+public class ThreadInputStream extends InputStream {
+    ThreadLocal<InputStream> map = new ThreadLocal<InputStream>();
+	InputStream dflt;
+
+	public ThreadInputStream(InputStream in) {
+		dflt = in;
+	}
+
+	public int read(byte[] buffer, int offset, int length) throws IOException {
+		return getCurrent().read(buffer, offset, length);
+	}
+
+	public int read(byte[] buffer) throws IOException {
+		return getCurrent().read(buffer);
+	}
+
+	private InputStream getCurrent() {
+		InputStream in = map.get();
+		if (in != null)
+			return in;
+		return dflt;
+	}
+
+	public int read() throws IOException {
+		return getCurrent().read();
+	}
+
+	public void setStream(InputStream in) {
+		if ( in != dflt && in != this )
+			map.set(in);
+		else
+			map.remove();
+	}
+
+	public void end() {
+		map.remove();
+	}
+
+	InputStream getRoot() {
+		return dflt;
+	}
+}

Added: felix/trunk/gogo/src/aQute/threadio/ThreadPrintStream.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/aQute/threadio/ThreadPrintStream.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/aQute/threadio/ThreadPrintStream.java (added)
+++ felix/trunk/gogo/src/aQute/threadio/ThreadPrintStream.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 aQute.threadio;
+
+import java.io.*;
+
+public class ThreadPrintStream extends PrintStream {
+	PrintStream dflt;
+	ThreadLocal<PrintStream>	map  = new ThreadLocal<PrintStream>();
+	
+	public ThreadPrintStream(PrintStream out) {
+		super(out);
+		dflt = out;
+	}
+
+	public void write(byte[] buffer, int offset, int length) {
+		getCurrent().write(buffer, offset, length);
+	}
+
+	public void write(byte[] buffer) throws IOException {
+		getCurrent().write(buffer);
+	}
+
+	public PrintStream getCurrent() {
+		PrintStream out = map.get();
+		if (out != null)
+			return out;
+		return dflt;
+	}
+
+	public void write(int b) {
+		getCurrent().write(b);
+	}
+
+	public void setStream(PrintStream out) {
+		if (out != dflt && out != this) {
+			map.set(out);
+		}
+		else {
+			map.remove();			
+		}
+	}
+
+	public void end() {
+		map.remove();
+	}
+	
+
+}

Added: felix/trunk/gogo/src/org/osgi/framework/boot/SystemBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/org/osgi/framework/boot/SystemBundle.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/org/osgi/framework/boot/SystemBundle.java (added)
+++ felix/trunk/gogo/src/org/osgi/framework/boot/SystemBundle.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.osgi.framework.boot;
+
+import java.util.*;
+
+/**
+ * This interface should be implemented by framework implementations when their
+ * main object is created. It allows a configurator to set the properties and
+ * launch the framework.
+ * 
+ * @author aqute
+ * 
+ */
+public interface SystemBundle {
+    /**
+     * The name of a Security Manager class with public empty constructor. A
+     * valid value is also true, this means that the framework should
+     * instantiate its own security manager. If not set, security could be
+     * defined by a parent framework or there is no security. This can be
+     * detected by looking if there is a security manager set
+     */
+    String SECURITY          = "org.osgi.framework.security";
+
+    /**
+     * A valid file path in the file system to a directory that exists. The
+     * framework is free to use this directory as it sees fit. This area can not
+     * be shared with anything else. If this property is not set, the framework
+     * should use a file area from the parent bundle. If it is not embedded, it
+     * must use a reasonable platform default.
+     */
+    String STORAGE           = "org.osgi.framework.storage";
+
+    /*
+     * A list of paths (separated by path separator) that point to additional
+     * directories to search for platform specific libraries
+     */
+    String LIBRARIES         = "org.osgi.framework.libraries";
+    /*
+     * The command to give a file executable permission. This is necessary in
+     * some environments for running shared libraries.
+     */
+    String EXECPERMISSION    = "org.osgi.framework.command.execpermission";
+
+    /*
+     * Points to a directory with certificates. ###??? Keystore? Certificate
+     * format?
+     */
+    String ROOT_CERTIFICATES = "org.osgi.framework.root.certificates";
+
+    /*
+     * Set by the configurator but the framework should provide a reasonable
+     * default.
+     */
+    String WINDOWSYSTEM      = "org.osgi.framework.windowsystem";
+
+    /**
+     * Configure this framework with the given properties. These properties can
+     * contain framework specific properties or of the general kind defined in
+     * the specification or in this interface.
+     * 
+     * @param properties
+     *            The properties. This properties can be backed by another
+     *            properties, it can there not be assumed that it contains all
+     *            keys. Use it only through the getProperty methods. This parameter may be null.
+     * 
+     */
+    void init(Properties configuration);
+
+    /**
+     * Wait until the framework is completely finished.
+     * 
+     * This method will return if the framework is stopped and has cleaned up
+     * all the framework resources. 
+     * 
+     * @param timeout Maximum number of milliseconds to wait until the framework is finished. Specifying a zero will wait indefinitely.
+     */
+    
+    void join(long timeout) throws InterruptedException;
+}

Added: felix/trunk/gogo/src/org/osgi/service/command/CommandProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/org/osgi/service/command/CommandProcessor.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/org/osgi/service/command/CommandProcessor.java (added)
+++ felix/trunk/gogo/src/org/osgi/service/command/CommandProcessor.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.osgi.service.command;
+
+import java.io.*;
+
+/**
+ * A command shell can create and maintain a number of command sessions.
+ * 
+ * @author aqute
+ * 
+ */
+public interface CommandProcessor {
+	/**
+	 * The scope of commands provided by this service. This name can be used to distinguish
+	 * between different command providers with the same function names.
+	 */
+	final static String	COMMAND_SCOPE		= "osgi.command.scope";
+
+	/**
+	 * A list of method names that may be called for this command provider. A
+	 * name may end with a *, this will then be calculated from all declared public
+	 * methods in this service.
+	 * 
+	 * Help information for the command may be supplied with a space as
+	 * separation.
+	 */
+	final static String	COMMAND_FUNCTION	= "osgi.command.function";
+
+	/**
+	 * Create a new command session associated with IO streams.
+	 * 
+	 * The session is bound to the life cycle of the bundle getting this
+	 * service. The session will be automatically closed when this bundle is
+	 * stopped or the service is returned.
+	 * 
+	 * The shell will provide any available commands to this session and
+	 * can set additional variables.
+	 * 
+	 * @param in
+	 *            The value used for System.in
+	 * @param out
+	 *            The stream used for System.out
+	 * @param err
+	 *            The stream used for System.err
+	 * @return A new session.
+	 */
+	CommandSession createSession(InputStream in, PrintStream out,
+			PrintStream err);
+}

Added: felix/trunk/gogo/src/org/osgi/service/command/CommandSession.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/org/osgi/service/command/CommandSession.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/org/osgi/service/command/CommandSession.java (added)
+++ felix/trunk/gogo/src/org/osgi/service/command/CommandSession.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.osgi.service.command;
+
+import java.io.*;
+
+public interface CommandSession {
+	/**
+	 * Execute a program in this session.
+	 * 
+	 * @param commandline 
+	 * @return the result of the execution
+	 */
+	Object execute(CharSequence commandline) throws Exception;
+
+	/**
+	 * Close this command session. After the session is closed, it will throw
+	 * IllegalStateException when it is used.
+	 * 
+	 * @param
+	 */
+	void close();
+
+	/**
+	 * Return the input stream that is the first of the pipeline. This stream is
+	 * sometimes necessary to communicate directly to the end user. For example,
+	 * a "less" or "more" command needs direct input from the keyboard to
+	 * control the paging.
+	 * 
+	 * @return InpuStream used closest to the user or null if input is from a
+	 *         file.
+	 */
+	InputStream getKeybord();
+
+	/**
+	 * Return the PrintStream for the console. This must always be the stream
+	 * "closest" to the user. This stream can be used to post messages that
+	 * bypass the piping. If the output is piped to a file, then the object
+	 * returned must be null.
+	 * 
+	 * @return
+	 */
+	PrintStream getConsole();
+
+	/**
+	 * Get the value of a variable.
+	 * 
+	 * @param name
+	 * @return
+	 */
+	Object get(String name);
+
+	/**
+	 * Set the value of a variable.
+	 * 
+	 * @param name
+	 *            Name of the variable.
+	 * @param value
+	 *            Value of the variable
+	 */
+	void put(String name, Object value);
+
+	/**
+	 * Convert an object to string form (CharSequence). The level is defined in
+	 * the Converter interface, it can be one of INSPECT, LINE, PART. This
+	 * function always returns a non null value. As a last resort, toString is
+	 * called on the Object.
+	 * 
+	 * @param target
+	 * @param level
+	 * @return
+	 */
+	CharSequence format(Object target, int level);
+
+	/**
+	 * Convert an object to another type.
+	 */
+	
+	Object convert(Class<?> type, Object instance);
+}

Added: felix/trunk/gogo/src/org/osgi/service/command/Converter.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/org/osgi/service/command/Converter.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/org/osgi/service/command/Converter.java (added)
+++ felix/trunk/gogo/src/org/osgi/service/command/Converter.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.osgi.service.command;
+
+
+/**
+ * A converter is a service that can help create specific object types from a
+ * string, and vice versa.
+ * 
+ * The shell is capable of coercing arguments to the their proper type. However,
+ * sometimes commands require extra help to do this conversion. This service can
+ * implement a converter for a number of types.
+ * 
+ * The command shell will rank these services in order of service.ranking and
+ * will then call them until one of the converters succeeds.
+ * 
+ */
+public interface Converter {
+	/**
+	 * This property is a string, or array of strings, and defines the classes
+	 * or interfaces that this converter recognizes. Recognized classes can be
+	 * converted from a string to a class and they can be printed in 3 different
+	 * modes.
+	 */
+	String	CONVERTER_CLASSES	= "osgi.converter.classes";
+
+	/**
+	 * Print the object in detail. This can contain multiple lines.
+	 */
+	int		INSPECT				= 0;
+
+	/**
+	 * Print the object as a row in a table. The columns should align for
+	 * multiple objects printed beneath each other. The print may run over
+	 * multiple lines but must not end in a CR.
+	 */
+	int		LINE				= 1;
+
+	/**
+	 * Print the value in a small format so that it is identifiable. This
+	 * printed format must be recognizable by the conversion method.
+	 */
+	int		PART				= 2;
+
+	/**
+	 * Convert an object to the desired type.
+	 * 
+	 * Return null if the conversion can not be done. Otherwise return and
+	 * object that extends the desired type or implements it.
+	 * 
+	 * @param desiredType
+	 *            The type that the returned object can be assigned to
+	 * @param in
+	 *            The object that must be converted
+	 * @return An object that can be assigned to the desired type or null.
+	 * @throws Exception
+	 */
+	Object convert(Class<?> desiredType, Object in) throws Exception;
+
+	/**
+	 * Convert an objet to a CharSequence object in the requested format. The
+	 * format can be INSPECT, LINE, or PART. Other values must throw
+	 * IllegalArgumentException.
+	 * 
+	 * @param target
+	 *            The object to be converted to a String
+	 * @param level
+	 *            One of INSPECT, LINE, or PART.
+	 * @param escape
+	 *            Use this object to format sub ordinate objects.
+	 * @return A printed object of potentially multiple lines
+	 * @throws Exception 
+	 */
+	CharSequence format(Object target, int level, Converter escape) throws Exception;
+}

Added: felix/trunk/gogo/src/org/osgi/service/command/Function.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/org/osgi/service/command/Function.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/org/osgi/service/command/Function.java (added)
+++ felix/trunk/gogo/src/org/osgi/service/command/Function.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.osgi.service.command;
+
+import java.util.*;
+
+/**
+ * A Function is a a block of code that can be executed with a set of arguments,
+ * it returns the result object of executing the script.
+ */
+public interface Function {
+	/**
+	 * Execute this function and return the result.
+	 * 
+	 * @return the result from the execution.
+	 * 
+	 * @throws Exception
+	 *             if anything goes terribly wrong
+	 */
+	Object execute(CommandSession session, List<Object> arguments)
+			throws Exception;
+}

Added: felix/trunk/gogo/src/org/osgi/service/threadio/ThreadIO.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/org/osgi/service/threadio/ThreadIO.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/src/org/osgi/service/threadio/ThreadIO.java (added)
+++ felix/trunk/gogo/src/org/osgi/service/threadio/ThreadIO.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.osgi.service.threadio;
+
+import java.io.*;
+
+/**
+ * Enable multiplexing of the standard IO streams for input, output, and error.
+ * 
+ * This service guards the central resource of IO streams. The standard streams
+ * are singletons. This service replaces the singletons with special versions that
+ * can find a unique stream for each thread. If no stream is associated with a
+ * thread, it will use the standard input/output that was originally set.
+ * 
+ * @author aqute
+ *
+ */
+public interface ThreadIO {
+	/**
+	 * Associate this streams with the current thread.
+	 * 
+	 * Ensure that when output is performed on System.in, System.out, System.err it
+	 * will happen on the given streams. 
+	 * 
+	 * The streams will automatically be canceled when the bundle that has gotten
+	 * this service is stopped or returns this service.
+	 * 
+	 * @param in InputStream to use for the current thread when System.in is used
+	 * @param out PrintStream to use for the current thread when System.out is used
+	 * @param err PrintStream to use for the current thread when System.err is used
+	 */
+	void setStreams(InputStream in, PrintStream out, PrintStream err);
+
+	/**
+	 * Cancel the streams associated with the current thread.
+	 * 
+	 * This method will not do anything when no streams are associated.
+	 */
+	void close();
+}

Added: felix/trunk/gogo/test/test/aQute/shell/runtime/Context.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/test/test/aQute/shell/runtime/Context.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/test/test/aQute/shell/runtime/Context.java (added)
+++ felix/trunk/gogo/test/test/aQute/shell/runtime/Context.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 test.aQute.shell.runtime;
+
+import aQute.shell.runtime.*;
+import aQute.threadio.*;
+
+public class Context extends CommandShellImpl {
+	public static final String EMPTY = "";
+	CommandSessionImpl session = (CommandSessionImpl) createSession(System.in,System.out,System.err);
+	static ThreadIOImpl threadio; 
+	
+	static  {
+		threadio = new ThreadIOImpl();
+		threadio.start();
+		
+	}
+	public Context() {
+		setThreadio( threadio );
+	}
+
+	public Object execute(CharSequence source) throws Exception {
+		return session.execute(source);
+	}
+
+	public void addCommand(String name, Object target ) {
+	    put("test:" + name, target );
+	}
+	
+
+}

Added: felix/trunk/gogo/test/test/aQute/shell/runtime/TestParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/test/test/aQute/shell/runtime/TestParser.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/test/test/aQute/shell/runtime/TestParser.java (added)
+++ felix/trunk/gogo/test/test/aQute/shell/runtime/TestParser.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 test.aQute.shell.runtime;
+
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+import junit.framework.*;
+
+import org.osgi.service.command.*;
+
+import aQute.shell.runtime.*;
+
+public class TestParser extends TestCase {
+    int beentheredonethat = 0;
+
+    public void testPipe() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        c.addCommand("capture", this);
+        c.addCommand("grep", this);
+        assertEquals("def", c
+                .execute("echo def|grep (d.*)|capture"));
+        assertEquals("def", c
+                .execute("echo abc; echo def; echo ghi|grep (d.*)|capture"));
+        assertEquals("hello world", c.execute("echo hello world|capture"));
+        assertEquals("defghi", c
+                .execute("echo abc; echo def; echo ghi|grep (def|ghi)|capture"));
+    }
+
+    public void testAssignment() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        c.addCommand("capture", this);
+        c.addCommand("grep", this);
+        assertEquals("hello", c.execute("echo hello|capture").toString());
+        assertEquals("hello", c.execute("a = <echo hello|capture>").toString());
+        assertEquals("a", c.execute("a = a; echo $<echo a>").toString());
+        assertEquals("3", c.execute("a=3; echo $a").toString());
+        assertEquals("3", c.execute("a = 3; echo $a").toString());
+        assertEquals("a", c.execute("a = a; echo $$a").toString());
+    }
+
+    public void testComment() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        assertEquals("1", c.execute("echo 1 // hello").toString());
+
+    }
+
+    public void testClosure() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        assertEquals("http://www.aqute.biz?com=2&biz=1", c.execute(
+                "['http://www.aqute.biz?com=2&biz=1'] get 0").toString());
+        assertEquals("{a=2, b=3}", c.execute("[a=2 b=3]").toString());
+        assertEquals("3", c.execute("[a=2 <b>=<3>] get b").toString());
+        assertEquals("[3, 4]", c.execute("[1 2 [3 4] 5 6] get 2").toString());
+        assertEquals(5, c.execute("[1 2 [3 4] 5 6] size"));
+
+    }
+
+    public void testArray() throws Exception {
+        Context c = new Context();
+        assertEquals("http://www.aqute.biz?com=2&biz=1", c.execute(
+                "['http://www.aqute.biz?com=2&biz=1'] get 0").toString());
+        assertEquals("{a=2, b=3}", c.execute("[a=2 b=3]").toString());
+        assertEquals("3", c.execute("[a=2 <b>=<3>] get b").toString());
+        assertEquals("[3, 4]", c.execute("[1 2 [3 4] 5 6] get 2").toString());
+        assertEquals(5, c.execute("[1 2 [3 4] 5 6] size"));
+
+    }
+
+    public void testEscape() {
+        Parser parser = new Parser("'a|b;c'");
+        CharSequence cs = parser.messy();
+        assertEquals("a|b;c", cs.toString());
+        assertEquals("a|b;c", new Parser(cs).unescape());
+    }
+
+
+    public void testParentheses() {
+        Parser parser = new Parser("(a|b)|(d|f)");
+        List<List<List<CharSequence>>> p = parser.program();
+        assertEquals("(a|b)", p.get(0).get(0).get(0));
+
+        parser = new Parser("grep (d.*)|grep (d|f)");
+        p = parser.program();
+        assertEquals("(d.*)", p.get(0).get(0).get(1));
+    }
+
+    public void testEcho() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        c.execute("echo peter");
+    }
+
+    public void grep(String match) throws IOException {
+        Pattern p = Pattern.compile(match);
+        BufferedReader rdr = new BufferedReader(
+                new InputStreamReader(System.in));
+        String s = rdr.readLine();
+        while (s != null) {
+            if (p.matcher(s).find()) {
+                System.out.println(s);
+            }
+            s = rdr.readLine();
+        }
+    }
+
+    public String capture() throws IOException {
+        StringWriter sw = new StringWriter();
+        BufferedReader rdr = new BufferedReader(
+                new InputStreamReader(System.in));
+        String s = rdr.readLine();
+        while (s != null) {
+            sw.write(s);
+            s = rdr.readLine();
+        }
+        return sw.toString();
+    }
+
+    public void testVars() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+
+        assertEquals("", c.execute(
+                "echo ${very.likely.that.this.does.not.exist}").toString());
+        assertNotNull(c.execute("echo ${java.runtime.name}"));
+    }
+
+    public void testFunny() throws Exception {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        assertEquals("a", c.execute("echo a") + "");
+        assertEquals("a", c.execute("<echo echo> a") + "");
+        assertEquals("a", c.execute("<<echo echo> echo> <echo a>") + "");
+    }
+
+    public CharSequence echo(Object args[]) {
+        if (args == null)
+            return "";
+        
+        StringBuilder sb = new StringBuilder();
+        String del = "";
+        for (Object arg : args) {
+            sb.append(del);
+            if (arg != null) {
+                sb.append(arg);
+                del = " ";
+            }
+        }
+        return sb;
+    }
+
+    public void testContext() throws Exception {
+        Context c = new Context();
+        c.addCommand("ls", this);
+        beentheredonethat = 0;
+        c.execute("ls");
+        assertEquals(1, beentheredonethat);
+
+        beentheredonethat = 0;
+        c.execute("ls 10");
+        assertEquals(10, beentheredonethat);
+
+        beentheredonethat = 0;
+        c.execute("ls a b c d e f g h i j");
+        assertEquals(10, beentheredonethat);
+
+        beentheredonethat = 0;
+        Integer result = (Integer) c.execute("ls <ls 5>");
+        assertEquals(10, beentheredonethat);
+        assertEquals((Integer) 5, result);
+
+    }
+
+    public void ls() {
+        beentheredonethat++;
+        System.out.println("Yes!");
+    }
+
+    public int ls(int onoff) {
+        beentheredonethat += onoff;
+        System.out.println("ls " + onoff);
+        return onoff;
+    }
+
+    public void ls(Object args[]) {
+        beentheredonethat = args.length;
+        System.out.print("ls [");
+        for (Object i : args)
+            System.out.print(i + " ");
+        System.out.println("]");
+    }
+
+    public void testProgram() {
+        List<List<List<CharSequence>>> x = new Parser(
+                "abc def|ghi jkl;mno pqr|stu vwx").program();
+        assertEquals("abc", x.get(0).get(0).get(0));
+        assertEquals("def", x.get(0).get(0).get(1));
+        assertEquals("ghi", x.get(1).get(0).get(0));
+        assertEquals("jkl", x.get(1).get(0).get(1));
+        assertEquals("mno", x.get(1).get(1).get(0));
+        assertEquals("pqr", x.get(1).get(1).get(1));
+        assertEquals("stu", x.get(2).get(0).get(0));
+        assertEquals("vwx", x.get(2).get(0).get(1));
+    }
+
+    public void testStatements() {
+        List<List<CharSequence>> x = new Parser("abc def;ghi jkl;mno pqr")
+                .statements();
+        assertEquals("abc", x.get(0).get(0));
+        assertEquals("def", x.get(0).get(1));
+        assertEquals("ghi", x.get(1).get(0));
+        assertEquals("jkl", x.get(1).get(1));
+        assertEquals("mno", x.get(2).get(0));
+        assertEquals("pqr", x.get(2).get(1));
+    }
+
+    public void testSimpleValue() {
+        List<CharSequence> x = new Parser(
+                "abc def.ghi http://www.osgi.org?abc=&x=1 [1,2,3] {{{{{{{xyz}}}}}}} <immediate> {'{{{{{'} {\\}} 'abc{}'")
+                .statement();
+        assertEquals("abc", x.get(0));
+        assertEquals("def.ghi", x.get(1));
+        assertEquals("http://www.osgi.org?abc=&x=1", x.get(2));
+        assertEquals("[1,2,3]", x.get(3));
+        assertEquals("{{{{{{{xyz}}}}}}}", x.get(4));
+        assertEquals("<immediate>", x.get(5));
+        assertEquals("{'{{{{{'}", x.get(6));
+        assertEquals("{\\}}", x.get(7));
+        assertEquals("abc{}", x.get(8));
+    }
+
+    void each(CommandSession session, Collection<Object> list, Function closure) throws Exception {
+        List<Object> args = new ArrayList<Object>();
+        args.add(null);
+        for (Object x : list) {
+            args.set(0, x );
+            closure.execute(session, args);
+        }
+    }
+
+}

Added: felix/trunk/gogo/test/test/aQute/threadio/TestThreadIO.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/test/test/aQute/threadio/TestThreadIO.java?rev=783826&view=auto
==============================================================================
--- felix/trunk/gogo/test/test/aQute/threadio/TestThreadIO.java (added)
+++ felix/trunk/gogo/test/test/aQute/threadio/TestThreadIO.java Thu Jun 11 16:07:20 2009
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 test.aQute.threadio;
+
+import java.io.*;
+import java.util.*;
+
+import junit.framework.*;
+import aQute.threadio.*;
+
+public class TestThreadIO extends TestCase {
+    
+    /**
+     * Test if the threadio works in a nested fashion. We first push
+     * ten markers on the stack and print a message for each, capturing
+     * the output in a ByteArrayOutputStream. Then we pop them, also printing
+     * a message identifying the level. Then we verify the output for each level.
+     */
+    public void testNested() {
+        ThreadIOImpl tio = new ThreadIOImpl();
+        tio.start();
+        List<ByteArrayOutputStream> list = new ArrayList<ByteArrayOutputStream>();
+        for ( int i =0; i<10; i++) {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            list.add(out);
+            tio.setStreams(System.in, new PrintStream(out), System.err);            
+            System.out.print("b" + i);
+        }
+        for ( int i =9; i>=0; i--) {
+            System.out.println("e" + i);            
+            tio.close();
+        }
+        tio.stop();        
+        for ( int i =0; i<10; i++) {
+            String message = list.get(i).toString().trim();
+            assertEquals("b"+i+"e"+i, message );
+        }
+    }
+
+    /**
+     * Simple test too see if the basics work.
+     */
+    public void testSimple() {
+        ThreadIOImpl tio = new ThreadIOImpl();
+        tio.start();
+        System.out.println("Hello World");   
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ByteArrayOutputStream err = new ByteArrayOutputStream();
+        tio.setStreams(System.in, new PrintStream(out), new PrintStream(err));
+        try {
+            System.out.println("Simple Normal Message");
+            System.err.println("Simple Error Message");
+        } finally {
+            tio.close();
+        }
+        tio.stop();
+        String normal = out.toString().trim();
+        //String error = err.toString().trim();
+        assertEquals("Simple Normal Message", normal );
+        //assertEquals("Simple Error Message", error );
+        System.out.println("Goodbye World");           
+    }
+}