From: <Qa...@us...> - 2006-12-10 17:40:07
|
Revision: 2885 http://jnode.svn.sourceforge.net/jnode/?rev=2885&view=rev Author: QaDeS Date: 2006-12-10 09:40:01 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Bug 911 quick fix Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/VmReflection.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java Modified: trunk/core/src/core/org/jnode/vm/VmReflection.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmReflection.java 2006-12-10 15:57:36 UTC (rev 2884) +++ trunk/core/src/core/org/jnode/vm/VmReflection.java 2006-12-10 17:40:01 UTC (rev 2885) @@ -318,6 +318,8 @@ } if (!method.isStatic()) { + if( o == null ) + throw new NullPointerException(); Unsafe.pushObject(o); } else { method.getDeclaringClass().initialize(); Modified: trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2006-12-10 15:57:36 UTC (rev 2884) +++ trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2006-12-10 17:40:01 UTC (rev 2885) @@ -33,6 +33,7 @@ import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; @@ -287,8 +288,12 @@ // new // thread? try { - AccessController.doPrivileged(new InvokeAction(method, - null, args)); + Object obj = null; + if(!Modifier.isStatic(method.getModifiers())) { + obj = cx.newInstance(); + } + AccessController.doPrivileged(new InvokeAction(method, + obj, args)); } catch (PrivilegedActionException ex) { throw ex.getException(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Qa...@us...> - 2006-12-12 22:50:00
|
Revision: 2905 http://jnode.svn.sourceforge.net/jnode/?rev=2905&view=rev Author: QaDeS Date: 2006-12-12 14:49:58 -0800 (Tue, 12 Dec 2006) Log Message: ----------- proportional font cursor fix (generic) tiny cleanups Modified Paths: -------------- trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java Modified: trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java 2006-12-12 22:20:48 UTC (rev 2904) +++ trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java 2006-12-12 22:49:58 UTC (rev 2905) @@ -14,7 +14,7 @@ public static void main(String[] argv) throws Exception { initEnv(); SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager(); - new Thread(new CommandShell((TextConsole) cm.createConsole(null, + new Thread(new CommandShell((TextConsole) cm.createConsole("Console 1", ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE))). start(); } Modified: trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java 2006-12-12 22:20:48 UTC (rev 2904) +++ trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java 2006-12-12 22:49:58 UTC (rev 2905) @@ -35,6 +35,7 @@ initializeKeyboard(systemScreen.getKeyboardDevice()); addPointerDevice(systemScreen.getPointerDevivce()); frame = new JFrame("Console"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter(){ public void windowClosed(WindowEvent e) { closeAll(); Modified: trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java 2006-12-12 22:20:48 UTC (rev 2904) +++ trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java 2006-12-12 22:49:58 UTC (rev 2905) @@ -15,6 +15,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.KeyboardFocusManager; import java.awt.event.*; @@ -88,11 +89,11 @@ int offset = i * SCREEN_WIDTH; int lenght = SCREEN_WIDTH; if (offset <= cursorOffset && cursorOffset < offset + SCREEN_WIDTH) { - char[] line = new char[SCREEN_WIDTH]; - for (int j = 0; j < SCREEN_WIDTH; j++) { - line[j] = offset + j == cursorOffset ? '_' : ' '; - } - g.drawChars(line, 0, lenght, margin, h + i * h); + FontMetrics fm = getFontMetrics(getFont()); + int x = margin + fm.charsWidth(buffer, offset, cursorOffset - offset); + int y = h + i * h; + int width = fm.charWidth(buffer[cursorOffset]); + g.drawLine(x, y, x+width, y); } g.drawChars(buffer, offset, lenght, margin, h + i * h); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qa...@us...> - 2006-12-15 01:52:01
|
Revision: 2931 http://jnode.svn.sourceforge.net/jnode/?rev=2931&view=rev Author: qades Date: 2006-12-14 17:51:58 -0800 (Thu, 14 Dec 2006) Log Message: ----------- reverted broken changes Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/java/net/PlainDatagramSocketImpl.java trunk/core/src/classpath/gnu/gnu/java/net/PlainSocketImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelSelectionKey.java trunk/core/src/classpath/gnu/gnu/java/nio/FileLockImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/NIOSocket.java trunk/core/src/classpath/gnu/gnu/java/nio/PipeImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/SelectionKeyImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/SelectorImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/SelectorProviderImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/ServerSocketChannelImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/ServerSocketChannelSelectionKey.java trunk/core/src/classpath/gnu/gnu/java/nio/SocketChannelImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/SocketChannelSelectionKey.java trunk/core/src/classpath/gnu/gnu/java/nio/SocketChannelSelectionKeyImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/charset/ByteCharset.java trunk/core/src/classpath/gnu/gnu/java/nio/charset/ISO_8859_1.java trunk/core/src/classpath/gnu/gnu/java/nio/charset/US_ASCII.java trunk/core/src/classpath/gnu/gnu/java/nio/charset/iconv/IconvDecoder.java trunk/core/src/classpath/gnu/gnu/java/nio/charset/iconv/IconvEncoder.java trunk/core/src/classpath/java/java/io/FileDescriptor.java trunk/core/src/classpath/java/java/io/FileInputStream.java trunk/core/src/classpath/java/java/io/FileOutputStream.java trunk/core/src/classpath/java/java/io/RandomAccessFile.java trunk/core/src/classpath/java/java/net/DatagramSocket.java trunk/core/src/classpath/vm/gnu/java/nio/VMPipe.java trunk/core/src/classpath/vm/gnu/java/nio/VMSelector.java trunk/core/src/classpath/vm/java/io/VMOpenMode.java trunk/core/src/classpath/vm/java/nio/channels/VMChannels.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/java/nio/channels/FileChannelImpl.java Removed Paths: ------------- trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectionKeyImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectorImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/FileChannelImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectionKeyImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/KqueueSelectorImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/NIOSocketImpl.java trunk/core/src/classpath/gnu/gnu/java/nio/VMChannelOwner.java trunk/core/src/classpath/vm/gnu/java/net/ trunk/core/src/classpath/vm/gnu/java/nio/VMChannel.java trunk/core/src/core/org/jnode/vm/VmChannel.java Modified: trunk/core/src/classpath/gnu/gnu/java/net/PlainDatagramSocketImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/net/PlainDatagramSocketImpl.java 2006-12-14 21:06:58 UTC (rev 2930) +++ trunk/core/src/classpath/gnu/gnu/java/net/PlainDatagramSocketImpl.java 2006-12-15 01:51:58 UTC (rev 2931) @@ -1,5 +1,5 @@ /* PlainDatagramSocketImpl.java -- Default DatagramSocket implementation - Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,10 +38,7 @@ package gnu.java.net; -import gnu.java.nio.VMChannel; - import java.io.IOException; -import java.io.InterruptedIOException; import java.net.DatagramPacket; import java.net.DatagramSocketImpl; import java.net.InetAddress; @@ -49,8 +46,8 @@ import java.net.NetworkInterface; import java.net.SocketAddress; import java.net.SocketException; -import java.net.SocketTimeoutException; -import java.nio.ByteBuffer; +import java.net.SocketOptions; +import gnu.classpath.Configuration; /** * Written using on-line Java Platform 1.2 API Specification, as well @@ -68,12 +65,17 @@ */ public final class PlainDatagramSocketImpl extends DatagramSocketImpl { - private final VMChannel channel; - + // @vm-specific removed System.loadLibrary + /** - * The platform-specific socket implementation. + * Option id for the IP_TTL (time to live) value. */ - private final VMPlainSocketImpl impl; + private static final int IP_TTL = 0x1E61; // 7777 + + /** + * This is the actual underlying file descriptor + */ + int native_fd = -1; /** * Lock object to serialize threads wanting to receive @@ -88,26 +90,24 @@ /** * Default do nothing constructor */ - public PlainDatagramSocketImpl() throws IOException + public PlainDatagramSocketImpl() { - channel = new VMChannel(); - impl = new VMPlainSocketImpl(channel); } - /*protected void finalize() throws Throwable + protected void finalize() throws Throwable { synchronized (this) { - if (channel.getState().isValid()) + if (native_fd != -1) close(); } super.finalize(); - }*/ + } - /*public int getNativeFD() + public int getNativeFD() { return native_fd; - }*/ + } /** * Binds this socket to a particular port and interface @@ -120,20 +120,9 @@ protected synchronized void bind(int port, InetAddress addr) throws SocketException { - try - { - impl.bind(new InetSocketAddress(addr, port)); - } - catch (SocketException se) - { - throw se; - } - catch (IOException ioe) - { - SocketException se = new SocketException(); - se.initCause(ioe); - throw se; - } + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** @@ -141,58 +130,13 @@ * * @exception SocketException If an error occurs */ - protected synchronized void create() throws SocketException - { - try - { - channel.initSocket(false); - } - catch (SocketException se) - { - throw se; - } - catch (IOException ioe) - { - SocketException se = new SocketException(); - se.initCause(ioe); - throw se; - } + protected synchronized void create() throws SocketException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** - * Connects to the remote address and port specified as arguments. - * - * @param addr The remote address to connect to - * @param port The remote port to connect to - * - * @exception SocketException If an error occurs - */ - protected void connect(InetAddress addr, int port) throws SocketException - { - channel.connect(new InetSocketAddress(addr, port), 0); - } - - /** - * Disconnects the socket. - * - * @since 1.4 - */ - protected void disconnect() - { - synchronized (this) - { - try - { - if (channel.getState().isValid()) - channel.disconnect(); - } - catch (IOException ioe) - { - } - } - } - - /** * Sets the Time to Live value for the socket * * @param ttl The new TTL value @@ -201,7 +145,7 @@ */ protected synchronized void setTimeToLive(int ttl) throws IOException { - impl.setTimeToLive(ttl); + setOption(IP_TTL, new Integer(ttl)); } /** @@ -213,60 +157,48 @@ */ protected synchronized int getTimeToLive() throws IOException { - return impl.getTimeToLive(); - } + Object obj = getOption(IP_TTL); - protected int getLocalPort() - { - if (channel == null) - return -1; + if (! (obj instanceof Integer)) + throw new IOException("Internal Error"); - try - { - InetSocketAddress local = channel.getLocalAddress(); - if (local == null) - return -1; - return local.getPort(); - } - catch (IOException ioe) - { - return -1; - } + return ((Integer) obj).intValue(); } /** * Sends a packet of data to a remote host * + * @param addr The address to send to + * @param port The port to send to + * @param buf The buffer to send + * @param offset The offset of the data in the buffer to send + * @param len The length of the data to send + * + * @exception IOException If an error occurs + */ + private void sendto (InetAddress addr, int port, + byte[] buf, int offset, int len) + throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); + } + + /** + * Sends a packet of data to a remote host + * * @param packet The packet to send * * @exception IOException If an error occurs */ protected void send(DatagramPacket packet) throws IOException { - synchronized (SEND_LOCK) + synchronized(SEND_LOCK) { - ByteBuffer buf = ByteBuffer.wrap(packet.getData(), - packet.getOffset(), - packet.getLength()); - InetAddress remote = packet.getAddress(); - int port = packet.getPort(); - if (remote == null) - throw new NullPointerException(); - if (port <= 0) - throw new SocketException("invalid port " + port); - while (true) - { - try - { - channel.send(buf, new InetSocketAddress(remote, port)); - break; - } - catch (InterruptedIOException ioe) - { - // Ignore; interrupted system call. - } - } + sendto(packet.getAddress(), packet.getPort(), packet.getData(), + packet.getOffset(), packet.getLength()); } + } /** @@ -279,123 +211,63 @@ protected void receive(DatagramPacket packet) throws IOException { - synchronized(RECEIVE_LOCK) - { - ByteBuffer buf = ByteBuffer.wrap(packet.getData(), - packet.getOffset(), - packet.getLength()); - SocketAddress addr = null; - while (true) - { - try - { - addr = channel.receive(buf); - break; - } - catch (SocketTimeoutException ste) - { - throw ste; - } - catch (InterruptedIOException iioe) - { - // Ignore. Loop. - } - } - if (addr != null) - packet.setSocketAddress(addr); - packet.setLength(buf.position() - packet.getOffset()); - } + synchronized(RECEIVE_LOCK) + { + receive0(packet); + } } + /** + * Native call to receive a UDP packet from the network + * + * @param packet The packet to fill in with the data received + * + * @exception IOException IOException If an error occurs + */ + private void receive0(DatagramPacket packet) throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); + } /** * Sets the value of an option on the socket * - * @param optionId The identifier of the option to set - * @param value The value of the option to set + * @param option_id The identifier of the option to set + * @param val The value of the option to set * * @exception SocketException If an error occurs */ - public synchronized void setOption(int optionId, Object value) - throws SocketException - { - switch (optionId) - { - case IP_MULTICAST_IF: - case IP_MULTICAST_IF2: - impl.setMulticastInterface(optionId, (InetAddress) value); - break; - - case IP_MULTICAST_LOOP: - case SO_BROADCAST: - case SO_KEEPALIVE: - case SO_OOBINLINE: - case TCP_NODELAY: - case IP_TOS: - case SO_LINGER: - case SO_RCVBUF: - case SO_SNDBUF: - case SO_TIMEOUT: - case SO_REUSEADDR: - impl.setOption(optionId, value); - return; - - default: - throw new SocketException("cannot set option " + optionId); - } + public synchronized void setOption(int option_id, Object val) + throws SocketException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** * Retrieves the value of an option on the socket * - * @param optionId The identifier of the option to retrieve + * @param option_id The identifier of the option to retrieve * * @return The value of the option * * @exception SocketException If an error occurs */ - public synchronized Object getOption(int optionId) - throws SocketException - { - if (optionId == SO_BINDADDR) - { - try - { - InetSocketAddress local = channel.getLocalAddress(); - if (local == null) - return null; - return local.getAddress(); - } - catch (SocketException se) - { - throw se; - } - catch (IOException ioe) - { - SocketException se = new SocketException(); - se.initCause(ioe); - throw se; - } - } - if (optionId == IP_MULTICAST_IF || optionId == IP_MULTICAST_IF2) - return impl.getMulticastInterface(optionId); - - return impl.getOption(optionId); + public synchronized Object getOption(int option_id) + throws SocketException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** * Closes the socket */ - protected synchronized void close() - { - try - { - if (channel.getState().isValid()) - channel.close(); - } - catch (IOException ioe) - { - } + protected synchronized void close() { + // @vm-specific no natives + //TODO implement me + throw new RuntimeException("Not implemented"); } /** @@ -433,9 +305,9 @@ * * @exception IOException If an error occurs */ - protected synchronized void join(InetAddress addr) throws IOException - { - impl.join(addr); + protected synchronized void join(InetAddress addr) throws IOException { + // @vm-specific no natives + throw new SocketException("Not implemented"); } /** @@ -445,9 +317,10 @@ * * @exception IOException If an error occurs */ - protected synchronized void leave(InetAddress addr) throws IOException - { - impl.leave(addr); + protected synchronized void leave(InetAddress addr) throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** @@ -465,22 +338,14 @@ } public void joinGroup(SocketAddress address, NetworkInterface netIf) - throws IOException { - if (address == null) - throw new NullPointerException(); - if (!(address instanceof InetSocketAddress)) - throw new SocketException("unknown address type"); - impl.joinGroup((InetSocketAddress) address, netIf); + throw new InternalError + ("PlainDatagramSocketImpl::joinGroup is not implemented"); } public void leaveGroup(SocketAddress address, NetworkInterface netIf) - throws IOException { - if (address == null) - throw new NullPointerException(); - if (!(address instanceof InetSocketAddress)) - throw new SocketException("unknown address type"); - impl.leaveGroup((InetSocketAddress) address, netIf); + throw new InternalError + ("PlainDatagramSocketImpl::leaveGroup is not implemented"); } } Modified: trunk/core/src/classpath/gnu/gnu/java/net/PlainSocketImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/net/PlainSocketImpl.java 2006-12-14 21:06:58 UTC (rev 2930) +++ trunk/core/src/classpath/gnu/gnu/java/net/PlainSocketImpl.java 2006-12-15 01:51:58 UTC (rev 2931) @@ -39,20 +39,16 @@ package gnu.java.net; -import gnu.java.nio.SocketChannelImpl; -import gnu.java.nio.VMChannel; - import java.io.InputStream; import java.io.IOException; -import java.io.InterruptedIOException; import java.io.OutputStream; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.SocketException; import java.net.SocketImpl; -import java.net.SocketTimeoutException; -import java.nio.ByteBuffer; +import java.net.SocketOptions; +import gnu.classpath.Configuration; /** * Written using on-line Java Platform 1.2 API Specification, as well @@ -70,13 +66,25 @@ * @author Nic Ferrier (nfe...@ta...) * @author Aaron M. Renn (ar...@ur...) */ -public class PlainSocketImpl extends SocketImpl +public final class PlainSocketImpl extends SocketImpl { + // Static initializer to load native library. + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javanet"); + } + } /** - * The underlying plain socket VM implementation. + * The OS file handle representing the socket. + * This is used for reads and writes to/from the socket and + * to close it. + * + * When the socket is closed this is reset to -1. */ - protected VMPlainSocketImpl impl; + int native_fd = -1; /** * A cached copy of the in stream for reading from the socket. @@ -93,14 +101,8 @@ * is being invoked on this socket. */ private boolean inChannelOperation; - + /** - * The socket channel we use for IO operation. Package-private for - * use by inner classes. - */ - SocketChannelImpl channel; - - /** * Indicates whether we should ignore whether any associated * channel is set to non-blocking mode. Certain operations * throw an <code>IllegalBlockingModeException</code> if the @@ -122,44 +124,48 @@ } /** - * Default do nothing constructor. + * Default do nothing constructor */ public PlainSocketImpl() { - this.impl = new VMPlainSocketImpl(); } + + protected void finalize() throws Throwable + { + synchronized (this) + { + if (native_fd != -1) + try + { + close(); + } + catch (IOException ex) + { + } + } + super.finalize(); + } + public int getNativeFD() + { + return native_fd; + } + /** * Sets the specified option on a socket to the passed in object. For * options that take an integer argument, the passed in object is an * Integer. The option_id parameter is one of the defined constants in * this interface. * - * @param optionId The identifier of the option - * @param value The value to set the option to + * @param option_id The identifier of the option + * @param val The value to set the option to * - * @throws SocketException if an error occurs + * @exception SocketException If an error occurs */ - public void setOption(int optionId, Object value) throws SocketException - { - switch (optionId) - { - case SO_LINGER: - case IP_MULTICAST_LOOP: - case SO_BROADCAST: - case SO_KEEPALIVE: - case SO_OOBINLINE: - case TCP_NODELAY: - case IP_TOS: - case SO_RCVBUF: - case SO_SNDBUF: - case SO_TIMEOUT: - case SO_REUSEADDR: - impl.setOption(optionId, value); - return; - default: - throw new SocketException("Unrecognized TCP option: " + optionId); - } + public void setOption(int optID, Object value) throws SocketException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** @@ -167,144 +173,133 @@ * will be an Integer for options that have integer values. The option_id * is one of the defined constants in this interface. * - * @param optionId the option identifier + * @param option_id The option identifier * - * @return the current value of the option + * @return The current value of the option * - * @throws SocketException if an error occurs + * @exception SocketException If an error occurs */ - public Object getOption(int optionId) throws SocketException - { - if (optionId == SO_BINDADDR) - { - try - { - return channel.getVMChannel().getLocalAddress().getAddress(); - } - catch (IOException ioe) - { - SocketException se = new SocketException(); - se.initCause(ioe); - throw se; - } - } - - // This filters options which are invalid for TCP. - switch (optionId) - { - case SO_LINGER: - case IP_MULTICAST_LOOP: - case SO_BROADCAST: - case SO_KEEPALIVE: - case SO_OOBINLINE: - case TCP_NODELAY: - case IP_TOS: - case SO_RCVBUF: - case SO_SNDBUF: - case SO_TIMEOUT: - case SO_REUSEADDR: - return impl.getOption(optionId); - default: - throw new SocketException("Unrecognized TCP option: " + optionId); - } - + public Object getOption(int optID) throws SocketException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } - public void shutdownInput() throws IOException + /** + * Flushes the input stream and closes it. If you read from the input stream + * after calling this method a <code>IOException</code> will be thrown. + * + * @throws IOException if an error occurs + */ + public void shutdownInput() { - impl.shutdownInput(); + // @vm-specific no natives + //TODO implement me + throw new InternalError ("PlainSocketImpl::shutdownInput not implemented"); } + /** + * Flushes the output stream and closes it. If you write to the output stream + * after calling this method a <code>IOException</code> will be thrown. + * + * @throws IOException if an error occurs + */ public void shutdownOutput() throws IOException { - impl.shutdownOutput(); + // @vm-specific no natives + //TODO implement me + throw new InternalError ("PlainSocketImpl::shutdownOutput not implemented"); } /** * Creates a new socket that is not bound to any local address/port and - * is not connected to any remote address/port. The stream parameter will be - * ignored since PlainSocketImpl always is a stream socket. Datagram sockets - * are handled by PlainDatagramSocketImpl. + * is not connected to any remote address/port. This will be created as + * a stream socket if the stream parameter is true, or a datagram socket + * if the stream parameter is false. * - * @param stream <code>true</code> for stream sockets, <code>false</code> for - * datagram sockets + * @param stream true for a stream socket, false for a datagram socket */ - protected synchronized void create(boolean stream) throws IOException - { - channel = new SocketChannelImpl(false); - VMChannel vmchannel = channel.getVMChannel(); - vmchannel.initSocket(stream); - channel.configureBlocking(true); - impl.getState().setChannelFD(vmchannel.getState()); + protected synchronized void create(boolean stream) throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** * Connects to the remote hostname and port specified as arguments. * - * @param hostname the remote hostname to connect to - * @param port the remote port to connect to + * @param hostname The remote hostname to connect to + * @param port The remote port to connect to * - * @throws IOException If an error occurs + * @exception IOException If an error occurs */ - protected synchronized void connect(String hostname, int port) - throws IOException + protected synchronized void connect(String host, int port) throws IOException { - connect(InetAddress.getByName(hostname), port); + connect(InetAddress.getByName(host), port); } /** * Connects to the remote address and port specified as arguments. * - * @param addr the remote address to connect to - * @param port the remote port to connect to + * @param addr The remote address to connect to + * @param port The remote port to connect to * - * @throws IOException If an error occurs + * @exception IOException If an error occurs */ - protected void connect(InetAddress addr, int port) throws IOException - { - connect(new InetSocketAddress(addr, port), 0); + protected void connect(InetAddress addr, int port) throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** * Connects to the remote socket address with a specified timeout. * - * @param address the remote address to connect to - * @param timeout the timeout to use for this connect, 0 means infinite. + * @param timeout The timeout to use for this connect, 0 means infinite. * - * @throws IOException If an error occurs + * @exception IOException If an error occurs */ - protected synchronized void connect(SocketAddress address, int timeout) - throws IOException + protected synchronized void connect(SocketAddress address, int timeout) throws IOException { - if (channel == null) - create(true); - boolean connected = channel.connect(address, timeout); - if (!connected) - throw new SocketTimeoutException("connect timed out"); + InetSocketAddress sockAddr = (InetSocketAddress) address; + InetAddress addr = sockAddr.getAddress(); + + if (addr == null) + throw new IllegalArgumentException("address is unresolved: " + sockAddr); + + int port = sockAddr.getPort(); - // Using the given SocketAddress is important to preserve - // hostnames given by the caller. - InetSocketAddress addr = (InetSocketAddress) address; - this.address = addr.getAddress(); - this.port = addr.getPort(); + if (timeout < 0) + throw new IllegalArgumentException("negative timeout"); + + Object oldTimeoutObj = null; + + try + { + oldTimeoutObj = this.getOption (SocketOptions.SO_TIMEOUT); + this.setOption (SocketOptions.SO_TIMEOUT, new Integer (timeout)); + connect (addr, port); + } + finally + { + if (oldTimeoutObj != null) + this.setOption (SocketOptions.SO_TIMEOUT, oldTimeoutObj); + } } /** * Binds to the specified port on the specified addr. Note that this addr * must represent a local IP address. **** How bind to INADDR_ANY? **** * - * @param addr the address to bind to - * @param port the port number to bind to + * @param addr The address to bind to + * @param port The port number to bind to * - * @throws IOException if an error occurs + * @exception IOException If an error occurs */ protected synchronized void bind(InetAddress addr, int port) - throws IOException - { - if (channel == null) - create(true); - impl.bind(new InetSocketAddress(addr, port)); - localport = channel.getVMChannel().getLocalAddress().getPort(); + throws IOException { + // @vm-specific no natives + throw new SocketException("Not implemented"); } /** @@ -315,12 +310,13 @@ * * @param queuelen The length of the pending connection queue * - * @throws IOException If an error occurs + * @exception IOException If an error occurs */ protected synchronized void listen(int queuelen) - throws IOException - { - impl.listen(queuelen); + throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** @@ -330,64 +326,78 @@ * @param impl The SocketImpl object to accept this connection. */ protected synchronized void accept(SocketImpl impl) - throws IOException - { - if (channel == null) - create(true); - if (!(impl instanceof PlainSocketImpl)) - throw new IOException("incompatible SocketImpl: " - + impl.getClass().getName()); - PlainSocketImpl that = (PlainSocketImpl) impl; - VMChannel c = channel.getVMChannel().accept(); - that.impl.getState().setChannelFD(c.getState()); - that.channel = new SocketChannelImpl(c); - that.setOption(SO_REUSEADDR, Boolean.TRUE); - // Reset the inherited timeout. - that.setOption(SO_TIMEOUT, Integer.valueOf(0)); - + throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** * Returns the number of bytes that the caller can read from this socket * without blocking. * - * @return the number of readable bytes before blocking + * @return The number of readable bytes before blocking * - * @throws IOException if an error occurs + * @exception IOException If an error occurs */ - protected int available() throws IOException - { - if (channel == null) - throw new SocketException("not connected"); - return channel.getVMChannel().available(); + protected int available() throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } /** * Closes the socket. This will cause any InputStream or OutputStream * objects for this Socket to be closed as well. - * * <p> * Note that if the SO_LINGER option is set on this socket, then the * operation could block. - * </p> * - * @throws IOException if an error occurs + * @exception IOException If an error occurs */ - protected void close() throws IOException - { - if (impl.getState().isValid()) - impl.close(); - - address = null; - port = -1; + protected void close() throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); } - public void sendUrgentData(int data) throws IOException + public void sendUrgentData(int data) { - impl.sendUrgentData(data); + throw new InternalError ("PlainSocketImpl::sendUrgentData not implemented"); } /** + * Internal method used by SocketInputStream for reading data from + * the connection. Reads up to len bytes of data into the buffer + * buf starting at offset bytes into the buffer. + * + * @return The actual number of bytes read or -1 if end of stream. + * + * @exception IOException If an error occurs + */ + protected int read(byte[] buf, int offset, int len) + throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); + + } + + /** + * Internal method used by SocketOuputStream for writing data to + * the connection. Writes up to len bytes of data from the buffer + * buf starting at offset bytes into the buffer. + * + * @exception IOException If an error occurs + */ + protected void write(byte[] buf, int offset, int len) + throws IOException { + // @vm-specific no natives + //TODO implement me + throw new SocketException("Not implemented"); + } + + /** * Returns an InputStream object for reading from this socket. This will * be an instance of SocketInputStream. * @@ -399,7 +409,7 @@ { if (in == null) in = new SocketInputStream(); - + return in; } @@ -415,104 +425,15 @@ { if (out == null) out = new SocketOutputStream(); - + return out; } - - public VMChannel getVMChannel() - { - if (channel == null) - return null; - return channel.getVMChannel(); - } - /* (non-Javadoc) - * @see java.net.SocketImpl#getInetAddress() - */ - protected InetAddress getInetAddress() - { - if (channel == null) - return null; - - try - { - InetSocketAddress remote = channel.getVMChannel().getPeerAddress(); - if (remote == null) - return null; - // To mimic behavior of the RI the InetAddress instance which was - // used to establish the connection is returned instead of one that - // was created by the native layer (this preserves exact hostnames). - if (address != null) - return address; - - return remote.getAddress(); - } - catch (IOException ioe) - { - return null; - } - } - - /* (non-Javadoc) - * @see java.net.SocketImpl#getLocalPort() - */ - protected int getLocalPort() - { - if (channel == null) - return -1; - try - { - InetSocketAddress local = channel.getVMChannel().getLocalAddress(); - if (local == null) - return -1; - return local.getPort(); - } - catch (IOException ioe) - { - return -1; - } - } - - public InetSocketAddress getLocalAddress() - { - if (channel == null) - return null; - try - { - return channel.getVMChannel().getLocalAddress(); - } - catch (IOException ioe) - { - return null; - } - } - - /* (non-Javadoc) - * @see java.net.SocketImpl#getPort() - */ - protected int getPort() - { - if (channel == null) - return -1; - - try - { - InetSocketAddress remote = channel.getVMChannel().getPeerAddress(); - if (remote == null) - return -1; - return remote.getPort(); - } - catch (IOException ioe) - { - return -1; - } - } - /** * This class contains an implementation of <code>InputStream</code> for * sockets. It in an internal only class used by <code>PlainSocketImpl</code>. * - * @author Nic Ferrier <nfe...@ta...> + * @author Nic Ferrier (nfe...@ta...) */ final class SocketInputStream extends InputStream @@ -544,23 +465,13 @@ */ public int read() throws IOException { - if (channel == null) - throw new SocketException("not connected"); - while (true) - { - try - { - return channel.getVMChannel().read(); - } - catch (SocketTimeoutException ste) - { - throw ste; - } - catch (InterruptedIOException iioe) - { - // Ignore; NIO may throw this; net io shouldn't - } - } + byte buf[] = new byte [1]; + int bytes_read = read(buf, 0, 1); + + if (bytes_read == -1) + return -1; + + return buf[0] & 0xFF; } /** @@ -577,24 +488,12 @@ */ public int read (byte[] buf, int offset, int len) throws IOException { - if (channel == null) - throw new SocketException("not connected"); - ByteBuffer b = ByteBuffer.wrap(buf, offset, len); - while (true) - { - try - { - return channel.read(b); - } - catch (SocketTimeoutException ste) - { - throw ste; - } - catch (InterruptedIOException iioe) - { - // Ignored; NIO may throw this; net IO not. - } - } + int bytes_read = PlainSocketImpl.this.read (buf, offset, len); + + if (bytes_read == 0) + return -1; + + return bytes_read; } } @@ -604,7 +503,7 @@ * <code>getOutputStream method</code>. It expects only to be used in that * context. * - * @author Nic Ferrier <nfe...@ta...> + * @author Nic Ferrier (nfe...@ta...) */ final class SocketOutputStream extends OutputStream @@ -630,20 +529,8 @@ */ public void write(int b) throws IOException { - if (channel == null) - throw new SocketException("not connected"); - while (true) - { - try - { - channel.getVMChannel().write(b); - return; - } - catch (InterruptedIOException iioe) - { - // Ignored. - } - } + byte buf[] = { (byte) b }; + write(buf, 0, 1); } /** @@ -658,21 +545,7 @@ */ public void write (byte[] buf, int offset, int len) throws IOException { - if (channel == null) - throw new SocketException("not connected"); - ByteBuffer b = ByteBuffer.wrap(buf, offset, len); - while (b.hasRemaining()) - { - try - { - if (channel.write(b) == -1) - throw new IOException("channel has been closed"); - } - catch (InterruptedIOException iioe) - { - // Ignored. - } - } + PlainSocketImpl.this.write (buf, offset, len); } } } Modified: trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelImpl.java 2006-12-14 21:06:58 UTC (rev 2930) +++ trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelImpl.java 2006-12-15 01:51:58 UTC (rev 2931) @@ -55,10 +55,8 @@ * @author Michael Koch */ public final class DatagramChannelImpl extends DatagramChannel - implements VMChannelOwner { private NIODatagramSocket socket; - private VMChannel channel; /** * Indicates whether this channel initiated whatever operation @@ -66,16 +64,6 @@ */ private boolean inChannelOperation; - protected DatagramChannelImpl (SelectorProvider provider) - throws IOException - { - super (provider); - socket = new NIODatagramSocket (new PlainDatagramSocketImpl(), this); - channel = new VMChannel(); - channel.initSocket(false); - configureBlocking(true); - } - /** * Indicates whether our datagram socket should ignore whether * we are set to non-blocking mode. Certain operations on our @@ -97,6 +85,14 @@ inChannelOperation = b; } + protected DatagramChannelImpl (SelectorProvider provider) + throws IOException + { + super (provider); + socket = new NIODatagramSocket (new PlainDatagramSocketImpl(), this); + configureBlocking(true); + } + public DatagramSocket socket () { return socket; @@ -105,13 +101,13 @@ protected void implCloseSelectableChannel () throws IOException { - channel.close(); + socket.close (); } protected void implConfigureBlocking (boolean blocking) throws IOException { - channel.setBlocking(blocking); + socket.setSoTimeout (blocking ? 0 : NIOConstants.DEFAULT_TIMEOUT); } public DatagramChannel connect (SocketAddress remote) @@ -120,43 +116,29 @@ if (!isOpen()) throw new ClosedChannelException(); - try - { - channel.connect((InetSocketAddress) remote, 0); - } - catch (ClassCastException cce) - { - throw new IOException("unsupported socked address type"); - } + socket.connect (remote); return this; } public DatagramChannel disconnect () throws IOException { - channel.disconnect(); + socket.disconnect (); return this; } - public boolean isConnected() + public boolean isConnected () { - try - { - return channel.getPeerAddress() != null; - } - catch (IOException ioe) - { - return false; - } + return socket.isConnected (); } - + public int write (ByteBuffer src) throws IOException { if (!isConnected ()) throw new NotYetConnectedException (); - return channel.write(src); + return send (src, socket.getRemoteSocketAddress()); } public long write (ByteBuffer[] srcs, int offset, int length) @@ -170,11 +152,13 @@ || (length < 0) || (length > (srcs.length - offset))) throw new IndexOutOfBoundsException(); + + long result = 0; - /* We are connected, meaning we will write these bytes to - * the host we connected to, so we don't need to explicitly - * give the host. */ - return channel.writeGathering(srcs, offset, length); + for (int index = offset; index < offset + length; index++) + result += write (srcs [index]); + + return result; } public int read (ByteBuffer dst) @@ -183,7 +167,9 @@ if (!isConnected ()) throw new NotYetConnectedException (); - return channel.read(dst); + int remaining = dst.remaining(); + receive (dst); + return remaining - dst.remaining(); } public long read (ByteBuffer[] dsts, int offset, int length) @@ -198,8 +184,12 @@ || (length > (dsts.length - offset))) throw new IndexOutOfBoundsException(); - /* Likewise, see the comment int write above. */ - return channel.readScattering(dsts, offset, length); + long result = 0; + + for (int index = offset; index < offset + length; index++) + result += read (dsts [index]); + + return result; } public SocketAddress receive (ByteBuffer dst) @@ -210,14 +200,51 @@ try { - begin(); - return channel.receive(dst); + DatagramPacket packet; + int len = dst.remaining(); + + if (dst.hasArray()) + { + packet = new DatagramPacket (dst.array(), + dst.arrayOffset() + dst.position(), + len); + } + else + { + packet = new DatagramPacket (new byte [len], len); + } + + boolean completed = false; + + try + { + begin(); + setInChannelOperation(true); + socket.receive (packet); + completed = true; + } + finally + { + end (completed); + setInChannelOperation(false); + } + + if (!dst.hasArray()) + { + dst.put (packet.getData(), packet.getOffset(), packet.getLength()); + } + else + { + dst.position (dst.position() + packet.getLength()); + } + + return packet.getSocketAddress(); } - finally - { - end(true); - } + catch (SocketTimeoutException e) + { + return null; } + } public int send (ByteBuffer src, SocketAddress target) throws IOException @@ -225,18 +252,46 @@ if (!isOpen()) throw new ClosedChannelException(); - if (!(target instanceof InetSocketAddress)) - throw new IOException("can only send to inet socket addresses"); - - InetSocketAddress dst = (InetSocketAddress) target; - if (dst.isUnresolved()) + if (target instanceof InetSocketAddress + && ((InetSocketAddress) target).isUnresolved()) throw new IOException("Target address not resolved"); - return channel.send(src, dst); + byte[] buffer; + int offset = 0; + int len = src.remaining(); + + if (src.hasArray()) + { + buffer = src.array(); + offset = src.arrayOffset() + src.position(); + } + else + { + buffer = new byte [len]; + src.get (buffer); } - - public VMChannel getVMChannel() + + DatagramPacket packet = new DatagramPacket (buffer, offset, len, target); + + boolean completed = false; + try { - return channel; + begin(); + setInChannelOperation(true); + socket.send(packet); + completed = true; + } + finally + { + end (completed); + setInChannelOperation(false); + } + + if (src.hasArray()) + { + src.position (src.position() + len); + } + + return len; } } Modified: trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelSelectionKey.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelSelectionKey.java 2006-12-14 21:06:58 UTC (rev 2930) +++ trunk/core/src/classpath/gnu/gnu/java/nio/DatagramChannelSelectionKey.java 2006-12-15 01:51:58 UTC (rev 2931) @@ -38,7 +38,6 @@ package gnu.java.nio; -import java.io.IOException; import java.nio.channels.spi.AbstractSelectableChannel; /** @@ -53,16 +52,10 @@ super (channel, selector); } - // FIXME don't use file descriptor integers public int getNativeFD() { - try - { - return ((DatagramChannelImpl) ch).getVMChannel().getState().getNativeFD(); - } - catch (IOException ioe) - { - throw new IllegalStateException(ioe); - } + NIODatagramSocket socket = + (NIODatagramSocket) ((DatagramChannelImpl) ch).socket(); + return socket.getPlainDatagramSocketImpl().getNativeFD(); } } Deleted: trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectionKeyImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectionKeyImpl.java 2006-12-14 21:06:58 UTC (rev 2930) +++ trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectionKeyImpl.java 2006-12-15 01:51:58 UTC (rev 2931) @@ -1,122 +0,0 @@ -/* EpollSelectionKeyImpl.java -- selection key for the epoll selector. - Copyright (C) 2006 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.nio.channels.CancelledKeyException; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.spi.AbstractSelectionKey; - -/** - * @author Casey Marshall (cs...@gn...) - */ -public class EpollSelectionKeyImpl extends AbstractSelectionKey -{ - final int fd; - private final EpollSelectorImpl selector; - private final SelectableChannel channel; - int interestOps; - int selectedOps; - int key; - boolean valid; - boolean cancelled; - - EpollSelectionKeyImpl(EpollSelectorImpl selector, - SelectableChannel channel, int fd) - { - this.selector = selector; - this.channel = channel; - this.fd = fd; - } - - /* (non-Javadoc) - * @see java.nio.channels.SelectionKey#channel() - */ - public SelectableChannel channel() - { - return channel; - } - - /* (non-Javadoc) - * @see java.nio.channels.SelectionKey#interestOps() - */ - public int interestOps() - { - return interestOps; - } - - /* (non-Javadoc) - * @see java.nio.channels.SelectionKey#interestOps(int) - */ - public SelectionKey interestOps(int ops) - { - if (cancelled) - throw new CancelledKeyException(); - if ((ops & ~(channel.validOps())) != 0) - throw new IllegalArgumentException("unsupported channel ops"); - try - { - selector.epoll_modify(this, ops); - interestOps = ops; - } - catch (IOException ioe) - { - throw new IllegalArgumentException(ioe); - } - return this; - } - - /* (non-Javadoc) - * @see java.nio.channels.SelectionKey#readyOps() - */ - public int readyOps() - { - return selectedOps; - } - - /* (non-Javadoc) - * @see java.nio.channels.SelectionKey#selector() - */ - public Selector selector() - { - return selector; - } -} Deleted: trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectorImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectorImpl.java 2006-12-14 21:06:58 UTC (rev 2930) +++ trunk/core/src/classpath/gnu/gnu/java/nio/EpollSelectorImpl.java 2006-12-15 01:51:58 UTC (rev 2931) @@ -1,399 +0,0 @@ -/* EpollSelectorImpl.java -- selector implementation using epoll - Copyright (C) 2006 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import gnu.classpath.Configuration; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.AbstractSelector; -import java.nio.channels.spi.SelectorProvider; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -/** - * An implementation of {@link Selector} that uses the epoll event - * notification mechanism on GNU/Linux. - * - * @author Casey Marshall (cs...@gn...) - */ -public class EpollSelectorImpl extends AbstractSelector -{ - // XXX is this reasonable? Does it matter? - private static final int DEFAULT_EPOLL_SIZE = 128; - private static final int sizeof_struct_epoll_event; - - private static final int OP_ACCEPT = SelectionKey.OP_ACCEPT; - private static final int OP_CONNECT = SelectionKey.OP_CONNECT; - private static final int OP_READ = SelectionKey.OP_READ; - private static final int OP_WRITE = SelectionKey.OP_WRITE; - - /** our epoll file descriptor. */ - private int epoll_fd; - - private final HashMap keys; - private Set selectedKeys; - private Thread waitingThread; - private ByteBuffer events; - - private static final int INITIAL_CAPACITY; - private static final int MAX_DOUBLING_CAPACITY; - private static final int CAPACITY_INCREMENT; - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - System.loadLibrary("javanio"); - - if (epoll_supported()) - sizeof_struct_epoll_event = sizeof_struct(); - else - sizeof_struct_epoll_event = -1; - - INITIAL_CAPACITY = 64 * sizeof_struct_epoll_event; - MAX_DOUBLING_CAPACITY = 1024 * sizeof_struct_epoll_event; - CAPACITY_INCREMENT = 128 * sizeof_struct_epoll_event; - } - - public EpollSelectorImpl(SelectorProvider provider) - throws IOException - { - super(provider); - epoll_fd = epoll_create(DEFAULT_EPOLL_SIZE); - keys = new HashMap(); - selectedKeys = null; - events = ByteBuffer.allocateDirect(INITIAL_CAPACITY); - } - - /* (non-Javadoc) - * @see java.nio.channels.Selector#keys() - */ - public Set keys() - { - return new HashSet(keys.values()); - } - - /* (non-Javadoc) - * @see java.nio.channels.Selector#select() - */ - public int select() throws IOException - { - return doSelect(-1); - } - - /* (non-Javadoc) - * @see java.nio.channels.Selector#select(long) - */ - public int select(long timeout) throws IOException - { - if (timeout > Integer.MAX_VALUE) - throw new IllegalArgumentException("timeout is too large"); - if (timeout < 0) - throw new IllegalArgumentException("invalid timeout"); - return doSelect((int) timeout); - } - - private int doSelect(int timeout) throws IOException - { - synchronized (keys) - { - Set cancelledKeys = cancelledKeys(); - synchronized (cancelledKeys) - { - for (Iterator it = cancelledKeys.iterator(); it.hasNext(); ) - { - EpollSelectionKeyImpl key = (EpollSelectionKeyImpl) it.next(); - epoll_delete(epoll_fd, key.fd); - key.valid = false; - keys.remove(Integer.valueOf(key.fd)); - it.remove(); - deregister(key); - } - - // Clear out closed channels. The fds are removed from the epoll - // fd when closed, so there is no need to remove them manually. - for (Iterator it = keys.values().iterator(); it.hasNext(); ) - { - EpollSelectionKeyImpl key = (EpollSelectionKeyImpl) it.next(); - SelectableChannel ch = key.channel(); - if (ch instanceof VMChannelOwner) - { - if (!((VMChannelOwner) ch).getVMChannel().getState().isValid()) - it.remove(); - } - } - - // Don't bother if we have nothing to select. - if (keys.isEmpty()) - return 0; - - int ret; - try - { - begin(); - waitingThread = Thread.currentThread(); - ret = epoll_wait(epoll_fd, events, keys.size(), timeout); - } - finally - { - Thread.interrupted(); - waitingThread = null; - end(); - } - - HashSet s = new HashSet(ret); - for (int i = 0; i < ret; i++) - { - events.position(i * sizeof_struct_epoll_event); - ByteBuffer b = events.slice(); - int fd = selected_fd(b); - EpollSelectionKeyImpl key - = (EpollSelectionKeyImpl) keys.get(Integer.valueOf(fd)); - if (key == null) - throw new IOException("fd was selected, but no key found"); - key.selectedOps = selected_ops(b) & key.interestOps; - s.add(key); - } - - reallocateBuffer(); - - selectedKeys = s; - return ret; - } - } - } - - /* (non-Javadoc) - * @see java.nio.channels.Selector#selectedKeys() - */ - public Set selectedKeys() - { - if (selectedKeys == null) - return Collections.EMPTY_SET; - return selectedKeys; - } - - /* (non-Javadoc) - * @see java.nio.channels.Selector#selectNow() - */ - public int selectNow() throws IOException - { - return doSelect(0); - } - - /* (non-Javadoc) - * @see java.nio.channels.Selector#wakeup() - */ - public Selector wakeup() - { - try - { - waitingThread.interrupt(); - } - catch (NullPointerException npe) - { - // Ignored, thrown if we are not in a blocking op. - } - return this; - } - - /* (non-Javadoc) - * @see java.nio.channels.spi.AbstractSelector#implCloseSelector() - */ - protected void implCloseSelector() throws IOException - { - VMChannel.close(epoll_fd); - } - - /* (non-Javadoc) - * @see java.nio.channels.spi.AbstractSelector#register(java.nio.channels.spi.AbstractSelectableChannel, int, java.lang.Object) - */ - protected SelectionKey register(AbstractSelectableChannel ch, int ops, Object att) - { - if (!(ch instanceof VMChannelOwner)) - throw new IllegalArgumentException("unsupported channel type"); - - VMChannel channel = ((VMChannelOwner) ch).getVMChannel(); - try - { - int native_fd = channel.getState().getNativeFD(); - synchronized (keys) - { - if (keys.containsKey(Integer.valueOf(native_fd))) - throw new IllegalArgumentException("channel already registered"); - EpollSelectionKeyImpl result = - new EpollSelectionKeyImpl(this, ch, native_fd); - if ((ops & ~(ch.validOps())) != 0) - throw new IllegalArgumentException("invalid ops for channel"); - result.interestOps = ops; - result.selectedOps = 0; - result.valid = true; - result.attach(att); - result.key = System.identityHashCode(result); - epoll_add(epoll_fd, result.fd, ops); - keys.put(Integer.valueOf(native_fd), result); - reallocateBuffer(); - return result; - } - } - catch (IOException ioe) - { - throw new IllegalArgumentException(ioe); - } - } - - private void reallocateBuffer() - { - // Ensure we have enough space for all potential events that may be - // returned. - if (events.capacity() < keys.size() * sizeof_struct_epoll_event) - { - int cap = events.capacity(); - if (cap < MAX_DOUBLING_CAPACITY) - cap <<= 1; - else - cap += CAPACITY_INCREMENT; - events = ByteBuffer.allocateDirect(cap); - } - // Ensure that the events buffer is not too large, given the number of - // events registered. - else if (events.capacity() > keys.size() * sizeof_struct_epoll_event * 2 + 1 - && events.capacity() > INITIAL_CAPACITY) - { - int cap = events.capacity() >>> 1; - events = ByteBuffer.allocateDirect(cap); - } - } - - void epoll_modify(EpollSelectionKeyImpl key, int ops) throws IOException - { - epoll_modify(epoll_fd, key.fd, ops); - } - - /** - * Tell if epoll is supported by this system, and support was compiled in. - * - * @return True if this system supports event notification with epoll. - */ - public static native boolean epoll_supported(); - - - /** - * Returns the size of `struct epoll_event'. - * - * @return The size of `struct epoll_event'. - */ - private static native int sizeof_struct(); - - - /** - * Open a new epoll file descriptor. - * - * @param size The size... [truncated message content] |
From: <qa...@us...> - 2006-12-20 08:51:19
|
Revision: 2945 http://jnode.svn.sourceforge.net/jnode/?rev=2945&view=rev Author: qades Date: 2006-12-20 00:51:17 -0800 (Wed, 20 Dec 2006) Log Message: ----------- consolidated arguments added optinal API constraint to DeviceArgument Modified Paths: -------------- trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java trunk/fs/src/fs/org/jnode/fs/command/FormatCommand.java trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java trunk/fs/src/fs/org/jnode/fs/jifs/command/createJIFS.java trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java trunk/gui/src/awt/org/jnode/awt/JNodeCursors.java trunk/gui/src/driver/org/jnode/driver/video/HardwareCursorImage.java trunk/gui/src/test/org/jnode/test/gui/FBTest.java trunk/net/descriptors/org.jnode.net.command.xml trunk/net/src/net/org/jnode/net/command/BootpCommand.java trunk/net/src/net/org/jnode/net/command/DhcpCommand.java trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java trunk/net/src/net/org/jnode/net/command/NetCommand.java trunk/net/src/net/org/jnode/net/command/PingCommand.java trunk/net/src/net/org/jnode/net/command/ResolverCommand.java trunk/net/src/net/org/jnode/net/command/RouteCommand.java trunk/net/src/net/org/jnode/net/command/TftpCommand.java trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java trunk/net/src/net/org/jnode/net/ipv4/dhcp/DHCPClient.java trunk/shell/.classpath trunk/shell/descriptors/org.jnode.shell.xml trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java trunk/shell/src/shell/org/jnode/shell/help/Argument.java Added Paths: ----------- trunk/net/src/net/org/jnode/net/help/ trunk/net/src/net/org/jnode/net/help/argument/ trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/ trunk/shell/src/shell/org/jnode/shell/help/argument/AliasArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/ClassNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/DeviceArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/HostNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/InetAddressArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/OptionArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/PluginArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/PropertyNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/StringArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/ThreadNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/URLArgument.java Removed Paths: ------------- trunk/net/src/net/org/jnode/net/command/HostArgument.java trunk/net/src/net/org/jnode/net/command/HostNameArgument.java trunk/net/src/net/org/jnode/net/command/NetworkArgument.java trunk/shell/src/shell/org/jnode/shell/help/AliasArgument.java trunk/shell/src/shell/org/jnode/shell/help/ClassNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/CountryArgument.java trunk/shell/src/shell/org/jnode/shell/help/DeviceArgument.java trunk/shell/src/shell/org/jnode/shell/help/FileArgument.java trunk/shell/src/shell/org/jnode/shell/help/InetAddressArgument.java trunk/shell/src/shell/org/jnode/shell/help/IntegerArgument.java trunk/shell/src/shell/org/jnode/shell/help/LanguageArgument.java trunk/shell/src/shell/org/jnode/shell/help/LongArgument.java trunk/shell/src/shell/org/jnode/shell/help/OptionArgument.java trunk/shell/src/shell/org/jnode/shell/help/PluginArgument.java trunk/shell/src/shell/org/jnode/shell/help/PropertyNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/StringArgument.java trunk/shell/src/shell/org/jnode/shell/help/StringListArgument.java trunk/shell/src/shell/org/jnode/shell/help/ThreadNameArgument.java trunk/shell/src/shell/org/jnode/shell/help/URLArgument.java Modified: trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -21,10 +21,10 @@ package org.jnode.apps.edit; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import java.io.File; Modified: trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -1,9 +1,9 @@ package org.jnode.apps.editor; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import java.io.File; Modified: trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java =================================================================== --- trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -25,13 +25,13 @@ import org.jnode.driver.block.ramdisk.RamDiskDevice; import org.jnode.driver.block.ramdisk.RamDiskDriver; import org.jnode.naming.InitialNaming; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.IntegerArgument; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.DeviceArgument; +import org.jnode.shell.help.argument.IntegerArgument; +import org.jnode.shell.help.argument.OptionArgument; /** * @author Ewout Prangsma (ep...@us...) Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -33,7 +33,7 @@ import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.FileArgument; +import org.jnode.shell.help.argument.FileArgument; /** * @author epr Modified: trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -27,10 +27,10 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; /** * @author Ewout Prangsma (ep...@us...) Modified: trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -32,11 +32,11 @@ import java.net.MalformedURLException; import java.net.URL; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.FileArgument; +import org.jnode.shell.help.argument.OptionArgument; /** * Modified: trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -29,10 +29,10 @@ import org.jnode.naming.InitialNaming; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import javax.naming.NameNotFoundException; Modified: trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -23,10 +23,10 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import org.jnode.util.NumberUtils; import java.io.File; Modified: trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -28,10 +28,10 @@ import org.jnode.driver.RemovableDeviceAPI; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.DeviceArgument; /** Modified: trunk/fs/src/fs/org/jnode/fs/command/FormatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/FormatCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/FormatCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -40,12 +40,12 @@ import org.jnode.naming.InitialNaming; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.DeviceArgument; +import org.jnode.shell.help.argument.OptionArgument; /** * @author gbin Modified: trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -7,10 +7,10 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Argument; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import org.jnode.util.NumberUtils; import java.io.File; Modified: trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -27,10 +27,10 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; /** * @author Guillaume BINET (gb...@us...) Modified: trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -30,11 +30,11 @@ import org.jnode.naming.InitialNaming; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.DeviceArgument; +import org.jnode.shell.help.argument.FileArgument; /** * @author Ewout Prangsma (ep...@us...) Modified: trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -27,10 +27,10 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; /** * Touch a file Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -33,10 +33,10 @@ import org.jnode.shell.CommandLine; import org.jnode.shell.Command; import org.jnode.shell.help.Argument; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import java.io.InputStream; import java.io.PrintStream; Modified: trunk/fs/src/fs/org/jnode/fs/jifs/command/createJIFS.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/jifs/command/createJIFS.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/jifs/command/createJIFS.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -33,10 +33,10 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.OptionArgument; /** * Just mounts initial JIFS on /Jifs Modified: trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -21,11 +21,11 @@ package org.jnode.fs.smbfs.command; -import org.jnode.shell.help.FileArgument; import org.jnode.shell.help.Argument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; import org.jnode.shell.CommandLine; import org.jnode.fs.service.FileSystemService; import org.jnode.fs.FileSystemType; Modified: trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -45,14 +45,14 @@ import org.jnode.partitions.ibm.IBMPartitionTableEntry; import org.jnode.partitions.ibm.IBMPartitionTableType; import org.jnode.partitions.ibm.IBMPartitionTypes; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.StringArgument; import org.jnode.shell.help.Syntax; import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.shell.help.argument.DeviceArgument; +import org.jnode.shell.help.argument.OptionArgument; +import org.jnode.shell.help.argument.StringArgument; /** * @author gbin * @author Trickkiste Modified: trunk/gui/src/awt/org/jnode/awt/JNodeCursors.java =================================================================== --- trunk/gui/src/awt/org/jnode/awt/JNodeCursors.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/gui/src/awt/org/jnode/awt/JNodeCursors.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -29,140 +29,186 @@ */ public class JNodeCursors { - /** White */ - private static final int W = 0xFFFFFFFF; - /** Black */ - private static final int B = 0xFF000000; - /** Transparent */ - private static final int T = 0x00000000; - private static final int[] ARROW_IMAGE_16x16 = { - B, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, - T, B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, - T, B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, - T, T, B, W, B, T, T, T, T, T, T, T, T, T, T, T, - T, T, B, B, T, T, T, T, T, T, T, T, T, T, T, T, + private static final String ARROW_IMAGE_16x16 = + "BBTTTTTTTTTTTTTT" + + "BWBTTTTTTTTTTTTT" + + "BWWBTTTTTTTTTTTT" + + "BWWWBTTTTTTTTTTT" + + "BWWWWBTTTTTTTTTT" + + "BWWWWWBTTTTTTTTT" + + "BWWWWWWBTTTTTTTT" + + "BWWWWWWWBTTTTTTT" + + "BWWWWWWWWBTTTTTT" + + "BWWWWWWWWWBTTTTT" + + "BWWBWWWBBBBBTTTT" + + "BWBTBWWBTTTTTTTT" + + "BBTTTBWWBTTTTTTT" + + "TTTTTTBWWBTTTTTT" + + "TTTTTTTBWWBTTTTT" + + "TTTTTTTTBBBTTTTT"; + + private static final String ARROW_IMAGE_32x32 = + "BTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BBTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWBTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWBTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWBTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWBTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWBTTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWBTTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWBTTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWBTTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWBTTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWBTTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWBTTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWBTTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWBTTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWBTTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWBTTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWWBTTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWWWBTTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWWWWBTTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWWWWWBTTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWWWWWWBTTTTTTTTTT" + + "BWWWWWWWWWWWWWWWWWWWWWBTTTTTTTTT" + + "BWWWWWWBWWWWWWBBBBBBBBBBTTTTTTTT" + + "BWWWWWBTBWWWWWWBTTTTTTTTTTTTTTTT" + + "BWWWWBTTTBWWWWWWBTTTTTTTTTTTTTTT" + + "BWWWBTTTTTBWWWWWWBTTTTTTTTTTTTTT" + + "BWWBTTTTTTTBWWWWWWBTTTTTTTTTTTTT" + + "BWBTTTTTTTTTBWWWWWWBTTTTTTTTTTTT" + + "BBTTTTTTTTTTTBWWWWWWBTTTTTTTTTTT" + + "BTTTTTTTTTTTTTBWWWWWWBTTTTTTTTTT" + + "TTTTTTTTTTTTTTTBBBBBBBBTTTTTTTTT"; +/* + private static final String ARROW_IMAGE_16x16 = { + BBTTTTTTTTTTTTTT, + BWBTTTTTTTTTTTTT, + BWBTTTTTTTTTTTTT, + BWWBTTTTTTTTTTTT, + BWWBTTTTTTTTTTTT, + BWWWBTTTTTTTTTTT, + BWWWBTTTTTTTTTTT, + BWWWWBTTTTTTTTTT, + BWWWWBTTTTTTTTTT, + BWWWBTTTTTTTTTTT, + BWWBTTTTTTTTTTTT, + BWWBTTTTTTTTTTTT, + TBWWBTTTTTTTTTTT, + TBWWBTTTTTTTTTTT, + TTBWBTTTTTTTTTTT, + TTBBTTTTTTTTTTTT, }; private static final int[] ARROW_IMAGE_32x32 = { - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, W, W, W, W, B, B, B, B, B, B, B, B, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, W, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, W, B, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, W, B, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, W, B, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, B, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - B, T, T, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, B, W, W, W, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, B, B, B, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, + TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT, + BTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT, + BBTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT, + BWBTTTTTTTTTTTTTTTTTTTTTTTTTTTTT, + BWWBTTTTTTTTTTTTTTTTTTTTTTTTTTTT, + BWWWBTTTTTTTTTTTTTTTTTTTTTTTTTTT, + BWWWWBTTTTTTTTTTTTTTTTTTTTTTTTTT, + BWWWWWBTTTTTTTTTTTTTTTTTTTTTTTTT, + BWWWWWWBTTTTTTTTTTTTTTTTTTTTTTTT, + BWWWWWWWBTTTTTTTTTTTTTTTTTTTTTTT, + BWWWWWWWWBTTTTTTTTTTTTTTTTTTTTTT, + BWWWWWWWWWBTTTTTTTTTTTTTTTTTTTTT, + BWWWWWWWWWWBTTTTTTTTTTTTTTTTTTTT, + BWWWWWWWWWWWBTTTTTTTTTTTTTTTTTTT, + BWWWWWWWWWWWWBTTTTTTTTTTTTTTTTTT, + BWWWWWWWWWWWWWBTTTTTTTTTTTTTTTTT, + BWWWWWWWWWWWWWWBTTTTTTTTTTTTTTTT, + BWWWWWWWWWWWWWWWBTTTTTTTTTTTTTTT, + BWWWWWWWWBBBBBBBBBTTTTTTTTTTTTTT, + BWWWWBWWWBTTTTTTTTTTTTTTTTTTTTTT, + BWWWBTBWWWBTTTTTTTTTTTTTTTTTTTTT, + BWWBTTBWWWBTTTTTTTTTTTTTTTTTTTTT, + BWBTTTTBWWWBTTTTTTTTTTTTTTTTTTTT, + BBTTTTTBWWWBTTTTTTTTTTTTTTTTTTTT, + BTTTTTTTBWWWBTTTTTTTTTTTTTTTTTTT, + TTTTTTTTBWWWBTTTTTTTTTTTTTTTTTTT, + TTTTTTTTTBWWWBTTTTTTTTTTTTTTTTTT, + TTTTTTTTTBWWWBTTTTTTTTTTTTTTTTTT, + TTTTTTTTTTBWWWBTTTTTTTTTTTTTTTTT, + TTTTTTTTTTBWWWBTTTTTTTTTTTTTTTTT, + TTTTTTTTTTTBBBTTTTTTTTTTTTTTTTTT, + TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT, }; +*/ + private static final String RESIZE_VERTICAL_IMAGE_16x16 = + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTBTTTTTTTTBTTT" + + "TTBTTTTTTTTTTBTT" + + "TBTTTTTTTTTTTTBT" + + "BBBBBBBBBBBBBBBB" + + "TBTTTTTTTTTTTTBT" + + "TTBTTTTTTTTTTBTT" + + "TTTBTTTTTTTTBTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + ; -// private static final int[] ARROW_IMAGE_32x32 = { -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, -// }; + + // --- Templates --- + + private static final String EMPTY_IMAGE_16x16 = + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTT"; - // to be used for feature cursors - /* - private static final int[] EMPTY_IMAGE_16x16 = { - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - };*/ - private static final int[] RESIZE_VERTICAL_IMAGE_16x16 = { - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, B, T, T, T, T, T, T, T, T, B, T, T, T, - T, T, B, T, T, T, T, T, T, T, T, T, T, B, T, T, - T, B, T, T, T, T, T, T, T, T, T, T, T, T, B, T, - B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, - T, B, T, T, T, T, T, T, T, T, T, T, T, T, B, T, - T, T, B, T, T, T, T, T, T, T, T, T, T, B, T, T, - T, T, T, B, T, T, T, T, T, T, T, T, B, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, - }; + private static final String EMPTY_IMAGE_32x32 = + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"; private static HardwareCursorImage ARROW_16x16 = new HardwareCursorImage(16, 16, ARROW_IMAGE_16x16, 0, 0); private static HardwareCursorImage ARROW_32x32 = new HardwareCursorImage(32, 32, ARROW_IMAGE_32x32, 0, 0); Modified: trunk/gui/src/driver/org/jnode/driver/video/HardwareCursorImage.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/video/HardwareCursorImage.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/gui/src/driver/org/jnode/driver/video/HardwareCursorImage.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -25,7 +25,14 @@ * @author Ewout Prangsma (ep...@us...) */ public class HardwareCursorImage { - + + /** White */ + private static final int W = 0xFFFFFFFF; + /** Black */ + private static final int B = 0xFF000000; + /** Transparent */ + private static final int T = 0x00000000; + private final int width; private final int height; private final int[] image; @@ -52,6 +59,46 @@ } /** + * Initialize this instance by parsing the pixels from a given String. + * @param width + * @param height + * @param image + * @param hotSpotX + * @param hotSpotY + */ + public HardwareCursorImage(int width, int height, String image, int hotSpotX, int hotSpotY) { + if (image.length() != width * height) { + throw new IllegalArgumentException("Invalid image length"); + } + this.width = width; + this.height = height; + this.image = parse(image); + this.hotSpotX = hotSpotX; + this.hotSpotY = hotSpotY; + } + + private int[] parse(String image) { + int[] res = new int[image.length()]; + int i = 0; + for( char c : image.toCharArray() ) { + switch( c ) { + case 'T': + res[i++] = T; + break; + case 'B': + res[i++] = B; + break; + case 'W': + res[i++] = W; + break; + default: + throw new IllegalArgumentException("Unknown pixel color indicator '" + c + "'"); + } + } + return res; + } + + /** * Gets the argb image. * @return int[] */ Modified: trunk/gui/src/test/org/jnode/test/gui/FBTest.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/FBTest.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/gui/src/test/org/jnode/test/gui/FBTest.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -39,9 +39,9 @@ import org.jnode.driver.video.Surface; import org.jnode.naming.InitialNaming; import org.jnode.shell.help.Argument; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; +import org.jnode.shell.help.argument.DeviceArgument; /** * @author epr Modified: trunk/net/descriptors/org.jnode.net.command.xml =================================================================== --- trunk/net/descriptors/org.jnode.net.command.xml 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/descriptors/org.jnode.net.command.xml 2006-12-20 08:51:17 UTC (rev 2945) @@ -30,6 +30,7 @@ <alias name="ping" class="org.jnode.net.command.PingCommand"/> <alias name="route" class="org.jnode.net.command.RouteCommand"/> <alias name="resolver" class="org.jnode.net.command.ResolverCommand"/> + <alias name="resolve" class="org.jnode.net.command.ResolveCommand"/> <alias name="tftp" class="org.jnode.net.command.TftpCommand"/> <alias name="wlanctl" class="org.jnode.net.command.WLanCtlCommand"/> <alias name="net" class="org.jnode.net.command.NetCommand"/> Modified: trunk/net/src/net/org/jnode/net/command/BootpCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/BootpCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/BootpCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -25,21 +25,22 @@ import java.io.PrintStream; import org.jnode.driver.Device; +import org.jnode.driver.net.NetDeviceAPI; import org.jnode.naming.InitialNaming; import org.jnode.net.ipv4.config.IPv4ConfigurationService; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.DeviceArgument; /** * @author epr */ public class BootpCommand implements Command { - static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to boot from"); + static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to boot from", NetDeviceAPI.class); public static Help.Info HELP_INFO = new Help.Info( "bootp", Modified: trunk/net/src/net/org/jnode/net/command/DhcpCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/DhcpCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/DhcpCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -25,21 +25,22 @@ import java.io.PrintStream; import org.jnode.driver.Device; +import org.jnode.driver.net.NetDeviceAPI; import org.jnode.naming.InitialNaming; import org.jnode.net.ipv4.config.IPv4ConfigurationService; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.DeviceArgument; /** * @author markhale */ public class DhcpCommand implements Command { - static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to boot from"); + static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to boot from", NetDeviceAPI.class); public static Help.Info HELP_INFO = new Help.Info( "dhcp", Deleted: trunk/net/src/net/org/jnode/net/command/HostArgument.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/HostArgument.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/HostArgument.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -1,49 +0,0 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.net.command; - -import org.jnode.net.ipv4.IPv4Address; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.ParsedArguments; - -/** - * @author qades - */ -public class HostArgument extends Argument { - - public HostArgument(String name, String description, boolean multi) { - super(name, description, multi); - } - - public HostArgument(String name, String description) { - super(name, description); - } - - // here the specific command line completion would be implemented - - public IPv4Address getAddress(ParsedArguments args) { - String value = getValue(args); - if( value == null ) - return null; - return new IPv4Address(value); - } -} Deleted: trunk/net/src/net/org/jnode/net/command/HostNameArgument.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/HostNameArgument.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/HostNameArgument.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -1,57 +0,0 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.net.command; - -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.ParsedArguments; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - * @author Martin Hartvig - */ - -public class HostNameArgument extends Argument -{ - - public HostNameArgument(String _name, String _description, boolean _multi) - { - super(_name, _description, _multi); - } - - public HostNameArgument(String _name, String _description) - { - super(_name, _description); - } - - - public InetAddress getAddress(ParsedArguments _parsedArguments) throws UnknownHostException - { - String value = getValue(_parsedArguments); - - if (value == null) - return null; - - return InetAddress.getByName(value); - } -} Modified: trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -29,22 +29,23 @@ import org.jnode.driver.net.NetDeviceAPI; import org.jnode.naming.InitialNaming; import org.jnode.net.ethernet.EthernetConstants; +import org.jnode.net.help.argument.HostArgument; import org.jnode.net.ipv4.IPv4Address; import org.jnode.net.ipv4.config.IPv4ConfigurationService; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.DeviceArgument; /** * @author epr */ public class IfconfigCommand implements Command { - static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device"); + static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device", NetDeviceAPI.class); static final HostArgument ARG_IP_ADDRESS = new HostArgument("ip-address", "the IP address to bind the device to"); static final HostArgument ARG_SUBNET_MASK = new HostArgument("subnet-mask", "if given, specifies the range of reachable subnets"); Modified: trunk/net/src/net/org/jnode/net/command/NetCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/NetCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/NetCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -13,11 +13,11 @@ import org.jnode.shell.CommandLine; import org.jnode.shell.help.Help; -import org.jnode.shell.help.InetAddressArgument; -import org.jnode.shell.help.IntegerArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.InetAddressArgument; +import org.jnode.shell.help.argument.IntegerArgument; public class NetCommand { Deleted: trunk/net/src/net/org/jnode/net/command/NetworkArgument.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/NetworkArgument.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/NetworkArgument.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -1,49 +0,0 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.net.command; - -import org.jnode.net.ipv4.IPv4Address; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.ParsedArguments; - -/** - * @author qades - */ -public class NetworkArgument extends Argument { - - public NetworkArgument(String name, String description, boolean multi) { - super(name, description, multi); - } - - public NetworkArgument(String name, String description) { - super(name, description); - } - - // here the specific command line completion would be implemented - - public IPv4Address getAddress(ParsedArguments args) { - String value = getValue(args); - if( "default".equals(value) ) - value = "0.0.0.0"; - return new IPv4Address(value); - } -} Modified: trunk/net/src/net/org/jnode/net/command/PingCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/PingCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/PingCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -42,6 +42,7 @@ import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.HostNameArgument; /** * @author JPG Modified: trunk/net/src/net/org/jnode/net/command/ResolverCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -23,12 +23,18 @@ import java.io.InputStream; import java.io.PrintStream; +import java.util.Collection; +import org.jnode.net.help.argument.HostArgument; import org.jnode.net.ipv4.IPv4Address; import org.jnode.net.ipv4.util.ResolverImpl; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.*; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.Parameter; +import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.OptionArgument; public class ResolverCommand implements Command @@ -70,8 +76,15 @@ if (cmdLine.size() == 0) { - System.out.println("DNS servers"); - ResolverImpl.printDnsServers(); + Collection<String> resolvers = ResolverImpl.getDnsServers(); + if( resolvers == null ) + System.out.println("No DNS servers found."); + else { + System.out.println("DNS servers"); + for (String dnsServer : resolvers) { + System.out.println(dnsServer); + } + } } else { Modified: trunk/net/src/net/org/jnode/net/command/RouteCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -27,18 +27,20 @@ import org.jnode.driver.Device; import org.jnode.naming.InitialNaming; import org.jnode.net.ethernet.EthernetConstants; +import org.jnode.net.help.argument.HostArgument; +import org.jnode.net.help.argument.NetworkArgument; import org.jnode.net.ipv4.IPv4Address; import org.jnode.net.ipv4.config.IPv4ConfigurationService; import org.jnode.net.ipv4.layer.IPv4NetworkLayer; import org.jnode.net.util.NetUtils; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.DeviceArgument; +import org.jnode.shell.help.argument.OptionArgument; /** * @author epr Modified: trunk/net/src/net/org/jnode/net/command/TftpCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -24,14 +24,15 @@ import java.io.InputStream; import java.io.PrintStream; +import org.jnode.net.help.argument.HostArgument; import org.jnode.net.ipv4.tftp.TFTPClient; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Argument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.Syntax; +import org.jnode.shell.help.argument.OptionArgument; /** * @author markhale Modified: trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java 2006-12-20 03:33:57 UTC (rev 2944) +++ trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -32,12 +32,12 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Argument; -import org.jnode.shell.help.DeviceArgument; import org.jnode.shell.help.Help; -import org.jnode.shell.help.OptionArgument; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.shell.help.argument.DeviceArgument; +import org.jnode.shell.help.argument.OptionArgument; /** * @author Ewout Prangsma (ep...@us...) @@ -52,7 +52,7 @@ FUNC_SETESSID, "Set the ESSID"), }); private static final DeviceArgument ARG_DEVICE = new DeviceArgument( - "device", "the device to control"); + "device", "the device to control", WirelessNetDeviceAPI.class); private static final Argument ARG_VALUE = new Argument("value", "Value of the function"); Added: trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java =================================================================== --- trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java (rev 0) +++ trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -0,0 +1,49 @@ +/* + * $Id: HostArgument.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.net.help.argument; + +import org.jnode.net.ipv4.IPv4Address; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.ParsedArguments; + +/** + * @author qades + */ +public class HostArgument extends Argument { + + public HostArgument(String name, String description, boolean multi) { + super(name, description, multi); + } + + public HostArgument(String name, String description) { + super(name, description); + } + + // here the specific command line completion would be implemented + + public IPv4Address getAddress(ParsedArguments args) { + String value = getValue(args); + if( value == null ) + return null; + return new IPv4Address(value); + } +} Added: trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java =================================================================== --- trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java (rev 0) +++ trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java 2006-12-20 08:51:17 UTC (rev 2945) @@ -0,0 +1,49 @@ +/* + * $Id: NetworkArgument.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.net.help.argument; + +import org.jnode.net.ipv4.IPv4Address; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.ParsedArguments; + +/** + * @author qades + */ +public class NetworkArgument extends Argument { + + public NetworkArgument(String name, String description, boolean multi) { + super(name, description, multi); + } + + public NetworkArgument(String name, String description) { + super(name, description); + } + + // here the specific command line completion would be implemented + + public IPv4Address getAddress(ParsedArguments args) { + String value = getValue(args); + if( "default".equals(value) ) + value = "0.0.0.0"; + return new IPv4Address(value); + } +} Modified: trunk/net/src/net/org/jnode/net/ipv4/dhcp/DHCPClient.java ==============================... [truncated message content] |
From: <fd...@us...> - 2007-05-17 19:15:06
|
Revision: 3217 http://jnode.svn.sourceforge.net/jnode/?rev=3217&view=rev Author: fduminy Date: 2007-05-17 12:15:01 -0700 (Thu, 17 May 2007) Log Message: ----------- fixed some classpath issues for eclipse Modified Paths: -------------- trunk/core/.classpath trunk/net/.classpath Modified: trunk/core/.classpath =================================================================== --- trunk/core/.classpath 2007-05-17 19:04:55 UTC (rev 3216) +++ trunk/core/.classpath 2007-05-17 19:15:01 UTC (rev 3217) @@ -1,6 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> + <classpathentry kind="src" path="src/openjdk/vm"/> + <classpathentry kind="src" path="src/openjdk/java"/> + <classpathentry kind="src" path="src/openjdk/javax"/> + <classpathentry kind="src" path="src/openjdk/sun"/> <classpathentry kind="src" path="src/classpath/gnu"/> + <classpathentry kind="src" path="src/classpath/sun"/> + <classpathentry kind="src" path="src/classpath/tools"/> <classpathentry kind="src" path="src/classpath/java"/> <classpathentry kind="src" path="src/classpath/javax"/> <classpathentry kind="src" path="src/classpath/org"/> @@ -16,7 +22,7 @@ <classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/> <classpathentry kind="lib" path="lib/junit.jar"/> <classpathentry kind="lib" path="lib/mx4j.jar"/> - <classpathentry sourcepath="D:/epr/cvswork/MMTk/src" kind="lib" path="lib/mmtk/mmtk.jar"/> + <classpathentry kind="lib" path="lib/mmtk/mmtk.jar" sourcepath="D:/epr/cvswork/MMTk/src"/> <classpathentry kind="src" path="src/nanoxml"/> <classpathentry kind="lib" path="lib/mauve.jar"/> <classpathentry kind="output" path="build/classes"/> Modified: trunk/net/.classpath =================================================================== --- trunk/net/.classpath 2007-05-17 19:04:55 UTC (rev 3216) +++ trunk/net/.classpath 2007-05-17 19:15:01 UTC (rev 3217) @@ -8,7 +8,7 @@ <classpathentry kind="src" path="/JNode-Shell"/> <classpathentry kind="lib" path="/JNode-Core/lib/gnu-crypto.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/javax-crypto.jar"/> - <classpathentry kind="lib" path="lib/dnsjava-2.0.1a.jar"/> + <classpathentry kind="lib" path="lib/dnsjava-2.0.3.jar"/> <classpathentry kind="lib" path="lib/jsch-0.1.24.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/commons-net-1.1.0.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/junit.jar"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-08-02 18:15:29
|
Revision: 3374 http://jnode.svn.sourceforge.net/jnode/?rev=3374&view=rev Author: lsantha Date: 2007-08-02 11:15:27 -0700 (Thu, 02 Aug 2007) Log Message: ----------- Keyboard input patch by Stephen Crawley. This patch enables line editting in programs like js and bsh. Modified Paths: -------------- trunk/core/src/core/org/jnode/log4j/config/Log4jConfigurePlugin.java trunk/core/src/core/org/jnode/util/SystemInputStream.java trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java trunk/core/src/driver/org/jnode/driver/console/TextConsole.java trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java trunk/core/src/driver/org/jnode/driver/input/Key.java trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java trunk/distr/src/emu/org/jnode/emu/EditEmu.java trunk/distr/src/emu/org/jnode/emu/ShellEmu.java trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java trunk/gui/src/test/org/jnode/test/gui/FBConsole.java trunk/shell/descriptors/org.jnode.shell.xml trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/Shell.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java trunk/textui/src/textui/charva/awt/Toolkit.java Added Paths: ----------- trunk/core/src/driver/org/jnode/driver/console/CommandHistory.java trunk/core/src/driver/org/jnode/driver/console/CompletionInfo.java trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java Removed Paths: ------------- trunk/core/src/driver/org/jnode/driver/input/KeyboardInputStream.java trunk/shell/src/shell/org/jnode/shell/CommandHistory.java trunk/shell/src/shell/org/jnode/shell/CompletionInfo.java trunk/shell/src/shell/org/jnode/shell/Line.java Modified: trunk/core/src/core/org/jnode/log4j/config/Log4jConfigurePlugin.java =================================================================== --- trunk/core/src/core/org/jnode/log4j/config/Log4jConfigurePlugin.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/core/org/jnode/log4j/config/Log4jConfigurePlugin.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -62,7 +62,13 @@ try { // Create the appenders final ConsoleManager conMgr = InitialNaming.lookup(ConsoleManager.NAME); - final TextConsole console = (TextConsole)conMgr.createConsole("Log4j", ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN); + final TextConsole console = + (TextConsole)conMgr.createConsole( + "Log4j", + (ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.SCROLLABLE | + ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR | + ConsoleManager.CreateOptions.NO_LINE_EDITTING)); conMgr.registerConsole(console); console.setAcceleratorKeyCode(KeyEvent.VK_F7); Modified: trunk/core/src/core/org/jnode/util/SystemInputStream.java =================================================================== --- trunk/core/src/core/org/jnode/util/SystemInputStream.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/core/org/jnode/util/SystemInputStream.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -61,7 +61,9 @@ final public void setIn(InputStream in) { - localeIn.set(in); + if (in != this) { + localeIn.set(in); + } } /** @@ -101,7 +103,7 @@ */ public void initialize(InputStream systemIn) { - if(this.systemIn == EMPTY) // register only the first keyboard + if (this.systemIn == EMPTY && systemIn != this) // register only the first keyboard { this.systemIn = systemIn; } Added: trunk/core/src/driver/org/jnode/driver/console/CommandHistory.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/CommandHistory.java (rev 0) +++ trunk/core/src/driver/org/jnode/driver/console/CommandHistory.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -0,0 +1,94 @@ +/* + * $Id: CommandHistory.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.driver.console; + +import java.util.ArrayList; +import java.util.List; + +/** Used to keep an archive of commands. + * @author Matt Paine + */ +public class CommandHistory { + + /** Holds the commands. **/ + private final List<String> history = new ArrayList<String>(); + + /** Constructs a CommandHistory object. **/ + public CommandHistory() { + } + + /** Adds a command to the archive. + * @param line The CommandLine to add to the archive. + **/ + public void addCommand(String line) { + if( history.contains(line) ) + history.remove(line); + history.add(line); + } + + /** Returns the number of commands held in the archive. + * @return the number of commands held in the archive. + **/ + public int size() { + return history.size(); + } + + /** Gets a command at a given index. + * TODO: make exception more specific + * @param index The index (starting at zero) of the command to return. + * @return The command at the index given or null if no command found + * (out of bounds index). + **/ + public String getCommand(int index) { + String retCommand = null; + try { + retCommand = (String)history.get(index); + } catch (Exception ex) { + } + return retCommand; + } + + /** Searches for the most recent command types starting with the specified + * string. + * @param start The string to search for. + * @return The most recent command matching the search string. + **/ + public String getCommand(String start) { + return getCommand(findCommand(start)); + } + + /** Searches the collection for the most recent command starting with the + * specified string. + * @param start the string to search for. + * @return the index number of the specified string (or -1 if not found). + **/ + private int findCommand(String start) { + for (int x = 0; x < history.size(); x++) { + String cmdLine = (String)history.get(x); + if (cmdLine != null) + if (cmdLine.startsWith(start)) + return x; + } + return -1; + } + +} Added: trunk/core/src/driver/org/jnode/driver/console/CompletionInfo.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/CompletionInfo.java (rev 0) +++ trunk/core/src/driver/org/jnode/driver/console/CompletionInfo.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -0,0 +1,94 @@ +/* + * $Id: CompletionInfo.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.driver.console; + +/** + * @author Ewout Prangsma (ep...@us...) + */ +public class CompletionInfo { + private String[] items = null; + + private String completed = null; + + private boolean newPrompt = false; + + /** + * @return Returns the completed. + */ + public String getCompleted() { + return completed; + } + + /** + * @param completed + * The completed to set. + */ + public void setCompleted(String completed) { + this.completed = completed; + } + + /** + * get the possible completions + * + * @return Returns the items. + */ + public String[] getItems() { + return items; + } + + /** + * Specify the possible completions + * + * @param items + * The items to set. + */ + public void setItems(String[] items) { + this.items = items; + this.completed = null; + this.newPrompt = true; + } + + /** + * Do we have more than one possible completion ? + * + * @return + */ + public boolean hasItems() { + return items != null; + } + + /** + * Specify if we need a new prompt or not + * + * @param newPrompt + */ + public void setNewPrompt(boolean newPrompt) { + this.newPrompt = newPrompt; + } + + /** + * @return true if we need to display a new prompt + */ + public boolean needNewPrompt() { + return newPrompt; + } +} Modified: trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -22,6 +22,7 @@ package org.jnode.driver.console; import java.util.Set; +import java.io.InputStream; import java.io.PrintStream; import org.jnode.driver.input.KeyboardListener; @@ -112,11 +113,15 @@ /** Create a scrollable console. */ public static final int SCROLLABLE = 0x02; - /** Do not claim System.out, err, in when focused. */ - public static final int NO_SYSTEM_OUT_ERR_IN = 0x04; + /** Do not claim System.out, err when focused. */ + public static final int NO_SYSTEM_OUT_ERR = 0x04; /** Stack console on the current screen */ public static final int STACKED = 0x08; + + /** Do not create a line-editting input stream for the console. + * The console's input will be whatever System.in currently is. */ + public static final int NO_LINE_EDITTING = 0x10; } /** Added: trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java (rev 0) +++ trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -0,0 +1,8 @@ +package org.jnode.driver.console; + + +public interface InputCompleter { + CompletionInfo complete(String partial); + + CommandHistory getCommandHistory(); +} Modified: trunk/core/src/driver/org/jnode/driver/console/TextConsole.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/TextConsole.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/console/TextConsole.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -21,6 +21,7 @@ package org.jnode.driver.console; +import java.io.InputStream; import java.io.PrintStream; /** @@ -155,6 +156,12 @@ */ public void ensureVisible(int row); + /** + * Gets the input stream of this console. + * @return + */ + public InputStream getIn(); + /** * Gets the error stream of this console. * @return @@ -177,4 +184,17 @@ * @param visible */ public void setCursorVisible(boolean visible); + + + /** + * Get the console's input completer + * @return The completer or <code>null</code>. + */ + public InputCompleter getCompleter(); + + /** + * Ges the console's input completer + * @param The new completer or <code>null</code>. + */ + public void setCompleter(InputCompleter completer); } Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -98,6 +98,10 @@ } } + protected KeyboardAPI getKeyboardApi() { + return kbApi; + } + /** * Add a pointer device * Added: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java (rev 0) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -0,0 +1,444 @@ +package org.jnode.driver.console.textscreen; + +import java.awt.event.KeyEvent; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; + +import javax.naming.NameNotFoundException; + +import org.jnode.driver.ApiNotFoundException; +import org.jnode.driver.Device; +import org.jnode.driver.DeviceListener; +import org.jnode.driver.DeviceManager; +import org.jnode.driver.console.CompletionInfo; +import org.jnode.driver.console.InputCompleter; +import org.jnode.driver.console.TextConsole; +import org.jnode.driver.input.KeyboardAPI; +import org.jnode.driver.input.KeyboardEvent; +import org.jnode.driver.input.KeyboardListener; +import org.jnode.naming.InitialNaming; +import org.jnode.system.BootLog; +import org.jnode.system.event.FocusEvent; +import org.jnode.system.event.FocusListener; +import org.jnode.util.Queue; + + +/** + * KeyInputStream maps keyboard events into a stream of characters. Current functionality includes: + * <ul> + * <li>line buffering and line editing, using a text console, + * <li>integrated input history and completion, + * <li>CTRL-D is interpretted as a 'soft' EOF mark,KeyboardInputStream + * <li>listens to keyboard focus events. + * </ul> + * + * Future enhancements include: + * <ul> + * <li>a "raw" mode in which characters and other keyboard events are delivered without line editing, + * <li>a "no echo" mode in which line editting occurs without echoing of input characters, + * <li>making the active characters and keycodes "soft", + * <li>making completion and history context sensitive; e.g. when switching between a shell and + * an application, and + * <li>code refactoring to support classical terminal devices and remote consoles. + * </ul> + * + * Bugs: + * <ul> + * <li>The current method of echoing the input is suboptimal, and is broken in the case where an + * application outputs a prompt string to stdout or stderr. + * </ul> + * + * @author cr...@jn... + * + */ +public class KeyboardInputStream extends InputStream +implements KeyboardListener, FocusListener, DeviceListener { + + public static final byte CTRL_L = 12; + public static final byte CTRL_D = 4; + + private boolean eof; + + private byte[] buffer; + private int pos; + private int lim; + + private static final char NO_CHAR = 0; + + private KeyboardAPI api; + private DeviceManager devMan; + + /** The queue of keyboard events */ + private final Queue<KeyboardEvent> queue = new Queue<KeyboardEvent>(); + + private final Line currentLine; + private final TextConsole console; + private InputCompleter completer; + private final PrintStream out; + private boolean hasFocus; + + private String currentPrompt; + + /** + * Contains an index to the current history line, counting from zero. The value + * -1 denotes the current line. + */ + private int historyIndex = -1; + + /** + * Contains the current line; i.e. the text being entered by the user. + */ + private String newestLine = ""; + + public KeyboardInputStream(KeyboardAPI api, TextConsole console) { + if (api != null) { + this.api = api; + this.api.addKeyboardListener(this); + } + else { + try { + this.devMan = InitialNaming.lookup(DeviceManager.NAME); + this.devMan.addListener(this); + } + catch (NameNotFoundException ex) { + BootLog.error("DeviceManager not found", ex); + } + } + this.console = console; + this.out = console.getOut(); + this.currentLine = new Line(console); + this.pos = this.lim = 0; + } + + private void registerKeyboardApi(Device device) { + if (this.api == null) { + try { + this.api = device.getAPI(KeyboardAPI.class); + this.api.addKeyboardListener(this); + } + catch (ApiNotFoundException ex) { + BootLog.error("KeyboardAPI not found", ex); + } + this.devMan.removeListener(this); + } + } + + public boolean isSoftEOF() { + return eof; + } + + public void clearSoftEOF() { + eof = false; + } + + @Override + public int available() throws IOException { + if (eof) { + return 0; /* per the JDK 1.6 API docs */ + } + else { + // FIXME - what about the case where the line buffer is empty + // and there are unconsumed input events in the queue? + return currentLine.getLineLength(); + } + } + + /** + * @see org.jnode.driver.input.KeyboardListener#keyPressed(org.jnode.driver.input.KeyboardEvent) + */ + public void keyPressed(KeyboardEvent event) { + if (hasFocus) { + queue.add(event); + } + } + + /** + * @see org.jnode.driver.input.KeyboardListener#keyReleased(org.jnode.driver.input.KeyboardEvent) + */ + public void keyReleased(KeyboardEvent event) { + } + + /** + * @see java.io.InputStream#close() + */ + public void close() throws IOException { + if (api != null) { + api.removeKeyboardListener(this); + } + super.close(); + } + + /** + * Pull a keyboard event from the queue and process it. + */ + private boolean processEvent() { + KeyboardEvent event = queue.get(); + if (!event.isConsumed()) { + char ch = event.getKeyChar(); + if (ch != NO_CHAR) { + event.consume(); + return !processChar(ch); + } + else { + int kc = event.getKeyCode(); + int mods = event.getModifiers(); + if (processVirtualKeystroke(kc, mods)) { + event.consume(); + } + return true; + } + } + else { + return true; + } + } + + /** + * Process a keystroke interpretted as a character. + * + * @param ch + * @return <code>true</code> if the character should cause the current line + * buffer contents to be returned to the user. + */ + private boolean processChar(char ch) { + boolean breakChar = false; + switch (ch) { + // if its a backspace we want to remove one from the end of our current + // line + case KeyEvent.VK_BACK_SPACE: + if (currentLine.backspace()) { + refreshCurrentLine(); + } + break; + // if its a delete we want to remove one under the cursor + case KeyEvent.VK_DELETE: + currentLine.delete(); + refreshCurrentLine(); + break; + // if its an enter key we want to process the command, and then resume + // the thread + case '\n': + currentLine.moveEnd(); + refreshCurrentLine(); + out.println(); + currentLine.appendChar(ch); + breakChar = true; + break; + // if it's the tab key, we want to trigger command line completion + case '\t': + if (completer != null) { + CompletionInfo completion = currentLine.complete(currentPrompt); + if (completion.needNewPrompt()) { + currentLine.start(true); + } + refreshCurrentLine(); + } + break; + case CTRL_D: + currentLine.moveEnd(); + refreshCurrentLine(); + out.println(); + eof = true; + breakChar = true; + break; + case CTRL_L: + this.console.clear(); + this.console.setCursor(0, 0); + out.print(currentPrompt); + currentLine.start(); + refreshCurrentLine(); + break; + default: + // otherwise add it to our current line + currentLine.appendChar(ch); + refreshCurrentLine(); + } + return breakChar; + } + + /** + * Process a keystroke that doesn't have an associated char value. + * @param code + * @param modifiers + * @return <code>true</code> if the keystroke has been recognized and + * acted on, <code>false</code> otherwise. + */ + private boolean processVirtualKeystroke(int code, int modifiers) { + if (modifiers != 0) { + return false; + } + switch (code) { + case KeyEvent.VK_UP: + // Previous history item + if (completer != null) { + if (historyIndex == -1) { + newestLine = currentLine.getContent(); + historyIndex = completer.getCommandHistory().size(); + } + historyIndex--; + redisplay(); + } + break; + case KeyEvent.VK_DOWN: + // Next history item + if (completer != null) { + if (historyIndex == completer.getCommandHistory().size() - 1) + historyIndex = -2; + else if (historyIndex == -1) + newestLine = currentLine.getContent(); + historyIndex++; + redisplay(); + } + break; + case KeyEvent.VK_LEFT: + // Left the cursor goes left + if (currentLine.moveLeft()) { + refreshCurrentLine(); + } + break; + case KeyEvent.VK_RIGHT: + // Right the cursor goes right + if (currentLine.moveRight()) { + refreshCurrentLine(); + } + break; + case KeyEvent.VK_HOME: + // The cursor goes at the start + currentLine.moveBegin(); + refreshCurrentLine(); + break; + case KeyEvent.VK_END: + // the cursor goes at the end of line + currentLine.moveEnd(); + refreshCurrentLine(); + break; + default: + // ignore other virtual keys. + return false; + } + return true; + } + + private void refreshCurrentLine() { + currentLine.refreshCurrentLine(currentPrompt); + } + + private void redisplay() { + if (historyIndex == -1) { + currentLine.setContent(newestLine); + } + else { + currentLine.setContent(completer.getCommandHistory().getCommand(historyIndex)); + } + refreshCurrentLine(); + currentLine.moveEnd(); + } + + private boolean fillBuffer() throws IOException { + int x = console.getCursorX(); + int y = console.getCursorY(); + StringBuffer sb = new StringBuffer(x); + for (int i = 0; i < x; i++) { + sb.append(console.getChar(i, y)); + } + currentPrompt = sb.toString(); + + currentLine.start(); + while (processEvent()) { /* */ } + buffer = currentLine.consumeBytes(); + lim = buffer.length; + pos = 0; + return pos < lim; + } + + @Override + public int read() throws IOException { + if (pos >= lim) { + if (eof || !fillBuffer()) { + return -1; + } + } + return buffer[pos++]; + } + + @Override + public int read(byte[] buff, int off, int len) throws IOException { + int nosRead = 0; + if (pos >= lim) { + if (eof || !fillBuffer()) { + return -1; + } + } + while (nosRead < len && pos < lim) { + buff[nosRead + off] = buffer[pos]; + nosRead++; + pos++; + } + return nosRead; + } + + @Override + public int read(byte[] buff) throws IOException { + return read(buff, 0, buff.length); + } + + @Override + public void mark(int readLimit) { + } + + @Override + public boolean markSupported() { + return false; + } + + @Override + public void reset() throws IOException { + throw new UnsupportedOperationException("Mark/reset not supported"); + } + + @Override + public long skip(long n) throws IOException { + // I don't expect this method will be used much. + for (long i = 0; i < n; i++) { + if (read() == -1) { + return i; + } + } + return n; + } + + public InputCompleter getCompleter() { + return completer; + } + + public void setCompleter(InputCompleter completer) { + this.completer = completer; + } + + public void focusGained(FocusEvent event) { + hasFocus = true; + } + + public void focusLost(FocusEvent event) { + hasFocus = false; + } + + /** + * @param device + * @see org.jnode.driver.DeviceListener#deviceStarted(org.jnode.driver.Device) + */ + public void deviceStarted(Device device) { + if (device.implementsAPI(KeyboardAPI.class)) { + registerKeyboardApi(device); + } + } + + /** + * @param device + * @see org.jnode.driver.DeviceListener#deviceStop(org.jnode.driver.Device) + */ + public void deviceStop(Device device) { + /* Do nothing */ + } +} Added: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java (rev 0) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -0,0 +1,323 @@ +/* + * $Id: Line.java 3119 2007-02-11 22:25:20Z fduminy $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.driver.console.textscreen; + +import java.io.PrintStream; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.driver.console.InputCompleter; +import org.jnode.driver.console.TextConsole; + + +/** + * A class that handles the content of the current command line in the shell. + * That can be : - a new command that the user is beeing editing - an existing + * command (from the command history) + * + * This class also handles the current cursor position in the command line and + * keep trace of the position (consoleX, consoleY) of the first character of the + * command line (to handle commands that are multilines). + * + * @author Ewout Prangsma (ep...@us...) + * @author Fabien DUMINY (fd...@jn...) + */ +class Line { + //TODO get the real screen width (in columns) + final static private int SCREEN_WIDTH = 80; + + private int consoleX; + + private int consoleY; + + /** + * Contains the current position of the cursor on the currentLine + */ + private int posOnCurrentLine = 0; + + /** Contains the current line * */ + private StringBuffer currentLine = new StringBuffer(80); + + private boolean shortened = true; + + private int oldLength = 0; + + private int maxLength = 0; + + private final TextConsole console; + + private PrintStream out; + + public Line(TextConsole console) { + this.console = console; + this.out = console.getOut(); + } + + public void start() { + start(false); + } + + public boolean isEmpty() { + return currentLine.toString().trim().length() == 0; + } + + public void start(boolean keepContent) { + if (keepContent) { + // we stay at the same position in X coordinate + // only Y may have changed + consoleY = console.getCursorY(); + } else { + consoleX = console.getCursorX(); + consoleY = console.getCursorY(); + + setContent(""); + console.setCursor( consoleX,consoleY);//move the cursor to the start of the line. + } + } + + public String getContent() { + return currentLine.toString(); + } + + public byte[] getBytes() { + return currentLine.toString().getBytes(); + } + + public byte[] consumeBytes() { + byte[] res = getBytes(); + currentLine.setLength(0); + return res; + } + + public void setContent(String content) { + startModif(); + currentLine.setLength(0); + currentLine.append(content); + moveEnd(); + endModif(); + } + + public boolean moveLeft() { + if (posOnCurrentLine > 0) { + posOnCurrentLine--; + return true; + } + return false; + } + + public boolean moveRight() { + if (posOnCurrentLine < currentLine.length()) { + posOnCurrentLine++; + return true; + } + return false; + } + + public void moveEnd() { + posOnCurrentLine = currentLine.length(); + } + + public void moveBegin() { + posOnCurrentLine = 0; + } + + public boolean backspace() { + if (posOnCurrentLine > 0) { + moveLeft(); + delete(); + return true; + } + return false; + } + + public void delete() { + if ((posOnCurrentLine >= 0) + && (posOnCurrentLine < currentLine.length())) { + startModif(); + currentLine.deleteCharAt(posOnCurrentLine); + endModif(); + } + } + + public CompletionInfo complete(String currentPrompt) { + CompletionInfo info = null; + InputCompleter completer = console.getCompleter(); + if (posOnCurrentLine != currentLine.length()) { + String ending = currentLine.substring(posOnCurrentLine); + info = completer.complete(currentLine.substring(0, posOnCurrentLine)); + printList(info, currentPrompt); + if (info.getCompleted() != null) { + setContent(info.getCompleted() + ending); + posOnCurrentLine = currentLine.length() - ending.length(); + } + } else { + info = completer.complete(currentLine.toString()); + printList(info, currentPrompt); + if (info.getCompleted() != null) { + setContent(info.getCompleted()); + posOnCurrentLine = currentLine.length(); + } + } + + return info; + } + + protected void printList(CompletionInfo info, String currentPrompt) { + if ((info != null) && info.hasItems()) { + int oldPosOnCurrentLine = posOnCurrentLine; + moveEnd(); + refreshCurrentLine(currentPrompt); + + out.println(); + String[] list = info.getItems(); + + final int minItemsToSplit = 5; + if(list.length > minItemsToSplit) + { + list = splitInColumns(list); + } + + // display items column (may be single or multiple columns) + for (String item : list) + { + // item may actually be a single item or in fact multiple items + if((item.length() % SCREEN_WIDTH) == 0) + { + // we are already at the first column of the next line + out.print(item); + } + else + { + // we aren't at the first column of the next line + out.println(item); + } + } + + posOnCurrentLine = oldPosOnCurrentLine; + } + } + + protected String[] splitInColumns(String[] items) + { + final int separatorWidth = 3; + + // compute the maximum width of items + int maxWidth = 0; + for(String item : items) + { + if(item.length() > maxWidth) + { + maxWidth = item.length(); + } + } + + final int columnWidth = Math.min(SCREEN_WIDTH, maxWidth + separatorWidth); + final int nbColumns = SCREEN_WIDTH / columnWidth; + final boolean lastLineIsFull = ((items.length % nbColumns) == 0); + final int nbLines = (items.length / nbColumns) + (lastLineIsFull ? 0 : 1); + + String[] lines = new String[nbLines]; + StringBuilder line = new StringBuilder(SCREEN_WIDTH); + int lineNum = 0; + for(int itemNum = 0 ; itemNum < items.length ; ) + { + for(int c = 0 ; c < nbColumns ; c++) + { + final String item = items[itemNum++]; + line.append(item); + + // add some blanks + final int nbBlanks = columnWidth - item.length(); + for(int i = 0 ; i < nbBlanks ; i++) + { + line.append(' '); + } + + if(itemNum >= items.length) break; + } + + lines[lineNum++] = line.toString(); + line.setLength(0); // clear the buffer + } + + return lines; + } + + public void appendChar(char c) { + startModif(); + if (posOnCurrentLine == currentLine.length()) { + currentLine.append(c); + } else { + currentLine.insert(posOnCurrentLine, c); + } + posOnCurrentLine++; + endModif(); + } + + protected void startModif() { + shortened = false; + oldLength = currentLine.length(); + } + + protected void endModif() { + maxLength = Math.max(oldLength, currentLine.length()); + shortened = oldLength > currentLine.length(); + oldLength = 0; + } + + public void refreshCurrentLine(String currentPrompt) { + try { + int x = consoleX; + int width = console.getWidth(); + int nbLines = ((x + maxLength) / width); + + if (((x + maxLength) % width) != 0) + nbLines++; + + // if the line has not been shortened (delete, backspace...) + if (!shortened) + // scroll up the buffer if necessary, and get the new y + console.ensureVisible(consoleY + nbLines - 1); + + for (int i = 0; i < nbLines; i++) { + console.clearRow(consoleY + i); + } + + // print the input line + console.setCursor(0, consoleY); + out.print(currentPrompt + currentLine); + + int posCurX = x + posOnCurrentLine; + int posCurY = consoleY; + if (posCurX >= width) { + posCurY += posCurX / width; + posCurX = (posCurX % width); + } + console.setCursor(posCurX, posCurY); + } catch (Exception e) { + //todo: why is it ignored? + } + } + + public int getLineLength() { + return currentLine.length(); + } +} Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -21,16 +21,19 @@ package org.jnode.driver.console.textscreen; +import java.io.InputStream; import java.io.PrintStream; import java.security.AccessController; import java.security.PrivilegedAction; import org.jnode.driver.console.ConsoleManager; +import org.jnode.driver.console.InputCompleter; import org.jnode.driver.console.TextConsole; import org.jnode.driver.console.spi.AbstractConsole; import org.jnode.driver.console.spi.ConsoleOutputStream; import org.jnode.driver.textscreen.TextScreen; import org.jnode.system.event.FocusEvent; +import org.jnode.system.event.FocusListener; import org.jnode.vm.isolate.VmIsolate; /** @@ -56,10 +59,14 @@ /** Current Y position */ private int curY; + + private InputStream in; private final PrintStream out; private final PrintStream err; + + private InputStream savedIn; private PrintStream savedOut; @@ -67,7 +74,7 @@ private boolean cursorVisible = true; - private final boolean claimSystemOutErrIn; + private final boolean claimSystemOutErr; private VmIsolate myIsolate; @@ -86,7 +93,7 @@ this, 0x07)); this.savedErr = this.err = new PrintStream(new ConsoleOutputStream( this, 0x04)); - this.claimSystemOutErrIn = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN) == 0); + this.claimSystemOutErr = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR) == 0); this.myIsolate = VmIsolate.currentIsolate(); } @@ -285,7 +292,33 @@ syncScreen(); } + public InputCompleter getCompleter() { + if (in instanceof KeyboardInputStream) { + return ((KeyboardInputStream) in).getCompleter(); + } + else { + return null; + } + } + + public void setCompleter(InputCompleter completer) { + if (in instanceof KeyboardInputStream) { + ((KeyboardInputStream) in).setCompleter(completer); + } + } + /** + * @see org.jnode.driver.console.TextConsole#getIn() + */ + public InputStream getIn() { + return in; + } + + void setIn(InputStream in) { + this.savedIn = this.in = in; + } + + /** * @see org.jnode.driver.console.TextConsole#getErr() */ public PrintStream getErr() { @@ -323,7 +356,10 @@ public void focusGained(FocusEvent event) { super.focusGained(event); syncScreen(); - if (claimSystemOutErrIn) { + if (in instanceof FocusListener) { + ((FocusListener) in).focusGained(event); + } + if (claimSystemOutErr) { myIsolate.invokeAndWait(new Runnable() { public void run() { AccessController.doPrivileged(new PrivilegedAction<Object>() { @@ -342,7 +378,10 @@ * @see org.jnode.system.event.FocusListener#focusLost(org.jnode.system.event.FocusEvent) */ public void focusLost(FocusEvent event) { - if (claimSystemOutErrIn) { + if (in instanceof FocusListener) { + ((FocusListener) in).focusLost(event); + } + if (claimSystemOutErr) { myIsolate.invokeAndWait(new Runnable() { public void run() { savedOut = System.out; Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -21,11 +21,10 @@ package org.jnode.driver.console.textscreen; -import java.awt.event.KeyEvent; +import java.io.InputStream; import javax.naming.NameNotFoundException; -import org.jnode.driver.console.Console; import org.jnode.driver.console.ConsoleException; import org.jnode.driver.console.spi.AbstractConsoleManager; import org.jnode.driver.textscreen.ScrollableTextScreen; @@ -53,7 +52,7 @@ * @see org.jnode.driver.console.ConsoleManager#createConsole(String, int) */ public TextScreenConsole createConsole(String name, int options) { - if ((options & CreateOptions.TEXT) != 0) { + if ((options & CreateOptions.TEXT) != 0) { final TextScreenManager tsm; tsm = getTextScreenManager(); final TextScreenConsole console; @@ -69,6 +68,11 @@ screen = tsm.getSystemScreen().createCompatibleBufferScreen(); console = new TextScreenConsole(this, name, screen, options); } + InputStream in = System.in; + if ((options & CreateOptions.NO_LINE_EDITTING) == 0) { + in = new KeyboardInputStream(getKeyboardApi(), console); + } + console.setIn(in); if ((options & CreateOptions.STACKED) != 0){ stackConsole(console); } else { @@ -81,7 +85,7 @@ throw new IllegalArgumentException("Unknown option " + options); } } - + protected TextScreenManager getTextScreenManager() { TextScreenManager tsm; try { Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -55,7 +55,10 @@ InitialNaming.bind(ConsoleManager.NAME, mgr); // Create the first console - final TextConsole first = (TextConsole)mgr.createConsole(null, ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE); + final TextConsole first = (TextConsole) mgr.createConsole( + null, + (ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.SCROLLABLE)); mgr.focus(first); System.setOut(first.getOut()); System.setErr(first.getErr()); Modified: trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -31,8 +31,6 @@ import org.jnode.driver.Device; import org.jnode.driver.DriverException; -import org.jnode.system.BootLog; -import org.jnode.util.EmptyInputStream; import org.jnode.util.SystemInputStream; /** @@ -105,18 +103,18 @@ dev.registerAPI(KeyboardAPI.class, this); dev.registerAPI(SystemTriggerAPI.class, this); - // If no inputstream has been defined, create and set one. - kis = null; - if (channel != null) { - kis = new KeyboardInputStream(this); - } - final InputStream systemIn = kis; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - SystemInputStream.getInstance().initialize(systemIn); - return null; - } - }); +// // If no inputstream has been defined, create and set one. +// kis = null; +// if (channel != null) { +// kis = new KeyboardInputStream(this); +// } +// final InputStream systemIn = kis; +// AccessController.doPrivileged(new PrivilegedAction() { +// public Object run() { +// SystemInputStream.getInstance().initialize(systemIn); +// return null; +// } +// }); } /** Modified: trunk/core/src/driver/org/jnode/driver/input/Key.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/Key.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/input/Key.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -125,6 +125,11 @@ { this.upperChar = upperChar; } + + public char getControlChar() + { + return (char) (upperChar & 0x1f); + } public char getAltGrChar() { Deleted: trunk/core/src/driver/org/jnode/driver/input/KeyboardInputStream.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/KeyboardInputStream.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInputStream.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -1,153 +0,0 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.driver.input; - -import java.io.IOException; -import java.io.InputStream; - -import org.jnode.util.Queue; - -/** - * @author epr - */ -public class KeyboardInputStream extends InputStream implements KeyboardListener { - - private final KeyboardAPI api; - /** The queue of keyboard events */ - private final Queue<KeyboardEvent> queue = new Queue<KeyboardEvent>(); - /** Should we echo keys on the System.out? */ - private boolean echo = true; - - /** - * Create a new instance - * @param api the keyboard API - */ - public KeyboardInputStream(KeyboardAPI api) { - this.api = api; - api.addKeyboardListener(this); - } - - /** - * @see java.io.InputStream#available() - */ - public int available() throws IOException { - return 0; - } - - /* - Doesn't block after the first blocking read. - public int read(byte[] b, int off, int len) throws IOException { - if (off < 0 || len < 0 || b.length - off < len) - throw new IndexOutOfBoundsException(); - - long time = System.currentTimeMillis(); - - int i = 0; - int ch = read(time); - - for(;;) { - b[off + i ++] = (byte) ch; - - if(i < len && queue.size() > 0) - ch = read(time); - else - break; - } - - return i; - } - */ - - public int read(byte[] b, int off, int len) throws IOException { - if (off < 0 || len < 0 || b.length - off < len) - throw new IndexOutOfBoundsException(); - - long time = System.currentTimeMillis(); - - int i = 0; - int ch = read(time); - - for(;;) { - b[off + i ++] = (byte) ch; - - if(i < len && ch != '\n') - ch = read(time); - else - break; - } - - return i; - } - - /** - * @see java.io.InputStream#read() - */ - public int read() throws IOException { - long time = System.currentTimeMillis(); - return read(time); - } - - private int read(long time){ - while (true) { - KeyboardEvent event = queue.get(); - int c = event2char(event, time); - if(c > 0) - return c; - } - } - - private int event2char(KeyboardEvent event, long time) { - if (!event.isConsumed() && event.getTime() - time > -10000) { - event.consume(); - char ch = event.getKeyChar(); - if (ch != 0) { - if (echo) { - System.out.print(ch); - } - return ch; - } - } - return -1; - } - - /** - * @see org.jnode.driver.input.KeyboardListener#keyPressed(org.jnode.driver.input.KeyboardEvent) - */ - public void keyPressed(KeyboardEvent event) { - queue.add(event); - } - - /** - * @see org.jnode.driver.input.KeyboardListener#keyReleased(org.jnode.driver.input.KeyboardEvent) - */ - public void keyReleased(KeyboardEvent event) { - } - - /** - * @see java.io.InputStream#close() - */ - public void close() throws IOException { - api.removeKeyboardListener(this); - super.close(); - } - -} Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -32,6 +32,10 @@ */ public abstract class KeyboardInterpreter { + // FIXME We are currently using the character zero (0x0000) to indicate that no + // (Unicode) character corresponds to a keycode. This means that we cannot represent + // the NUL control character. Instead we should really be using 0xffff which Unicode + // defines to be a non-character. private int flags; @@ -110,8 +114,13 @@ catch (UnsupportedKeyException e) { final char ch; - if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) + + if ((flags & InputEvent.CTRL_DOWN_MASK) != 0) { + ch = keys.getKey(scancode).getControlChar(); + } + else if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) + { ch = keys.getKey(scancode).getUpperChar(); if (!extendedMode) Modified: trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -28,9 +28,11 @@ TextScreenConsoleManager manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager(); SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager(); cm.setParent(manager); - new Thread(new CommandShell((TextConsole) cm.createConsole(null, - ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE)), "SwingConsoleCommandShell"). - start(); + TextConsole console = cm.createConsole( + null, + (ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.SCROLLABLE)); + new Thread(new CommandShell(console), "SwingConsoleCommandShell").start(); synchronized(SwingConsole.class){ frame = cm.getFrame(); Modified: trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -36,10 +36,12 @@ ShellManager sm = InitialNaming.lookup(ShellManager.NAME); TextScreenConsoleManager manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager(); - TextConsole console = manager.createConsole("editor", - ConsoleManager.CreateOptions.TEXT | - ConsoleManager.CreateOptions.STACKED | - ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN); + TextConsole console = manager.createConsole( + "editor", + (ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.STACKED | + ConsoleManager.CreateOptions.NO_LINE_EDITTING | + ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR)); manager.focus(console); TextEditor te = new TextEditor(console); Modified: trunk/distr/src/emu/org/jnode/emu/EditEmu.java =================================================================== --- trunk/distr/src/emu/org/jnode/emu/EditEmu.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/distr/src/emu/org/jnode/emu/EditEmu.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -21,8 +21,11 @@ } SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager(); - final TextScreenConsole console = cm.createConsole(null, - ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN); + final TextScreenConsole console = cm.createConsole( + null, + (ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR | + ConsoleManager.CreateOptions.NO_LINE_EDITTING)); TextEditor te = new TextEditor(console); File f = new File(argv[0]); Modified: trunk/distr/src/emu/org/jnode/emu/ShellEmu.java =================================================================== --- trunk/distr/src/emu/org/jnode/emu/ShellEmu.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/distr/src/emu/org/jnode/emu/ShellEmu.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -12,8 +12,9 @@ public static void main(String[] argv) throws Exception { initEnv(); SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager(); - new Thread(new CommandShell(cm.createConsole("Console 1", - ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE))). - start(); + new Thread(new CommandShell(cm.createConsole( + "Console 1", + (ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.SCROLLABLE)))).start(); } } Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -22,6 +22,7 @@ package org.jnode.fs.command; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.net.MalformedURLException; @@ -38,6 +39,7 @@ /** * @author epr * @author Andreas H\u00e4nel + * @author Stephen Crawley */ public class CatCommand implements Command{ @@ -45,8 +47,10 @@ "the file (or URL) to print out"); public static Help.Info HELP_INFO = new Help.Info("cat", - "Print the contents of the given file (or URL)", - new Parameter[] { new Parameter(ARG_FILE, Parameter.MANDATORY)}); + "Print the contents of the given file (or URL). " + + "If the file is omitted, standard input is read until EOF is reached; " + + "e.g. ^D when reading keyboard input.", + new Parameter[] { new Parameter(ARG_FILE, Parameter.OPTIONAL)}); public static void main(String[] args) throws Exception { new CatCommand().execute(new CommandLine(args), System.in, System.out, System.err); @@ -54,20 +58,40 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { ParsedArguments cmdLine = HELP_INFO.parse(commandLine.toStringArray()); - URL url = openURL(ARG_FILE.getValue(cmdLine)); - InputStream is = url.openStream(); - if (is == null) { - err.println("Not found " + ARG_FILE.getValue(cmdLine)); - } else { - int len; - final byte[] buf = new byte[ 1024]; - while ((len = is.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.println(); - out.flush(); - is.close(); - } + String fileName = ARG_FILE.getValue(cmdLine); + InputStream is = null; + try { + if (fileName == null) { + is = in; + } + else { + URL url = openURL(fileName); + try { + is = url.openStream(); + } + catch (IOException ex) { + /* drop through ... */ + } + if (is == null) { + err.println("Not found " + ARG_FILE.getValue(cmdLine)); + // FIXME ... System.exit(1); + return; + } + } + int len; + final byte[] buf = new byte[ 1024]; + while ((len = is.read(buf)) > 0) { + out.write(buf, 0, len); + } + // FIXME ... Why are we adding an extra newline??? + out.println(); + out.flush(); + } + finally { + if (is != null && fileName != null) { + is.close(); + } + } } private URL openURL(String fname) throws MalformedURLException { Modified: trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -62,7 +62,8 @@ screen = new JTextAreaTextScreen(80,24); manager = new TextScreenConsoleManager(); - console = new TextScreenConsole(manager, "test", screen, ConsoleManager.CreateOptions.TEXT); + console = new TextScreenConsole( + manager, "test", screen, ConsoleManager.CreateOptions.TEXT); manager.focus(console); CommandShell commandShell = new CommandShell(console); Modified: trunk/gui/src/test/org/jnode/test/gui/FBConsole.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/FBConsole.java 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/gui/src/test/org/jnode/test/gui/FBConsole.java 2007-08-02 18:15:27 UTC (rev 3374) @@ -58,7 +58,8 @@ ScrollableTextScreen ts = new FBConsole.FBPcTextScreen(g).createCompatibleScrollableBufferScreen(500); - ScrollableTextScreenConsole first = new ScrollableTextScreenConsole(mgr, "console", ts, + ScrollableTextScreenConsole first = + new ScrollableTextScreenConsole(mgr, "console", ts, ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE); Modified: trunk/shell/descriptors/org.jnode.shell.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.xml 2007-07-31 18:23:49 UTC (rev 3373) +++ trunk/shell/descriptors/org.jnode.shell.xml 2007-08-02 18:15:27 UTC (rev 3374) @@ -32,6 +32,7 @@ <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/> <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> <permission class="java.lang.RuntimePermission" name="modifyThread"/> + <permission class="java.lang.RuntimePermission" name="setIO"/> <permission class="java.net.SocketPermission" name="*" actions="resolve,listen,connect"/> <permission class="java.net.SocketPermission" name="*:0-" actions="connect,reso... [truncated message content] |
From: <ls...@us...> - 2007-08-04 09:31:08
|
Revision: 3377 http://jnode.svn.sourceforge.net/jnode/?rev=3377&view=rev Author: lsantha Date: 2007-08-04 02:31:03 -0700 (Sat, 04 Aug 2007) Log Message: ----------- Updated Intellij IDEA module files. Modified Paths: -------------- trunk/all/all.iml trunk/builder/builder.iml trunk/core/core.iml trunk/distr/distr.iml trunk/fs/fs.iml trunk/gui/gui.iml trunk/jnode.iml trunk/net/net.iml trunk/shell/shell.iml trunk/textui/textui.iml Modified: trunk/all/all.iml =================================================================== --- trunk/all/all.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/all/all.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/builder/builder.iml =================================================================== --- trunk/builder/builder.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/builder/builder.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/core/core.iml =================================================================== --- trunk/core/core.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/core/core.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/distr/distr.iml =================================================================== --- trunk/distr/distr.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/distr/distr.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/fs/fs.iml =================================================================== --- trunk/fs/fs.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/fs/fs.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> @@ -14,6 +14,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module" module-name="core" /> <orderEntry type="library" name="core" level="project" /> + <orderEntry type="module" module-name="shell" /> <orderEntryProperties /> </component> </module> Modified: trunk/gui/gui.iml =================================================================== --- trunk/gui/gui.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/gui/gui.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/jnode.iml =================================================================== --- trunk/jnode.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/jnode.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/net/net.iml =================================================================== --- trunk/net/net.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/net/net.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/shell/shell.iml =================================================================== --- trunk/shell/shell.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/shell/shell.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> Modified: trunk/textui/textui.iml =================================================================== --- trunk/textui/textui.iml 2007-08-02 20:12:03 UTC (rev 3376) +++ trunk/textui/textui.iml 2007-08-04 09:31:03 UTC (rev 3377) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module version="4" relativePaths="true" type="JAVA_MODULE"> <component name="ModuleRootManager" /> - <component name="NewModuleRootManager"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/classes" /> <exclude-output /> <exclude-exploded /> @@ -10,6 +10,8 @@ </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="core" /> + <orderEntry type="module" module-name="shell" /> <orderEntryProperties /> </component> </module> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-08-13 18:27:42
|
Revision: 3396 http://jnode.svn.sourceforge.net/jnode/?rev=3396&view=rev Author: lsantha Date: 2007-08-13 11:27:41 -0700 (Mon, 13 Aug 2007) Log Message: ----------- General input history support for command line applications - by crawley. Modified Paths: -------------- trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/Shell.java trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java Added Paths: ----------- trunk/core/src/driver/org/jnode/driver/console/InputHistory.java Modified: trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java 2007-08-13 07:38:53 UTC (rev 3395) +++ trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -4,5 +4,11 @@ public interface InputCompleter { CompletionInfo complete(String partial); - CommandHistory getCommandHistory(); + /** + * Gets the completer's current InputHistory object. If the completer is modal, + * different histories may be returned at different times. + */ + public InputHistory getInputHistory(); + + } Added: trunk/core/src/driver/org/jnode/driver/console/InputHistory.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/InputHistory.java (rev 0) +++ trunk/core/src/driver/org/jnode/driver/console/InputHistory.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -0,0 +1,103 @@ +/* + * $Id: CommandHistory.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.driver.console; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class is used to manage history lists for command shell and application input. + * <p> + * TODO - support conventional history list (no removal of duplicates), an optional + * upper bound on the history list size, and loading from / saving to a file. + * + * @author Matt Paine + * @author cr...@jn... + */ +public class InputHistory { + + /** Holds the history lines. **/ + private final List<String> history = new ArrayList<String>(); + + /** Constructs an InputHistory object. **/ + public InputHistory() { + } + + /** + * Adds a line to the end of the history list, removing it if is already present + * @param line the input line to be recorded. + */ + public void addLine(String line) { + if (history.contains(line)) { + history.remove(line); + } + history.add(line); + } + + /** + * Returns the current number of history recorded. + * @return the number of lines in the history list. + */ + public int size() { + return history.size(); + } + + /** + * Gets the history line at a given index in the list + * @param index The index (starting at zero) for the history line to be returned. + * @return The history line requested or <code>null</code> if the index is out of range. + */ + public String getLineAt(int index) { + try { + return history.get(index); + } catch (IndexOutOfBoundsException ex) { + return null; + } + } + + /** + * Searches for the most recent command types starting with the specified + * string. + * @param start The string to search for. + * @return The most recent command matching the search string. + */ + public String getLineWithPrefix(String start) { + return getLineAt(findLine(start)); + } + + /** + * Searches the collection for the most recent line starting with the + * specified string. + * @param start the string to search for. + * @return the index number of the specified string (or -1 if not found). + */ + private int findLine(String start) { + for (int x = 0; x < history.size(); x++) { + String line = history.get(x); + if (line != null && line.startsWith(start)) { + return x; + } + } + return -1; + } + +} Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-13 07:38:53 UTC (rev 3395) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -227,6 +227,7 @@ if (completion.needNewPrompt()) { currentLine.start(true); } + out.print(currentPrompt); refreshCurrentLine(); } break; @@ -273,7 +274,7 @@ // Previous history item if (completer != null) { if (historyIndex == -1) { - historyIndex = completer.getCommandHistory().size(); + historyIndex = completer.getInputHistory().size(); savedCurrentLine = currentLine.getContent(); } historyIndex--; @@ -287,7 +288,7 @@ if (historyIndex == -1) savedCurrentLine = currentLine.getContent(); - if (historyIndex == completer.getCommandHistory().size() - 1) + if (historyIndex == completer.getInputHistory().size() - 1) historyIndex = -2; historyIndex++; @@ -332,7 +333,7 @@ private void updateCurrentLine() { if (historyIndex > -1) { - currentLine.setContent(completer.getCommandHistory().getCommand(historyIndex)); + currentLine.setContent(completer.getInputHistory().getLineAt(historyIndex)); } else { currentLine.setContent(savedCurrentLine); } Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-13 07:38:53 UTC (rev 3395) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -347,6 +347,7 @@ // ensure that the location of the input cursor is included. console.ensureVisible(inputCursorY); } + console.setCursorVisible(true); } catch (Exception e) { // TODO - why ignore these exceptions? Are they due to the console methods // not being thread-safe??? Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-08-13 07:38:53 UTC (rev 3395) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -25,6 +25,7 @@ import gnu.java.security.action.SetPropertyAction; import java.io.File; +import java.io.FilterInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; @@ -42,10 +43,9 @@ import javax.naming.NameNotFoundException; import org.apache.log4j.Logger; -import org.jnode.driver.console.CommandHistory; +import org.jnode.driver.console.InputHistory; import org.jnode.driver.console.CompletionInfo; import org.jnode.driver.console.ConsoleManager; -import org.jnode.driver.console.InputCompleter; import org.jnode.driver.console.TextConsole; import org.jnode.driver.console.ConsoleListener; import org.jnode.driver.console.ConsoleEvent; @@ -66,8 +66,9 @@ /** * @author epr * @author Fabien DUMINY + * @authod crawley */ -public class CommandShell implements Runnable, Shell, ConsoleListener, InputCompleter { +public class CommandShell implements Runnable, Shell, ConsoleListener { public static final String PROMPT_PROPERTY_NAME = "jnode.prompt"; @@ -92,14 +93,27 @@ /** * Contains the archive of commands. * */ - private CommandHistory history = new CommandHistory(); + private InputHistory commandHistory = new InputHistory(); + + /** + * Contains the application input history for the current thread. + */ + private static InheritableThreadLocal<InputHistory> applicationHistory = + new InheritableThreadLocal<InputHistory> (); + + private boolean readingCommand; /** - * Contains the newest command being typed in * + * Contains the last command entered */ - private String newestLine = ""; + private String lastCommandLine = ""; /** + * Contains the last application input line entered + */ + private String lastInputLine = ""; + + /** * Flag to know when to wait (while input is happening). This is (hopefully) * a thread safe implementation. * */ @@ -205,7 +219,7 @@ if (e.startsWith(command)) { final String cmd = e.substring(command.length()); out.println(prompt() + cmd); - processCommand(cmd); + processCommand(cmd, false); } } catch (Throwable ex) { ex.printStackTrace(err); @@ -231,10 +245,10 @@ try { clearEof(); out.print(prompt()); + readingCommand = true; String line = readInputLine().trim(); if (line.length() > 0) { - clearEof(); - processCommand(line); + processCommand(line, true); } if (VmSystem.isShuttingDown()) { @@ -264,63 +278,24 @@ } } - protected void processCommand(String cmdLineStr) { - commandInvoker.invoke(cmdLineStr); + protected void processCommand(String cmdLineStr, boolean interactive) { + clearEof(); + if (interactive) { + readingCommand = false; + // Each interactive command is launched with a fresh history + // for input completion + applicationHistory.set(new InputHistory()); + } + commandInvoker.invoke(cmdLineStr); + if (interactive) { + applicationHistory.set(null); + } } public void invokeCommand(String command) { - processCommand(command); + processCommand(command, false); } - // /** - // * Execute a single command line. - // * - // * @param cmdLineStr - // */ - // protected void processCommand(String cmdLineStr) { - // - // final CommandLine cmdLine = new CommandLine(cmdLineStr); - // if (!cmdLine.hasNext()) - // return; - // String cmdName = cmdLine.next(); - // - // // Add this command to the history. - // if (!cmdLineStr.equals(newestLine)) - // history.addCommand(cmdLineStr); - // - // try { - // Class cmdClass = getCommandClass(cmdName); - // final Method main = cmdClass.getMethod("main", MAIN_ARG_TYPES); - // try { - // main.invoke(null, new Object[] { - // cmdLine.getRemainder().toStringArray()}); - // } catch (InvocationTargetException ex) { - // Throwable tex = ex.getTargetException(); - // if (tex instanceof SyntaxError) { - // Help.getInfo(cmdClass).usage(); - // err.println(tex.getMessage()); - // } else { - // err.println("Exception in command"); - // tex.printStackTrace(err); - // } - // } catch (Exception ex) { - // err.println("Exception in command"); - // ex.printStackTrace(err); - // } catch (Error ex) { - // err.println("Fatal error in command"); - // ex.printStackTrace(err); - // } - // } catch (NoSuchMethodException ex) { - // err.println("Alias class has no main method " + cmdName); - // } catch (ClassNotFoundException ex) { - // err.println("Unknown alias class " + ex.getMessage()); - // } catch (ClassCastException ex) { - // err.println("Invalid command " + cmdName); - // } catch (Exception ex) { - // err.println("I FOUND AN ERROR: " + ex); - // } - // } - protected CommandInfo getCommandClass(String cmd) throws ClassNotFoundException { try { @@ -341,13 +316,25 @@ } /** - * Gets the CommandHistory object associated with this shell. + * Gets the shell's command InputHistory object. */ - public CommandHistory getCommandHistory() { - return history; + public InputHistory getCommandHistory() { + return commandHistory; } /** + * Gets the shell's currently active InputHistory object. + */ + public InputHistory getInputHistory() { + if (readingCommand) { + return commandHistory; + } + else { + return CommandShell.applicationHistory.get(); + } + } + + /** * Gets the expanded prompt */ protected String prompt() { @@ -405,14 +392,23 @@ private CompletionInfo completion; public CompletionInfo complete(String partial) { + if (!readingCommand) { + // dummy completion behavior for application input. + CompletionInfo completion = new CompletionInfo(); + completion.setCompleted(partial); + completion.setNewPrompt(true); + return completion; + } + // workaround to set the currentShell to this shell try { ShellUtils.getShellManager().registerShell(this); } catch (NameNotFoundException ex) { } + // do command completion + String result = null; completion = new CompletionInfo(); - String result = null; try { CommandLine cl = new CommandLine(partial); String cmd = ""; @@ -472,13 +468,73 @@ } public void addCommandToHistory(String cmdLineStr) { - // Add this command to the history. - if (isHistoryEnabled() && !cmdLineStr.equals(newestLine)) - history.addCommand(cmdLineStr); + // Add this command to the command history. + if (isHistoryEnabled() && !cmdLineStr.equals(lastCommandLine)) { + commandHistory.addLine(cmdLineStr); + lastCommandLine = cmdLineStr; + } } + public void addInputToHistory(String inputLine) { + // Add this input to the application input history. + if (isHistoryEnabled() && !inputLine.equals(lastInputLine)) { + InputHistory history = applicationHistory.get(); + if (history != null) { + history.addLine(inputLine); + lastInputLine = inputLine; + } + } + } + public InputStream getInputStream() { - return in; + if (isHistoryEnabled()) { + // Insert a filter on the input stream that adds completed input lines + // to the application input history. + // TODO - revisit for support of muilt-byte character encodings. + return new FilterInputStream(in) { + private StringBuilder line = new StringBuilder(); + + @Override + public int read() throws IOException { + int res = super.read(); + if (res != -1) { + filter((byte) res); + } + return res; + } + + @Override + public int read(byte[] buf, int offset, int len) throws IOException { + int res = super.read(buf, offset, len); + for (int i = 0; i < res; i++) { + filter(buf[offset + i]); + } + return res; + } + + @Override + public int read(byte[] buf) throws IOException { + int res = super.read(buf); + for (int i = 0; i < res; i++) { + filter(buf[i]); + } + return res; + } + + private void filter(byte b) { + if (b == '\n') { + addInputToHistory(line.toString()); + line.setLength(0); + } + else { + line.append((char) b); + } + } + }; + } + else { + return in; + } } public PrintStream getOutputStream() { Modified: trunk/shell/src/shell/org/jnode/shell/Shell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/Shell.java 2007-08-13 07:38:53 UTC (rev 3395) +++ trunk/shell/src/shell/org/jnode/shell/Shell.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -22,13 +22,14 @@ package org.jnode.shell; import org.jnode.shell.alias.AliasManager; -import org.jnode.driver.console.CommandHistory; import org.jnode.driver.console.Console; +import org.jnode.driver.console.InputCompleter; +import org.jnode.driver.console.InputHistory; /** * @author epr */ -public interface Shell { +public interface Shell extends InputCompleter { /** * Gets the alias manager of this shell @@ -36,16 +37,17 @@ public AliasManager getAliasManager(); /** - * Gets the CommandHistory object associated with this shell. - */ - public CommandHistory getCommandHistory(); - - /** * Prints a list of choices for command line completion. */ public void list(String[] items); /** + * Gets the shell's command InputHistory object. Unlike getInputHistory, + * this method is not modal. + */ + public InputHistory getCommandHistory(); + + /** * Returns the console where the shell is running. * @return the console */ Modified: trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2007-08-13 07:38:53 UTC (rev 3395) +++ trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2007-08-13 18:27:41 UTC (rev 3396) @@ -23,7 +23,7 @@ import java.io.PrintStream; import javax.naming.NameNotFoundException; -import org.jnode.driver.console.CommandHistory; +import org.jnode.driver.console.InputHistory; import org.jnode.shell.help.*; import org.jnode.shell.help.argument.OptionArgument; import org.jnode.shell.Shell; @@ -70,7 +70,7 @@ private PrintStream out; /** Reference to the CommandHistory to work with. **/ - private CommandHistory history; + private InputHistory history; //********** Constructor **********// @@ -115,7 +115,7 @@ /** List out every command from the history, with each commands index. **/ public void listCommands() { for (int x = 0; x < history.size(); x++) - out.println("" + x + ": " + history.getCommand(x)); + out.println("" + x + ": " + history.getLineAt(x)); out.println(); } @@ -178,10 +178,10 @@ private String parseCommandArg(String arg) { try { int i = Integer.parseInt(arg); - return history.getCommand(i); + return history.getLineAt(i); } catch (NumberFormatException nfex) { - return history.getCommand(arg); + return history.getLineWithPrefix(arg); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-08-20 20:44:12
|
Revision: 3399 http://jnode.svn.sourceforge.net/jnode/?rev=3399&view=rev Author: fduminy Date: 2007-08-20 13:44:06 -0700 (Mon, 20 Aug 2007) Log Message: ----------- - refactored some JNode ant tasks around abstract class FileSetTask - created ant task to add annotations on classes (useful for adding @SharedStatics on openjdk classes without modifying the original source code) Modified Paths: -------------- trunk/all/build.xml trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java trunk/builder/src/builder/org/jnode/ant/taskdefs/Native2AsciiTask.java trunk/core/.classpath trunk/core/descriptors/org.objectweb.asm.xml trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java Added Paths: ----------- trunk/all/conf/openjdk-annotations.properties trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java trunk/core/lib/asm-1.5.3.jar trunk/core/lib/asm-attrs-1.5.3.jar Removed Paths: ------------- trunk/core/lib/asm.jar Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2007-08-15 18:21:25 UTC (rev 3398) +++ trunk/all/build.xml 2007-08-20 20:44:06 UTC (rev 3399) @@ -55,9 +55,10 @@ <property name="jmock-cglib.jar" value="${root.dir}/core/lib/jmock-cglib-1.0.1.jar"/> <property name="jmock.jar" value="${root.dir}/core/lib/jmock-1.0.1.jar"/> <property name="cglib.jar" value="${root.dir}/core/lib/cglib-2.1.jar"/> - <property name="asm.jar" value="${root.dir}/core/lib/asm.jar"/> - <property name="jcfe.jar" value="${root.dir}/core/lib/jcfe.jar"/> - <property name="jfunc.jar" value="${root.dir}/core/lib/jfunc.jar"/> + <property name="asm.jar" value="${root.dir}/core/lib/asm-1.5.3.jar"/> + <property name="asm-attrs.jar" value="${root.dir}/core/lib/asm-attrs-1.5.3.jar"/> + <property name="jcfe.jar" value="${root.dir}/core/lib/jcfe.jar"/> + <property name="jfunc.jar" value="${root.dir}/core/lib/jfunc.jar"/> <property name="log4j.jar" value="${root.dir}/core/lib/log4j-1.2.8.jar"/> <property name="gnu-crypto.jar" value="${root.dir}/core/lib/gnu-crypto.jar"/> @@ -92,6 +93,7 @@ <pathelement location="${jmock.jar}"/> <pathelement location="${jmock-cglib.jar}"/> <pathelement location="${asm.jar}"/> + <pathelement location="${asm-attrs.jar}"/> <pathelement location="${cglib.jar}"/> <pathelement location="${log4j.jar}"/> <pathelement location="${gnu-crypto.jar}"/> @@ -164,7 +166,7 @@ </target> <!-- Assemble all plugins --> - <target name="assemble-plugins" depends="assemble-projects"> + <target name="assemble-plugins" depends="assemble-projects,openjdk-annotate"> <!-- Now assemble all plugins --> <taskdef name="plugin" classname="org.jnode.build.PluginTask" classpathref="cp-jnode"/> <plugin todir="${plugins.dir}" tmpdir="${build.dir}/tmp/plugins" pluginDir="${descriptors.dir}"> @@ -199,6 +201,7 @@ <libalias name="jmock-1.0.1.jar" alias="${jmock.jar}"/> <libalias name="jmock-cglib-1.0.1.jar" alias="${jmock-cglib.jar}"/> <libalias name="asm.jar" alias="${asm.jar}"/> + <libalias name="asm-attrs.jar" alias="${asm-attrs.jar}"/> <libalias name="cglib.jar" alias="${cglib.jar}"/> <libalias name="mauve.jar" alias="${mauve.jar}"/> <libalias name="jcfe.jar" alias="${jcfe.jar}"/> @@ -571,7 +574,6 @@ <patternset id="cp-sources-pattern"> <exclude name="com/sun/demo/**/*"/> <exclude name="com/sun/tools/hat/**/*"/> - <exclude name="com/sun/tools/hat/**/*"/> <exclude name="com/sun/tools/example/**/*"/> <exclude name="com/sun/tools/javah/**/*"/> <exclude name="com/sun/tools/internal/txw2/**/*"/> @@ -621,6 +623,19 @@ </cp-compare> </target> + <!-- add annotations to compiled openjdk classes --> + <target name="openjdk-annotate" depends="assemble-projects"> + <echo message="openjdk-annotate"/> + <taskdef name="oj-annotate" classname="org.jnode.ant.taskdefs.AnnotateTask" + classpathref="cp-jnode"/> + + <oj-annotate annotationFile="${root.dir}/all/conf/openjdk-annotations.properties"> + <fileset dir="${root.dir}/core/build/classes"> + <patternset includes="**/*.class"/> + </fileset> + </oj-annotate> + </target> + <!-- Run all tests --> <target name="tests" depends="assemble"> <ant target="tests" dir="${root.dir}/fs" inheritall="on" inheritrefs="on"/> Added: trunk/all/conf/openjdk-annotations.properties =================================================================== --- trunk/all/conf/openjdk-annotations.properties (rev 0) +++ trunk/all/conf/openjdk-annotations.properties 2007-08-20 20:44:06 UTC (rev 3399) @@ -0,0 +1 @@ +sun.misc.SharedSecrets=SharedStatics \ No newline at end of file Added: trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java (rev 0) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-08-20 20:44:06 UTC (rev 3399) @@ -0,0 +1,266 @@ +/* + * $Id: HeaderTask.java 3379 2007-08-04 10:19:57Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.ant.taskdefs; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Collections; +import java.util.Properties; + +import org.apache.tools.ant.BuildException; +import org.jnode.vm.annotation.SharedStatics; +import org.objectweb.asm.ClassAdapter; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; +import org.objectweb.asm.attrs.Annotation; +import org.objectweb.asm.attrs.RuntimeVisibleAnnotations; +import org.objectweb.asm.util.AbstractVisitor; +import org.objectweb.asm.util.CheckClassAdapter; +import org.objectweb.asm.util.TraceClassVisitor; + +/** + * That ant task will add some annotations to some compiled classes + * mentioned in a property file. + * For now, it's only necessary to add SharedStatics annotations to some + * openjdk classes to avoid modifying the original source code. + * + * @author Fabien DUMINY (fduminy at jnode.org) + * + */ +public class AnnotateTask extends FileSetTask { + + private File annotationFile; + private String[] classesFiles; + + public void execute() throws BuildException { + classesFiles = readProperties(annotationFile); + processFiles(); + } + + public final File getAnnotationFile() { + return annotationFile; + } + + public final void setAnnotationFile(File annotationFile) { + this.annotationFile = annotationFile; + } + + /** + * Read the properties file. For now, it simply contains a list of + * classes that need the SharedStatics annotation. + * + * @return + * @throws BuildException + */ + private static String[] readProperties(File file) throws BuildException + { + if(file == null) + { + throw new BuildException("annotationFile is mandatory"); + } + + Properties props = new Properties(); + FileInputStream fis = null; + try + { + fis = new FileInputStream(file); + props.load(fis); + } catch (IOException e) { + throw new BuildException(e); + } + finally + { + if(fis != null) + { + try { + fis.close(); + } catch (IOException e) { + throw new BuildException(e); + } + } + } + if(props.isEmpty()) + { + System.err.println("WARNING: annotationFile is empty"); + return new String[0]; + } + + String[] classesFiles = new String[props.size()]; + int i = 0; + for(Object name : props.keySet()) + { + String className = String.valueOf(name); + String annotations = props.getProperty(className); + if("SharedStatics".equals(annotations)) + { + className = className.replace('.', File.separatorChar); + className += ".class"; + classesFiles[i++] = className; + } + } + + // we must sort the classes in reverse order so that + // classes with longest package name will be used first + // (that is only necessary for classes whose name is the same + // but package is different ; typical such class name : "Constants") + Arrays.sort(classesFiles, Collections.reverseOrder()); + + return classesFiles; + } + + private static boolean hasFile(String[] files, File file) + { + boolean found = false; + String filePath = file.getAbsolutePath(); + for(String f : files) + { + if(filePath.endsWith(f)) + { + found = true; + break; + } + } + + return found; + } + + @Override + protected void processFile(File file) throws IOException { + if(!hasFile(classesFiles, file)) + { + return; + } + + System.out.println("adding annotation to file "+file.getAbsolutePath()); + File tmpFile = new File(file.getParentFile(), file.getName()+".tmp"); + FileInputStream fis = null; + FileOutputStream fos = null; + + try + { + fis = new FileInputStream(file); + fos = new FileOutputStream(tmpFile); + addAnnotation(file.getName(), fis, fos); + } + finally + { + if(fis != null) + { + fis.close(); + } + if(fos != null) + { + fos.close(); + } + } + + if(!file.delete()) + { + throw new IOException("can delete "+file.getAbsolutePath()); + } + + if(!tmpFile.renameTo(file)) + { + throw new IOException("can rename "+tmpFile.getAbsolutePath()); + } + + //traceClass(file); + } + + /** + * Simple debug method that trace a class file. + * It can be used to visually check that the annotations has been + * properly added + * + * @param file + * @throws IOException + */ + private void traceClass(File file) throws IOException + { + System.out.println("trace for "+file.getAbsolutePath()); + FileInputStream fis = null; + try + { + fis = new FileInputStream(file); + + ClassReader cr = new ClassReader(fis); + TraceClassVisitor tcv = new TraceClassVisitor(new PrintWriter(System.out)); + cr.accept(tcv, + AbstractVisitor.getDefaultAttributes(), false); + } + finally + { + if(fis != null) + { + fis.close(); + } + } + } + + private void addAnnotation(String fileName, InputStream inputClass, OutputStream outputClass) throws BuildException { + ClassWriter cw = new ClassWriter(false); + try { + ClassReader cr = new ClassReader(inputClass); + cr.accept(new MarkerClassVisitor(cw), + AbstractVisitor.getDefaultAttributes(), false); + + byte[] b = cw.toByteArray(); + outputClass.write(b); + } catch (Exception ex) { + throw new BuildException("Unable to load class in file "+fileName); + } + } + + private static class MarkerClassVisitor extends ClassAdapter { + + public MarkerClassVisitor(ClassVisitor cv) { + super(cv); + } + + public void visit(int version, int access, String name, + String superName, String sourceFile, String[] interfaces) { + super.visit(org.objectweb.asm.Constants.V1_5, access, name, superName, + sourceFile, interfaces); + } + + @SuppressWarnings("unchecked") + public void visitEnd() { + String t = Type.getDescriptor(SharedStatics.class); + Annotation ann = new Annotation(t); + + RuntimeVisibleAnnotations attr = new RuntimeVisibleAnnotations(); + attr.annotations.add(ann); + cv.visitAttribute(attr); + + super.visitEnd(); + } + } +} Added: trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java (rev 0) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java 2007-08-20 20:44:06 UTC (rev 3399) @@ -0,0 +1,70 @@ +/* + * $Id: HeaderTask.java 3379 2007-08-04 10:19:57Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.ant.taskdefs; + +import java.io.*; +import java.util.ArrayList; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.FileSet; + +/** + * Abstract class for ant task that process one or more FileSet + * The concrete classes only have to implement the <i>process</i> method + * for doing the concrete work on a file. + * + * @author Fabien DUMINY (fduminy at jnode.org) + * + */ +abstract public class FileSetTask extends Task { + + private final ArrayList<FileSet> fileSets = new ArrayList<FileSet>(); + + public void addFileSet(FileSet fs) { + fileSets.add(fs); + } + + public void execute() throws BuildException { + // default implementation : simply iterate on all files + processFiles(); + } + + final protected void processFiles() throws BuildException + { + final Project project = getProject(); + try { + for (FileSet fs : fileSets) { + final String[] files = fs.getDirectoryScanner(project) + .getIncludedFiles(); + final File projectDir = fs.getDir(project); + for (String fname : files) { + processFile(new File(projectDir, fname)); + } + } + } catch (IOException e) { + throw new BuildException(e); + } + } + + abstract protected void processFile(File file) throws IOException; +} Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java 2007-08-15 18:21:25 UTC (rev 3398) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java 2007-08-20 20:44:06 UTC (rev 3399) @@ -30,16 +30,12 @@ /** * @author Ewout Prangsma (ep...@us...) */ -public class HeaderTask extends Task { +public class HeaderTask extends FileSetTask { - private final ArrayList<FileSet> fileSets = new ArrayList<FileSet>(); - private File headerFile; + private String[] header; private boolean update = false; - public void addFileSet(FileSet fs) { - fileSets.add(fs); - } private boolean compareHeader(String[] lines, String[] header) { final int linesCnt = lines.length; @@ -77,18 +73,8 @@ throw new BuildException("HeaderFile must be set"); } try { - final String[] header = readFile(headerFile); - - for (FileSet fs : fileSets) { - final String[] files = fs.getDirectoryScanner(getProject()) - .getIncludedFiles(); - final int fileCount = files.length; - for (int j = 0; j < fileCount; j++) { - final String fname = files[j]; - processFile(new File(fs.getDir(getProject()), fname), header); - } - - } + header = readFile(headerFile); + processFiles(); } catch (IOException ex) { throw new BuildException(ex); } @@ -102,7 +88,8 @@ return update; } - private void processFile(File file, String[] header) throws IOException { + @Override + protected void processFile(File file) throws IOException { final String[] inp = readFile(file); if (!compareHeader(inp, header)) { if (update) { Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/Native2AsciiTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/Native2AsciiTask.java 2007-08-15 18:21:25 UTC (rev 3398) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/Native2AsciiTask.java 2007-08-20 20:44:06 UTC (rev 3399) @@ -34,38 +34,16 @@ /** * @author Ewout Prangsma (ep...@us...) */ -public class Native2AsciiTask extends Task { +public class Native2AsciiTask extends FileSetTask { - private final ArrayList<FileSet> fileSets = new ArrayList<FileSet>(); - private boolean update = false; - public void addFileSet(FileSet fs) { - fileSets.add(fs); - } - - public void execute() throws BuildException { - try { - for (FileSet fs : fileSets) { - final String[] files = fs.getDirectoryScanner(getProject()) - .getIncludedFiles(); - final int fileCount = files.length; - for (int j = 0; j < fileCount; j++) { - final String fname = files[j]; - processFile(new File(fs.getDir(getProject()), fname)); - } - - } - } catch (IOException ex) { - throw new BuildException(ex); - } - } - public final boolean isUpdate() { return update; } - private void processFile(File file) throws IOException { + @Override + protected void processFile(File file) throws IOException { if (containsNonAscii(file)) { final File tmp = File.createTempFile("jnode", "n2a"); try { Modified: trunk/core/.classpath =================================================================== --- trunk/core/.classpath 2007-08-15 18:21:25 UTC (rev 3398) +++ trunk/core/.classpath 2007-08-20 20:44:06 UTC (rev 3399) @@ -24,6 +24,8 @@ <classpathentry kind="lib" path="lib/junit.jar"/> <classpathentry kind="lib" path="lib/mx4j.jar"/> <classpathentry kind="lib" path="lib/mmtk/mmtk.jar" sourcepath="D:/epr/cvswork/MMTk/src"/> + <classpathentry exported="true" kind="lib" path="lib/asm-1.5.3.jar"/> + <classpathentry exported="true" kind="lib" path="lib/asm-attrs-1.5.3.jar"/> <classpathentry kind="src" path="src/nanoxml"/> <classpathentry kind="lib" path="lib/mauve.jar"/> <classpathentry kind="output" path="build/classes"/> Modified: trunk/core/descriptors/org.objectweb.asm.xml =================================================================== --- trunk/core/descriptors/org.objectweb.asm.xml 2007-08-15 18:21:25 UTC (rev 3398) +++ trunk/core/descriptors/org.objectweb.asm.xml 2007-08-20 20:44:06 UTC (rev 3399) @@ -3,7 +3,7 @@ <plugin id="org.objectweb.asm" name="ASM classes" - version="1" + version="1.5.3" provider-name="Objectweb" provider-url="http://objectweb.org" license-name="bsd"> @@ -12,5 +12,8 @@ <library name="asm.jar"> <export name="org.objectweb.asm.*"/> </library> + <library name="asm-attrs.jar"> + <export name="org.objectweb.asm.*"/> + </library> </runtime> </plugin> \ No newline at end of file Added: trunk/core/lib/asm-1.5.3.jar =================================================================== (Binary files differ) Property changes on: trunk/core/lib/asm-1.5.3.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/core/lib/asm-attrs-1.5.3.jar =================================================================== (Binary files differ) Property changes on: trunk/core/lib/asm-attrs-1.5.3.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Deleted: trunk/core/lib/asm.jar =================================================================== (Binary files differ) Modified: trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java =================================================================== --- trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java 2007-08-15 18:21:25 UTC (rev 3398) +++ trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java 2007-08-20 20:44:06 UTC (rev 3399) @@ -38,7 +38,6 @@ This framework avoids the primary disadvantage of using reflection for this purpose, namely the loss of compile-time checking. */ -...@or...aredStatics //jnode public class SharedSecrets { private static final Unsafe unsafe = Unsafe.getUnsafe(); private static JavaUtilJarAccess javaUtilJarAccess; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-08-23 20:59:29
|
Revision: 3400 http://jnode.svn.sourceforge.net/jnode/?rev=3400&view=rev Author: lsantha Date: 2007-08-23 13:59:27 -0700 (Thu, 23 Aug 2007) Log Message: ----------- Reworked the patch sent by crawley for proclet support in jnode, to factor out proclets from the vm into org.jnode.shell.proclet package under the shell project. Modified Paths: -------------- trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java trunk/core/src/core/org/jnode/vm/VmSystem.java trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java trunk/fs/descriptors/org.jnode.fs.command.xml trunk/fs/descriptors/org.jnode.fs.xml trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml trunk/shell/descriptors/org.jnode.shell.xml trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java Added Paths: ----------- trunk/core/src/core/org/jnode/vm/IOContext.java trunk/core/src/core/org/jnode/vm/VmIOContext.java trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/proclet/ trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletException.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyInputStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProxyStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProxyStreamException.java Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -229,13 +229,11 @@ ClassWriter cw = new ClassWriter(false); try { ClassReader cr = new ClassReader(inputClass); - cr.accept(new MarkerClassVisitor(cw), - AbstractVisitor.getDefaultAttributes(), false); - + cr.accept(new MarkerClassVisitor(cw), AbstractVisitor.getDefaultAttributes(), false); byte[] b = cw.toByteArray(); outputClass.write(b); } catch (Exception ex) { - throw new BuildException("Unable to load class in file "+fileName); + throw new BuildException("Unable to load class in file "+fileName, ex); } } Added: trunk/core/src/core/org/jnode/vm/IOContext.java =================================================================== --- trunk/core/src/core/org/jnode/vm/IOContext.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/IOContext.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -0,0 +1,24 @@ +/* + * $Id$ + */ +package org.jnode.vm; + +import java.io.InputStream; +import java.io.PrintStream; + +/** + * @author Levente S\xE1ntha + */ +public interface IOContext { + void setGlobalInStream(InputStream in); + InputStream getGlobalInStream(); + void setGlobalOutStream(PrintStream out); + PrintStream getGlobalOutStream(); + void setGlobalErrStream(PrintStream err); + PrintStream getGlobalErrStream(); + void setSystemIn(InputStream in); + void setSystemOut(PrintStream out); + void setSystemErr(PrintStream err); + void enterContext(); + void exitContext(); +} Added: trunk/core/src/core/org/jnode/vm/VmIOContext.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmIOContext.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -0,0 +1,63 @@ +/* + * $Id$ + */ +package org.jnode.vm; + +import java.io.InputStream; +import java.io.PrintStream; + +/** + * @author Levente S\xE1ntha + */ +class VmIOContext implements IOContext { + private static InputStream globalInStream; + private static PrintStream globalOutStream; + private static PrintStream globalErrStream; + + public void setGlobalInStream(InputStream in) { + globalInStream = in; + } + + public void setGlobalOutStream(PrintStream out) { + globalOutStream = out; + } + + public PrintStream getGlobalOutStream() { + return globalOutStream; + } + + public void setGlobalErrStream(PrintStream err) { + globalErrStream = err; + } + + public PrintStream getGlobalErrStream(){ + return globalErrStream; + } + + public InputStream getGlobalInStream() { + return globalInStream; + } + + public void setSystemIn(InputStream in) { + globalInStream = in; + VmSystem.setStaticField(System.class, "in", in); + } + + public void setSystemOut(PrintStream out) { + globalOutStream = out; + VmSystem.setStaticField(System.class, "out", out); + } + + public void setSystemErr(PrintStream err) { + globalErrStream = err; + VmSystem.setStaticField(System.class, "err", err); + } + + public void enterContext() { + + } + + public void exitContext() { + + } +} Modified: trunk/core/src/core/org/jnode/vm/VmSystem.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -43,7 +43,6 @@ import org.jnode.system.ResourceNotFreeException; import org.jnode.system.ResourceOwner; import org.jnode.system.SimpleResourceOwner; -import org.jnode.util.SystemInputStream; import org.jnode.vm.annotation.Internal; import org.jnode.vm.annotation.KernelSpace; import org.jnode.vm.annotation.MagicPermission; @@ -213,6 +212,10 @@ if (bootOut == null) { bootOut = new SystemOutputStream(); bootOutStream = new PrintStream(bootOut, true); + //globalOutStream = globalErrStream = bootOutStream; + ioContext.setGlobalOutStream(bootOutStream); + ioContext.setGlobalErrStream(bootOutStream); + } return bootOutStream; } @@ -969,42 +972,50 @@ } /** - * Set in to a new InputStream. + * Set the effective System.in to a different InputStream. The actual behavior depends + * on whether we're in proclet mode or not. If we are, we set the appropriate proxied stream, + * to the new stream, depending on whether the current thread is a ProcletContext or not. + * Otherwise, we update the System.in field. * - * @param in - * the new InputStream + * @param in the new InputStream * @see #setIn(InputStream) */ + @PrivilegedActionPragma public static void setIn(InputStream in) { - SystemInputStream.getInstance().setIn(in); + ioContext.setSystemIn(in); } /** - * Set {@link #out}to a new PrintStream. + * Set the effective System.out to a different PrintStream. The actual behavior depends + * on whether we're in proclet mode or not. If we are, we set the appropriate proxied stream, + * to the new stream, depending on whether the current thread is a ProcletContext or not. + * Otherwise, we update the System.out field. * - * @param out - * the new PrintStream - * @see #setOut(PrintStream) + * @param out the new PrintStream + * @see java.lang.System#setOut(PrintStream) */ @PrivilegedActionPragma public static void setOut(PrintStream out) { - setStaticField(System.class, "out", out); + ioContext.setSystemOut(out); } /** - * Set err to a new PrintStream. + * Set the effective System.err to a different PrintStream. The actual behavior depends + * on whether we're in proclet mode or not. If we are, we set the appropriate proxied stream, + * to the new stream, depending on whether the current thread is a ProcletContext or not. + * Otherwise, we update the System.err field. * - * @param err - * the new PrintStream - * @see #setErr(PrintStream) + * @param err the new PrintStream + * @see java.lang.System#setErr(PrintStream) */ @PrivilegedActionPragma public static void setErr(PrintStream err) { - setStaticField(System.class, "err", err); + ioContext.setSystemErr(err); } + //todo protect this method from arbitrary access @PrivilegedActionPragma - private static void setStaticField(Class< ? > clazz, String fieldName, + public static void setStaticField(Class< ? > clazz, String fieldName, Object value) { final VmStaticField f = (VmStaticField) clazz.getVmClass().getField( fieldName); @@ -1020,4 +1031,56 @@ final Address ptr = VmMagic.getArrayData(staticsTable); ptr.store(ObjectReference.fromObject(value), offset); } + + //io context related + private static final IOContext vmIoContext = new VmIOContext(); + private static IOContext ioContext = vmIoContext; + + public static boolean hasVmIOContext(){ + return ioContext instanceof VmIOContext; + } + + + /** + * Get the current global (i.e. non-ProcletContext) flavor of System.err. + * + * @return the global 'err' stream. + */ + public static PrintStream getGlobalErrStream() { + return ioContext.getGlobalErrStream(); + } + + /** + * Get the current global (i.e. non-ProcletContext) flavor of System.in. + * + * @return the global 'in' stream. + */ + public static InputStream getGlobalInStream() { + return ioContext.getGlobalInStream(); + } + + /** + * Get the current global (i.e. non-ProcletContext) flavor of System.out. + * + * @return the global 'out' stream. + */ + public static PrintStream getGlobalOutStream() { + return ioContext.getGlobalOutStream(); + } + + public static void switchToExternalIOContext(IOContext context){ + if (hasVmIOContext()){ + ioContext = context; + context.enterContext(); + } + } + + public static void resetIOContext(){ + if (!hasVmIOContext()){ + ioContext.exitContext(); + ioContext = vmIoContext; + } else { + throw new RuntimeException("IO Context cannot be reset"); + } + } } Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -35,6 +35,7 @@ import org.jnode.driver.textscreen.TextScreen; import org.jnode.system.event.FocusEvent; import org.jnode.system.event.FocusListener; +import org.jnode.vm.VmSystem; import org.jnode.vm.isolate.VmIsolate; /** @@ -363,7 +364,7 @@ if (in instanceof FocusListener) { ((FocusListener) in).focusGained(event); } - if (claimSystemOutErr) { + if (claimSystemOutErr && VmSystem.hasVmIOContext()) { myIsolate.invokeAndWait(new Runnable() { public void run() { AccessController.doPrivileged(new PrivilegedAction<Object>() { @@ -385,7 +386,7 @@ if (in instanceof FocusListener) { ((FocusListener) in).focusLost(event); } - if (claimSystemOutErr) { + if (claimSystemOutErr && VmSystem.hasVmIOContext()) { myIsolate.invokeAndWait(new Runnable() { public void run() { savedOut = System.out; Modified: trunk/fs/descriptors/org.jnode.fs.command.xml =================================================================== --- trunk/fs/descriptors/org.jnode.fs.command.xml 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/fs/descriptors/org.jnode.fs.command.xml 2007-08-23 20:59:27 UTC (rev 3400) @@ -39,7 +39,8 @@ <permission class="java.net.SocketPermission" name="*:0-" actions="connect,resolve"/> <permission class="java.util.PropertyPermission" name="user.dir" actions="read,write"/> <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> - <permission class="java.net.NetPermission" name="specifyStreamHandler"/> + <permission class="java.net.NetPermission" name="specifyStreamHandler"/> + <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> </extension> </plugin> Modified: trunk/fs/descriptors/org.jnode.fs.xml =================================================================== --- trunk/fs/descriptors/org.jnode.fs.xml 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/fs/descriptors/org.jnode.fs.xml 2007-08-23 20:59:27 UTC (rev 3400) @@ -32,6 +32,7 @@ <permission class="java.net.SocketPermission" name="*:0-" actions="connect,resolve"/> <permission class="java.net.NetPermission" name="specifyStreamHandler"/> <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> + <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> </extension> </plugin> Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2007-08-23 20:59:27 UTC (rev 3400) @@ -23,6 +23,15 @@ </extension> <extension point="org.jnode.security.permissions"> - <permission class="java.util.PropertyPermission" name="jnode.prompt" actions="read"/> + <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/> + <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> + <permission class="java.lang.RuntimePermission" name="modifyThread"/> + <permission class="java.lang.RuntimePermission" name="setIO"/> + <permission class="java.net.SocketPermission" name="*" actions="resolve,listen,connect"/> + <permission class="java.net.SocketPermission" name="*:0-" actions="connect,resolve,listen"/> + <permission class="java.util.PropertyPermission" name="jnode.cmdline" actions="read"/> + <permission class="java.util.PropertyPermission" name="jnode.invoker" actions="read"/> + <permission class="java.util.PropertyPermission" name="jnode.prompt" actions="read,write"/> + <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/> </extension> </plugin> \ No newline at end of file Modified: trunk/shell/descriptors/org.jnode.shell.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.xml 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/shell/descriptors/org.jnode.shell.xml 2007-08-23 20:59:27 UTC (rev 3400) @@ -23,6 +23,7 @@ <export name="org.jnode.shell.help.*"/> <export name="org.jnode.shell.help.argument.*"/> <export name="org.jnode.shell.help.def.*"/> + <export name="org.jnode.shell.proclet.*"/> </library> </runtime> @@ -36,7 +37,9 @@ <permission class="java.net.SocketPermission" name="*" actions="resolve,listen,connect"/> <permission class="java.net.SocketPermission" name="*:0-" actions="connect,resolve,listen"/> <permission class="java.util.PropertyPermission" name="jnode.cmdline" actions="read"/> + <permission class="java.util.PropertyPermission" name="jnode.invoker" actions="read"/> <permission class="java.util.PropertyPermission" name="jnode.prompt" actions="read,write"/> + <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/> </extension> Added: trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -0,0 +1,281 @@ +/* + * $Id: ThreadCommandInvoker.java 3374 2007-08-02 18:15:27Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +import gnu.java.security.action.InvokeAction; + +import java.awt.event.KeyEvent; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; + +import org.jnode.driver.input.KeyboardEvent; +import org.jnode.driver.input.KeyboardListener; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.HelpException; +import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.vm.VmExit; + +/** + * User: Sam Reid Date: Dec 20, 2003 Time: 1:20:33 AM Copyright (c) Dec 20, 2003 + * by Sam Reid + * + * @author Sam Reid + * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... + */ +public abstract class AsyncCommandInvoker implements CommandInvoker, KeyboardListener { + + PrintStream err; + + CommandShell commandShell; + + static final Class[] MAIN_ARG_TYPES = new Class[] { String[].class }; + + static final Class[] EXECUTE_ARG_TYPES = new Class[] { + CommandLine.class, InputStream.class, PrintStream.class, + PrintStream.class }; + + static final String MAIN_METHOD = "main"; + + static final String EXECUTE_METHOD = "execute"; + + boolean blocking; + + Thread blockingThread; + + Thread threadProcess = null; + + String cmdName; + + public AsyncCommandInvoker(CommandShell commandShell) { + this.commandShell = commandShell; + this.err = commandShell.getErrorStream(); + commandShell.getConsole().addKeyboardListener(this);// listen for + // ctrl-c + } + + public void invoke(String cmdLineStr) { + commandShell.addCommandToHistory(cmdLineStr); + + InputStream inputStream = commandShell.getInputStream(); + InputStream nextInputStream = null; + PrintStream errStream = commandShell.getErrorStream(); + PrintStream outputStream = null; + boolean mustCloseOutputStream = false; + + CommandLine cmdLine; + Method method; + Runnable cr; + CommandInfo cmdInfo; + + String[] commands = cmdLineStr.split("\\|"); + String command; + ByteArrayOutputStream byteArrayOutputStream = null; + + for (int i = 0; i < commands.length; i++) { + command = commands[i].trim(); + cmdLine = new CommandLine(command); + + if (!cmdLine.hasNext()) + continue; + + cmdName = cmdLine.next(); + + try { + cmdInfo = commandShell.getCommandClass(cmdName); + + if (cmdLine.sendToOutFile()) { + File file = new File(cmdLine.getOutFileName()); + + try { + FileOutputStream fileOutputStream = new FileOutputStream( + file); + outputStream = new PrintStream(fileOutputStream); + mustCloseOutputStream = true; + } catch (SecurityException e) { + e.printStackTrace(); + return; // FIXME + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; // FIXME + } + } else if (i + 1 < commands.length) { + byteArrayOutputStream = new ByteArrayOutputStream(); + outputStream = new PrintStream(byteArrayOutputStream); + } else { + outputStream = commandShell.getOutputStream(); + } + + if (byteArrayOutputStream != null) { + nextInputStream = new ByteArrayInputStream( + byteArrayOutputStream.toByteArray()); + } + + if (nextInputStream != null) + inputStream = nextInputStream; + + CommandLine commandLine = null; + + if (inputStream.available() > 0) { + // FIXME we shouldn't do this. It consumes keyboard typeahead + // that should be delivered to the command's standard input!! + commandLine = new CommandLine(inputStream); + } else { + commandLine = cmdLine.getRemainder(); + } + + commandLine.setOutFileName(cmdLine.getOutFileName()); + try { + method = cmdInfo.getCommandClass().getMethod( + EXECUTE_METHOD, EXECUTE_ARG_TYPES); + + cr = createRunner(cmdInfo.getCommandClass(), method, + new Object[] { commandLine, inputStream, + outputStream, errStream }, + inputStream, outputStream, errStream); + } catch (NoSuchMethodException e) { + method = cmdInfo.getCommandClass().getMethod(MAIN_METHOD, + MAIN_ARG_TYPES); + cr = createRunner(cmdInfo.getCommandClass(), method, + new Object[] { cmdLine.getRemainder().toStringArray() }, + commandShell.getInputStream(), commandShell.getOutputStream(), + commandShell.getErrorStream()); + } + try { + if (cmdInfo.isInternal()) { + cr.run(); + } else { + threadProcess = createThread(cr, inputStream, + outputStream, errStream); + threadProcess.start(); + + this.blocking = true; + this.blockingThread = Thread.currentThread(); + while (blocking) { + try { + Thread.sleep(6000); + } catch (InterruptedException interrupted) { + if (!blocking) { + // interruption was okay, break normally. + } else { + // abnormal interruption + interrupted.printStackTrace(); + return; // FIXME + } + } + } + } + } catch (Exception ex) { + err.println("Exception in command"); + ex.printStackTrace(err); + return; // FIXME + } catch (Error ex) { + err.println("Fatal error in command"); + ex.printStackTrace(err); + return; // FIXME + } + } catch (NoSuchMethodException ex) { + err.println("Alias class has no main method " + cmdName); + return; // FIXME + } catch (ClassNotFoundException ex) { + err.println("Unknown alias class " + ex.getMessage()); + return; // FIXME + } catch (ClassCastException ex) { + err.println("Invalid command " + cmdName); + return; // FIXME + } catch (Exception ex) { + err.println("Unknown error: " + ex.getMessage()); + ex.printStackTrace(err); + return; // FIXME + } + finally { + if (mustCloseOutputStream) { + outputStream.close(); + mustCloseOutputStream = false; + } + } + } + + nextInputStream = null; + } + + abstract Thread createThread(Runnable cr, InputStream inputStream, + PrintStream outputStream, PrintStream errStream); + + public void keyPressed(KeyboardEvent ke) { + if (ke.isControlDown() && ke.getKeyCode() == KeyEvent.VK_C) { + doCtrlC(); + } + if (ke.isControlDown() && ke.getKeyCode() == KeyEvent.VK_Z) { + doCtrlZ(); + } + } + + private void doCtrlZ() { + System.err.println("ctrl-z: Returning focus to console. (" + cmdName + + " is still running)"); + unblock(); + } + + @SuppressWarnings("deprecation") + private void doCtrlC() { + System.err.println("ctrl-c: Returning focus to console. (" + cmdName + + " has been killed)"); + + if (threadProcess != null) { + unblock(); + + AccessController.doPrivileged(new PrivilegedAction(){ + public Object run() { + threadProcess.stop(new ThreadDeath()); + return null; + }}); + } + } + + final void unblock() { + blocking = false; + blockingThread.interrupt(); + } + + final boolean isBlocking() { + return blocking; + } + + public void keyReleased(KeyboardEvent event) { + } + + abstract Runnable createRunner(Class cx, Method method, Object[] args, + InputStream commandIn, PrintStream commandOut, PrintStream commandErr); + +} Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -131,6 +131,8 @@ private ThreadCommandInvoker threadCommandInvoker; private DefaultCommandInvoker defaultCommandInvoker; + + private ProcletCommandInvoker procletCommandInvoker; private boolean historyEnabled = true; @@ -148,13 +150,26 @@ } public void setThreadCommandInvoker() { - this.commandInvoker = threadCommandInvoker; + if (this.commandInvoker != threadCommandInvoker) { + err.println("Switched to thread invoker"); + this.commandInvoker = threadCommandInvoker; + } } public void setDefaultCommandInvoker() { - this.commandInvoker = defaultCommandInvoker; + if (this.commandInvoker != defaultCommandInvoker) { + err.println("Switched to default invoker"); + this.commandInvoker = defaultCommandInvoker; + } } + public void setProcletCommandInvoker() { + if (this.commandInvoker != procletCommandInvoker) { + err.println("Switched to proclet invoker"); + this.commandInvoker = procletCommandInvoker; + } + } + /** * Create a new instance * @@ -176,6 +191,7 @@ defaultCommandInvoker = new DefaultCommandInvoker(this); threadCommandInvoker = new ThreadCommandInvoker(this); + procletCommandInvoker = new ProcletCommandInvoker(this); this.commandInvoker = threadCommandInvoker; // default to separate this.console.addConsoleListener(this); // threads for commands. @@ -243,6 +259,18 @@ // Now become interactive while (!isExitted()) { try { + // Temporary mechanism for switching invokers + String invokerName = System.getProperty("jnode.invoker", ""); + if (invokerName.equalsIgnoreCase("default")) { + setDefaultCommandInvoker(); + } + else if (invokerName.equalsIgnoreCase("thread")) { + setThreadCommandInvoker(); + } + else if (invokerName.equalsIgnoreCase("proclet")) { + setProcletCommandInvoker(); + } + clearEof(); out.print(prompt()); readingCommand = true; Added: trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -0,0 +1,133 @@ +/* + * $Id: ThreadCommandInvoker.java 3374 2007-08-02 18:15:27Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +import gnu.java.security.action.InvokeAction; + +import java.io.InputStream; +import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedActionException; + +import org.jnode.shell.help.Help; +import org.jnode.shell.help.HelpException; +import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.shell.proclet.ProcletContext; +import org.jnode.shell.proclet.ProcletIOContext; +import org.jnode.vm.VmExit; +import org.jnode.vm.VmSystem; + +/** + * User: Sam Reid Date: Dec 20, 2003 Time: 1:20:33 AM Copyright (c) Dec 20, 2003 + * by Sam Reid + * + * @author Sam Reid + * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... + */ +public class ProcletCommandInvoker extends AsyncCommandInvoker { + + public ProcletCommandInvoker(CommandShell commandShell) { + super(commandShell); + } + + Thread createThread(Runnable cr, InputStream inputStream, + PrintStream outputStream, PrintStream errStream) { + VmSystem.switchToExternalIOContext(new ProcletIOContext()); + return ProcletContext.createProclet( + cr, null, null, + new Object[]{inputStream, outputStream, errStream}, + cmdName); + } + + Runnable createRunner(Class cx, Method method, Object[] args, InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { + return new CommandRunner(cx, method, args); + } + + class CommandRunner implements Runnable { + + private Class cx; + + Method method; + + Object[] args; + + boolean finished = false; + + public CommandRunner(Class cx, Method method, Object[] args) { + this.cx = cx; + this.method = method; + this.args = args; + } + + public void run() { + try { + try { + Object obj = null; + if(!Modifier.isStatic(method.getModifiers())) { + obj = cx.newInstance(); + } + AccessController.doPrivileged(new InvokeAction(method, + obj, args)); + } catch (PrivilegedActionException ex) { + throw ex.getException(); + } + if (!isBlocking()) { + // somebody already hit ctrl-c. + } else { + finished = true; + // System.err.println("Finished invocation, notifying + // blockers."); + // done with invoke, stop waiting for a ctrl-c + unblock(); + } + } catch (InvocationTargetException ex) { + Throwable tex = ex.getTargetException(); + if (tex instanceof SyntaxErrorException) { + try { + Help.getInfo(cx).usage(); + } catch (HelpException ex1) { + // Don't care + ex1.printStackTrace(); + } + err.println(tex.getMessage()); + unblock(); + } else if (tex instanceof VmExit) { + err.println(tex.getMessage()); + unblock(); + } else { + err.println("Exception in command"); + tex.printStackTrace(err); + unblock(); + } + } catch (Exception ex) { + err.println("Exception in command"); + ex.printStackTrace(err); + unblock(); + } + finished = true; + } + } +} Modified: trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2007-08-20 20:44:06 UTC (rev 3399) +++ trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -23,12 +23,6 @@ import gnu.java.security.action.InvokeAction; -import java.awt.event.KeyEvent; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -38,8 +32,6 @@ import java.security.PrivilegedAction; import java.security.PrivilegedActionException; -import org.jnode.driver.input.KeyboardEvent; -import org.jnode.driver.input.KeyboardListener; import org.jnode.shell.help.Help; import org.jnode.shell.help.HelpException; import org.jnode.shell.help.SyntaxErrorException; @@ -48,222 +40,28 @@ /** * User: Sam Reid Date: Dec 20, 2003 Time: 1:20:33 AM Copyright (c) Dec 20, 2003 * by Sam Reid - * + * * @author Sam Reid * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... */ -public class ThreadCommandInvoker implements CommandInvoker, KeyboardListener { +public class ThreadCommandInvoker extends AsyncCommandInvoker { - PrintStream err; - - CommandShell commandShell; - - private static final Class[] MAIN_ARG_TYPES = new Class[] { String[].class }; - - private static final Class[] EXECUTE_ARG_TYPES = new Class[] { - CommandLine.class, InputStream.class, PrintStream.class, - PrintStream.class }; - - private static final String MAIN_METHOD = "main"; - - private static final String EXECUTE_METHOD = "execute"; - - private boolean blocking; - - private Thread blockingThread; - - private Thread threadProcess = null; - - private String cmdName; - public ThreadCommandInvoker(CommandShell commandShell) { - this.commandShell = commandShell; - this.err = commandShell.getErrorStream(); - commandShell.getConsole().addKeyboardListener(this);// listen for - // ctrl-c + super(commandShell); } + + Thread createThread(Runnable cr, InputStream inputStream, PrintStream outputStream, PrintStream errStream) { + return new Thread(cr, cmdName); + } + + Runnable createRunner(Class cx, Method method, Object[] args, InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { + return new CommandRunner(cx, method, args, commandIn, commandOut, commandErr); + } - public void invoke(String cmdLineStr) { - commandShell.addCommandToHistory(cmdLineStr); - InputStream inputStream = commandShell.getInputStream(); - InputStream nextInputStream = null; - PrintStream errStream = commandShell.getErrorStream(); - PrintStream outputStream = null; - boolean mustCloseOutputStream = false; + class CommandRunner implements Runnable { - CommandLine cmdLine; - Method method; - CommandRunner cr; - CommandInfo cmdInfo; - - String[] commands = cmdLineStr.split("\\|"); - String command; - ByteArrayOutputStream byteArrayOutputStream = null; - - for (int i = 0; i < commands.length; i++) { - command = commands[i].trim(); - cmdLine = new CommandLine(command); - - if (!cmdLine.hasNext()) - continue; - - cmdName = cmdLine.next(); - - try { - cmdInfo = commandShell.getCommandClass(cmdName); - - try { - method = cmdInfo.getCommandClass().getMethod( - EXECUTE_METHOD, EXECUTE_ARG_TYPES); - - if (cmdLine.sendToOutFile()) { - File file = new File(cmdLine.getOutFileName()); - - try { - FileOutputStream fileOutputStream = new FileOutputStream( - file); - outputStream = new PrintStream(fileOutputStream); - mustCloseOutputStream = true; - } catch (SecurityException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } else if (i + 1 < commands.length) { - byteArrayOutputStream = new ByteArrayOutputStream(); - outputStream = new PrintStream(byteArrayOutputStream); - } else { - outputStream = commandShell.getOutputStream(); - } - - if (byteArrayOutputStream != null) { - nextInputStream = new ByteArrayInputStream( - byteArrayOutputStream.toByteArray()); - } - - if (nextInputStream != null) - inputStream = nextInputStream; - - CommandLine commandLine = null; - - if (inputStream.available() > 0) { - // FIXME we shouldn't do this. It consumes keyboard typeahead - // that should be delivered to the command's standard input!! - commandLine = new CommandLine(inputStream); - } else { - commandLine = cmdLine.getRemainder(); - } - - commandLine.setOutFileName(cmdLine.getOutFileName()); - - cr = new CommandRunner(cmdInfo.getCommandClass(), method, - new Object[] { commandLine, inputStream, - outputStream, errStream }, - inputStream, outputStream, errStream); - } catch (NoSuchMethodException e) { - method = cmdInfo.getCommandClass().getMethod(MAIN_METHOD, - MAIN_ARG_TYPES); - cr = new CommandRunner(cmdInfo.getCommandClass(), method, - new Object[] { cmdLine.getRemainder().toStringArray() }, - commandShell.getInputStream(), commandShell.getOutputStream(), - commandShell.getErrorStream()); - } - try { - if (cmdInfo.isInternal()) { - cr.run(); - } else { - threadProcess = new Thread(cr, cmdName); - threadProcess.start(); - - this.blocking = true; - this.blockingThread = Thread.currentThread(); - while (blocking) { - try { - Thread.sleep(6000); - } catch (InterruptedException interrupted) { - if (!blocking) { - // interruption was okay, break normally. - } else { - // abnormal interruption - interrupted.printStackTrace(); - } - } - } - } - } catch (Exception ex) { - err.println("Exception in command"); - ex.printStackTrace(err); - } catch (Error ex) { - err.println("Fatal error in command"); - ex.printStackTrace(err); - } - } catch (NoSuchMethodException ex) { - err.println("Alias class has no main method " + cmdName); - } catch (ClassNotFoundException ex) { - err.println("Unknown alias class " + ex.getMessage()); - } catch (ClassCastException ex) { - err.println("Invalid command " + cmdName); - } catch (Exception ex) { - err.println("Unknown error: " + ex.getMessage()); - ex.printStackTrace(err); - } - finally { - if (mustCloseOutputStream) { - outputStream.close(); - mustCloseOutputStream = false; - } - } - } - - nextInputStream = null; - } - - public void keyPressed(KeyboardEvent ke) { - if (ke.isControlDown() && ke.getKeyCode() == KeyEvent.VK_C) { - doCtrlC(); - } - if (ke.isControlDown() && ke.getKeyCode() == KeyEvent.VK_Z) { - doCtrlZ(); - } - } - - private void doCtrlZ() { - System.err.println("ctrl-z: Returning focus to console. (" + cmdName - + " is still running)"); - unblock(); - } - - @SuppressWarnings("deprecation") - private void doCtrlC() { - System.err.println("ctrl-c: Returning focus to console. (" + cmdName - + " has been killed)"); - - if (threadProcess != null) { - unblock(); - - AccessController.doPrivileged(new PrivilegedAction(){ - public Object run() { - threadProcess.stop(new ThreadDeath()); - return null; - }}); - } - } - - final void unblock() { - blocking = false; - blockingThread.interrupt(); - } - - final boolean isBlocking() { - return blocking; - } - - public void keyReleased(KeyboardEvent event) { - } - - class CommandRunner implements Runnable { - private Class cx; Method method; @@ -342,6 +140,5 @@ } finished = true; } - } } Added: trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -0,0 +1,265 @@ +/* + * $Id$ + * + * JNode.org + * Copyright (C) 2003-2007 JNode.org + */ + +/* PrintStream.java -- OutputStream for printing output + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package org.jnode.shell.proclet; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.Locale; +import java.util.Formatter; + +import gnu.classpath.SystemProperties; + + +/** + * This class prints provides infrastructure for PrintStream proxies + */ +public abstract class AbstractProxyPrintStream extends PrintStream +implements ProxyStream<PrintStream> +{ + /* Note: the implementation is mostly copied from PrintStream. Blame this on limitations + * of the afore-mentioned class's specification ... */ + private static PrintStream nullStream; + private static final char[] line_separator = + SystemProperties.getProperty("line.separator", "\n").toCharArray(); + + private boolean error_occurred = false; + + + public AbstractProxyPrintStream() { + super((OutputStream) null); + } + + public boolean checkError() { + flush(); + return error_occurred || effectiveOutput().checkError(); + } + + protected void setError() { + error_occurred = true; + } + + protected abstract PrintStream effectiveOutput(); + + public void close() { + PrintStream eo = effectiveOutput(); + eo.flush(); + eo.close(); + } + + public void flush() { + effectiveOutput().flush(); + } + + protected synchronized void print (String str, boolean println) { + PrintStream eo = effectiveOutput(); + writeChars(eo, str, 0, str.length()); + if (println) { + writeChars(eo, line_separator, 0, line_separator.length); + } + flush(); + } + + protected synchronized void print (char[] chars, int pos, int len, + boolean println) { + PrintStream eo = effectiveOutput(); + writeChars(eo, chars, pos, len); + if (println) { + writeChars(eo, line_separator, 0, line_separator.length); + } + flush(); + } + + protected void writeChars(PrintStream eo, char[] buf, int offset, int count) { + // This is inefficient, but it ensures that we use the encoding + // scheme of the effective stream + eo.print(new String(buf, offset, count)); + } + + protected void writeChars(PrintStream eo, String str, int offset, int count) { + // This is inefficient, but it ensures that we use the encoding + // scheme of the effective stream + eo.print(str.substring(offset, offset + count)); + } + + public void print (boolean bool) { + print(String.valueOf(bool), false); + } + + public void print (int inum) { + print(String.valueOf(inum), false); + } + + public void print (long lnum) { + print(String.valueOf(lnum), false); + } + + public void print (float fnum) { + print(String.valueOf(fnum), false); + } + + public void print (double dnum) { + print(String.valueOf(dnum), false); + } + + public void print (Object obj) { + print(obj == null ? "null" : obj.toString(), false); + } + + public void print (String str) { + print(str == null ? "null" : str, false); + } + + public synchronized void print (char ch) { + print(new char[]{ch}, 0, 1, false); + } + + public void print (char[] charArray) { + print(charArray, 0, charArray.length, false); + } + + public void println() { + print(line_separator, 0, line_separator.length, false); + } + + public void println (boolean bool) { + print(String.valueOf(bool), true); + } + + public void println (int inum) { + print(String.valueOf(inum), true); + } + + public void println (long lnum) { + print(String.valueOf(lnum), true); + } + + public void println (float fnum) { + print(String.valueOf(fnum), true); + } + + public void println (double dnum) { + print(String.valueOf(dnum), true); + } + + public void println (Object obj) { + print(obj == null ? "null" : obj.toString(), true); + } + + public void println (String str) { + print (str == null ? "null" : str, true); + } + + public synchronized void println (char ch) { + print(new char[]{ch}, 0, 1, true); + } + + public void println (char[] charArray) { + print(charArray, 0, charArray.length, true); + } + + public void write (int oneByte) { + effectiveOutput().write (oneByte & 0xff); + if (oneByte == '\n') { + flush(); + } + } + + public void write (byte[] buffer, int offset, int len) { + effectiveOutput().write (buffer, offset, len); + flush(); + } + + public PrintStream append(char c) { + print(c); + return this; + } + + public PrintStream append(CharSequence cs) { + print(cs == null ? "null" : cs.toString()); + return this; + } + + public PrintStream append(CharSequence cs, int start, int end) { + print(cs == null ? "null" : cs.subSequence(start, end).toString()); + return this; + } + + public PrintStream printf(String format, Object... args) { + return format(format, args); + } + + public PrintStream printf(Locale locale, String format, Object... args) { + return format(locale, format, args); + } + + public PrintStream format(String format, Object... args) { + return format(Locale.getDefault(), format, args); + } + + public PrintStream format(Locale locale, String format, Object... args) { + Formatter f = new Formatter(this, locale); + f.format(format, args); + return this; + } + + /** + * Return a print stream that will "deep six" any output. + */ + protected static synchronized PrintStream getNullPrintStream() { + if (nullStream == null) { + nullStream = new PrintStream( + new OutputStream() { + @Override + public void write(int b) throws IOException { + } + }, + false); + } + return nullStream; + } +} Added: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-08-23 20:59:27 UTC (rev 3400) @@ -0,0 +1,307 @@ +package org.jnode.shell.proclet; + +import java.io.Closeable; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.jnode.vm.VmSystem; +import org.jnode.vm.VmExit; + + +/** + * This class implements the proclet-specific state used in the JNode proclet mechanism. + * <p> + * A 'proclet' is group of threads that has its own version of the system properties, streams + * and environment and superficially behaves as if it was a self-contained application. + * + * @author cr...@jn... + */ +public class ProcletContext extends ThreadGroup { + private Properties properties; + private Object[] streams; + private Map<String, String> environment; + private int threadCount; + private final int pid; + + private int exitStatus = 0; + private Throwable uncaughtException; + + private static int nextPid = 1; + + private ProcletContext(ThreadGroup parent, Properties properties, + Map<String, String> environment, Object[] streams) + throws ProcletException { + super(parent, nextProcletName()); + ProcletContext parentContext = getParentContext(parent); + if (properties == null) { + if (parentContext != null) { + properties = parentContext.properties; + } + if (properties == null) { + properties = AccessController.doPrivileged( + new PrivilegedAction<Properties>() { + public Properties run() { + return System.getProperties(); + } + }); + } + properties = (Properties) properties.clone(); + } + if (streams == null) { + if (parentContext != null) { + streams = parentContext.streams; + } + if (streams == null) { + try { + streams = new Object[]{ + resolve(System.in), resolve(System.out), resolve(System.err)}; + } + catch (ProxyStreamException ex) { + throw new ProcletException("Broken streams", ex); + } + } + else { + streams = (Object[]) streams.clone(); + } + } + if (environment == null) { + if (parentContext != null) { + environment = new HashMap<String, String>(parentContext.environment); + } + else { + environment = new HashMap<String, String>(); + } + } + this.environment = environment; + this.properties = properties; + this.streams = streams; + this.pid = extractPid(getName()); + } + + private Closeable resolve(Closeable stream) throws ProxyStreamException { + return (stream instanceof ProxyStream) ? + ((ProxyStream) stream).getProxiedStream() : stream; + } + + /** + * Get the proclet's unique PID. This value uniquely identifies the proclet. + * @return the pid + */ + public int getPid() { + return pid; + } + + public synchronized Map<String, String> getEnvironment() { + return environment; + } + + public synchronized Properties getProperties() { + return properties; + } + + /** + * Set the stream object that corresponds to a given 'fd'. + * + * @param fd a non-negative index into the streams vector. + * @param stream the stream object to set. + */ + synchronized void setStream(int fd, Object stream) { + if (stream instanceof ProcletProxyStream) { + throw new IllegalArgumentException("stream is a proclet proxy stream"); + } + if (fd < 0) { + throw new IllegalArgumentException("fd is negative"); + } + if (fd >= streams.length) { + Object[] tmp = new Object[fd + 1]; + System.arraycopy(streams, 0, tmp, 0, streams.length); + streams = tmp; + } + streams[fd] = stream; + } + + /** + * Get the stream object that corresponds to a given 'fd'. + * + * @param fd a non-negative index into the streams vector. + * @return the stream object, or <code>null</code> + */ + public synchronized Object getStream(int fd) { + if (fd < 0) { + throw new IllegalArgumentException("fd is negative"); + } + else if (fd > streams.length) { + return null; + } + else { + return streams[fd]; + } + } + + public synchronized void setProperties(Properties properties) { + this.properties = properties; + } + + /** + * Get the ProcletContext for the current thread. + * + * @return the context, or <code>null</code> if the current thread + * is not a member of a proclet. + */ + public static ProcletContext currentProcletContext() { + if (!VmSystem.hasVmIOContext()) { + return getParentContext(Thread.currentThread().getThreadGroup()); + } + else { + return null; + } + } + + /** + * Get the ProcletContext for a thread group. This is the thread group + * itself, or the innermost enclosing parent thread group that is a + * ProcletContect instance. + * + * @param threadGroup the starting thread group + * @return the context, or <code>null</code> if the thread group does + * not have an ancestor that is a ProcletContex. + */ + private static ProcletContext getParentContext(ThreadGroup threadGroup) { + while (threadGroup != null) { + if (threadGroup instanceof ProcletContext) { + return (ProcletContext) threadGroup; + } + threadGroup = threadGroup.getParent(); + } + return null; + } + + /** + * Create a new Thread as the initial thread for a new proclet. The + * proclet context will be initialised from the current thread's + * proclet context (if it exists) or from {@link java.lang.System#in}, + * {@link java.lang.System#out}, {@link java.lang.System#err}, and + * {@link java.lang.System#getProperties()}. + * + * @param target the new Thread's Runnable object. + * @return the new Thread + */ + public static Thread createProclet(Runnable target) { + return createProclet(target, null, null, null, null, 0); + } + + /** + * Create a new Thread as the initial thread for a new proclet, using a + * supplied set of system properties, and environment and streams vector. + * If any of these is null, the corresponding proclet context will be + * initialised from the current thread's proclet context (if it exists) + * or from {@link java.lang.System#in}, {@link java.lang.System#out}, + * {@link java.lang.System#err}, and {@link java.lang.System#getProperties()}. + * + * @param properties the proclet's system properties, or <code>null</code>. + * @param environment the proclet's environment, or <code>null</code>. + * @param streams the proclet's streams vector, or <code>null</code>. + * @param target the new Thread's Runnable object. + * @return the new Thread + */ + public static Thread createProclet(Runnable target, Properties properties, + Map<String, String> environment, Object[] streams) { + return createProclet(target, properties, environment, streams, null, 0); + } + + /** + * Create a new Thread as the initial thread for a new proclet, using a + * supplied set of system properties, and environment and streams vector. + * If any of these is null, the corresponding proclet context will be + * initialised from the current thread's proclet context (if it exists) + * or from {@link java.lang.System#in}, {@link java.lang.System#out}, + * {@link java.lang.System#err}, and {@link java.lang.System#getProperties()}. + * This overload also supplies an optional thread name. + * + * @param properties the proclet's system properties, or <code>null</code>. + * @param environment the proclet's environment, or <code>null</code>. + * @param streams the proclet's streams vector, or <code>null</code>. + * @param target the new Thread's Runnable object. + * @param name an optional Thread name. + * @return the new Thread + */ + public static Thread createProclet(Runnable target, Properties properties, + Map<String, String> environment, Object[] streams, String name) { + return... [truncated message content] |
From: <ls...@us...> - 2007-08-24 16:36:01
|
Revision: 3401 http://jnode.svn.sourceforge.net/jnode/?rev=3401&view=rev Author: lsantha Date: 2007-08-24 09:35:54 -0700 (Fri, 24 Aug 2007) Log Message: ----------- Disabled the oj-annotate task in build by FabienD since it is still buggy. Modified Paths: -------------- trunk/all/build.xml trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2007-08-23 20:59:27 UTC (rev 3400) +++ trunk/all/build.xml 2007-08-24 16:35:54 UTC (rev 3401) @@ -166,7 +166,7 @@ </target> <!-- Assemble all plugins --> - <target name="assemble-plugins" depends="assemble-projects,openjdk-annotate"> + <target name="assemble-plugins" depends="assemble-projects"> <!-- Now assemble all plugins --> <taskdef name="plugin" classname="org.jnode.build.PluginTask" classpathref="cp-jnode"/> <plugin todir="${plugins.dir}" tmpdir="${build.dir}/tmp/plugins" pluginDir="${descriptors.dir}"> Modified: trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java =================================================================== --- trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java 2007-08-23 20:59:27 UTC (rev 3400) +++ trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java 2007-08-24 16:35:54 UTC (rev 3401) @@ -28,6 +28,7 @@ import java.util.jar.JarFile; import java.io.Console; import java.io.File; +import org.jnode.vm.annotation.SharedStatics; /** A repository of "shared secrets", which are a mechanism for calling implementation-private methods in another package without @@ -38,6 +39,7 @@ This framework avoids the primary disadvantage of using reflection for this purpose, namely the loss of compile-time checking. */ +@SharedStatics public class SharedSecrets { private static final Unsafe unsafe = Unsafe.getUnsafe(); private static JavaUtilJarAccess javaUtilJarAccess; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-08-26 11:11:51
|
Revision: 3433 http://jnode.svn.sourceforge.net/jnode/?rev=3433&view=rev Author: fduminy Date: 2007-08-26 00:53:04 -0700 (Sun, 26 Aug 2007) Log Message: ----------- openjdk integration Modified Paths: -------------- trunk/all/conf/full-plugin-list.xml trunk/core/.classpath Added Paths: ----------- trunk/core/descriptors/com.sun.tools.jdi.xml trunk/core/src/openjdk/com/com/sun/jdi/ trunk/core/src/openjdk/com/com/sun/jdi/AbsentInformationException.java trunk/core/src/openjdk/com/com/sun/jdi/Accessible.java trunk/core/src/openjdk/com/com/sun/jdi/ArrayReference.java trunk/core/src/openjdk/com/com/sun/jdi/ArrayType.java trunk/core/src/openjdk/com/com/sun/jdi/BooleanType.java trunk/core/src/openjdk/com/com/sun/jdi/BooleanValue.java trunk/core/src/openjdk/com/com/sun/jdi/Bootstrap.java trunk/core/src/openjdk/com/com/sun/jdi/ByteType.java trunk/core/src/openjdk/com/com/sun/jdi/ByteValue.java trunk/core/src/openjdk/com/com/sun/jdi/CharType.java trunk/core/src/openjdk/com/com/sun/jdi/CharValue.java trunk/core/src/openjdk/com/com/sun/jdi/ClassLoaderReference.java trunk/core/src/openjdk/com/com/sun/jdi/ClassNotLoadedException.java trunk/core/src/openjdk/com/com/sun/jdi/ClassNotPreparedException.java trunk/core/src/openjdk/com/com/sun/jdi/ClassObjectReference.java trunk/core/src/openjdk/com/com/sun/jdi/ClassType.java trunk/core/src/openjdk/com/com/sun/jdi/DoubleType.java trunk/core/src/openjdk/com/com/sun/jdi/DoubleValue.java trunk/core/src/openjdk/com/com/sun/jdi/Field.java trunk/core/src/openjdk/com/com/sun/jdi/FloatType.java trunk/core/src/openjdk/com/com/sun/jdi/FloatValue.java trunk/core/src/openjdk/com/com/sun/jdi/IncompatibleThreadStateException.java trunk/core/src/openjdk/com/com/sun/jdi/InconsistentDebugInfoException.java trunk/core/src/openjdk/com/com/sun/jdi/IntegerType.java trunk/core/src/openjdk/com/com/sun/jdi/IntegerValue.java trunk/core/src/openjdk/com/com/sun/jdi/InterfaceType.java trunk/core/src/openjdk/com/com/sun/jdi/InternalException.java trunk/core/src/openjdk/com/com/sun/jdi/InvalidCodeIndexException.java trunk/core/src/openjdk/com/com/sun/jdi/InvalidLineNumberException.java trunk/core/src/openjdk/com/com/sun/jdi/InvalidStackFrameException.java trunk/core/src/openjdk/com/com/sun/jdi/InvalidTypeException.java trunk/core/src/openjdk/com/com/sun/jdi/InvocationException.java trunk/core/src/openjdk/com/com/sun/jdi/JDIPermission.java trunk/core/src/openjdk/com/com/sun/jdi/LocalVariable.java trunk/core/src/openjdk/com/com/sun/jdi/Locatable.java trunk/core/src/openjdk/com/com/sun/jdi/Location.java trunk/core/src/openjdk/com/com/sun/jdi/LongType.java trunk/core/src/openjdk/com/com/sun/jdi/LongValue.java trunk/core/src/openjdk/com/com/sun/jdi/Method.java trunk/core/src/openjdk/com/com/sun/jdi/Mirror.java trunk/core/src/openjdk/com/com/sun/jdi/MonitorInfo.java trunk/core/src/openjdk/com/com/sun/jdi/NativeMethodException.java trunk/core/src/openjdk/com/com/sun/jdi/ObjectCollectedException.java trunk/core/src/openjdk/com/com/sun/jdi/ObjectReference.java trunk/core/src/openjdk/com/com/sun/jdi/PathSearchingVirtualMachine.java trunk/core/src/openjdk/com/com/sun/jdi/PrimitiveType.java trunk/core/src/openjdk/com/com/sun/jdi/PrimitiveValue.java trunk/core/src/openjdk/com/com/sun/jdi/ReferenceType.java trunk/core/src/openjdk/com/com/sun/jdi/ShortType.java trunk/core/src/openjdk/com/com/sun/jdi/ShortValue.java trunk/core/src/openjdk/com/com/sun/jdi/StackFrame.java trunk/core/src/openjdk/com/com/sun/jdi/StringReference.java trunk/core/src/openjdk/com/com/sun/jdi/ThreadGroupReference.java trunk/core/src/openjdk/com/com/sun/jdi/ThreadReference.java trunk/core/src/openjdk/com/com/sun/jdi/Type.java trunk/core/src/openjdk/com/com/sun/jdi/TypeComponent.java trunk/core/src/openjdk/com/com/sun/jdi/VMCannotBeModifiedException.java trunk/core/src/openjdk/com/com/sun/jdi/VMDisconnectedException.java trunk/core/src/openjdk/com/com/sun/jdi/VMMismatchException.java trunk/core/src/openjdk/com/com/sun/jdi/VMOutOfMemoryException.java trunk/core/src/openjdk/com/com/sun/jdi/Value.java trunk/core/src/openjdk/com/com/sun/jdi/VirtualMachine.java trunk/core/src/openjdk/com/com/sun/jdi/VirtualMachineManager.java trunk/core/src/openjdk/com/com/sun/jdi/VoidType.java trunk/core/src/openjdk/com/com/sun/jdi/VoidValue.java trunk/core/src/openjdk/com/com/sun/jdi/connect/ trunk/core/src/openjdk/com/com/sun/jdi/connect/AttachingConnector.java trunk/core/src/openjdk/com/com/sun/jdi/connect/Connector.java trunk/core/src/openjdk/com/com/sun/jdi/connect/IllegalConnectorArgumentsException.java trunk/core/src/openjdk/com/com/sun/jdi/connect/LaunchingConnector.java trunk/core/src/openjdk/com/com/sun/jdi/connect/ListeningConnector.java trunk/core/src/openjdk/com/com/sun/jdi/connect/Transport.java trunk/core/src/openjdk/com/com/sun/jdi/connect/TransportTimeoutException.java trunk/core/src/openjdk/com/com/sun/jdi/connect/VMStartException.java trunk/core/src/openjdk/com/com/sun/jdi/connect/package.html trunk/core/src/openjdk/com/com/sun/jdi/connect/spi/ trunk/core/src/openjdk/com/com/sun/jdi/connect/spi/ClosedConnectionException.java trunk/core/src/openjdk/com/com/sun/jdi/connect/spi/Connection.java trunk/core/src/openjdk/com/com/sun/jdi/connect/spi/TransportService.java trunk/core/src/openjdk/com/com/sun/jdi/connect/spi/package.html trunk/core/src/openjdk/com/com/sun/jdi/doc-files/ trunk/core/src/openjdk/com/com/sun/jdi/doc-files/signature.html trunk/core/src/openjdk/com/com/sun/jdi/event/ trunk/core/src/openjdk/com/com/sun/jdi/event/AccessWatchpointEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/BreakpointEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/ClassPrepareEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/ClassUnloadEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/Event.java trunk/core/src/openjdk/com/com/sun/jdi/event/EventIterator.java trunk/core/src/openjdk/com/com/sun/jdi/event/EventQueue.java trunk/core/src/openjdk/com/com/sun/jdi/event/EventSet.java trunk/core/src/openjdk/com/com/sun/jdi/event/ExceptionEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/LocatableEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/MethodEntryEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/MethodExitEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/ModificationWatchpointEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/MonitorContendedEnterEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/MonitorContendedEnteredEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/MonitorWaitEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/MonitorWaitedEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/StepEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/ThreadDeathEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/ThreadStartEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/VMDeathEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/VMDisconnectEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/VMStartEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/WatchpointEvent.java trunk/core/src/openjdk/com/com/sun/jdi/event/package.html trunk/core/src/openjdk/com/com/sun/jdi/package.html trunk/core/src/openjdk/com/com/sun/jdi/request/ trunk/core/src/openjdk/com/com/sun/jdi/request/AccessWatchpointRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/BreakpointRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/ClassPrepareRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/ClassUnloadRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/DuplicateRequestException.java trunk/core/src/openjdk/com/com/sun/jdi/request/EventRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/EventRequestManager.java trunk/core/src/openjdk/com/com/sun/jdi/request/ExceptionRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/InvalidRequestStateException.java trunk/core/src/openjdk/com/com/sun/jdi/request/MethodEntryRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/MethodExitRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/ModificationWatchpointRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/MonitorContendedEnterRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/MonitorContendedEnteredRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/MonitorWaitRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/MonitorWaitedRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/StepRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/ThreadDeathRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/ThreadStartRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/VMDeathRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/WatchpointRequest.java trunk/core/src/openjdk/com/com/sun/jdi/request/package.html trunk/core/src/openjdk/com/com/sun/tools/attach/ trunk/core/src/openjdk/com/com/sun/tools/attach/AgentInitializationException.java trunk/core/src/openjdk/com/com/sun/tools/attach/AgentLoadException.java trunk/core/src/openjdk/com/com/sun/tools/attach/AttachNotSupportedException.java trunk/core/src/openjdk/com/com/sun/tools/attach/AttachPermission.java trunk/core/src/openjdk/com/com/sun/tools/attach/VirtualMachine.java trunk/core/src/openjdk/com/com/sun/tools/attach/VirtualMachineDescriptor.java trunk/core/src/openjdk/com/com/sun/tools/attach/package.html trunk/core/src/openjdk/com/com/sun/tools/attach/spi/ trunk/core/src/openjdk/com/com/sun/tools/attach/spi/AttachProvider.java trunk/core/src/openjdk/com/com/sun/tools/attach/spi/package.html trunk/core/src/openjdk/com/com/sun/tools/jdi/JDWP.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractCommandNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractGroupNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractNamedNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractSimpleNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractSimpleTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractTypeListNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AbstractTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/AltNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ArrayObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ArrayRegionTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ArrayTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/BooleanTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ByteTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ClassLoaderObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ClassObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ClassTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/CommandNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/CommandSetNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/CommentNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ConstantNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ConstantSetNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/Context.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ErrorNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ErrorSetNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/EventNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/FieldTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/FrameTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/GroupNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/IntTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/InterfaceTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/LocationTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/LongTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/Main.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/MethodTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/NameNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/NameValueNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/Node.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/OutNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/Parse.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ReferenceIDTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ReferenceTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/RepeatNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ReplyNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/RootNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/SelectNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/StringObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/StringTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/TaggedObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ThreadGroupObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ThreadObjectTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/TypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/UntaggedValueTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/ValueTypeNode.java trunk/core/src/openjdk/com/com/sun/tools/jdwpgen/jdwp.spec Modified: trunk/all/conf/full-plugin-list.xml =================================================================== --- trunk/all/conf/full-plugin-list.xml 2007-08-25 20:54:26 UTC (rev 3432) +++ trunk/all/conf/full-plugin-list.xml 2007-08-26 07:53:04 UTC (rev 3433) @@ -10,6 +10,7 @@ <plugin id="sun.tools"/> <plugin id="javax.ext.tools"/> <plugin id="com.sun.tools.javac"/> + <plugin id="com.sun.tools.jdi"/> <plugin id="org.jnode.install"/> Modified: trunk/core/.classpath =================================================================== --- trunk/core/.classpath 2007-08-25 20:54:26 UTC (rev 3432) +++ trunk/core/.classpath 2007-08-26 07:53:04 UTC (rev 3433) @@ -7,7 +7,7 @@ <classpathentry kind="src" path="src/classpath/gnu"/> <classpathentry kind="src" path="src/openjdk/java"/> <classpathentry kind="src" path="src/openjdk/javax"/> - <classpathentry kind="src" path="src/openjdk/sun"/> + <classpathentry excluding="**/*-template.java" kind="src" path="src/openjdk/sun"/> <classpathentry kind="src" path="src/classpath/tools"/> <classpathentry kind="src" path="src/classpath/java"/> <classpathentry kind="src" path="src/classpath/javax"/> Added: trunk/core/descriptors/com.sun.tools.jdi.xml =================================================================== --- trunk/core/descriptors/com.sun.tools.jdi.xml (rev 0) +++ trunk/core/descriptors/com.sun.tools.jdi.xml 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plugin SYSTEM "jnode.dtd"> + +<plugin id="com.sun.tools.jdi" + name="The Java Debugger Interface from Sun" + version="@VERSION@" + plugin-version="@VERSION@" + provider-name="Sun Microsystems" + provider-url="http://sun.com" + license-name="classpath"> + + <runtime> + <library name="jnode-core.jar"> + <export name="com.sun.jdi.*"/> + <export name="com.sun.jdi.connect.*"/> + <export name="com.sun.jdi.connect.spi.*"/> + <export name="com.sun.jdi.event.*"/> + <export name="com.sun.jdi.request.*"/> + + <export name="com.sun.tools.attach.*"/> + <export name="com.sun.tools.attach.spi.*"/> + <export name="com.sun.tools.jdi.*"/> + </library> + </runtime> +</plugin> Added: trunk/core/src/openjdk/com/com/sun/jdi/AbsentInformationException.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/AbsentInformationException.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/AbsentInformationException.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,45 @@ +/* + * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Thrown to indicate line number or variable information is not available. + * + * @author Gordon Hirsch + * @since 1.3 + */ +public class AbsentInformationException extends Exception +{ + public AbsentInformationException() + { + super(); + } + + public AbsentInformationException(String s) + { + super(s); + } +} Added: trunk/core/src/openjdk/com/com/sun/jdi/Accessible.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/Accessible.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/Accessible.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,110 @@ +/* + * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Provides information on the accessibility of a type or type component. + * Mirrors for program elements which allow an + * an access specifier (private, protected, public) provide information + * on that part of the declaration through this interface. + * + * @author Robert Field + * @author Gordon Hirsch + * @author James McIlree + * @since 1.3 + */ +public interface Accessible { + + /** + * Returns the Java<sup><font size=-2>TM</font></sup> + * programming language modifiers, encoded in an integer. + * <p> + * The modifier encodings are defined in the + * <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual Machine + * Specification</a>, in the <code>access_flag</code> tables for + * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734">classes</a>, + * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#88358">fields</a>, and + * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75568">methods</a>. + */ + public int modifiers(); + + /** + * Determines if this object mirrors a private item. + * For {@link ArrayType}, the return value depends on the + * array component type. For primitive arrays the return value + * is always false. For object arrays, the return value is the + * same as would be returned for the component type. + * For primitive classes, such as {@link java.lang.Integer#TYPE}, + * the return value is always false. + * + * @return <code>true</code> for items with private access; + * <code>false</code> otherwise. + */ + boolean isPrivate(); + + /** + * Determines if this object mirrors a package private item. + * A package private item is declared with no access specifier. + * For {@link ArrayType}, the return value depends on the + * array component type. For primitive arrays the return value + * is always false. For object arrays, the return value is the + * same as would be returned for the component type. + * For primitive classes, such as {@link java.lang.Integer#TYPE}, + * the return value is always false. + * + * @return <code>true</code> for items with package private access; + * <code>false</code> otherwise. + */ + boolean isPackagePrivate(); + + /** + * Determines if this object mirrors a protected item. + * For {@link ArrayType}, the return value depends on the + * array component type. For primitive arrays the return value + * is always false. For object arrays, the return value is the + * same as would be returned for the component type. + * For primitive classes, such as {@link java.lang.Integer#TYPE}, + * the return value is always false. + * + * @return <code>true</code> for items with private access; + * <code>false</code> otherwise. + */ + boolean isProtected(); + + /** + * Determines if this object mirrors a public item. + * For {@link ArrayType}, the return value depends on the + * array component type. For primitive arrays the return value + * is always true. For object arrays, the return value is the + * same as would be returned for the component type. + * For primitive classes, such as {@link java.lang.Integer#TYPE}, + * the return value is always true. + * + * @return <code>true</code> for items with public access; + * <code>false</code> otherwise. + */ + boolean isPublic(); +} Added: trunk/core/src/openjdk/com/com/sun/jdi/ArrayReference.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/ArrayReference.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/ArrayReference.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,210 @@ +/* + * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +import java.util.List; + +/** + * Provides access to an array object and its components in the target VM. + * Each array component is mirrored by a {@link Value} object. + * The array components, in aggregate, are placed in {@link java.util.List} + * objects instead of arrays for consistency with the rest of the API and + * for interoperability with other APIs. + * + * @author Robert Field + * @author Gordon Hirsch + * @author James McIlree + * @since 1.3 + */ +public interface ArrayReference extends ObjectReference { + + /** + * Returns the number of components in this array. + * + * @return the integer count of components in this array. + */ + int length(); + + /** + * Returns an array component value. + * + * @param index the index of the component to retrieve + * @return the {@link Value} at the given index. + * @throws java.lang.IndexOutOfBoundsException if + * <CODE><I>index</I></CODE> is outside the range of this array, + * that is, if either of the following are true: + * <PRE> + * <I>index</I> < 0 + * <I>index</I> >= {@link #length() length()} </PRE> + */ + Value getValue(int index); + + /** + * Returns all of the components in this array. + * + * @return a list of {@link Value} objects, one for each array + * component ordered by array index. For zero length arrays, + * an empty list is returned. + */ + List<Value> getValues(); + + /** + * Returns a range of array components. + * + * @param index the index of the first component to retrieve + * @param length the number of components to retrieve, or -1 to + * retrieve all components to the end of this array. + * @return a list of {@link Value} objects, one for each requested + * array component ordered by array index. When there are + * no elements in the specified range (e.g. + * <CODE><I>length</I></CODE> is zero) an empty list is returned + * + * @throws java.lang.IndexOutOfBoundsException if the range + * specified with <CODE><I>index</I></CODE> and + * <CODE><I>length</I></CODE> is not within the range of the array, + * that is, if either of the following are true: + * <PRE> + * <I>index</I> < 0 + * <I>index</I> > {@link #length() length()} </PRE> + * or if <CODE><I>length</I> != -1</CODE> and + * either of the following are true: + * <PRE> + * <I>length</I> < 0 + * <I>index</I> + <I>length</I> > {@link #length() length()}</PRE> + */ + List<Value> getValues(int index, int length); + + /** + * Replaces an array component with another value. + * <p> + * Object values must be assignment compatible with the component type + * (This implies that the component type must be loaded through the + * declaring class's class loader). Primitive values must be + * either assignment compatible with the component type or must be + * convertible to the component type without loss of information. + * See JLS section 5.2 for more information on assignment + * compatibility. + * + * @param value the new value + * @param index the index of the component to set + * @throws java.lang.IndexOutOfBoundsException if + * <CODE><I>index</I></CODE> is outside the range of this array, + * that is, if either of the following are true: + * <PRE> + * <I>index</I> < 0 + * <I>index</I> >= {@link #length() length()} </PRE> + * @throws InvalidTypeException if the type of <CODE><I>value</I></CODE> + * is not compatible with the declared type of array components. + * @throws ClassNotLoadedException if the array component type + * has not yet been loaded + * through the appropriate class loader. + * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. + * + * @see ArrayType#componentType() + */ + void setValue(int index, Value value) + throws InvalidTypeException, + ClassNotLoadedException; + + /** + * Replaces all array components with other values. If the given + * list is larger in size than the array, the values at the + * end of the list are ignored. + * <p> + * Object values must be assignment compatible with the element type + * (This implies that the component type must be loaded through the + * enclosing class's class loader). Primitive values must be + * either assignment compatible with the component type or must be + * convertible to the component type without loss of information. + * See JLS section 5.2 for more information on assignment + * compatibility. + * + * @param values a list of {@link Value} objects to be placed + * in this array. If <CODE><I>values</I>.size()</CODE> is + * less that the length of the array, the first + * <CODE><I>values</I>.size()</CODE> elements are set. + * @throws InvalidTypeException if any of the + * new <CODE><I>values</I></CODE> + * is not compatible with the declared type of array components. + * @throws ClassNotLoadedException if the array component + * type has not yet been loaded + * through the appropriate class loader. + * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. + * + * @see ArrayType#componentType() + */ + void setValues(List<? extends Value> values) + throws InvalidTypeException, + ClassNotLoadedException; + + /** + * Replaces a range of array components with other values. + * <p> + * Object values must be assignment compatible with the component type + * (This implies that the component type must be loaded through the + * enclosing class's class loader). Primitive values must be + * either assignment compatible with the component type or must be + * convertible to the component type without loss of information. + * See JLS section 5.2 for more information on assignment + * compatibility. + * + * @param index the index of the first component to set. + * @param values a list of {@link Value} objects to be placed + * in this array. + * @param srcIndex the index of the first source value to use. + * @param length the number of components to set, or -1 to set + * all components to the end of this array or the end of + * <CODE><I>values</I></CODE> (whichever comes first). + * @throws InvalidTypeException if any element of + * <CODE><I>values</I></CODE> + * is not compatible with the declared type of array components. + * @throws java.lang.IndexOutOfBoundsException if the + * array range specified with + * <CODE><I>index</I></CODE> and <CODE><I>length</I></CODE> + * is not within the range of the array, + * or if the source range specified with + * <CODE><I>srcIndex</I></CODE> and <CODE><I>length</I></CODE> + * is not within <CODE><I>values</I></CODE>, + * that is, if any of the following are true: + * <PRE> + * <I>index</I> < 0 + * <I>index</I> > {@link #length() length()} + * <I>srcIndex</I> < 0 + * <I>srcIndex</I> > <I>values</I>.size() </PRE> + * or if <CODE><I>length</I> != -1</CODE> and any of the + * following are true: + * <PRE> + * <I>length</I> < 0 + * <I>index</I> + <I>length</I> > {@link #length() length()} + * <I>srcIndex</I> + <I>length</I> > <I>values</I>.size() </PRE> + * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. + * @see ArrayType#componentType() + */ + void setValues(int index, List<? extends Value> values, int srcIndex, int length) + throws InvalidTypeException, + ClassNotLoadedException; +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/ArrayType.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/ArrayType.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/ArrayType.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,99 @@ +/* + * Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +import java.util.List; + +/** + * Provides access to the class of an array and the type of + * its components in the target VM. + * + * @see ArrayReference + * + * @author Robert Field + * @author Gordon Hirsch + * @author James McIlree + * @since 1.3 + */ +public interface ArrayType extends ReferenceType { + + /** + * Creates a new instance of this array class in the target VM. + * The array is created with the given length and each component + * is initialized to is standard default value. + * + * @param length the number of components in the new array + * @return the newly created {@link ArrayReference} mirroring + * the new object in the target VM. + * + * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. + */ + ArrayReference newInstance(int length); + + /** + * Gets the JNI signature of the components of this + * array class. The signature + * describes the declared type of the components. If the components + * are objects, their actual type in a particular run-time context + * may be a subclass of the declared class. + * + * @return a string containing the JNI signature of array components. + */ + String componentSignature(); + + /** + * Returns a text representation of the component + * type of this array. + * + * @return a text representation of the component type. + */ + String componentTypeName(); + + /** + * Returns the component type of this array, + * as specified in the array declaration. + * <P> + * Note: The component type of a array will always be + * created or loaded before the array - see the + * <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual + * Machine Specification</a>, section + * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ConstantPool.doc.html#79473">5.3.3 + * Creating Array Classes</a>. + * However, although the component type will be loaded it may + * not yet be prepared, in which case the type will be returned + * but attempts to perform some operations on the returned type + * (e.g. {@link ReferenceType#fields() fields()}) will throw + * a {@link ClassNotPreparedException}. + * Use {@link ReferenceType#isPrepared()} to determine if + * a reference type is prepared. + * + * @see Type + * @see Field#type() Field.type() - for usage examples + * @return the {@link Type} of this array's components. + */ + Type componentType() throws ClassNotLoadedException; +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/BooleanType.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/BooleanType.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/BooleanType.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,40 @@ +/* + * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * The type of all primitive <code>boolean</code> values + * accessed in the target VM. Calls to {@link Value#type} will return an + * implementor of this interface. + * + * @see BooleanValue + * + * @author James McIlree + * @since 1.3 + */ +public interface BooleanType extends PrimitiveType { +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/BooleanValue.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/BooleanValue.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/BooleanValue.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,62 @@ +/* + * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Provides access to a primitive <code>boolean</code> value in + * the target VM. + * + * @author Robert Field + * @author Gordon Hirsch + * @author James McIlree + * @since 1.3 + */ +public interface BooleanValue extends PrimitiveValue +{ + /** + * Returns this BooleanValue as a boolean. + * + * @return the <code>boolean</code> mirrored by this object. + */ + boolean value(); + + /** + * Compares the specified Object with this BooleanValue for equality. + * + * @return true if the Object is a BooleanValue and if applying "==" + * to the two mirrored primitives would evaluate to true; false + * otherwise. + */ + boolean equals(Object obj); + + /** + * Returns the hash code value for this BooleanValue. + * + * @return the integer hash code + */ + int hashCode(); +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/Bootstrap.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/Bootstrap.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/Bootstrap.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,56 @@ +/* + * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Initial class that provides access to the default implementation + * of JDI interfaces. A debugger application uses this class to access the + * single instance of the {@link VirtualMachineManager} interface. + * + * @author Gordon Hirsch + * @since 1.3 + */ + +public class Bootstrap extends Object { + + /** + * Returns the virtual machine manager. + * + * <p> May throw an unspecified error if initialization of the + * {@link com.sun.jdi.VirtualMachineManager} fails or if + * the virtual machine manager is unable to locate or create + * any {@link com.sun.jdi.connect.Connector Connectors}. </p> + * <p> + * @throws java.lang.SecurityException if a security manager has been + * installed and it denies {@link JDIPermission} + * <tt>("virtualMachineManager")</tt> or other unspecified + * permissions required by the implementation. + * </p> + */ + static public synchronized VirtualMachineManager virtualMachineManager() { + return com.sun.tools.jdi.VirtualMachineManagerImpl.virtualMachineManager(); + } +} Added: trunk/core/src/openjdk/com/com/sun/jdi/ByteType.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/ByteType.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/ByteType.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,41 @@ +/* + * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * The type of all primitive byte values accessed in + * the target VM. Calls to {@link Value#type} will return an + * implementor of this interface. + * + * @see ByteValue + * + * @author James McIlree + * @since 1.3 + */ +public interface ByteType extends PrimitiveType +{ +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/ByteValue.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/ByteValue.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/ByteValue.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,61 @@ +/* + * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Provides access to a primitive <code>byte</code> value in the target VM. + * + * @author Robert Field + * @author Gordon Hirsch + * @author James McIlree + * @since 1.3 + */ +public interface ByteValue extends PrimitiveValue, Comparable<ByteValue> +{ + /** + * Returns this ByteValue as a <code>byte</code>. + * + * @return the <code>byte</code> mirrored by this object. + */ + byte value(); + + /** + * Compares the specified Object with this ByteValue for equality. + * + * @return true if the Object is a ByteValue and if applying "==" + * to the two mirrored primitives would evaluate to true; false + * otherwise. + */ + boolean equals(Object obj); + + /** + * Returns the hash code value for this BooleanValue. + * + * @return the integer hash code + */ + int hashCode(); +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/CharType.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/CharType.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/CharType.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,41 @@ +/* + * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * The type of all primitive char values accessed in + * the target VM. Calls to {@link Value#type} will return an + * implementor of this interface. + * + * @see CharValue + * + * @author James McIlree + * @since 1.3 + */ +public interface CharType extends PrimitiveType +{ +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/CharValue.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/CharValue.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/CharValue.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,62 @@ +/* + * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Provides access to a primitive <code>char</code> value in + * the target VM. + * + * @author Robert Field + * @author Gordon Hirsch + * @author James McIlree + * @since 1.3 + */ +public interface CharValue extends PrimitiveValue, Comparable<CharValue> +{ + /** + * Returns this CharValue as a <code>char</code>. + * + * @return the <code>char</code> mirrored by this object. + */ + char value(); + + /** + * Compares the specified Object with this CharValue for equality. + * + * @return true if the Object is a CharValue and if applying "==" + * to the two mirrored primitives would evaluate to true; false + * otherwise. + */ + boolean equals(Object obj); + + /** + * Returns the hash code value for this CharValue. + * + * @return the integer hash code + */ + int hashCode(); +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/ClassLoaderReference.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/ClassLoaderReference.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/ClassLoaderReference.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,96 @@ +/* + * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +import java.util.List; + +/** + * A class loader object from the target VM. + * A ClassLoaderReference is an {@link ObjectReference} with additional + * access to classloader-specific information from the target VM. Instances + * ClassLoaderReference are obtained through calls to + * {@link ReferenceType#classLoader} + * + * @see ObjectReference + * + * @author Gordon Hirsch + * @since 1.3 + */ +public interface ClassLoaderReference extends ObjectReference { + + /** + * Returns a list of all loaded classes that were defined by this + * class loader. No ordering of this list guaranteed. + * <P> + * The returned list will include reference types + * loaded at least to the point of preparation and + * types (like array) for which preparation is + * not defined. + * + * @return a List of {@link ReferenceType} objects mirroring types + * loaded by this class loader. The list has length 0 if no types + * have been defined by this classloader. + */ + List<ReferenceType> definedClasses(); + + /** + * Returns a list of all classes for which this class loader has + * been recorded as the initiating loader in the target VM. + * The list contains ReferenceTypes defined directly by this loader + * (as returned by {@link #definedClasses}) and any types for which + * loading was delegated by this class loader to another class loader. + * <p> + * The visible class list has useful properties with respect to + * the type namespace. A particular type name will occur at most + * once in the list. Each field or variable declared with that + * type name in a class defined by + * this class loader must be resolved to that single type. + * <p> + * No ordering of the returned list is guaranteed. + * <p> + * See the revised + * <a href="http://java.sun.com/docs/books/vmspec/">Java + * Virtual Machine Specification</a> section + * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ConstantPool.doc.html#72007">5.3 + * Creation and Loading</a> + * for more information on the initiating classloader. + * <p> + * Note that unlike {@link #definedClasses()} + * and {@link VirtualMachine#allClasses()}, + * some of the returned reference types may not be prepared. + * Attempts to perform some operations on unprepared reference types + * (e.g. {@link ReferenceType#fields() fields()}) will throw + * a {@link ClassNotPreparedException}. + * Use {@link ReferenceType#isPrepared()} to determine if + * a reference type is prepared. + * + * @return a List of {@link ReferenceType} objects mirroring classes + * initiated by this class loader. The list has length 0 if no classes + * are visible to this classloader. + */ + List<ReferenceType> visibleClasses(); +} + Added: trunk/core/src/openjdk/com/com/sun/jdi/ClassNotLoadedException.java =================================================================== --- trunk/core/src/openjdk/com/com/sun/jdi/ClassNotLoadedException.java (rev 0) +++ trunk/core/src/openjdk/com/com/sun/jdi/ClassNotLoadedException.java 2007-08-26 07:53:04 UTC (rev 3433) @@ -0,0 +1,87 @@ +/* + * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jdi; + +/** + * Thrown to indicate that the requested class has + * not yet been loaded through the appropriate class loader. + * <p> + * Due to the lazy class linking performed by many VMs, it is + * possible for a field or variable to be visible in a program + * before the associated class is loaded. Until the class is loaded + * all that is available is a signature string. If an attempt is made to + * set the value of such a field or variable from JDI, the appropriate + * type checking cannot be done because the destination class has not been + * loaded. The same is true for the element class of array elements. + * <p> + * It is not advisable to solve this problem by attempting a class load on + * the fly in this case. There are two problems in having the debugger load + * a class instead of waiting for it to load over the normal course + * of events. + * <ul> + * <li>There can be no guarantee that running the appropriate class + * loader won't cause a deadlock in loading the + * class. Class loaders can consist of arbitrary + * Java<sup><font size=-2>TM</font></sup> programming language code and the + * class loading methods are usually synchronized. Most of the work + * done by a debugger happens when threads are suspended. If another + * application thread is suspended within the same class loader, + * a deadlock is very possible. + * <li>Changi... [truncated message content] |
From: <ls...@us...> - 2007-09-06 14:43:31
|
Revision: 3458 http://jnode.svn.sourceforge.net/jnode/?rev=3458&view=rev Author: lsantha Date: 2007-09-06 07:43:30 -0700 (Thu, 06 Sep 2007) Log Message: ----------- openjdk integration Modified Paths: -------------- trunk/builder/src/builder/org/jnode/build/ObjectEmitter.java trunk/core/src/classpath/vm/java/lang/Class.java trunk/core/src/classpath/vm/java/lang/VMThrowable.java trunk/core/src/core/org/jnode/security/JNodeSecurityManager.java Modified: trunk/builder/src/builder/org/jnode/build/ObjectEmitter.java =================================================================== --- trunk/builder/src/builder/org/jnode/build/ObjectEmitter.java 2007-09-06 14:42:12 UTC (rev 3457) +++ trunk/builder/src/builder/org/jnode/build/ObjectEmitter.java 2007-09-06 14:43:30 UTC (rev 3458) @@ -234,6 +234,10 @@ bis.writeObjectRef(null); // name bis.writeObjectRef(null); + // enumConstants + bis.writeObjectRef(null); + // enumConstantsDirectory + bis.writeObjectRef(null); } } catch (ClassNotFoundException ex) { throw new BuildException("emitting object: [" + c + "]", ex); @@ -244,9 +248,9 @@ // This layout should match the order and type of fields // in java.lang.String bis.writeObjectRef(s.toCharArray()); // char[] value + os.write32(0); // int offset os.write32(s.length()); // int count - os.write32(s.hashCode()); // int cachedHashCode - os.write32(0); // int offset + os.write32(s.hashCode()); // int cachedHashCode } private void emitInteger(Integer i) throws BuildException { Modified: trunk/core/src/classpath/vm/java/lang/Class.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/Class.java 2007-09-06 14:42:12 UTC (rev 3457) +++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-09-06 14:43:30 UTC (rev 3458) @@ -1411,5 +1411,67 @@ return p.getInterfaceTypes(); } + //jnode openjdk + /** + * Returns the elements of this enum class or null if this + * Class object does not represent an enum type; + * identical to getEnumConstantsShared except that + * the result is uncloned, cached, and shared by all callers. + */ + T[] getEnumConstantsShared() { + if (enumConstants == null) { + if (!isEnum()) return null; + try { + final Method values = getMethod("values"); + java.security.AccessController.doPrivileged + (new java.security.PrivilegedAction() { + public Object run() { + values.setAccessible(true); + return null; + } + }); + enumConstants = (T[]) values.invoke(null); + } + // These can happen when users concoct enum-like classes + // that don't comply with the enum spec. + catch (InvocationTargetException ex) { + return null; + } + catch (NoSuchMethodException ex) { + return null; + } + catch (IllegalAccessException ex) { + return null; + } + } + return enumConstants; + } + private volatile transient T[] enumConstants; + + /** + * Returns a map from simple name to enum constant. This package-private + * method is used internally by Enum to implement + * public static <T extends Enum<T>> T valueOf(Class<T>, String) + * efficiently. Note that the map is returned by this method is + * created lazily on first use. Typically it won't ever get created. + */ + HashMap<String, T> enumConstantDirectory() { + if (enumConstantDirectory == null) { + T[] universe = getEnumConstantsShared(); + if (universe == null) + throw new IllegalArgumentException( + getName() + " is not an enum type"); + HashMap<String, T> m = new HashMap<String, T>(2 * universe.length); + for (T constant : universe) + m.put(((Enum) constant).name(), constant); + enumConstantDirectory = m; + } + return enumConstantDirectory; + } + private volatile transient HashMap enumConstantDirectory; + + ClassLoader getClassLoader0(){ + return getClassLoader(); + } } Modified: trunk/core/src/classpath/vm/java/lang/VMThrowable.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/VMThrowable.java 2007-09-06 14:42:12 UTC (rev 3457) +++ trunk/core/src/classpath/vm/java/lang/VMThrowable.java 2007-09-06 14:43:30 UTC (rev 3458) @@ -93,7 +93,7 @@ final String fname = (vmClass == null) ? null : vmClass.getSourceFile(); final String cname = (vmClass == null) ? "<unknown class>" : vmClass.getName(); final String mname = (method == null) ? "<unknown method>" : method.getName(); - trace[i] = new StackTraceElement(fname, lineNumber, cname, mname, method.isNative()); + trace[i] = new StackTraceElement(cname, mname, fname, method == null || method.isNative() ? -2 : lineNumber); } return trace; } Modified: trunk/core/src/core/org/jnode/security/JNodeSecurityManager.java =================================================================== --- trunk/core/src/core/org/jnode/security/JNodeSecurityManager.java 2007-09-06 14:42:12 UTC (rev 3457) +++ trunk/core/src/core/org/jnode/security/JNodeSecurityManager.java 2007-09-06 14:43:30 UTC (rev 3458) @@ -36,10 +36,12 @@ */ @Override public void checkPermission(Permission perm) { + /* if (perm.implies(SET_SECURITY_MANAGER)) { throw new SecurityException("Cannot override security manager"); } super.checkPermission(perm); + */ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-09-14 09:47:32
|
Revision: 3496 http://jnode.svn.sourceforge.net/jnode/?rev=3496&view=rev Author: lsantha Date: 2007-09-14 02:47:29 -0700 (Fri, 14 Sep 2007) Log Message: ----------- Fixed my name. Modified Paths: -------------- trunk/builder/src/builder/org/jnode/jnasm/assembler/gen/JNAsm.jj trunk/builder/src/builder/org/jnode/jnasm/preprocessor/gen/JNAsmPP.jj trunk/core/src/core/org/jnode/vm/IOContext.java trunk/core/src/core/org/jnode/vm/VmIOContext.java trunk/core/src/openjdk/vm/java/io/NativeConsole.java trunk/core/src/openjdk/vm/java/io/NativeUnixFileSystem.java trunk/core/src/openjdk/vm/java/lang/NativeCompiler.java trunk/core/src/openjdk/vm/java/lang/NativeDouble.java trunk/core/src/openjdk/vm/java/lang/NativeFloat.java trunk/core/src/openjdk/vm/java/lang/NativeObject.java trunk/core/src/openjdk/vm/java/lang/NativeRuntime.java trunk/core/src/openjdk/vm/java/lang/NativeString.java trunk/core/src/openjdk/vm/java/lang/NativeSystem.java trunk/core/src/openjdk/vm/java/lang/reflect/NativeProxy.java trunk/core/src/openjdk/vm/java/util/NativeResourceBundle.java trunk/core/src/openjdk/vm/java/util/logging/NativeFileHandler.java trunk/core/src/openjdk/vm/java/util/prefs/NativeFileSystemPreferences.java trunk/core/src/openjdk/vm/sun/awt/NativeSunToolkit.java trunk/core/src/openjdk/vm/sun/misc/NativeMessageUtils.java trunk/core/src/openjdk/vm/sun/misc/NativeUnsafe.java trunk/core/src/openjdk/vm/sun/misc/UnsafeHelper.java trunk/core/src/openjdk/vm/sun/reflect/NativeConstantPool.java trunk/core/src/openjdk/vm/sun/reflect/NativeReflection.java trunk/core/src/openjdk/vm/sun/rmi/server/NativeMarshalInputStream.java trunk/distr/src/emu/org/jnode/emu/DeviceManager.java trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java trunk/distr/src/install/org/jnode/install/AbstractInstaller.java trunk/distr/src/install/org/jnode/install/ActionInput.java trunk/distr/src/install/org/jnode/install/ActionOutput.java trunk/distr/src/install/org/jnode/install/CopyFile.java trunk/distr/src/install/org/jnode/install/InputContext.java trunk/distr/src/install/org/jnode/install/InstallerAction.java trunk/distr/src/install/org/jnode/install/OutputContext.java trunk/distr/src/install/org/jnode/install/ProgressAware.java trunk/distr/src/install/org/jnode/install/ProgressEvent.java trunk/distr/src/install/org/jnode/install/ProgressListener.java trunk/distr/src/install/org/jnode/install/ProgressSupport.java trunk/distr/src/install/org/jnode/install/ProgressiveAction.java trunk/distr/src/install/org/jnode/install/action/ActionConstants.java trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java trunk/gui/src/test/org/jnode/test/gui/Rubik.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineConstants.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineCore.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDesc.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDriver.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineFlags.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRing.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRxRing.java trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineTxRing.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java Modified: trunk/builder/src/builder/org/jnode/jnasm/assembler/gen/JNAsm.jj =================================================================== --- trunk/builder/src/builder/org/jnode/jnasm/assembler/gen/JNAsm.jj 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/builder/src/builder/org/jnode/jnasm/assembler/gen/JNAsm.jj 2007-09-14 09:47:29 UTC (rev 3496) @@ -16,7 +16,7 @@ import org.jnode.jnasm.assembler.Identifier; /** - * @author Levente Santha (ls...@us...) + * @author Levente S\u00e1ntha (ls...@us...) */ public class JNAsm extends Assembler{ Modified: trunk/builder/src/builder/org/jnode/jnasm/preprocessor/gen/JNAsmPP.jj =================================================================== --- trunk/builder/src/builder/org/jnode/jnasm/preprocessor/gen/JNAsmPP.jj 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/builder/src/builder/org/jnode/jnasm/preprocessor/gen/JNAsmPP.jj 2007-09-14 09:47:29 UTC (rev 3496) @@ -13,7 +13,7 @@ import org.jnode.jnasm.preprocessor.Preprocessor; /** - * @author Levente Santha (ls...@us...) + * @author Levente S\u00e1ntha (ls...@us...) */ public class JNAsmPP extends Preprocessor { protected void clearTokens(Token start, Token end){ Modified: trunk/core/src/core/org/jnode/vm/IOContext.java =================================================================== --- trunk/core/src/core/org/jnode/vm/IOContext.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/core/org/jnode/vm/IOContext.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import java.io.PrintStream; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface IOContext { void setGlobalInStream(InputStream in); Modified: trunk/core/src/core/org/jnode/vm/VmIOContext.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import java.io.PrintStream; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class VmIOContext implements IOContext { private static InputStream globalInStream; Modified: trunk/core/src/openjdk/vm/java/io/NativeConsole.java =================================================================== --- trunk/core/src/openjdk/vm/java/io/NativeConsole.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/io/NativeConsole.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.io; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeConsole { private static String encoding(){ Modified: trunk/core/src/openjdk/vm/java/io/NativeUnixFileSystem.java =================================================================== --- trunk/core/src/openjdk/vm/java/io/NativeUnixFileSystem.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/io/NativeUnixFileSystem.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.io; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeUnixFileSystem { private static String canonicalize0(UnixFileSystem ufs, String path) throws IOException { Modified: trunk/core/src/openjdk/vm/java/lang/NativeCompiler.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeCompiler.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeCompiler.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.lang; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeCompiler { /** Modified: trunk/core/src/openjdk/vm/java/lang/NativeDouble.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeDouble.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeDouble.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -6,7 +6,7 @@ import org.jnode.vm.VmMagic; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeDouble { /** Modified: trunk/core/src/openjdk/vm/java/lang/NativeFloat.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeFloat.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeFloat.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -6,7 +6,7 @@ import org.jnode.vm.VmMagic; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeFloat { /** Modified: trunk/core/src/openjdk/vm/java/lang/NativeObject.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeObject.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeObject.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.lang; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha * @see Object */ public class NativeObject { Modified: trunk/core/src/openjdk/vm/java/lang/NativeRuntime.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeRuntime.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeRuntime.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import org.jnode.vm.VmSystem; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeRuntime { /** Modified: trunk/core/src/openjdk/vm/java/lang/NativeString.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeString.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeString.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.lang; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeString { public static String intern(String instance){ Modified: trunk/core/src/openjdk/vm/java/lang/NativeSystem.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/NativeSystem.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/NativeSystem.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -10,7 +10,7 @@ /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeSystem { Modified: trunk/core/src/openjdk/vm/java/lang/reflect/NativeProxy.java =================================================================== --- trunk/core/src/openjdk/vm/java/lang/reflect/NativeProxy.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/lang/reflect/NativeProxy.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.lang.reflect; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeProxy { /** Modified: trunk/core/src/openjdk/vm/java/util/NativeResourceBundle.java =================================================================== --- trunk/core/src/openjdk/vm/java/util/NativeResourceBundle.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/util/NativeResourceBundle.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -6,7 +6,7 @@ import org.jnode.vm.VmSystem; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeResourceBundle { static Class[] getClassContext(){ Modified: trunk/core/src/openjdk/vm/java/util/logging/NativeFileHandler.java =================================================================== --- trunk/core/src/openjdk/vm/java/util/logging/NativeFileHandler.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/util/logging/NativeFileHandler.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.util.logging; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeFileHandler { /** Modified: trunk/core/src/openjdk/vm/java/util/prefs/NativeFileSystemPreferences.java =================================================================== --- trunk/core/src/openjdk/vm/java/util/prefs/NativeFileSystemPreferences.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/java/util/prefs/NativeFileSystemPreferences.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package java.util.prefs; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeFileSystemPreferences { /** Modified: trunk/core/src/openjdk/vm/sun/awt/NativeSunToolkit.java =================================================================== --- trunk/core/src/openjdk/vm/sun/awt/NativeSunToolkit.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/awt/NativeSunToolkit.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package sun.awt; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeSunToolkit { static void closeSplashScreen() { Modified: trunk/core/src/openjdk/vm/sun/misc/NativeMessageUtils.java =================================================================== --- trunk/core/src/openjdk/vm/sun/misc/NativeMessageUtils.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/misc/NativeMessageUtils.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package sun.misc; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeMessageUtils { /** Modified: trunk/core/src/openjdk/vm/sun/misc/NativeUnsafe.java =================================================================== --- trunk/core/src/openjdk/vm/sun/misc/NativeUnsafe.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/misc/NativeUnsafe.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -9,7 +9,7 @@ import org.vmmagic.unboxed.Address; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeUnsafe { static void registerNatives() { Modified: trunk/core/src/openjdk/vm/sun/misc/UnsafeHelper.java =================================================================== --- trunk/core/src/openjdk/vm/sun/misc/UnsafeHelper.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/misc/UnsafeHelper.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -8,7 +8,7 @@ import org.vmmagic.unboxed.ObjectReference; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class UnsafeHelper { private static final int OFFSET_OF_vmField_IN_Field = Modified: trunk/core/src/openjdk/vm/sun/reflect/NativeConstantPool.java =================================================================== --- trunk/core/src/openjdk/vm/sun/reflect/NativeConstantPool.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/reflect/NativeConstantPool.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import java.lang.reflect.Member; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class NativeConstantPool { private static int getSize0(ConstantPool instance, Object constantPoolOop) { Modified: trunk/core/src/openjdk/vm/sun/reflect/NativeReflection.java =================================================================== --- trunk/core/src/openjdk/vm/sun/reflect/NativeReflection.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/reflect/NativeReflection.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ /** * @see sun.reflect.Reflection - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeReflection { /** Modified: trunk/core/src/openjdk/vm/sun/rmi/server/NativeMarshalInputStream.java =================================================================== --- trunk/core/src/openjdk/vm/sun/rmi/server/NativeMarshalInputStream.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/core/src/openjdk/vm/sun/rmi/server/NativeMarshalInputStream.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package sun.rmi.server; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class NativeMarshalInputStream { static ClassLoader latestUserDefinedLoader(){ Modified: trunk/distr/src/emu/org/jnode/emu/DeviceManager.java =================================================================== --- trunk/distr/src/emu/org/jnode/emu/DeviceManager.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/emu/org/jnode/emu/DeviceManager.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -10,7 +10,7 @@ import org.jnode.driver.*; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class DeviceManager extends AbstractDeviceManager { public static final Logger log = Logger.getLogger(DeviceManager.class); Modified: trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java =================================================================== --- trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -9,7 +9,7 @@ import org.jnode.plugin.PluginDescriptor; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class DummyExtensionPoint implements ExtensionPoint { public String getSimpleIdentifier() { Modified: trunk/distr/src/install/org/jnode/install/AbstractInstaller.java =================================================================== --- trunk/distr/src/install/org/jnode/install/AbstractInstaller.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/AbstractInstaller.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -8,7 +8,7 @@ import java.util.ListIterator; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public abstract class AbstractInstaller { public static enum Step {back, forth, quit} Modified: trunk/distr/src/install/org/jnode/install/ActionInput.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ActionInput.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ActionInput.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface ActionInput { AbstractInstaller.Step collect(); Modified: trunk/distr/src/install/org/jnode/install/ActionOutput.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ActionOutput.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ActionOutput.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface ActionOutput { AbstractInstaller.Step show(); Modified: trunk/distr/src/install/org/jnode/install/CopyFile.java =================================================================== --- trunk/distr/src/install/org/jnode/install/CopyFile.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/CopyFile.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class CopyFile implements ProgressAware { private ProgressSupport progress = new ProgressSupport(); Modified: trunk/distr/src/install/org/jnode/install/InputContext.java =================================================================== --- trunk/distr/src/install/org/jnode/install/InputContext.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/InputContext.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -6,7 +6,7 @@ import java.util.HashMap; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public abstract class InputContext { private HashMap<String, Object> values = new HashMap<String, Object>(); Modified: trunk/distr/src/install/org/jnode/install/InstallerAction.java =================================================================== --- trunk/distr/src/install/org/jnode/install/InstallerAction.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/InstallerAction.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface InstallerAction { ActionInput getInput(InputContext inContext); Modified: trunk/distr/src/install/org/jnode/install/OutputContext.java =================================================================== --- trunk/distr/src/install/org/jnode/install/OutputContext.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/OutputContext.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface OutputContext { public void showMessage(String msg); Modified: trunk/distr/src/install/org/jnode/install/ProgressAware.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ProgressAware.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ProgressAware.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface ProgressAware { void addProgressListener(ProgressListener p); Modified: trunk/distr/src/install/org/jnode/install/ProgressEvent.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ProgressEvent.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ProgressEvent.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class ProgressEvent { private int progress; Modified: trunk/distr/src/install/org/jnode/install/ProgressListener.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ProgressListener.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ProgressListener.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface ProgressListener { void progress(ProgressEvent e); Modified: trunk/distr/src/install/org/jnode/install/ProgressSupport.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ProgressSupport.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ProgressSupport.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import java.util.List; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class ProgressSupport implements ProgressAware{ List<ProgressListener> listenerList = new ArrayList<ProgressListener>(); Modified: trunk/distr/src/install/org/jnode/install/ProgressiveAction.java =================================================================== --- trunk/distr/src/install/org/jnode/install/ProgressiveAction.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/ProgressiveAction.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface ProgressiveAction extends InstallerAction, ProgressAware { Modified: trunk/distr/src/install/org/jnode/install/action/ActionConstants.java =================================================================== --- trunk/distr/src/install/org/jnode/install/action/ActionConstants.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/action/ActionConstants.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.install.action; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public interface ActionConstants { String INSTALL_ROOT_DIR = "INSTALL_ROOT_DIR"; Modified: trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java =================================================================== --- trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import org.jnode.install.*; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class CopyFilesAction implements InstallerAction { private String targetDirectory; Modified: trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java =================================================================== --- trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import org.jnode.install.*; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class GrubInstallerAction implements InstallerAction { private String disk; Modified: trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java =================================================================== --- trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -13,7 +13,7 @@ import org.jnode.install.action.GrubInstallerAction; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class CommandLineInstaller extends AbstractInstaller { Modified: trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java =================================================================== --- trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/gui/src/awt/org/jnode/awt/image/BufferedImageSurface.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -13,7 +13,7 @@ import java.awt.geom.AffineTransform; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class BufferedImageSurface extends AbstractSurface { Modified: trunk/gui/src/test/org/jnode/test/gui/Rubik.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/Rubik.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/gui/src/test/org/jnode/test/gui/Rubik.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -23,7 +23,7 @@ // Rubik's Cube 3D simulator // Karl H\xF6rnell, March 11 1996 // Last modified October 6 -// Adapted to JNode by Levente Santha +// Adapted to JNode by Levente S\u00e1ntha import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineConstants.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineConstants.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineConstants.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -4,7 +4,7 @@ package org.jnode.driver.net.via_rhine; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ interface ViaRhineConstants { Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineCore.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineCore.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineCore.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -24,7 +24,7 @@ import java.io.*; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class ViaRhineCore extends AbstractDeviceCore implements IRQHandler { private final int ioBase; Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDesc.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDesc.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDesc.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -10,7 +10,7 @@ import org.vmmagic.unboxed.Address; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class ViaRhineDesc { private static final int OWN_BIT_MASK = 0x80000000; Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDriver.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDriver.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineDriver.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -13,7 +13,7 @@ import java.security.PrivilegedExceptionAction; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class ViaRhineDriver extends BasicEthernetDriver { /** Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineFlags.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineFlags.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineFlags.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import org.jnode.plugin.ConfigurationElement; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class ViaRhineFlags implements Flags { private final String name; Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRing.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRing.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRing.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -7,7 +7,7 @@ import java.util.Arrays; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ abstract class ViaRhineRing<T extends ViaRhineDesc> { final int RING_SIZE; Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRxRing.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRxRing.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineRxRing.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -8,7 +8,7 @@ import org.jnode.net.SocketBuffer; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class ViaRhineRxRing extends ViaRhineRing<ViaRhineRxRing.RxDesc> { ViaRhineRxRing(ResourceManager rm){ Modified: trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineTxRing.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineTxRing.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/net/src/driver/org/jnode/driver/net/via_rhine/ViaRhineTxRing.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -11,7 +11,7 @@ import org.jnode.system.ResourceManager; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ class ViaRhineTxRing extends ViaRhineRing<ViaRhineTxRing.TxDesc> { ViaRhineTxRing(ResourceManager rm) { Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2007-09-14 07:44:42 UTC (rev 3495) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2007-09-14 09:47:29 UTC (rev 3496) @@ -9,7 +9,7 @@ import org.jnode.vm.VmSystem; /** - * @author Levente S\xE1ntha + * @author Levente S\u00e1ntha */ public class ProcletIOContext implements IOContext { private static InputStream globalInStream; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-09-15 00:33:47
|
Revision: 3498 http://jnode.svn.sourceforge.net/jnode/?rev=3498&view=rev Author: fduminy Date: 2007-09-14 17:33:44 -0700 (Fri, 14 Sep 2007) Log Message: ----------- fixed AnnotateTask and re-enabled it in the build process Modified Paths: -------------- trunk/all/build.xml trunk/all/lib/jnode.xml trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2007-09-14 11:30:08 UTC (rev 3497) +++ trunk/all/build.xml 2007-09-15 00:33:44 UTC (rev 3498) @@ -166,7 +166,7 @@ </target> <!-- Assemble all plugins --> - <target name="assemble-plugins" depends="assemble-projects"> + <target name="assemble-plugins" depends="assemble-projects,openjdk-annotate"> <!-- Now assemble all plugins --> <taskdef name="plugin" classname="org.jnode.build.PluginTask" classpathref="cp-jnode"/> <plugin todir="${plugins.dir}" tmpdir="${build.dir}/tmp/plugins" pluginDir="${descriptors.dir}"> @@ -637,7 +637,8 @@ <taskdef name="oj-annotate" classname="org.jnode.ant.taskdefs.AnnotateTask" classpathref="cp-jnode"/> - <oj-annotate annotationFile="${root.dir}/all/conf/openjdk-annotations.properties"> + <oj-annotate annotationFile="${root.dir}/all/conf/openjdk-annotations.properties" + trace="false"> <fileset dir="${root.dir}/core/build/classes"> <patternset includes="**/*.class"/> </fileset> Modified: trunk/all/lib/jnode.xml =================================================================== --- trunk/all/lib/jnode.xml 2007-09-14 11:30:08 UTC (rev 3497) +++ trunk/all/lib/jnode.xml 2007-09-15 00:33:44 UTC (rev 3498) @@ -14,7 +14,7 @@ target="${java.target}" source="${java.source}" encoding="${java.encoding}" - excludes="**/*-template.java,**/package-info.java, **/AnnotateTask.java"> + excludes="**/*-template.java,**/package-info.java"> <bootclasspath path="${jnode-core.jar}"/> <compilerarg value="${compilerarg}"/> </javac> Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-09-14 11:30:08 UTC (rev 3497) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-09-15 00:33:44 UTC (rev 3498) @@ -23,7 +23,6 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -41,9 +40,11 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Type; import org.objectweb.asm.attrs.Annotation; +import org.objectweb.asm.attrs.Attributes; import org.objectweb.asm.attrs.RuntimeVisibleAnnotations; -import org.objectweb.asm.util.AbstractVisitor; -import org.objectweb.asm.util.CheckClassAdapter; +//import org.objectweb.asm.util.AbstractVisitor; +//import org.objectweb.asm.util.CheckClassAdapter; +//import org.objectweb.asm.util.TraceClassVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** @@ -59,6 +60,7 @@ private File annotationFile; private String[] classesFiles; + private boolean trace = true; public void execute() throws BuildException { classesFiles = readProperties(annotationFile); @@ -72,6 +74,11 @@ public final void setAnnotationFile(File annotationFile) { this.annotationFile = annotationFile; } + + public final void setTrace(boolean trace) + { + this.trace = trace; + } /** * Read the properties file. For now, it simply contains a list of @@ -166,9 +173,19 @@ try { + if(trace) + { + traceClass(file, "before"); + } + fis = new FileInputStream(file); fos = new FileOutputStream(tmpFile); addAnnotation(file.getName(), fis, fos); + + if(trace) + { + traceClass(file, "after"); + } } finally { @@ -184,12 +201,12 @@ if(!file.delete()) { - throw new IOException("can delete "+file.getAbsolutePath()); + throw new IOException("can't delete "+file.getAbsolutePath()); } if(!tmpFile.renameTo(file)) { - throw new IOException("can rename "+tmpFile.getAbsolutePath()); + throw new IOException("can't rename "+tmpFile.getAbsolutePath()); } //traceClass(file); @@ -203,18 +220,17 @@ * @param file * @throws IOException */ - private void traceClass(File file) throws IOException + private void traceClass(File file, String message) throws IOException { - System.out.println("trace for "+file.getAbsolutePath()); + System.out.println("===== ("+message+") trace for "+file.getAbsolutePath()+" ====="); FileInputStream fis = null; try { fis = new FileInputStream(file); ClassReader cr = new ClassReader(fis); - TraceClassVisitor tcv = new TraceClassVisitor(new PrintWriter(System.out)); - cr.accept(tcv, - AbstractVisitor.getDefaultAttributes(), false); + TraceClassVisitor tcv = new TraceClassVisitor(null, new PrintWriter(System.out)); + cr.accept(tcv, Attributes.getDefaultAttributes(), true); } finally { @@ -223,16 +239,21 @@ fis.close(); } } + System.out.println("----- end trace -----"); } private void addAnnotation(String fileName, InputStream inputClass, OutputStream outputClass) throws BuildException { ClassWriter cw = new ClassWriter(false); try { ClassReader cr = new ClassReader(inputClass); - cr.accept(new MarkerClassVisitor(cw), AbstractVisitor.getDefaultAttributes(), false); + cr.accept(new MarkerClassVisitor(cw), + Attributes.getDefaultAttributes(), + true); byte[] b = cw.toByteArray(); + outputClass.write(b); } catch (Exception ex) { + ex.printStackTrace(); throw new BuildException("Unable to load class in file "+fileName, ex); } } @@ -243,16 +264,18 @@ super(cv); } + @Override public void visit(int version, int access, String name, - String superName, String sourceFile, String[] interfaces) { - super.visit(org.objectweb.asm.Constants.V1_5, access, name, superName, - sourceFile, interfaces); + String superName, String[] interfaces, String sourceFile) { + super.visit(org.objectweb.asm.Constants.V1_5, access, + name, superName, interfaces, sourceFile); } @SuppressWarnings("unchecked") public void visitEnd() { String t = Type.getDescriptor(SharedStatics.class); Annotation ann = new Annotation(t); + ann.add("name", ""); RuntimeVisibleAnnotations attr = new RuntimeVisibleAnnotations(); attr.annotations.add(ann); Modified: trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java =================================================================== --- trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java 2007-09-14 11:30:08 UTC (rev 3497) +++ trunk/core/src/openjdk/sun/sun/misc/SharedSecrets.java 2007-09-15 00:33:44 UTC (rev 3498) @@ -39,7 +39,6 @@ This framework avoids the primary disadvantage of using reflection for this purpose, namely the loss of compile-time checking. */ -@SharedStatics public class SharedSecrets { private static final Unsafe unsafe = Unsafe.getUnsafe(); private static JavaUtilJarAccess javaUtilJarAccess; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-09-15 18:01:42
|
Revision: 3501 http://jnode.svn.sourceforge.net/jnode/?rev=3501&view=rev Author: lsantha Date: 2007-09-15 11:01:39 -0700 (Sat, 15 Sep 2007) Log Message: ----------- Various console related fixes by crawley. Modified Paths: -------------- trunk/core/src/classpath/ext/javax/isolate/Isolate.java trunk/core/src/core/org/jnode/vm/IOContext.java trunk/core/src/core/org/jnode/vm/VmIOContext.java trunk/core/src/core/org/jnode/vm/VmSystem.java trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java Modified: trunk/core/src/classpath/ext/javax/isolate/Isolate.java =================================================================== --- trunk/core/src/classpath/ext/javax/isolate/Isolate.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/classpath/ext/javax/isolate/Isolate.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -58,6 +58,7 @@ * * @param mainClass * @param args + * @param properties */ public Isolate(Properties properties, String mainClass, String[] args) { this(new StreamBindings(), properties, mainClass, args); @@ -68,10 +69,8 @@ * * @param mainClass * @param mainArgs - * @param context - * @param stdin - * @param stdout - * @param stderr + * @param bindings + * @param properties */ public Isolate(StreamBindings bindings, Properties properties, String mainClass, String[] args) { Modified: trunk/core/src/core/org/jnode/vm/IOContext.java =================================================================== --- trunk/core/src/core/org/jnode/vm/IOContext.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/core/org/jnode/vm/IOContext.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -7,18 +7,91 @@ import java.io.PrintStream; /** + * This interface provides the hooks for implementing special semantics for System.in, System.out + * and System.err. Specifically, it is used to implement 'proclet' mode where the stream objects + * are proxies for context specific streams. + * * @author Levente S\u00e1ntha + * @author cr...@jn... */ public interface IOContext { + + /** + * This hook is used to set the 'global' version of System.in; e.g. the one used + * when there is no active proclet context. + * + * @param in the new global System.in + */ void setGlobalInStream(InputStream in); + + /** + * This hook is used to get the 'global' version of System.in. + */ InputStream getGlobalInStream(); + + /** + * This hook is used to set the 'global' version of System.out; e.g. the one used + * when there is no active proclet context. + * + * @param out the new global System.out + */ void setGlobalOutStream(PrintStream out); + + /** + * This hook is used to get the 'global' version of System.out. + */ PrintStream getGlobalOutStream(); + + /** + * This hook is used to set the 'global' version of System.err; e.g. the one used + * when there is no active proclet context. + * + * @param err the new global System.err + */ void setGlobalErrStream(PrintStream err); + + /** + * This hook is used to get the 'global' version of System.err. + */ PrintStream getGlobalErrStream(); + + /** + * This hook is used when "setting" System.in; i.e. via System.setIn(in). + * + * @param in the application supplied value for System.in + */ void setSystemIn(InputStream in); + + /** + * This hook is used when "setting" System.out; i.e. via System.setOut(out). + * + * @param out the application supplied value for System.out + */ void setSystemOut(PrintStream out); + + /** + * This hook is used when "setting" System.err; i.e. via System.setErr(err). + * + * @param err the application supplied value for System.err + */ void setSystemErr(PrintStream err); + + /** + * This hook is used to get the 'real' stream underlying System.in in the current context. + */ + InputStream getRealSystemIn(); + + /** + * This hook is used to get the 'real' stream underlying System.out in the current context. + */ + PrintStream getRealSystemOut(); + + /** + * This hook is used to get the 'real' stream underlying System.err in the current context. + */ + PrintStream getRealSystemErr(); + void enterContext(); + void exitContext(); } Modified: trunk/core/src/core/org/jnode/vm/VmIOContext.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -8,8 +8,9 @@ /** * @author Levente S\u00e1ntha + * @author cr...@jn... */ -class VmIOContext implements IOContext { +public class VmIOContext implements IOContext { private static InputStream globalInStream; private static PrintStream globalOutStream; private static PrintStream globalErrStream; @@ -54,10 +55,22 @@ } public void enterContext() { - + // No-op } public void exitContext() { - + // No-op } + + public PrintStream getRealSystemErr() { + return System.err; + } + + public InputStream getRealSystemIn() { + return System.in; + } + + public PrintStream getRealSystemOut() { + return System.out; + } } Modified: trunk/core/src/core/org/jnode/vm/VmSystem.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -59,6 +59,7 @@ import org.jnode.vm.classmgr.VmMethod; import org.jnode.vm.classmgr.VmStaticField; import org.jnode.vm.classmgr.VmType; +import org.jnode.vm.isolate.VmIsolate; import org.jnode.vm.memmgr.VmWriteBarrier; import org.jnode.vm.scheduler.VmProcessor; import org.jnode.vm.scheduler.VmThread; @@ -209,15 +210,21 @@ * @return the system output stream */ public static PrintStream getSystemOut() { - if (bootOut == null) { - bootOut = new SystemOutputStream(); - bootOutStream = new PrintStream(bootOut, true); - //globalOutStream = globalErrStream = bootOutStream; - ioContext.setGlobalOutStream(bootOutStream); - ioContext.setGlobalErrStream(bootOutStream); - } - return bootOutStream; + if (bootOut == null) { + bootOut = new SystemOutputStream(); + bootOutStream = new PrintStream(bootOut, true); + IOContext ioContext = getIOContext(); + ioContext.setGlobalOutStream(bootOutStream); + ioContext.setGlobalErrStream(bootOutStream); + return bootOutStream; + } + else if (VmIsolate.isRoot()) { + return bootOutStream; + } + else { + return VmIsolate.currentIsolate().getIOContext().getGlobalOutStream(); + } } /** @@ -328,7 +335,12 @@ * @return String */ public static String getBootLog() { - return bootOut.getData(); + if (bootOut != null) { + return bootOut.getData(); + } + else { + return ""; + } } // ------------------------------------------ @@ -982,7 +994,7 @@ */ @PrivilegedActionPragma public static void setIn(InputStream in) { - ioContext.setSystemIn(in); + getIOContext().setSystemIn(in); } /** @@ -996,7 +1008,7 @@ */ @PrivilegedActionPragma public static void setOut(PrintStream out) { - ioContext.setSystemOut(out); + getIOContext().setSystemOut(out); } /** @@ -1010,7 +1022,7 @@ */ @PrivilegedActionPragma public static void setErr(PrintStream err) { - ioContext.setSystemErr(err); + getIOContext().setSystemErr(err); } //todo protect this method from arbitrary access @@ -1033,11 +1045,15 @@ } //io context related - private static final IOContext vmIoContext = new VmIOContext(); - private static IOContext ioContext = vmIoContext; + // private static final IOContext vmIoContext = new VmIOContext(); + // private static IOContext ioContext = vmIoContext; + + public static IOContext getIOContext() { + return VmIsolate.currentIsolate().getIOContext(); + } public static boolean hasVmIOContext(){ - return ioContext instanceof VmIOContext; + return getIOContext() instanceof VmIOContext; } @@ -1047,7 +1063,7 @@ * @return the global 'err' stream. */ public static PrintStream getGlobalErrStream() { - return ioContext.getGlobalErrStream(); + return getIOContext().getGlobalErrStream(); } /** @@ -1056,7 +1072,7 @@ * @return the global 'in' stream. */ public static InputStream getGlobalInStream() { - return ioContext.getGlobalInStream(); + return getIOContext().getGlobalInStream(); } /** @@ -1065,20 +1081,20 @@ * @return the global 'out' stream. */ public static PrintStream getGlobalOutStream() { - return ioContext.getGlobalOutStream(); + return getIOContext().getGlobalOutStream(); } public static void switchToExternalIOContext(IOContext context){ if (hasVmIOContext()){ - ioContext = context; + VmIsolate.currentIsolate().setIOContext(context); context.enterContext(); } } public static void resetIOContext(){ if (!hasVmIOContext()){ - ioContext.exitContext(); - ioContext = vmIoContext; + getIOContext().exitContext(); + VmIsolate.currentIsolate().resetIOContext(); } else { throw new RuntimeException("IO Context cannot be reset"); } Modified: trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -40,6 +40,11 @@ this.stdout = stdout; this.stderr = stderr; this.stdin = stdin; + + //TODO crawley, review this, looks like a serious side effect for creating a thread + System.setIn(stdin); + System.setOut(stdout); + System.setErr(stderr); } /** Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -114,6 +114,16 @@ * Links passed to the start of this isolate */ private VmDataLink[] dataLinks; + + /** + * The isolate-specific default IO context + */ + private final IOContext vmIoContext = new VmIOContext(); + + /** + * The isolate-specific switchable IO context + */ + private IOContext ioContext = vmIoContext; /** * Isolate states. @@ -189,10 +199,8 @@ * @param isolate * @param mainClass * @param args - * @param context - * @param stdin - * @param stdout - * @param stderr + * @param bindings + * @param properties */ public VmIsolate(Isolate isolate, VmStreamBindings bindings, Properties properties, String mainClass, String[] args) { @@ -608,4 +616,16 @@ throw new SecurityException("Method called by invalid isolate"); } } + + public IOContext getIOContext() { + return ioContext; + } + + public void setIOContext(IOContext context) { + ioContext = context; + } + + public void resetIOContext() { + ioContext = vmIoContext; + } } Modified: trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -13,6 +13,8 @@ import java.io.PrintStream; import java.net.Socket; +import org.jnode.vm.IOContext; + /** * Class used to pass stdout/stderr/stdin streams to a new isolate. * @author Ewout Prangsma (ep...@us...) @@ -88,11 +90,12 @@ final PrintStream createIsolatedOut() throws IOException { final OutputStream stream; if (outStream != null) { - stream = new FilterOutputStream(outStream); + stream = new FilterOutputStream(outStream); } else if (outSocket != null) { - stream = new FilterOutputStream(outSocket.getOutputStream()); + stream = new FilterOutputStream(outSocket.getOutputStream()); } else { - stream = new FilterOutputStream(System.out); + IOContext ioContext = VmIsolate.getRoot().getIOContext(); + stream = new FilterOutputStream(ioContext.getRealSystemOut()); } return new PrintStream(stream); } @@ -109,7 +112,8 @@ } else if (errSocket != null) { stream = new FilterOutputStream(errSocket.getOutputStream()); } else { - stream = new FilterOutputStream(System.err); + IOContext ioContext = VmIsolate.getRoot().getIOContext(); + stream = new FilterOutputStream(ioContext.getRealSystemErr()); } return new PrintStream(stream); } @@ -126,7 +130,8 @@ } else if (inSocket != null) { stream = new WrappedInputStream(inSocket.getInputStream()); } else { - stream = new WrappedInputStream(System.in); + IOContext ioContext = VmIsolate.getRoot().getIOContext(); + stream = new WrappedInputStream(ioContext.getRealSystemIn()); } return stream; } @@ -137,6 +142,6 @@ */ public WrappedInputStream(InputStream in) { super(in); - } + } } } Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -21,7 +21,6 @@ package org.jnode.driver.console.textscreen; -import java.io.PrintStream; import java.util.Arrays; import org.jnode.driver.console.CompletionInfo; @@ -29,9 +28,7 @@ import org.jnode.driver.console.TextConsole; import org.jnode.driver.console.spi.ConsolePrintStream; -import com.sun.tools.javac.code.Attribute.Array; - /** * A class that handles the content of the current command line in the shell. * That can be : - a new command that the user is beeing editing - an existing Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -93,7 +93,9 @@ this, 0x07)); this.savedErr = this.err = new ConsolePrintStream(new ConsoleOutputStream( this, 0x04)); - this.claimSystemOutErr = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR) == 0); + //todo crawley, will the console not set System.out/err any more? +// this.claimSystemOutErr = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR) == 0); + this.claimSystemOutErr = false; this.myIsolate = VmIsolate.currentIsolate(); } Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -192,7 +192,7 @@ defaultCommandInvoker = new DefaultCommandInvoker(this); threadCommandInvoker = new ThreadCommandInvoker(this); procletCommandInvoker = new ProcletCommandInvoker(this); - this.commandInvoker = threadCommandInvoker; // default to separate + setThreadCommandInvoker(); // default to separate this.console.addConsoleListener(this); // threads for commands. aliasMgr = ((AliasManager) InitialNaming.lookup(AliasManager.NAME)) @@ -518,53 +518,59 @@ if (isHistoryEnabled()) { // Insert a filter on the input stream that adds completed input lines // to the application input history. - // TODO - revisit for support of muilt-byte character encodings. - return new FilterInputStream(in) { - private StringBuilder line = new StringBuilder(); - - @Override - public int read() throws IOException { - int res = super.read(); - if (res != -1) { - filter((byte) res); - } - return res; - } - - @Override - public int read(byte[] buf, int offset, int len) throws IOException { - int res = super.read(buf, offset, len); - for (int i = 0; i < res; i++) { - filter(buf[offset + i]); - } - return res; - } - - @Override - public int read(byte[] buf) throws IOException { - int res = super.read(buf); - for (int i = 0; i < res; i++) { - filter(buf[i]); - } - return res; - } - - private void filter(byte b) { - if (b == '\n') { - addInputToHistory(line.toString()); - line.setLength(0); - } - else { - line.append((char) b); - } - } - }; + return new HistoryInputStream(in); } else { return in; } } + + private class HistoryInputStream extends FilterInputStream { + // TODO - revisit for support of multi-byte character encodings. + private StringBuilder line = new StringBuilder(); + + public HistoryInputStream(InputStream in) { + super(in); + } + + @Override + public int read() throws IOException { + int res = super.read(); + if (res != -1) { + filter((byte) res); + } + return res; + } + @Override + public int read(byte[] buf, int offset, int len) throws IOException { + int res = super.read(buf, offset, len); + for (int i = 0; i < res; i++) { + filter(buf[offset + i]); + } + return res; + } + + @Override + public int read(byte[] buf) throws IOException { + int res = super.read(buf); + for (int i = 0; i < res; i++) { + filter(buf[i]); + } + return res; + } + + private void filter(byte b) { + if (b == '\n') { + addInputToHistory(line.toString()); + line.setLength(0); + } + else { + line.append((char) b); + } + } + } + public PrintStream getOutputStream() { return out; } Modified: trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -29,6 +29,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import org.jnode.shell.help.Help; @@ -62,12 +63,15 @@ cmdName); } - Runnable createRunner(Class cx, Method method, Object[] args, InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { - return new CommandRunner(cx, method, args); + Runnable createRunner(Class cx, Method method, Object[] args, + InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { + return new CommandRunner(cx, method, args,commandIn, commandOut, commandErr); } class CommandRunner implements Runnable { - + private final InputStream commandIn; + private final PrintStream commandOut; + private final PrintStream commandErr; private Class cx; Method method; @@ -76,16 +80,28 @@ boolean finished = false; - public CommandRunner(Class cx, Method method, Object[] args) { + public CommandRunner(Class cx, Method method, Object[] args, + InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { this.cx = cx; this.method = method; this.args = args; + this.commandIn = commandIn; + this.commandOut = commandOut; + this.commandErr = commandErr; } public void run() { try { try { - Object obj = null; + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + System.setOut(commandOut); + System.setErr(commandErr); + System.setIn(commandIn); + return null; + } + }); + Object obj = null; if(!Modifier.isStatic(method.getModifiers())) { obj = cx.newInstance(); } Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -109,21 +109,17 @@ } else if (newConsole) { if (isolateNewConsole) { try { - Isolate newIsolate = new Isolate(ConsoleCommand.class.getName(), new String[] { "-n" }); + Isolate newIsolate = new Isolate( + ConsoleCommand.IsolatedConsole.class.getName(), + new String[0]); newIsolate.start(); + System.out.println("Started new isolated console"); } catch (IsolateStartupException ex) { System.out.println("Failed to start new isolated console"); ex.printStackTrace(System.err); } } else { - final TextConsole console = (TextConsole) conMgr.createConsole( - null, ConsoleManager.CreateOptions.TEXT - | ConsoleManager.CreateOptions.SCROLLABLE); - CommandShell commandShell = new CommandShell(console); - new Thread(commandShell).start(); - - System.out.println("Console created with name:" - + console.getConsoleName()); + createConsoleWithShell(conMgr); } } else { System.out.println("test RawTextConsole"); @@ -134,4 +130,36 @@ console.clear(); } } + + private static class IsolatedConsole { + + public static void main(String[] args) { + try { + final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); + final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); + TextConsole console = createConsoleWithShell(conMgr); + System.setIn(console.getIn()); + System.setOut(console.getOut()); + System.setErr(console.getErr()); + } + catch (Exception ex) { + // FIXME + System.out.println("Problem creating the isolated console"); + ex.printStackTrace(System.err); + } + } + } + + private static TextConsole createConsoleWithShell(final ConsoleManager conMgr) + throws ShellException { + final TextConsole console = (TextConsole) conMgr.createConsole( + null, ConsoleManager.CreateOptions.TEXT + | ConsoleManager.CreateOptions.SCROLLABLE); + CommandShell commandShell = new CommandShell(console); + new Thread(commandShell).start(); + + System.out.println("Console created with name:" + + console.getConsoleName()); + return console; + } } Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -304,4 +304,17 @@ public Throwable getUncaughtException() { return uncaughtException; } + + /** + * Return a human-readable String representing this ProcletContext. + * @return a human-readable String representing this ProcletContext + */ + public String toString() + { + return getClass().getName() + + "[name=" + getName() + ",maxpri=" + getMaxPriority() + + ",pid=" + getPid() + ']'; + } + + } Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2007-09-15 08:37:26 UTC (rev 3500) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2007-09-15 18:01:39 UTC (rev 3501) @@ -10,6 +10,7 @@ /** * @author Levente S\u00e1ntha + * @author cr...@jn... */ public class ProcletIOContext implements IOContext { private static InputStream globalInStream; @@ -117,4 +118,31 @@ VmSystem.setStaticField(System.class, "out", out); VmSystem.setStaticField(System.class, "err", err); } + + public PrintStream getRealSystemErr() { + ProcletContext procletContext = ProcletContext.currentProcletContext(); + if (procletContext != null) { + return (PrintStream) procletContext.getStream(2); + } else { + return globalErrStream; + } + } + + public InputStream getRealSystemIn() { + ProcletContext procletContext = ProcletContext.currentProcletContext(); + if (procletContext != null) { + return (InputStream) procletContext.getStream(0); + } else { + return globalInStream; + } + } + + public PrintStream getRealSystemOut() { + ProcletContext procletContext = ProcletContext.currentProcletContext(); + if (procletContext != null) { + return (PrintStream) procletContext.getStream(1); + } else { + return globalOutStream; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-09-15 18:14:08
|
Revision: 3502 http://jnode.svn.sourceforge.net/jnode/?rev=3502&view=rev Author: fduminy Date: 2007-09-15 11:14:00 -0700 (Sat, 15 Sep 2007) Log Message: ----------- Added ant task to check that native methods are properly implemented. For now, method signature is not checked. Modified Paths: -------------- trunk/all/build.xml trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java trunk/core/.classpath trunk/core/src/core/org/jnode/vm/VmSystemClassLoader.java trunk/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java Added Paths: ----------- trunk/builder/src/builder/org/jnode/ant/taskdefs/NativeCheckTask.java trunk/core/src/core/org/jnode/vm/VmUtils.java Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/all/build.xml 2007-09-15 18:14:00 UTC (rev 3502) @@ -166,7 +166,7 @@ </target> <!-- Assemble all plugins --> - <target name="assemble-plugins" depends="assemble-projects,openjdk-annotate"> + <target name="assemble-plugins" depends="assemble-projects,openjdk-annotate,native-method-check"> <!-- Now assemble all plugins --> <taskdef name="plugin" classname="org.jnode.build.PluginTask" classpathref="cp-jnode"/> <plugin todir="${plugins.dir}" tmpdir="${build.dir}/tmp/plugins" pluginDir="${descriptors.dir}"> @@ -623,7 +623,7 @@ </fileset> </vmspecificsources> <classpathsources> - <fileset dir="${root.dir}/../openjdk/j2se/src/share/classes/"> + <fileset dir="${root.dir}/../../openjdk/j2se/src/share/classes/"> <patternset refid="cp-includes-pattern"/> <patternset refid="cp-sources-pattern"/> </fileset> @@ -638,13 +638,26 @@ classpathref="cp-jnode"/> <oj-annotate annotationFile="${root.dir}/all/conf/openjdk-annotations.properties" - trace="false"> + trace="false" failonerror="true"> <fileset dir="${root.dir}/core/build/classes"> <patternset includes="**/*.class"/> </fileset> </oj-annotate> </target> + <!-- check that all native methods are properly implemented for JNode --> + <target name="native-method-check" depends="assemble-projects"> + <echo message="native-method-check"/> + <taskdef name="native-check" classname="org.jnode.ant.taskdefs.NativeCheckTask" + classpathref="cp-jnode"/> + + <native-check trace="false" failonerror="false"> + <fileset dir="${root.dir}/core/build/classes"> + <patternset includes="**/*.class"/> + </fileset> + </native-check> + </target> + <!-- Run all tests --> <target name="tests" depends="assemble"> <ant target="tests" dir="${root.dir}/fs" inheritall="on" inheritrefs="on"/> Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/AnnotateTask.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -60,9 +60,8 @@ private File annotationFile; private String[] classesFiles; - private boolean trace = true; - public void execute() throws BuildException { + protected void doExecute() throws BuildException { classesFiles = readProperties(annotationFile); processFiles(); } @@ -74,11 +73,6 @@ public final void setAnnotationFile(File annotationFile) { this.annotationFile = annotationFile; } - - public final void setTrace(boolean trace) - { - this.trace = trace; - } /** * Read the properties file. For now, it simply contains a list of Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/FileSetTask.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -37,14 +37,55 @@ * */ abstract public class FileSetTask extends Task { - + protected boolean trace = false; + protected boolean failOnError = true; + private final ArrayList<FileSet> fileSets = new ArrayList<FileSet>(); + public final void setTrace(boolean trace) + { + this.trace = trace; + } + + public final void setFailOnError(boolean failOnError) + { + this.failOnError = failOnError; + } + public void addFileSet(FileSet fs) { fileSets.add(fs); } - public void execute() throws BuildException { + final public void execute() throws BuildException { + try + { + doExecute(); + } + catch(BuildException be) + { + if(failOnError) + { + throw be; + } + else + { + be.printStackTrace(); + } + } + catch(Throwable t) + { + if(failOnError) + { + throw new BuildException(t); + } + else + { + t.printStackTrace(); + } + } + } + + protected void doExecute() throws BuildException { // default implementation : simply iterate on all files processFiles(); } Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -68,7 +68,7 @@ return line.trim().equals(hdrLine.trim()); } - public void execute() throws BuildException { + protected void doExecute() throws BuildException { if (headerFile == null) { throw new BuildException("HeaderFile must be set"); } Added: trunk/builder/src/builder/org/jnode/ant/taskdefs/NativeCheckTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/NativeCheckTask.java (rev 0) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/NativeCheckTask.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -0,0 +1,333 @@ +/* + * $Id: HeaderTask.java 3379 2007-08-04 10:19:57Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.ant.taskdefs; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.tools.ant.BuildException; +import org.jnode.vm.VmUtils; +import org.objectweb.asm.Attribute; +import org.objectweb.asm.ClassAdapter; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.CodeVisitor; +import org.objectweb.asm.attrs.Attributes; + +/** + * That ant task will check that native methods are properly implemented + * for JNode. + * + * @author Fabien DUMINY (fduminy at jnode.org) + * + */ +public class NativeCheckTask extends FileSetTask { + /** + * potential implementation of the native methods for JNode. + * key: className (String) + * value: native methods for the class (List<NativeMethod>) + */ + private Map<String,List<NativeMethod>> jnodeNativeMethods = new HashMap<String, List<NativeMethod>>(); + + /** + * native methods per class + * key: className (String) + * value: native methods for the class (List<NativeMethod>) + */ + private Map<String,List<NativeMethod>> nativeMethods = new HashMap<String,List<NativeMethod>>(); + + private Set<String> missingClasses = new TreeSet<String>(); + private Map<String,List<NativeMethod>> missingMethods = new HashMap<String,List<NativeMethod>>(); + + protected void doExecute() throws BuildException { + // process all classes to find native methods + // and classes that could potentially implement native methods + // for JNode + processFiles(); + + // now, check all native methods are properly implemented + // for JNode + int nbNativeMethods = 0; + for(String className : nativeMethods.keySet()) + { + List<NativeMethod> methods = nativeMethods.get(className); + for(NativeMethod method : methods) + { + nbNativeMethods++; + checkNativeMethod(className, method); + } + } + + // report + final String INDENT = " "; + + int nbMissingClasses = missingClasses.size(); + if(!missingClasses.isEmpty()) + { + System.err.println("Missing classes:"); + for(String missingClass : missingClasses) + { + System.err.println(INDENT+missingClass); + } + } + + int nbMissingMethods = 0; + if(!missingMethods.isEmpty()) + { + System.err.println("Missing methods:"); + for(String cls : missingMethods.keySet()) + { + System.err.println(INDENT+" class "+cls); + for(NativeMethod m : missingMethods.get(cls)) + { + System.err.println(INDENT+INDENT+m.getName()); + nbMissingMethods++; + } + } + } + + System.out.println("Found "+nbNativeMethods+" native methods in "+nativeMethods.size()+" classes"); + if((nbMissingMethods != 0) || (nbMissingClasses != 0)) + { + System.err.println(missingClasses.size()+" missing classes. "+nbMissingMethods+" missing methods"); + + String message = "Some native methods are not properly implemented (see errors above)"; + if(failOnError) + { + throw new BuildException(message); + } + else + { + System.err.println("[FAILED] "+message); + } + } + else + { + System.out.println("[OK] All native methods are properly defined"); + } + } + + private boolean checkNativeMethod(String className, NativeMethod method) + { + boolean hasError = false; + String jnodeNativeClass = VmUtils.getNativeClassName(className.replace('/', '.')); + + if(jnodeNativeMethods.containsKey(jnodeNativeClass)) + { + List<NativeMethod> methods = jnodeNativeMethods.get(jnodeNativeClass); + boolean found = false; + for(NativeMethod nvMethod : methods) + { + if(method.getName().equals(nvMethod.getName())) + { + found = true; + break; + } + } + + if(!found) + { + List<NativeMethod> methodList = missingMethods.get(jnodeNativeClass); + if(methodList == null) + { + methodList = new ArrayList<NativeMethod>(); + missingMethods.put(jnodeNativeClass, methodList); + } + + methodList.add(method); + hasError = true; + } + } + else + { + missingClasses.add(jnodeNativeClass); + hasError = true; + } + + return hasError; + } + + @Override + protected void processFile(File file) throws IOException { + FileInputStream fis = null; + + try + { + fis = new FileInputStream(file); + NativeMethodClassVisitor v = getNativeMethods(file, fis); + if((v != null) && !v.getNativeMethods().isEmpty()) + { + if(v.couldImplementNativeMethods()) + { + jnodeNativeMethods.put(v.getClassName(), v.getNativeMethods()); + } + else + { + nativeMethods.put(v.getClassName(), v.getNativeMethods()); + } + } + } + finally + { + if(fis != null) + { + fis.close(); + } + } + } + + private NativeMethodClassVisitor getNativeMethods(File file, InputStream inputClass) throws BuildException { + ClassWriter cw = new ClassWriter(false); + NativeMethodClassVisitor v = null; + try { + ClassReader cr = new ClassReader(inputClass); + v = new NativeMethodClassVisitor(file, cw); + cr.accept(v, Attributes.getDefaultAttributes(), true); + + if(v.allowNatives()) + { + // if natives are allowed for that class, no need to check + // for a pure java implementation + v = null; + } + } catch (Exception ex) { + System.err.println("Unable to load class in file "+file.getAbsolutePath()+" : "+ex.getMessage()); + } + return v; + } + + private static class NativeMethodClassVisitor extends ClassAdapter { + private String className; + private boolean couldImplementNativeMethods; + private boolean allowNatives = false; + private List<NativeMethod> nativeMethods = new ArrayList<NativeMethod>(); + + public NativeMethodClassVisitor(File file, ClassVisitor cv) { + super(cv); + } + + @Override + public void visit(int version, + int access, + String name, + String superName, + String[] interfaces, + String sourceFile) + { + this.className = name.replace('/','.'); + this.allowNatives = VmUtils.allowNatives(className, "x86"); //TODO hard coded architecture: change that ! + this.couldImplementNativeMethods = VmUtils.couldImplementNativeMethods(className); + + super.visit(version, access, name, superName, interfaces, sourceFile); + } + + @Override + public CodeVisitor visitMethod(int access, + String name, + String desc, + String[] exceptions, + Attribute attrs) + { + if(!allowNatives) + { + // we don't allow native for that class => + // we must have a pure java implementation for that method + + if((couldImplementNativeMethods && isStatic(access)) || + isNative(access)) + { + nativeMethods.add(new NativeMethod(access, name, desc)); + } + } + + return null; // we don't to visit inside the method + } + + public String getClassName() { + return className; + } + + public List<NativeMethod> getNativeMethods() { + return nativeMethods; + } + + public boolean couldImplementNativeMethods() { + return couldImplementNativeMethods; + } + + public boolean allowNatives() { + return allowNatives; + } + } + + private static class NativeMethod + { + private final int access; + private final String name; + private final String desc; + public NativeMethod(int access, String name, String desc) { + super(); + this.access = access; + this.name = name; + this.desc = desc; + } + public int getAccess() { + return access; + } + public String getName() { + return name; + } + public String getDesc() { + return desc; + } + + public String toString() + { + return name + " " + desc; + } + } + + public static boolean isNative(int access) + { + return isSet(access, org.objectweb.asm.Constants.ACC_NATIVE); + } + + public static boolean isStatic(int access) + { + return isSet(access, org.objectweb.asm.Constants.ACC_STATIC); + } + + private static boolean isSet(int access, int flag) + { + return ((access & flag) == flag); + } +} Modified: trunk/core/.classpath =================================================================== --- trunk/core/.classpath 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/core/.classpath 2007-09-15 18:14:00 UTC (rev 3502) @@ -26,6 +26,7 @@ <classpathentry kind="lib" path="lib/mmtk/mmtk.jar" sourcepath="D:/epr/cvswork/MMTk/src"/> <classpathentry exported="true" kind="lib" path="lib/asm-1.5.3.jar"/> <classpathentry exported="true" kind="lib" path="lib/asm-attrs-1.5.3.jar"/> + <classpathentry exported="true" kind="lib" path="lib/asm-util-1.5.3.jar"/> <classpathentry kind="src" path="src/nanoxml"/> <classpathentry kind="lib" path="lib/mauve.jar"/> <classpathentry kind="output" path="build/classes"/> Modified: trunk/core/src/core/org/jnode/vm/VmSystemClassLoader.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmSystemClassLoader.java 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/core/src/core/org/jnode/vm/VmSystemClassLoader.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -401,11 +401,8 @@ private VmType loadNormalClass(String name) throws IOException, ClassNotFoundException { - boolean allowNatives = false; - allowNatives |= name.equals("org.jnode.vm.Unsafe"); final String archN = arch.getName(); - allowNatives |= name.equals("org.jnode.vm." + archN + ".Unsafe" - + archN.toUpperCase()); + boolean allowNatives = VmUtils.allowNatives(name, archN); // System.out.println("bvi.loadClass: " +name); final ByteBuffer image = getClassData(name); Added: trunk/core/src/core/org/jnode/vm/VmUtils.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmUtils.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/VmUtils.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -0,0 +1,37 @@ +package org.jnode.vm; + +import gnu.java.lang.VMClassHelper; + +/** + * Utility class to share some Vm features. + * For now, it's especially used to know how native methods are implemented in JNode. + * + * @author Fabien DUMINY (fduminy at jnode.org) + * + */ +public class VmUtils { + private static final String NATIVE_CLASSNAME_PREFIX = "Native"; + public static boolean couldImplementNativeMethods(String className) + { + String clsName = VMClassHelper.getClassNamePortion(className); + return clsName.startsWith(NATIVE_CLASSNAME_PREFIX); + } + + public static String getNativeClassName(String className) + { + final String pkg = VMClassHelper.getPackagePortion(className); + final String nativeClassName = pkg + ((pkg.length() > 0) ? "." : "") + + NATIVE_CLASSNAME_PREFIX + VMClassHelper.getClassNamePortion(className); + return nativeClassName; + } + + public static boolean allowNatives(String className, String architectureName) + { + boolean allowNatives = false; + allowNatives |= className.equals("org.jnode.vm.Unsafe"); + allowNatives |= className.equals("org.jnode.vm." + architectureName + ".Unsafe" + + architectureName.toUpperCase()); + + return allowNatives; + } +} Modified: trunk/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java =================================================================== --- trunk/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java 2007-09-15 18:01:39 UTC (rev 3501) +++ trunk/core/src/core/org/jnode/vm/classmgr/ClassDecoder.java 2007-09-15 18:14:00 UTC (rev 3502) @@ -29,6 +29,7 @@ import java.security.ProtectionDomain; import org.jnode.system.BootLog; +import org.jnode.vm.VmUtils; import org.jnode.vm.annotation.AllowedPackages; import org.jnode.vm.annotation.CheckPermission; import org.jnode.vm.annotation.DoPrivileged; @@ -482,9 +483,7 @@ private static VmByteCode getNativeCodeReplacement(VmMethod method, VmClassLoader cl, boolean verbose) { final String className = method.getDeclaringClass().getName(); - final String pkg = VMClassHelper.getPackagePortion(className); - final String nativeClassName = pkg + ((pkg.length() > 0) ? "." : "") - + "Native" + VMClassHelper.getClassNamePortion(className); + final String nativeClassName = VmUtils.getNativeClassName(className); final VmType nativeType; try { nativeType = cl.loadClass(nativeClassName, true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-09-16 02:55:10
|
Revision: 3505 http://jnode.svn.sourceforge.net/jnode/?rev=3505&view=rev Author: fduminy Date: 2007-09-15 19:55:08 -0700 (Sat, 15 Sep 2007) Log Message: ----------- fixed build error Modified Paths: -------------- trunk/all/build.xml trunk/core/descriptors/org.objectweb.asm.xml Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2007-09-15 21:45:19 UTC (rev 3504) +++ trunk/all/build.xml 2007-09-16 02:55:08 UTC (rev 3505) @@ -57,6 +57,7 @@ <property name="cglib.jar" value="${root.dir}/core/lib/cglib-2.1.jar"/> <property name="asm.jar" value="${root.dir}/core/lib/asm-1.5.3.jar"/> <property name="asm-attrs.jar" value="${root.dir}/core/lib/asm-attrs-1.5.3.jar"/> + <property name="asm-util.jar" value="${root.dir}/core/lib/asm-util-1.5.3.jar"/> <property name="jcfe.jar" value="${root.dir}/core/lib/jcfe.jar"/> <property name="jfunc.jar" value="${root.dir}/core/lib/jfunc.jar"/> @@ -94,6 +95,7 @@ <pathelement location="${jmock-cglib.jar}"/> <pathelement location="${asm.jar}"/> <pathelement location="${asm-attrs.jar}"/> + <pathelement location="${asm-util.jar}"/> <pathelement location="${cglib.jar}"/> <pathelement location="${log4j.jar}"/> <pathelement location="${gnu-crypto.jar}"/> @@ -202,6 +204,7 @@ <libalias name="jmock-cglib-1.0.1.jar" alias="${jmock-cglib.jar}"/> <libalias name="asm.jar" alias="${asm.jar}"/> <libalias name="asm-attrs.jar" alias="${asm-attrs.jar}"/> + <libalias name="asm-util.jar" alias="${asm-util.jar}"/> <libalias name="cglib.jar" alias="${cglib.jar}"/> <libalias name="mauve.jar" alias="${mauve.jar}"/> <libalias name="jcfe.jar" alias="${jcfe.jar}"/> Modified: trunk/core/descriptors/org.objectweb.asm.xml =================================================================== --- trunk/core/descriptors/org.objectweb.asm.xml 2007-09-15 21:45:19 UTC (rev 3504) +++ trunk/core/descriptors/org.objectweb.asm.xml 2007-09-16 02:55:08 UTC (rev 3505) @@ -15,5 +15,8 @@ <library name="asm-attrs.jar"> <export name="org.objectweb.asm.*"/> </library> + <library name="asm-util.jar"> + <export name="org.objectweb.asm.*"/> + </library> </runtime> </plugin> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-09-21 08:42:01
|
Revision: 3514 http://jnode.svn.sourceforge.net/jnode/?rev=3514&view=rev Author: lsantha Date: 2007-09-21 01:41:58 -0700 (Fri, 21 Sep 2007) Log Message: ----------- Support for multiple argument to cat, by crawley. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/shell/src/shell/org/jnode/shell/help/Syntax.java Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-09-17 20:22:50 UTC (rev 3513) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-09-21 08:41:58 UTC (rev 3514) @@ -30,7 +30,6 @@ import java.net.MalformedURLException; import java.net.URL; -import org.apache.log4j.Logger; import org.jnode.shell.Command; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Argument; @@ -45,17 +44,19 @@ * @author Stephen Crawley * @author Fabien DUMINY (fd...@jn...) */ -public class CatCommand implements Command{ - //private static final Logger log = Logger.getLogger(CatCommand.class); +public class CatCommand implements Command { static final Argument ARG_FILE = new FileArgument("file", - "the file (or URL) to print out"); + "the files (or URLs) to be concatenated", true); public static Help.Info HELP_INFO = new Help.Info("cat", - "Print the contents of the given file (or URL). " + - "If the file is omitted, standard input is read until EOF is reached; " + + "Concatenate the contents of the files, writing them to standatd output. " + + "If there are no arguments, standard input is read until EOF is reached; " + "e.g. ^D when reading keyboard input.", new Parameter[] { new Parameter(ARG_FILE, Parameter.OPTIONAL)}); + + private static final int BUFFER_SIZE = 1024; + public static void main(String[] args) throws Exception { new CatCommand().execute(new CommandLine(args), System.in, System.out, System.err); @@ -63,94 +64,102 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { ParsedArguments cmdLine = HELP_INFO.parse(commandLine.toStringArray()); - String fileName = ARG_FILE.getValue(cmdLine); - InputStream is = null; - boolean isNewFile = false; + String[] fileNames = ARG_FILE.getValues(cmdLine); + boolean ok = true; try { - if (fileName == null) { - isNewFile = true; - is = in; + if (fileNames.length == 0) { + process(in, out); } else { - URL url = openURL(fileName); - if(url != null) - { - try { - is = url.openStream(); - } - catch (IOException ex) { - //log.error("can't read "+fileName, ex); - err.println("Can't access file from url " + fileName); - } + for (String fileName : fileNames) { + InputStream is = null; + try { + try { + // Try to parse the argument as a URL + URL url = new URL(fileName); + try { + // Open stream connection for URL + is = url.openStream(); + } catch (IOException ex) { + err.println("Can't access file from url " + + fileName + ": " + ex.getMessage()); + } + } catch (MalformedURLException ex) { + // If the argument didn't parse as a URL, treat it as a filename + // and open a FileInputStream + is = openFile(fileName, err); + } + + if (is == null) { + ok = false; + } + else { + process(is, out); + } + } finally { + if (is != null) { + try { + is.close(); + } + catch (IOException ex) { + // ignore. + } + } + } } - else - { - // it's not really an error since we can expect a file - // instead of an url -> write to out and not to err - //out.println("Not an url -> assuming it's a file."); - - is = openFile(fileName, err); - } - - if (is == null) { - // Here, we already have printed an appropriate - // error message. Simply return an errorcode. - - // FIXME ... System.exit(1); - return; - } } - - int len; - final byte[] buf = new byte[ 1024]; - while ((len = is.read(buf)) > 0) { - out.write(buf, 0, len); - } - - out.flush(); + out.flush(); + } catch (IOException ex) { + // Deal with i/o errors reading from in/is or writing to out. + err.println("Problem concatenating file(s): " + ex.getMessage()); + ok = false; } - finally { - if (is != null && !isNewFile) { - is.close(); - } - } + // TODO need to set a 'return code'; e.g. + // if (!ok) { System.exit(1); } } - - private URL openURL(String fname) { - URL url = null; - - try { - url = new URL(fname); - } catch (MalformedURLException ex) { - //log.error(ex); - } - - return url; + + /** + * Copy all of stream 'in' to stream 'out' + * @param in + * @param out + * @throws IOException + */ + private void process(InputStream in, PrintStream out) throws IOException { + int len; + final byte[] buf = new byte[BUFFER_SIZE]; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } } + /** + * Attempt to open a file, writing an error message on failure. + * @param fname the filename of the file to be opened + * @param err where we write error messages + * @return An open stream, or <code>null</code>. + */ private InputStream openFile(String fname, PrintStream err) { InputStream is = null; try { File file = new File(fname); - if(!file.exists()) - { + // FIXME we shouldn't be doing these tests. Rather, we should be + // just trying to create the FileInputStream and printing the + // exception message on failure. (That assumes that the exception + // message is accurate!) + if (!file.exists()) { err.println("File doesn't exist"); } - else if(file.isDirectory()) - { - err.println("Can't print content of a directory"); + else if (file.isDirectory()) { + err.println("Can't concatenate a directory"); } - else - { + else { is = new FileInputStream(file); } } catch (FileNotFoundException ex) { // should never happen since we check for existence before } - // here, if is is null we should have already printed - // an appropriate error message return is; } Modified: trunk/shell/src/shell/org/jnode/shell/help/Syntax.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/Syntax.java 2007-09-17 20:22:50 UTC (rev 3513) +++ trunk/shell/src/shell/org/jnode/shell/help/Syntax.java 2007-09-21 08:41:58 UTC (rev 3514) @@ -118,20 +118,19 @@ } else { throw new SyntaxErrorException("Unexpected argument \"" + s + "\""); } - //} + } - // no check if there is an argument, as else we would have - // exited before (Parameter satisfied) - final boolean last = !cmdLine.hasNext(); - Argument arg = param.getArgument(); - String value = visitor.visitValue(s, last, cmdLine.getTokenType()); - if (value != null) { - if (visitor.isValueValid(arg, value, last)) { - arg.setValue(value); - } else { - throw new SyntaxErrorException("Invalid value for argument"); - } - } + // no check if there is an argument, as else we would have + // exited before (Parameter satisfied) + final boolean last = !cmdLine.hasNext(); + Argument arg = param.getArgument(); + String value = visitor.visitValue(s, last, cmdLine.getTokenType()); + if (value != null) { + if (visitor.isValueValid(arg, value, last)) { + arg.setValue(value); + } else { + throw new SyntaxErrorException("Invalid value for argument"); + } } if (param.isSatisfied()) param = null; } while (cmdLine.hasNext()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-09-21 21:06:26
|
Revision: 3515 http://jnode.svn.sourceforge.net/jnode/?rev=3515&view=rev Author: lsantha Date: 2007-09-21 14:06:24 -0700 (Fri, 21 Sep 2007) Log Message: ----------- Enabled networking support for isolates. Modified Paths: -------------- trunk/core/src/classpath/java/java/net/ServerSocket.java trunk/core/src/classpath/java/java/net/Socket.java trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java trunk/net/src/net/org/jnode/net/command/PingCommand.java Modified: trunk/core/src/classpath/java/java/net/ServerSocket.java =================================================================== --- trunk/core/src/classpath/java/java/net/ServerSocket.java 2007-09-21 08:41:58 UTC (rev 3514) +++ trunk/core/src/classpath/java/java/net/ServerSocket.java 2007-09-21 21:06:24 UTC (rev 3515) @@ -43,11 +43,11 @@ import java.io.IOException; import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.ServerSocketChannel; +import org.jnode.vm.annotation.SharedStatics; - /* Written using on-line Java Platform 1.2 API Specification. - * Status: I believe all methods are implemented. - */ +* Status: I believe all methods are implemented. +*/ /** * This class models server side sockets. The basic model is that the @@ -62,6 +62,7 @@ * @author Aaron M. Renn (ar...@ur...) * @author Per Bothner (bo...@cy...) */ +@SharedStatics public class ServerSocket { /** Modified: trunk/core/src/classpath/java/java/net/Socket.java =================================================================== --- trunk/core/src/classpath/java/java/net/Socket.java 2007-09-21 08:41:58 UTC (rev 3514) +++ trunk/core/src/classpath/java/java/net/Socket.java 2007-09-21 21:06:24 UTC (rev 3515) @@ -45,11 +45,11 @@ import java.io.OutputStream; import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.SocketChannel; +import org.jnode.vm.annotation.SharedStatics; - /* Written using on-line Java Platform 1.2 API Specification. - * Status: I believe all methods are implemented. - */ +* Status: I believe all methods are implemented. +*/ /** * This class models a client site socket. A socket is a TCP/IP endpoint @@ -68,6 +68,7 @@ * @author Aaron M. Renn (ar...@ur...) * @author Per Bothner (bo...@cy...) */ +@SharedStatics public class Socket { /** @@ -368,17 +369,20 @@ } catch (IOException exception) { - close(); + exception.printStackTrace(); + close(); throw exception; } catch (RuntimeException exception) { - close(); + exception.printStackTrace(); + close(); throw exception; } catch (Error error) { - close(); + error.printStackTrace(); + close(); throw error; } } Modified: trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java =================================================================== --- trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java 2007-09-21 08:41:58 UTC (rev 3514) +++ trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java 2007-09-21 21:06:24 UTC (rev 3515) @@ -251,8 +251,9 @@ } catch( IOException ioe ) { - System.err.println( "Couldn't start server:\n" + ioe ); - System.exit( -1 ); + System.err.println( "Couldn't start server:\n"); + ioe.printStackTrace(); + System.exit( -1 ); } nh.myFileDir = new File(""); Modified: trunk/net/src/net/org/jnode/net/command/PingCommand.java =================================================================== --- trunk/net/src/net/org/jnode/net/command/PingCommand.java 2007-09-21 08:41:58 UTC (rev 3514) +++ trunk/net/src/net/org/jnode/net/command/PingCommand.java 2007-09-21 21:06:24 UTC (rev 3515) @@ -43,6 +43,7 @@ import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; import org.jnode.shell.help.argument.HostNameArgument; +import org.jnode.vm.annotation.SharedStatics; /** * @author JPG @@ -167,7 +168,7 @@ this.stat.recordPacket(roundtrip); } } - +@SharedStatics class Request extends TimerTask { private static Map<Integer, Request> requests = new HashMap<Integer, Request>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-10-11 20:12:49
|
Revision: 3544 http://jnode.svn.sourceforge.net/jnode/?rev=3544&view=rev Author: lsantha Date: 2007-10-11 13:12:46 -0700 (Thu, 11 Oct 2007) Log Message: ----------- Tidy up usage of java.security.PrivilegedAction by crawley. Modified Paths: -------------- trunk/core/src/classpath/vm/gnu/java/security/action/GetBooleanAction.java trunk/core/src/classpath/vm/gnu/java/security/action/GetIntegerAction.java trunk/core/src/classpath/vm/gnu/java/security/action/GetPolicyAction.java trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java trunk/core/src/classpath/vm/gnu/java/security/action/InvokeAction.java trunk/core/src/classpath/vm/gnu/java/security/action/SetPropertyAction.java trunk/core/src/classpath/vm/java/lang/Class.java trunk/core/src/classpath/vm/java/lang/ClassLoader.java trunk/core/src/core/org/jnode/debugger/Debugger.java trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java trunk/gui/src/awt/org/jnode/awt/KeyboardHandler.java trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java trunk/gui/src/driver/org/jnode/driver/video/ati/radeon/RadeonCore.java trunk/gui/src/test/org/jnode/test/gui/ConsoleTest.java trunk/gui/src/test/org/jnode/test/gui/Editor.java trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/ThreadNameArgument.java Modified: trunk/core/src/classpath/vm/gnu/java/security/action/GetBooleanAction.java =================================================================== --- trunk/core/src/classpath/vm/gnu/java/security/action/GetBooleanAction.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/gnu/java/security/action/GetBooleanAction.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -29,7 +29,7 @@ * @see Boolean#getBoolean(String) * @author Ewout Prangsma (ep...@us...) */ -public class GetBooleanAction implements PrivilegedAction { +public class GetBooleanAction implements PrivilegedAction<Boolean> { private final String key; @@ -40,7 +40,7 @@ /** * @see java.security.PrivilegedAction#run() */ - public Object run() { + public Boolean run() { return Boolean.valueOf(Boolean.getBoolean(key)); } } Modified: trunk/core/src/classpath/vm/gnu/java/security/action/GetIntegerAction.java =================================================================== --- trunk/core/src/classpath/vm/gnu/java/security/action/GetIntegerAction.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/gnu/java/security/action/GetIntegerAction.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -30,7 +30,7 @@ * @see Integer#getInteger(String, Integer) * @author Ewout Prangsma (ep...@us...) */ -public class GetIntegerAction implements PrivilegedAction { +public class GetIntegerAction implements PrivilegedAction<Integer> { private final String key; private final Integer defaultValue; @@ -51,7 +51,7 @@ /** * @see java.security.PrivilegedAction#run() */ - public Object run() { + public Integer run() { return Integer.getInteger(key, defaultValue); } } Modified: trunk/core/src/classpath/vm/gnu/java/security/action/GetPolicyAction.java =================================================================== --- trunk/core/src/classpath/vm/gnu/java/security/action/GetPolicyAction.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/gnu/java/security/action/GetPolicyAction.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -30,7 +30,7 @@ * @see java.security.Policy * @author Ewout Prangsma (ep...@us...) */ -public class GetPolicyAction implements PrivilegedAction { +public class GetPolicyAction implements PrivilegedAction<Policy> { private static final GetPolicyAction instance = new GetPolicyAction(); @@ -45,7 +45,7 @@ /** * @see java.security.PrivilegedAction#run() */ - public Object run() { + public Policy run() { return Policy.getPolicy(); } Modified: trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java =================================================================== --- trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -22,6 +22,7 @@ package gnu.java.security.action; import java.security.PrivilegedAction; +import java.util.Properties; /** @@ -29,12 +30,12 @@ * * @author Ewout Prangsma (ep...@us...) */ -public class GetPropertiesAction implements PrivilegedAction { +public class GetPropertiesAction implements PrivilegedAction<Properties> { /** * @see java.security.PrivilegedAction#run() */ - public Object run() { + public Properties run() { return System.getProperties(); } } Modified: trunk/core/src/classpath/vm/gnu/java/security/action/InvokeAction.java =================================================================== --- trunk/core/src/classpath/vm/gnu/java/security/action/InvokeAction.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/gnu/java/security/action/InvokeAction.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -31,7 +31,7 @@ * * @author Ewout Prangsma (ep...@us...) */ -public class InvokeAction implements PrivilegedExceptionAction { +public class InvokeAction implements PrivilegedExceptionAction<Object> { private final Method method; private final Object object; Modified: trunk/core/src/classpath/vm/gnu/java/security/action/SetPropertyAction.java =================================================================== --- trunk/core/src/classpath/vm/gnu/java/security/action/SetPropertyAction.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/gnu/java/security/action/SetPropertyAction.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -29,7 +29,7 @@ * * @author Ewout Prangsma (ep...@us...) */ -public class SetPropertyAction implements PrivilegedAction { +public class SetPropertyAction implements PrivilegedAction<Void> { private final String key; private final String value; @@ -47,7 +47,7 @@ * Set the property * @see java.security.PrivilegedAction#run() */ - public Object run() { + public Void run() { System.setProperty(key, value); return null; } Modified: trunk/core/src/classpath/vm/java/lang/Class.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/Class.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -1424,8 +1424,8 @@ try { final Method values = getMethod("values"); java.security.AccessController.doPrivileged - (new java.security.PrivilegedAction() { - public Object run() { + (new java.security.PrivilegedAction<Void>() { + public Void run() { values.setAccessible(true); return null; } Modified: trunk/core/src/classpath/vm/java/lang/ClassLoader.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/ClassLoader.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/classpath/vm/java/lang/ClassLoader.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -133,9 +133,9 @@ static final ProtectionDomain defaultProtectionDomain; static { final CodeSource cs = new CodeSource(null, null); - PermissionCollection perm = (PermissionCollection) AccessController - .doPrivileged(new PrivilegedAction() { - public Object run() { + PermissionCollection perm = AccessController + .doPrivileged(new PrivilegedAction<PermissionCollection>() { + public PermissionCollection run() { return Policy.getPolicy().getPermissions(cs); } }); @@ -406,10 +406,10 @@ } if (protDomain == null) { - protDomain = (ProtectionDomain) AccessController - .doPrivileged(new PrivilegedAction() { + protDomain = AccessController + .doPrivileged(new PrivilegedAction<ProtectionDomain>() { - public Object run() { + public ProtectionDomain run() { return getDefaultProtectionDomain(); } }); @@ -434,10 +434,9 @@ throw new NullPointerException(); } if (protDomain == null) { - protDomain = (ProtectionDomain) AccessController - .doPrivileged(new PrivilegedAction() { - - public Object run() { + protDomain = AccessController.doPrivileged( + new PrivilegedAction<ProtectionDomain>() { + public ProtectionDomain run() { return getDefaultProtectionDomain(); } }); Modified: trunk/core/src/core/org/jnode/debugger/Debugger.java =================================================================== --- trunk/core/src/core/org/jnode/debugger/Debugger.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/core/src/core/org/jnode/debugger/Debugger.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -42,7 +42,7 @@ * @author Ewout Prangsma (ep...@us...) */ public class Debugger implements SystemTriggerListener, KeyboardListener, - PrivilegedAction { + PrivilegedAction<Void> { private boolean enabled; @@ -93,7 +93,7 @@ * * @see java.security.PrivilegedAction#run() */ - public Object run() { + public Void run() { final PrintStream out = VmSystem.getOut(); DebugState st = this.state; @@ -143,7 +143,7 @@ private void setPreferredListener() { final KeyboardListener l = this; - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { try { Modified: trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java =================================================================== --- trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -492,9 +492,9 @@ */ public Image getImage(final String filename) { log.debug("getImage(" + filename + ")"); - return testErrorImage((Image) AccessController.doPrivileged(new PrivilegedAction() { + return testErrorImage(AccessController.doPrivileged(new PrivilegedAction<Image>() { - public Object run() { + public Image run() { try { final String userDir = (String) AccessController.doPrivileged( new GetPropertyAction("user.dir")); @@ -514,8 +514,8 @@ * @see java.awt.Toolkit#getImage(java.net.URL) */ public Image getImage(final URL url) { - return testErrorImage((Image) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return testErrorImage(AccessController.doPrivileged(new PrivilegedAction<Image>() { + public Image run() { try { return ImageIO.read(url); } catch (Exception ex) { @@ -663,8 +663,8 @@ screenSize, eventQueue, keyboardHandler); keyboardHandler.install(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { onInitialize(); return null; } Modified: trunk/gui/src/awt/org/jnode/awt/KeyboardHandler.java =================================================================== --- trunk/gui/src/awt/org/jnode/awt/KeyboardHandler.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/gui/src/awt/org/jnode/awt/KeyboardHandler.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -70,8 +70,8 @@ keyboardAPI = (KeyboardAPI) keyboardDevice .getAPI(KeyboardAPI.class); keyboardAPI.addKeyboardListener(this); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { keyboardAPI.setPreferredListener(KeyboardHandler.this); return null; } @@ -147,8 +147,8 @@ if (key_code == KeyEvent.VK_F12 && event.isAltDown() || key_code == KeyEvent.VK_BACK_SPACE && event.isAltDown() && event.isControlDown()) { event.consume(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { JNodeToolkit.stopGui(); return null; } @@ -156,8 +156,8 @@ return true; } else if (key_code == KeyEvent.VK_F11 && event.isAltDown()) { event.consume(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { JNodeToolkit.getJNodeToolkit().leaveGUI(); return null; } @@ -165,8 +165,8 @@ return true; } else if (key_code == KeyEvent.VK_F5 && event.isControlDown() && event.isAltDown()) { event.consume(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { JNodeToolkit.refreshGui(); return null; } @@ -196,8 +196,8 @@ * Install this handler as current keyboard focus manager. */ public void install() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { //setCurrentKeyboardFocusManager(KeyboardHandler.this); return null; } @@ -208,8 +208,8 @@ * Uninstall this handler as current keyboard focus manager. */ public void uninstall() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { //setCurrentKeyboardFocusManager(null); return null; } Modified: trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/gui/src/driver/org/jnode/driver/console/swing/SwingTextScreenConsoleManager.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -28,8 +28,8 @@ } protected void openInput(DeviceManager devMan) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { SwingPcTextScreen systemScreen = getTextScreenManager().getSystemScreen(); final JComponent screen = systemScreen.getScreenComponent(); initializeKeyboard(systemScreen.getKeyboardDevice()); Modified: trunk/gui/src/driver/org/jnode/driver/video/ati/radeon/RadeonCore.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/video/ati/radeon/RadeonCore.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/gui/src/driver/org/jnode/driver/video/ati/radeon/RadeonCore.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -393,10 +393,10 @@ */ private final MemoryResource findRom(final ResourceOwner owner, final ResourceManager rm) throws ResourceNotFreeException { - final MemoryScanner scanner = (MemoryScanner) AccessController - .doPrivileged(new PrivilegedAction() { + final MemoryScanner scanner = AccessController + .doPrivileged(new PrivilegedAction<MemoryScanner>() { - public Object run() { + public MemoryScanner run() { return rm.getMemoryScanner(); } }); Modified: trunk/gui/src/test/org/jnode/test/gui/ConsoleTest.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/ConsoleTest.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/gui/src/test/org/jnode/test/gui/ConsoleTest.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -55,8 +55,8 @@ private void claimPrintStreams() { System.out.println( "Claiming print streams." ); - AccessController.doPrivileged( new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged( new PrivilegedAction<Void>() { + public Void run() { System.setOut( savedOut ); System.setErr( savedOut ); return null; Modified: trunk/gui/src/test/org/jnode/test/gui/Editor.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/Editor.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/gui/src/test/org/jnode/test/gui/Editor.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -161,8 +161,8 @@ } private void readFile(final File file) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { try { FileInputStream fis = new FileInputStream(file); byte[] data = new byte[fis.available()]; @@ -189,8 +189,8 @@ } private void writeFile(final File file) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { try { FileWriter fw = new FileWriter(file); fw.write(textArea.getText()); Modified: trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -255,8 +255,8 @@ if (threadProcess != null) { unblock(); - AccessController.doPrivileged(new PrivilegedAction(){ - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>(){ + public Void run() { threadProcess.stop(new ThreadDeath()); return null; }}); Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -243,8 +243,8 @@ } final String user_home = (String) AccessController.doPrivileged(new GetPropertyAction("user.home", "")); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { try { final File shell_ini = new File(user_home + "/shell.ini"); if(shell_ini.exists()) Modified: trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -65,8 +65,8 @@ try { // System.err.println("Invoking..."); try { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { System.setOut(commandShell.getOutputStream()); System.setErr(commandShell.getErrorStream()); System.setIn(commandShell.getInputStream()); Modified: trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -93,8 +93,8 @@ public void run() { try { try { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { System.setOut(commandOut); System.setErr(commandErr); System.setIn(commandIn); Modified: trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -88,8 +88,8 @@ try { try { // - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { System.setOut(commandOut); System.setErr(commandErr); System.setIn(commandIn); Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -91,10 +91,9 @@ // Find the final File f = new File(dir); - final String[] names = (String[]) AccessController - .doPrivileged(new PrivilegedAction() { - - public Object run() { + final String[] names = AccessController + .doPrivileged(new PrivilegedAction <String[]>() { + public String[] run() { if (!f.exists()) { return null; } else { Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/ThreadNameArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/ThreadNameArgument.java 2007-10-11 09:16:06 UTC (rev 3543) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/ThreadNameArgument.java 2007-10-11 20:12:46 UTC (rev 3544) @@ -48,8 +48,8 @@ } final ThreadGroup grp_f = grp; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { findList(grp_f, partial, names); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-10-17 18:30:20
|
Revision: 3557 http://jnode.svn.sourceforge.net/jnode/?rev=3557&view=rev Author: lsantha Date: 2007-10-17 11:30:15 -0700 (Wed, 17 Oct 2007) Log Message: ----------- Initial version of NFS file system implementation by Andrei Dore. Modified Paths: -------------- trunk/all/build.xml trunk/all/conf/default-plugin-list.xml trunk/fs/.classpath trunk/fs/build.xml trunk/net/.classpath trunk/net/build.xml trunk/net/descriptors/org.jnode.net.command.xml Added Paths: ----------- trunk/fs/descriptors/org.jnode.fs.nfs.command.xml trunk/fs/descriptors/org.jnode.fs.nfs.xml trunk/fs/src/fs/org/jnode/fs/nfs/ trunk/fs/src/fs/org/jnode/fs/nfs/command/ trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Device.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Directory.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Driver.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Entry.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2File.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystem.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Object.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2RootEntry.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/DirPath.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/FileHandle.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Mount1Client.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/MountResult.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Name.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/AbstractResult.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/Entry.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileAttribute.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileType.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/ListDirectoryResult.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/LookupResult.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/NFS2Client.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/ReadFileResult.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/Status.java trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/Time.java trunk/net/descriptors/org.acplt.oncrpc.xml trunk/net/lib/oncrpc.jar trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2007-10-16 08:24:55 UTC (rev 3556) +++ trunk/all/build.xml 2007-10-17 18:30:15 UTC (rev 3557) @@ -50,6 +50,7 @@ <property name="edtftpj.jar" value="${root.dir}/fs/lib/edtftpj-1.5.2.jar"/> <property name="jcifs.jar" value="${root.dir}/fs/lib/jcifs-1.2.6.jar"/> <property name="ejc.jar" value="${root.dir}/core/lib/ejc-3.1.1.jar"/> + <property name="oncrpc.jar" value="${root.dir}/net/lib/oncrpc.jar"/> <!-- libraries needed to run tests --> <property name="jmock-cglib.jar" value="${root.dir}/core/lib/jmock-cglib-1.0.1.jar"/> @@ -217,7 +218,8 @@ <libalias name="edtftpj.jar" alias="${edtftpj.jar}"/> <libalias name="jcifs.jar" alias="${jcifs.jar}"/> <libalias name="ejc.jar" alias="${ejc.jar}"/> - + <libalias name="oncrpc.jar" alias="${oncrpc.jar}"/> + <descriptors dir="${descriptors.dir}/"> <include name="*.xml"/> <exclude name="*plugin-list.xml"/> Modified: trunk/all/conf/default-plugin-list.xml =================================================================== --- trunk/all/conf/default-plugin-list.xml 2007-10-16 08:24:55 UTC (rev 3556) +++ trunk/all/conf/default-plugin-list.xml 2007-10-17 18:30:15 UTC (rev 3557) @@ -119,6 +119,9 @@ <plugin id="jcifs"/> <plugin id="org.jnode.fs.smbfs"/> <plugin id="org.jnode.fs.smbfs.command"/> + + <plugin id="org.jnode.fs.nfs"/> + <plugin id="org.jnode.fs.nfs.command"/> <plugin id="org.jnode.partitions"/> @@ -140,6 +143,8 @@ <plugin id="org.jnode.protocol"/> <plugin id="org.jnode.protocol.ftp"/> <plugin id="org.jnode.protocol.tftp"/> + + <plugin id="org.acplt.oncrpc"/> <plugin id="org.jnode.shell"/> <plugin id="org.jnode.shell.help"/> Modified: trunk/fs/.classpath =================================================================== --- trunk/fs/.classpath 2007-10-16 08:24:55 UTC (rev 3556) +++ trunk/fs/.classpath 2007-10-17 18:30:15 UTC (rev 3557) @@ -17,5 +17,6 @@ <classpathentry kind="lib" path="/JNode-Core/lib/commons-net-1.1.0.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/jcfe.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/jfunc.jar"/> + <classpathentry kind="lib" path="/JNode-Net/lib/oncrpc.jar"/> <classpathentry kind="output" path="build/classes"/> </classpath> Modified: trunk/fs/build.xml =================================================================== --- trunk/fs/build.xml 2007-10-16 08:24:55 UTC (rev 3556) +++ trunk/fs/build.xml 2007-10-17 18:30:15 UTC (rev 3557) @@ -14,6 +14,7 @@ <pathelement location="${edtftpj.jar}"/> <pathelement location="${commons-net.jar}"/> <pathelement location="${jcifs.jar}"/> + <pathelement location="${oncrpc.jar}"/> <path refid="cp"/> </path> Added: trunk/fs/descriptors/org.jnode.fs.nfs.command.xml =================================================================== --- trunk/fs/descriptors/org.jnode.fs.nfs.command.xml (rev 0) +++ trunk/fs/descriptors/org.jnode.fs.nfs.command.xml 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plugin SYSTEM "jnode.dtd"> + +<plugin id="org.jnode.fs.nfs.command" + name="NFS file system commands for JNode" + version="@VERSION@" + license-name="lgpl" + provider-name="JNode.org"> + + + <requires> + <import plugin="org.jnode.shell"/> + <import plugin="org.jnode.fs.nfs"/> + </requires> + + <runtime> + <library name="jnode-fs.jar"> + <export name="org.jnode.fs.nfs.command.*"/> + </library> + </runtime> + + <extension point="org.jnode.shell.aliases"> + <alias name="nfsmount" + class="org.jnode.fs.nfs.command.NFSMountCommand"/> + </extension> + + <extension point="org.jnode.security.permissions"> + <permission class="java.net.SocketPermission" name="*" actions="connect,resolve"/> + </extension> + +</plugin> \ No newline at end of file Added: trunk/fs/descriptors/org.jnode.fs.nfs.xml =================================================================== --- trunk/fs/descriptors/org.jnode.fs.nfs.xml (rev 0) +++ trunk/fs/descriptors/org.jnode.fs.nfs.xml 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plugin SYSTEM "jnode.dtd"> + +<plugin id="org.jnode.fs.nfs" + name="NFS file system for JNode" + version="@VERSION@" + license-name="lgpl" + provider-name="JNode.org"> + + + <requires> + <import plugin="org.jnode.fs"/> + <import plugin="org.acplt.oncrpc"/> + </requires> + + <runtime> + <library name="jnode-fs.jar"> + <export name="org.jnode.fs.nfs.*"/> + <export name="org.jnode.fs.nfs.nfs2.*"/> + <export name="org.jnode.fs.nfs.nfs2.rpc.mount.*"/> + <export name="org.jnode.fs.nfs.nfs2.rpc.nfs.*"/> + </library> + </runtime> + + + <extension point="org.jnode.fs.types"> + <type class="org.jnode.fs.nfs.nfs2.NFS2FileSystemType"/> + </extension> + + + <extension point="org.jnode.security.permissions"> + <permission class="java.net.SocketPermission" name="*" actions="connect,resolve"/> + </extension> + +</plugin> \ No newline at end of file Added: trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,82 @@ +/* + * $Id: NFSMountCommand.java 2945 2006-12-20 08:51:17Z qades $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.command; + +import java.io.InputStream; +import java.io.PrintStream; + +import org.jnode.driver.DeviceManager; +import org.jnode.driver.DeviceUtils; +import org.jnode.fs.FileSystem; +import org.jnode.fs.FileSystemType; +import org.jnode.fs.nfs.nfs2.NFS2Device; +import org.jnode.fs.nfs.nfs2.NFS2Driver; +import org.jnode.fs.nfs.nfs2.NFS2FileSystemType; +import org.jnode.fs.service.FileSystemService; +import org.jnode.naming.InitialNaming; +import org.jnode.shell.Command; +import org.jnode.shell.CommandLine; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.Parameter; +import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.FileArgument; + +/** + * @author Andrei Dore + */ +public class NFSMountCommand implements Command { + private static final FileArgument MOUNTPOINT_ARG = new FileArgument("directory", "the mountpoint"); + private static final Argument HOST_ARG = new Argument("host", "NFS host"); + private static final Argument REMOTE_DIRECTORY_ARG = new Argument("remoteDir", "remote directory"); + static Help.Info HELP_INFO = new Help.Info("mount", "Mount an NFS filesystem", + new Parameter[]{new Parameter(MOUNTPOINT_ARG, Parameter.MANDATORY), + new Parameter(HOST_ARG, Parameter.MANDATORY), new Parameter(REMOTE_DIRECTORY_ARG, Parameter.MANDATORY) + }); + + public static void main(String[] args) throws Exception { + new NFSMountCommand().execute(new CommandLine(args), System.in, + System.out, System.err); + } + + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + ParsedArguments cmdLine = HELP_INFO.parse(commandLine.toStringArray()); + + final String mount_point = MOUNTPOINT_ARG.getValue(cmdLine); + final String host = HOST_ARG.getValue(cmdLine); + final String remoteDirectory = REMOTE_DIRECTORY_ARG.getValue(cmdLine); + + + final NFS2Device dev = new NFS2Device(host, remoteDirectory); + dev.setDriver(new NFS2Driver()); + final DeviceManager dm = DeviceUtils.getDeviceManager(); + dm.register(dev); + final FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME); + FileSystemType type = fss.getFileSystemTypeForNameSystemTypes(NFS2FileSystemType.NAME); + final FileSystem fs = type.create(dev, true); + fss.registerFileSystem(fs); + fss.mount(mount_point, fs, null); + + + } +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Device.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Device.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Device.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,51 @@ +/* + * $Id: FTPFSDevice.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import org.jnode.driver.Device; + +/** + * @author Andrei Dore + */ +public class NFS2Device extends Device { + private String host; + private String remoteDirectory; + + + public NFS2Device(String host, String remoteDirectory) { + super(null, "nfs-(" + host + "," + remoteDirectory + ")"); + this.host = host; + this.remoteDirectory = remoteDirectory; + + } + + public String getHost() { + return host; + } + + + public String getRemoteDirectory() { + return remoteDirectory; + } + + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Directory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Directory.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Directory.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,172 @@ +/* + * $Id: FTPFSDirectory.java 2260 2006-01-22 11:10:07Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.acplt.oncrpc.OncRpcException; +import org.jnode.fs.FSDirectory; +import org.jnode.fs.FSEntry; +import org.jnode.fs.nfs.nfs2.rpc.nfs.Entry; +import org.jnode.fs.nfs.nfs2.rpc.nfs.ListDirectoryResult; +import org.jnode.fs.nfs.nfs2.rpc.nfs.LookupResult; +import org.jnode.fs.nfs.nfs2.rpc.nfs.NFS2Client; +import org.jnode.fs.nfs.nfs2.rpc.nfs.Status; + +/** + * @author Andrei Dore + */ +public class NFS2Directory extends NFS2Object implements FSDirectory { + + private static final Iterator<NFS2Entry> EMPTY_ENTRY_ITERATOR = new EmptyIterator(); + + private byte[] fileHandle; + + NFS2Directory(NFS2FileSystem fileSystem, byte[] fileHandle) { + super(fileSystem); + this.fileHandle = fileHandle; + } + + /** + * Gets the entry with the given name. + * + * @param name + * @throws java.io.IOException + */ + public NFS2Entry getEntry(String name) throws IOException { + + NFS2Client nfsClient = ((NFS2FileSystem) getFileSystem()).getNFSClient(); + + LookupResult lookupResult; + try { + lookupResult = nfsClient.lookup(fileHandle, name); + } catch (OncRpcException e) { + throw new IOException("Can not call the rpc method"); + } + + if (lookupResult != null && lookupResult.getStatus() == Status.NFS_OK) { + + NFS2Entry nfs2Entry = new NFS2Entry((NFS2FileSystem) getFileSystem(), this, name, lookupResult + .getFileHandle(), lookupResult.getFileAttribute()); + + return nfs2Entry; + + } + + return null; + + } + + /** + * Gets an iterator used to iterate over all the entries of this directory. + * All elements returned by the iterator must be instanceof FSEntry. + */ + public Iterator<? extends NFS2Entry> iterator() throws IOException { + + NFS2Client nfsClient = ((NFS2FileSystem) getFileSystem()).getNFSClient(); + + try { + ListDirectoryResult result = nfsClient.listDirectory(fileHandle, new byte[NFS2Client.COOKIE_SIZE], 1024); + + if (result.getStatus() == Status.NFS_OK) { + + if (result.isEof()) { + + return EMPTY_ENTRY_ITERATOR; + } + + Entry entry = result.getEntry(); + + List<NFS2Entry> nfsEntryList = new ArrayList<NFS2Entry>(); + while (entry != null) { + + LookupResult lookupResult = nfsClient.lookup(fileHandle, entry.getName()); + + if (lookupResult.getStatus() == Status.NFS_OK) { + + NFS2Entry nfs2Entry = new NFS2Entry((NFS2FileSystem) getFileSystem(), this, entry.getName(), + lookupResult.getFileHandle(), lookupResult.getFileAttribute()); + + + nfsEntryList.add(nfs2Entry); + + } + + entry = entry.getNextEntry(); + + } + + + return nfsEntryList.iterator(); + + } else { + throw new IOException("Response is not ok." + result.getStatus()); + // return null; + } + + } catch (OncRpcException e) { + throw new IOException( + "An error occurs when the nfs file system tried to fetch the content of the directory", e); + } + + } + + public FSEntry addDirectory(String name) throws IOException { + // TODO Auto-generated method stub + return null; + } + + public FSEntry addFile(String name) throws IOException { + // TODO Auto-generated method stub + return null; + } + + public void flush() throws IOException { + // TODO Auto-generated method stub + + } + + public void remove(String name) throws IOException { + // TODO Auto-generated method stub + + } + + private static final class EmptyIterator implements Iterator<NFS2Entry> { + + public boolean hasNext() { + return false; + } + + public NFS2Entry next() { + return null; + } + + public void remove() { + + } + + } + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Driver.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Driver.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Driver.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,56 @@ +/* + * $Id: NFSDriver.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import org.jnode.driver.DeviceAlreadyRegisteredException; +import org.jnode.driver.Driver; +import org.jnode.driver.DriverException; + +/** + * @author Andrei Dore + */ +public class NFS2Driver extends Driver { + /** + * Start the device. + * + * @throws org.jnode.driver.DriverException + * + */ + protected void startDevice() throws DriverException { + try { + NFS2Device device = (NFS2Device) getDevice(); + device.getManager().rename(device, device.getId(), true); + } catch (DeviceAlreadyRegisteredException ex) { + throw new DriverException(ex); + } + } + + /** + * Stop the device. + * + * @throws org.jnode.driver.DriverException + * + */ + protected void stopDevice() throws DriverException { + + } +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Entry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Entry.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Entry.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,133 @@ +/* + * $Id: FTPFSEntry.java 2260 2006-01-22 11:10:07Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import java.io.IOException; + +import org.jnode.fs.FSAccessRights; +import org.jnode.fs.FSDirectory; +import org.jnode.fs.FSEntry; +import org.jnode.fs.FSFile; +import org.jnode.fs.nfs.nfs2.rpc.nfs.FileAttribute; +import org.jnode.fs.nfs.nfs2.rpc.nfs.FileType; + +/** + * @author Andrei Dore + */ +public class NFS2Entry extends NFS2Object implements FSEntry { + + private NFS2Directory parent; + + private NFS2Directory directory; + + private NFS2File file; + + private byte[] fileHandle; + + private FileAttribute fileAttribute; + + private String name; + + NFS2Entry(NFS2FileSystem fileSystem, NFS2Directory parent, String name, byte[] fileHandle, + FileAttribute fileAttribute) { + super(fileSystem); + + this.parent = parent; + this.name = name; + this.fileAttribute = fileAttribute; + + if (fileAttribute.getType() == FileType.DIRECTORY) { + directory = new NFS2Directory(fileSystem, fileHandle); + + } else if (fileAttribute.getType() == FileType.FILE) { + file = new NFS2File(fileSystem, fileHandle, fileAttribute); + + } + + } + + public FSDirectory getParent() { + return parent; + } + + public String getName() { + return name; + } + + public FSAccessRights getAccessRights() throws IOException { + // TODO Auto-generated method stub + return null; + } + + public FSDirectory getDirectory() throws IOException { + if (!isDirectory()) { + throw new IOException(getName() + " is not a directory"); + } + + return directory; + } + + public FSFile getFile() throws IOException { + if (!isFile()) { + throw new IOException(getName() + " is not a file"); + } + + return file; + } + + public long getLastModified() throws IOException { + return fileAttribute.getLastModified().getMicroSeconds(); + } + + public boolean isDirectory() { + + if (fileAttribute.getType() == FileType.DIRECTORY) { + return true; + } + + return false; + } + + public boolean isDirty() throws IOException { + return false; + } + + public boolean isFile() { + + if (fileAttribute.getType() == FileType.FILE) { + return true; + } + + return false; + } + + public void setLastModified(long lastModified) throws IOException { + // TODO Auto-generated method stub + + } + + public void setName(String newName) throws IOException { + // TODO Auto-generated method stub + + } + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2File.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2File.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2File.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,118 @@ +/* + * $Id: FTPFSFile.java 2406 2006-03-23 06:17:24Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.acplt.oncrpc.OncRpcException; +import org.jnode.fs.FSFile; +import org.jnode.fs.nfs.nfs2.rpc.nfs.FileAttribute; +import org.jnode.fs.nfs.nfs2.rpc.nfs.NFS2Client; +import org.jnode.fs.nfs.nfs2.rpc.nfs.ReadFileResult; +import org.jnode.fs.nfs.nfs2.rpc.nfs.Status; + +/** + * @author Andrei Dore + */ +public class NFS2File extends NFS2Object implements FSFile { + + private byte[] fileHandle; + private FileAttribute fileAttribute; + + NFS2File(NFS2FileSystem fileSystem, byte[] fileHandle, FileAttribute fileAttribute) { + super(fileSystem); + this.fileHandle = fileHandle; + this.fileAttribute = fileAttribute; + } + + /** + * Gets the length (in bytes) of this file + * + * @return long + */ + public long getLength() { + return fileAttribute.getSize(); + } + + /** + * Read <code>len</code> bytes from the given position. The read data is + * read fom this file starting at offset <code>fileOffset</code> and + * stored in <code>dest</code> starting at offset <code>ofs</code>. + * + * @param fileOffset + * @param dest + * @throws java.io.IOException + */ + public void read(long fileOffset, ByteBuffer dest) throws IOException { + + NFS2Client client = getNFSClient(); + + try { + ReadFileResult result = client.readFile(fileHandle, (int) fileOffset, dest.remaining()); + + if (result.getStatus() == Status.NFS_OK) { + fileAttribute = result.getFileAttribute(); + dest.put(result.getData()); + } else { + throw new IOException("Error " + result.getStatus()); + } + + } catch (OncRpcException e) { + throw new IOException(e.getMessage(), e); + } + + } + + /** + * Flush any cached data to the disk. + * + * @throws java.io.IOException + */ + public void flush() throws IOException { + + } + + /** + * Sets the length of this file. + * + * @param length + * @throws java.io.IOException + */ + public void setLength(long length) throws IOException { + + } + + /** + * Write <code>len</code> bytes to the given position. The data is read + * from <code>src</code> starting at offset <code>ofs</code> and written + * to this file starting at offset <code>fileOffset</code>. + * + * @param fileOffset + * @param src + * @throws java.io.IOException + */ + public void write(long fileOffset, ByteBuffer src) throws IOException { + + } + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystem.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystem.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,178 @@ +/* + * $Id: FTPFileSystem.java 3337 2007-06-30 11:58:44Z fduminy $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.OncRpcProtocols; +import org.jnode.driver.Device; +import org.jnode.driver.DeviceListener; +import org.jnode.fs.FSEntry; +import org.jnode.fs.FileSystem; +import org.jnode.fs.FileSystemException; +import org.jnode.fs.nfs.nfs2.rpc.mount.DirPath; +import org.jnode.fs.nfs.nfs2.rpc.mount.Mount1Client; +import org.jnode.fs.nfs.nfs2.rpc.mount.MountResult; +import org.jnode.fs.nfs.nfs2.rpc.nfs.NFS2Client; + +/** + * @author Andrei Dore + */ +public class NFS2FileSystem implements FileSystem { + + private NFS2Device device; + + private NFS2RootEntry root; + + private Mount1Client mountClient; + private NFS2Client nfsClient; + + private boolean closed; + + public NFS2FileSystem(final NFS2Device device) throws FileSystemException { + this.device = device; + device.addListener(new DeviceListener() { + public void deviceStarted(Device device) { + } + + public void deviceStop(Device device) { + try { + close(); + } catch (IOException x) { + // Ignore this + } + } + }); + + try { + mountClient = new Mount1Client(InetAddress.getByName(device.getHost()), OncRpcProtocols.ONCRPC_UDP); + + nfsClient = new NFS2Client(InetAddress.getByName(device.getHost()), OncRpcProtocols.ONCRPC_UDP); + + MountResult result = mountClient.mount(new DirPath(device.getRemoteDirectory())); + + // + if (result.getStatus() == Mount1Client.MOUNT_OK) { + + root = new NFS2RootEntry(this, result.getDirectory().getValue()); + + } else { + throw new IOException("The status of the call it is not ok "); + } + + } catch (Exception e) { + + // Not good . Improve exception handling . Give more detail . + throw new FileSystemException(e.getMessage(), e); + } + + } + + /** + * Close this filesystem. After a close, all invocations of method of this + * filesystem or objects created by this filesystem will throw an + * IOException. + * + * @throws java.io.IOException + */ + public void close() throws IOException { + + // Improve the exception !!!!!!!!!!!!!!! + Exception unmountException = null; + try { + mountClient.unmount(new DirPath(device.getRemoteDirectory())); + } catch (OncRpcException ex) { + unmountException = ex; + } + + Exception nfsException = null; + try { + nfsClient.close(); + } catch (OncRpcException ex) { + nfsException = ex; + } + + Exception mountException = null; + try { + mountClient.close(); + } catch (OncRpcException ex) { + mountException = ex; + } + + if (unmountException != null || nfsException != null || mountException != null) { + throw new IOException("Can not close the nfs file system "); + } + + } + + /** + * Gets the device this FS driver operates on. + */ + public NFS2Device getDevice() { + return device; + } + + /** + * Gets the root entry of this filesystem. This is usually a directory, but + * this is not required. + */ + public FSEntry getRootEntry() throws IOException { + return root; + } + + /** + * Is this filesystem closed. + */ + public synchronized boolean isClosed() { + return closed; + } + + /** + * Is the filesystem mounted in readonly mode ? + */ + public boolean isReadOnly() { + return true; + } + + public long getFreeSpace() { + // TODO implement me + return 0; + } + + public long getTotalSpace() { + // TODO implement me + return 0; + } + + public long getUsableSpace() { + // TODO implement me + return 0; + } + + NFS2Client getNFSClient() { + return nfsClient; + } + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2FileSystemType.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,77 @@ +/* + * $Id: NFSFileSystemType.java 2452 2006-04-09 16:44:50Z fduminy $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.fs.nfs.nfs2; + +import org.jnode.driver.Device; +import org.jnode.driver.block.FSBlockDeviceAPI; +import org.jnode.fs.FileSystemException; +import org.jnode.fs.FileSystemType; +import org.jnode.partitions.PartitionTableEntry; + +/** + * @author Andrei Dore + */ +public class NFS2FileSystemType implements FileSystemType<NFS2FileSystem> { + public static final String NAME = "NFS2"; + + /** + * Create a filesystem from a given device. + * + * @param device + * @param readOnly + */ + public NFS2FileSystem create(Device device, boolean readOnly) throws FileSystemException { + return new NFS2FileSystem((NFS2Device) device); + } + + /** + * Gets the unique name of this file system type. + */ + public String getName() { + return NAME; + } + + /** + * Can this file system type be used on the given first sector of a + * blockdevice? + * + * @param pte The partition table entry, if any. If null, there is no + * partition table entry. + * @param firstSector + */ + public boolean supports(PartitionTableEntry pte, byte[] firstSector, FSBlockDeviceAPI devApi) { + return false; + } + + /** + * Format a filesystem for a given device according to its Partition table entry. + * + * @param device The device on which you want to format with this FileSystemType + * @param specificOptions the specific options for this filesystemType + * @return the newly created FileSystem + * @throws org.jnode.fs.FileSystemException + * + */ + public NFS2FileSystem format(Device device, Object specificOptions) throws FileSystemException { + return null; + } +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Object.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Object.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2Object.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,28 @@ +package org.jnode.fs.nfs.nfs2; + +import org.jnode.fs.FSObject; +import org.jnode.fs.FileSystem; +import org.jnode.fs.nfs.nfs2.rpc.nfs.NFS2Client; + +public class NFS2Object implements FSObject { + + private NFS2FileSystem fileSystem; + + NFS2Object(NFS2FileSystem fileSystem) { + this.fileSystem = fileSystem; + } + + public FileSystem getFileSystem() { + return fileSystem; + } + + public boolean isValid() { + // TODO Auto-generated method stub + return false; + } + + public NFS2Client getNFSClient() { + return fileSystem.getNFSClient(); + } + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2RootEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2RootEntry.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/NFS2RootEntry.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,74 @@ +package org.jnode.fs.nfs.nfs2; + +import java.io.IOException; + +import org.jnode.fs.FSAccessRights; +import org.jnode.fs.FSDirectory; +import org.jnode.fs.FSEntry; +import org.jnode.fs.FSFile; + +public class NFS2RootEntry extends NFS2Object implements FSEntry { + + private byte[] fileHandle; + + private NFS2Directory directory; + + NFS2RootEntry(NFS2FileSystem fileSystem, byte[] fileHandle) { + + super(fileSystem); + + this.fileHandle = fileHandle; + + directory = new NFS2Directory(fileSystem, fileHandle); + + } + + public FSAccessRights getAccessRights() throws IOException { + // TODO Auto-generated method stub + return null; + } + + public FSDirectory getDirectory() throws IOException { + return directory; + } + + public FSFile getFile() throws IOException { + throw new IOException("It is not a file. It is the root of the file system."); + } + + public long getLastModified() throws IOException { + return 0; + } + + public String getName() { + return "/"; + } + + public FSDirectory getParent() { + return null; + } + + public boolean isDirectory() { + return true; + } + + public boolean isDirty() throws IOException { + return false; + } + + public boolean isFile() { + return false; + } + + public void setLastModified(long lastModified) throws IOException { + throw new IOException("Cannot change last modified of root directory"); + + } + + public void setName(String newName) throws IOException { + throw new IOException("Cannot change name of root directory"); + + } + + +} Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/DirPath.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/DirPath.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/DirPath.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,48 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:09 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.mount; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public class DirPath implements XdrAble { + + private String value; + + + public DirPath() { + } + + public DirPath(String value) { + this.value = value; + } + + public DirPath(XdrDecodingStream xdr) + throws OncRpcException, IOException { + xdrDecode(xdr); + } + + public void xdrEncode(XdrEncodingStream xdr) + throws OncRpcException, IOException { + xdr.xdrEncodeString(value); + } + + public void xdrDecode(XdrDecodingStream xdr) + throws OncRpcException, IOException { + value = xdr.xdrDecodeString(); + } + + public String getValue() { + return value; + } + + +} +// End of DirPath.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/FileHandle.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/FileHandle.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/FileHandle.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,48 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:09 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.mount; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public class FileHandle implements XdrAble { + + private byte[] value; + + + public FileHandle() { + } + + public FileHandle(byte[] value) { + this.value = value; + } + + public FileHandle(XdrDecodingStream xdr) + throws OncRpcException, IOException { + xdrDecode(xdr); + } + + public void xdrEncode(XdrEncodingStream xdr) + throws OncRpcException, IOException { + xdr.xdrEncodeOpaque(value, Mount1Client.FILE_HANDLE_SIZE); + } + + public void xdrDecode(XdrDecodingStream xdr) + throws OncRpcException, IOException { + value = xdr.xdrDecodeOpaque(Mount1Client.FILE_HANDLE_SIZE); + } + + public byte[] getValue() { + return value; + } + + +} +// End of FileHandle.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Mount1Client.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Mount1Client.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Mount1Client.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,99 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:09 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.mount; + +import java.io.IOException; +import java.net.InetAddress; + +import org.acplt.oncrpc.OncRpcClientStub; +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrVoid; + +/** + * The class <code>Mount1Client</code> implements the client stub proxy for + * the MOUNTPROG remote program. It provides method stubs which, when called, in + * turn call the appropriate remote method (procedure). + */ +public class Mount1Client extends OncRpcClientStub { + + private static final int MOUNT_CODE = 100005; + private static final int MOUNT_VERSION = 1; + + private static final int PROCEDURE_TEST = 0; + private static final int PROCEDURE_MOUNT = 1; + private static final int PROCEDURE_UNMOUNT = 3; + + public static final int FILE_HANDLE_SIZE = 32; + public static final int MAX_PATH_LENGHT = 1024; + public static final int MAX_NAME_LENGHT = 255; + + public static final int MOUNT_OK = 0; + + /** + * Constructs a <code>Mount1Client</code> client stub proxy object from + * which the MOUNTPROG remote program can be accessed. + * + * @param host Internet address of host where to contact the remote + * program. + * @param protocol {@link org.acplt.oncrpc.OncRpcProtocols Protocol} to be + * used for ONC/RPC calls. + * @throws OncRpcException if an ONC/RPC error occurs. + * @throws IOException if an I/O error occurs. + */ + public Mount1Client(InetAddress host, int protocol) throws OncRpcException, IOException { + super(host, MOUNT_CODE, 1, 0, protocol); + } + + /** + * Constructs a <code>Mount1Client</code> client stub proxy object from + * which the MOUNTPROG remote program can be accessed. + * + * @param host Internet address of host where to contact the remote + * program. + * @param port Port number at host where the remote program can be + * reached. + * @param protocol {@link org.acplt.oncrpc.OncRpcProtocols Protocol} to be + * used for ONC/RPC calls. + * @throws OncRpcException if an ONC/RPC error occurs. + * @throws IOException if an I/O error occurs. + */ + public Mount1Client(InetAddress host, int port, int protocol) throws OncRpcException, IOException { + super(host, MOUNT_CODE, 1, port, protocol); + } + + /** + * Call remote procedure test. + * + * @throws OncRpcException if an ONC/RPC error occurs. + * @throws IOException if an I/O error occurs. + */ + public void test() throws OncRpcException, IOException { + XdrVoid argument = XdrVoid.XDR_VOID; + XdrVoid result = XdrVoid.XDR_VOID; + client.call(PROCEDURE_TEST, MOUNT_VERSION, argument, result); + } + + /** + * Call remote procedure mount. + * + * @param dirPath parameter (of type DirPath) to the remote procedure call. + * @return Result from remote procedure call (of type MountResult). + * @throws OncRpcException if an ONC/RPC error occurs. + * @throws IOException if an I/O error occurs. + */ + public MountResult mount(DirPath dirPath) throws OncRpcException, IOException { + MountResult result = new MountResult(); + client.call(PROCEDURE_MOUNT, MOUNT_VERSION, dirPath, result); + return result; + } + + public void unmount(DirPath dirPath) throws OncRpcException, IOException { + client.call(PROCEDURE_UNMOUNT, MOUNT_VERSION, dirPath, XdrVoid.XDR_VOID); + + } + +} +// End of Mount1Client.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/MountResult.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/MountResult.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/MountResult.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,61 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:09 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.mount; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public class MountResult implements XdrAble { + private int status; + private FileHandle directory; + + public MountResult() { + } + + public MountResult(XdrDecodingStream xdr) + throws OncRpcException, IOException { + xdrDecode(xdr); + } + + public void xdrEncode(XdrEncodingStream xdr) + throws OncRpcException, IOException { + xdr.xdrEncodeInt(status); + switch (status) { + case 0: + directory.xdrEncode(xdr); + break; + default: + break; + } + } + + public void xdrDecode(XdrDecodingStream xdr) + throws OncRpcException, IOException { + status = xdr.xdrDecodeInt(); + switch (status) { + case 0: + directory = new FileHandle(xdr); + break; + default: + break; + } + } + + public int getStatus() { + return status; + } + + public FileHandle getDirectory() { + return directory; + } + + +} +// End of MountResult.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Name.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Name.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/mount/Name.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,48 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:09 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.mount; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public class Name implements XdrAble { + + private String value; + + + public Name() { + } + + public Name(String value) { + this.value = value; + } + + public Name(XdrDecodingStream xdr) + throws OncRpcException, IOException { + xdrDecode(xdr); + } + + public void xdrEncode(XdrEncodingStream xdr) + throws OncRpcException, IOException { + xdr.xdrEncodeString(value); + } + + public void xdrDecode(XdrDecodingStream xdr) + throws OncRpcException, IOException { + value = xdr.xdrDecodeString(); + } + + public String getValue() { + return value; + } + + +} +// End of Name.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/AbstractResult.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/AbstractResult.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/AbstractResult.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,36 @@ +package org.jnode.fs.nfs.nfs2.rpc.nfs; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public abstract class AbstractResult implements XdrAble { + + private int status; + + public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException { + // TODO Auto-generated method stub + + } + + public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException { + status = xdr.xdrDecodeInt(); + switch (status) { + case Status.NFS_OK: + decode(xdr); + break; + default: + break; + } + + } + + public int getStatus() { + return status; + } + + public abstract void decode(XdrDecodingStream xdr) throws OncRpcException, IOException; +} \ No newline at end of file Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/Entry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/Entry.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/Entry.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,85 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:51 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.nfs; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public class Entry implements XdrAble { + private int fileId; + private String name; + private byte[] cookie; + private Entry nextEntry; + + public Entry() { + } + + public Entry(XdrDecodingStream xdr) throws OncRpcException, IOException { + xdrDecode(xdr); + } + + + public void setFileId(int x) { + this.fileId = x; + } + + public int getFileId() { + return this.fileId; + } + + public void setName(String x) { + this.name = x; + } + + public String getName() { + return this.name; + } + + public void setCookie(byte[] x) { + this.cookie = x; + } + + public byte[] getCookie() { + return this.cookie; + } + + public void setNextEntry(Entry x) { + this.nextEntry = x; + } + + public Entry getNextEntry() { + return this.nextEntry; + } + + + public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException { + Entry currentEntry = this; + do { + xdr.xdrEncodeInt(currentEntry.getFileId()); + xdr.xdrEncodeString(currentEntry.getName()); + xdr.xdrEncodeOpaque(currentEntry.getCookie(), NFS2Client.COOKIE_SIZE); + currentEntry = currentEntry.getNextEntry(); + xdr.xdrEncodeBoolean(currentEntry != null); + } while (currentEntry != null); + } + + public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException { + Entry currentEntry = this; + do { + currentEntry.setFileId(xdr.xdrDecodeInt()); + currentEntry.setName(xdr.xdrDecodeString()); + currentEntry.setCookie(xdr.xdrDecodeOpaque(NFS2Client.COOKIE_SIZE)); + currentEntry.setNextEntry(xdr.xdrDecodeBoolean() ? new Entry() : null); + currentEntry = currentEntry.getNextEntry(); + } while (currentEntry != null); + } + +} +// End of Entry.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileAttribute.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileAttribute.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,185 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:51 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.nfs; + +import java.io.IOException; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrDecodingStream; +import org.acplt.oncrpc.XdrEncodingStream; + +public class FileAttribute implements XdrAble { + protected int type; + protected int mode; + protected int nlink; + protected int uid; + protected int gid; + protected int size; + protected int blocksize; + protected int rdev; + protected int blocks; + protected int fsid; + protected int fileid; + protected Time lastAccessed; + protected Time lastModified; + protected Time lastStatusChanged; + + public void setType(int x) { + this.type = x; + } + + public int getType() { + return this.type; + } + + public void setMode(int x) { + this.mode = x; + } + + public int getMode() { + return this.mode; + } + + public void setNlink(int x) { + this.nlink = x; + } + + public int getNlink() { + return this.nlink; + } + + public void setUid(int x) { + this.uid = x; + } + + public int getUid() { + return this.uid; + } + + public void setGid(int x) { + this.gid = x; + } + + public int getGid() { + return this.gid; + } + + public void setSize(int x) { + this.size = x; + } + + public int getSize() { + return this.size; + } + + public void setBlocksize(int x) { + this.blocksize = x; + } + + public int getBlocksize() { + return this.blocksize; + } + + public void setRdev(int x) { + this.rdev = x; + } + + public int getRdev() { + return this.rdev; + } + + public void setBlocks(int x) { + this.blocks = x; + } + + public int getBlocks() { + return this.blocks; + } + + public void setFsid(int x) { + this.fsid = x; + } + + public int getFsid() { + return this.fsid; + } + + public void setFileid(int x) { + this.fileid = x; + } + + public int getFileid() { + return this.fileid; + } + + public void setLastAccessed(Time x) { + this.lastAccessed = x; + } + + public Time getLastAccessed() { + return this.lastAccessed; + } + + public void setLastModified(Time x) { + this.lastModified = x; + } + + public Time getLastModified() { + return this.lastModified; + } + + public void setLastStatusChanged(Time x) { + this.lastStatusChanged = x; + } + + public Time getLastStatusChanged() { + return this.lastStatusChanged; + } + + public FileAttribute() { + } + + public FileAttribute(XdrDecodingStream xdr) throws OncRpcException, IOException { + xdrDecode(xdr); + } + + public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException { + xdr.xdrEncodeInt(type); + xdr.xdrEncodeInt(mode); + xdr.xdrEncodeInt(nlink); + xdr.xdrEncodeInt(uid); + xdr.xdrEncodeInt(gid); + xdr.xdrEncodeInt(size); + xdr.xdrEncodeInt(blocksize); + xdr.xdrEncodeInt(rdev); + xdr.xdrEncodeInt(blocks); + xdr.xdrEncodeInt(fsid); + xdr.xdrEncodeInt(fileid); + lastAccessed.xdrEncode(xdr); + lastModified.xdrEncode(xdr); + lastStatusChanged.xdrEncode(xdr); + } + + public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException { + type = xdr.xdrDecodeInt(); + mode = xdr.xdrDecodeInt(); + nlink = xdr.xdrDecodeInt(); + uid = xdr.xdrDecodeInt(); + gid = xdr.xdrDecodeInt(); + size = xdr.xdrDecodeInt(); + blocksize = xdr.xdrDecodeInt(); + rdev = xdr.xdrDecodeInt(); + blocks = xdr.xdrDecodeInt(); + fsid = xdr.xdrDecodeInt(); + fileid = xdr.xdrDecodeInt(); + lastAccessed = new Time(xdr); + lastModified = new Time(xdr); + lastStatusChanged = new Time(xdr); + } + +} +// End of FileAttribute.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileType.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/FileType.java 2007-10-17 18:30:15 UTC (rev 3557) @@ -0,0 +1,21 @@ +/* + * Automatically generated by jrpcgen 1.0.7 on 10/5/07 11:51 PM + * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java + * See http://remotetea.sourceforge.net for details + */ +package org.jnode.fs.nfs.nfs2.rpc.nfs; + +/** + * Enumeration (collection of constants). + */ +public interface FileType { + + public static final int NON_FILE = 0; + public static final int FILE = 1; + public static final int DIRECTORY = 2; + public static final int BLOCK_SPECIAL_DEVICE = 3; + public static final int CHARACTER_SPECIAL_DEVICE = 4; + public static final int SYMBOLIC_LINK = 5; + +} +// End of FileType.java Added: trunk/fs/src/fs/org/jnode/fs/nfs/nfs2/rpc/nfs/ListDirectoryRe... [truncated message content] |
From: <ls...@us...> - 2007-10-17 18:38:16
|
Revision: 3558 http://jnode.svn.sourceforge.net/jnode/?rev=3558&view=rev Author: lsantha Date: 2007-10-17 11:38:12 -0700 (Wed, 17 Oct 2007) Log Message: ----------- Fixed Intellij Idea project modules. Modified Paths: -------------- trunk/fs/fs.iml trunk/net/net.iml Modified: trunk/fs/fs.iml =================================================================== --- trunk/fs/fs.iml 2007-10-17 18:30:15 UTC (rev 3557) +++ trunk/fs/fs.iml 2007-10-17 18:38:12 UTC (rev 3558) @@ -15,6 +15,15 @@ <orderEntry type="module" module-name="core" /> <orderEntry type="library" name="core" level="project" /> <orderEntry type="module" module-name="shell" /> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/../net/lib/oncrpc.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> <orderEntryProperties /> </component> </module> Modified: trunk/net/net.iml =================================================================== --- trunk/net/net.iml 2007-10-17 18:30:15 UTC (rev 3557) +++ trunk/net/net.iml 2007-10-17 18:38:12 UTC (rev 3558) @@ -17,7 +17,7 @@ <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/lib/dnsjava-1.5.0.jar!/" /> + <root url="jar://$MODULE_DIR$/lib/jsch-0.1.24.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> @@ -26,7 +26,7 @@ <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/lib/jsch-0.1.24.jar!/" /> + <root url="jar://$MODULE_DIR$/lib/oncrpc.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> @@ -35,12 +35,13 @@ <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/lib/commons-net-1.1.0.jar!/" /> + <root url="jar://$MODULE_DIR$/lib/dnsjava-2.0.3.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry> + <orderEntry type="module" module-name="shell" /> <orderEntryProperties /> </component> </module> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-10-20 10:29:41
|
Revision: 3561 http://jnode.svn.sourceforge.net/jnode/?rev=3561&view=rev Author: lsantha Date: 2007-10-20 03:29:35 -0700 (Sat, 20 Oct 2007) Log Message: ----------- Extensions to the command shell by crawley. Modified Paths: -------------- trunk/fs/descriptors/org.jnode.fs.command.xml trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml trunk/shell/src/shell/org/jnode/shell/ShellException.java trunk/shell/src/shell/org/jnode/shell/help/Argument.java trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java trunk/shell/src/shell/org/jnode/shell/help/HelpException.java trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java trunk/shell/src/shell/org/jnode/shell/CommandThread.java trunk/shell/src/shell/org/jnode/shell/Completable.java trunk/shell/src/shell/org/jnode/shell/NullInputStream.java trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java Modified: trunk/fs/descriptors/org.jnode.fs.command.xml =================================================================== --- trunk/fs/descriptors/org.jnode.fs.command.xml 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/fs/descriptors/org.jnode.fs.command.xml 2007-10-20 10:29:35 UTC (rev 3561) @@ -41,6 +41,7 @@ <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> <permission class="java.net.NetPermission" name="specifyStreamHandler"/> <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> + <permission class="java.lang.RuntimePermission" name="exitVM"/> </extension> </plugin> Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -108,14 +108,17 @@ } } } - out.flush(); + if (out.checkError()) { + ok = false; + } } catch (IOException ex) { // Deal with i/o errors reading from in/is or writing to out. err.println("Problem concatenating file(s): " + ex.getMessage()); ok = false; } - // TODO need to set a 'return code'; e.g. - // if (!ok) { System.exit(1); } + if (!ok) { + System.exit(1); + } } /** Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2007-10-20 10:29:35 UTC (rev 3561) @@ -29,9 +29,6 @@ <permission class="java.lang.RuntimePermission" name="setIO"/> <permission class="java.net.SocketPermission" name="*" actions="resolve,listen,connect"/> <permission class="java.net.SocketPermission" name="*:0-" actions="connect,resolve,listen"/> - <permission class="java.util.PropertyPermission" name="jnode.cmdline" actions="read"/> - <permission class="java.util.PropertyPermission" name="jnode.invoker" actions="read"/> - <permission class="java.util.PropertyPermission" name="jnode.prompt" actions="read,write"/> - <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/> + <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> </extension> </plugin> \ No newline at end of file Added: trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,56 @@ +/* + * $Id: ThreadCommandInvoker.java 3374 2007-08-02 18:15:27Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +/** + * This is the API that a shell-based interpreter must implement. + * + * @author cr...@jn... + */ +public interface CommandInterpreter { + /** + * Parse and execute a command line, and return the resulting return code. + * + * @param shell the CommandShell that provides low-level command invocation, + * command history and so on. + * @param line the line of input to be interpreted. + * @return the return code. + * @throws ShellException + */ + int interpret(CommandShell shell, String line) throws ShellException; + + /** + * Parse a partial command line, returning the command line fragment to be completed. + * + * @param shell the current CommandShell. + * @param partial a input to the interpreter. + * @return the CommandLine represent the fragment of the supplied command input to be completed. + * @throws ShellException + */ + Completable parsePartial(CommandShell shell, String partial) throws ShellSyntaxException; + + /** + * Get the interpreter's name + * @return the name + */ + String getName(); +} Added: trunk/shell/src/shell/org/jnode/shell/CommandThread.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandThread.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/CommandThread.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,94 @@ +/* + * $Id: ThreadCommandInvoker.java 3374 2007-08-02 18:15:27Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +/** + * The CommandThread class enhances Thread with a simple mechanism for recording + * a 'command's return code. + * + * @author cr...@jn... + */ +public class CommandThread extends Thread { + + private int rc; + private ThreadExitListener listener; + + /** + * @param group the parent group for the thread + * @param target the runnable that implements the command + * @param name a thread name + * @param size the threads stack size + * @param invoker the invoker to be notified of the thread's exit + */ + public CommandThread(ThreadGroup group, Runnable target, String name, long size) { + super(group, target, name, size); + } + + /** + * @param group the parent group for the thread + * @param target the runnable that implements the command + * @param invoker the invoker to be notified of the thread's exit + */ + public CommandThread(ThreadGroup group, Runnable target) { + super(group, target); + } + + /** + * @param target the runnable that implements the command + * @param name a thread name + * @param invoker the invoker to be notified of the thread's exit + */ + public CommandThread(Runnable target, String name) { + super(target, name); + } + + @Override + public void run() { + super.run(); + if (listener != null) { + listener.notifyThreadExitted(this); + } + } + + /** + * This overload for start registers an optional thread exit listener + * to be notified of the thread's exit + * + * @param listener the listener or <code>null</code> + */ + public void start(ThreadExitListener listener) { + this.listener = listener; + super.start(); + } + + public final int getReturnCode() { + return rc; + } + + public final void setReturnCode(int rc) { + this.rc = rc; + } + + public static final void setRC(int rc) throws ClassCastException { + ((CommandThread) Thread.currentThread()).setReturnCode(rc); + } +} Added: trunk/shell/src/shell/org/jnode/shell/Completable.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/Completable.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/Completable.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,10 @@ +package org.jnode.shell; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.shell.help.CompletionException; + +public interface Completable { + + void complete(CompletionInfo completion, CommandShell shell) throws CompletionException; + +} Added: trunk/shell/src/shell/org/jnode/shell/NullInputStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/NullInputStream.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/NullInputStream.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,12 @@ +package org.jnode.shell; + +import java.io.IOException; +import java.io.InputStream; + +public class NullInputStream extends InputStream { + + @Override + public int read() throws IOException { + return 0; + } +} Added: trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,13 @@ +package org.jnode.shell; + +import java.io.IOException; +import java.io.OutputStream; + +public class NullOutputStream extends OutputStream { + + @Override + public void write(int b) throws IOException { + // black-hole all output. + } + +} Modified: trunk/shell/src/shell/org/jnode/shell/ShellException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellException.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/ShellException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -29,6 +29,11 @@ /** * */ + private static final long serialVersionUID = 1L; + + /** + * + */ public ShellException() { super(); } Added: trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,48 @@ +/* + * $Id: ShellException.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +/** + * This exception is used to signal an internal error in the + * command shell, interpretter or invoker. + * + * @author cr...@jn... + */ +public class ShellFailureException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * @param message + * @param cause + */ + public ShellFailureException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param s + */ + public ShellFailureException(String s) { + super(s); + } +} Added: trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,19 @@ +package org.jnode.shell; + +public class ShellInvocationException extends ShellException { + + private static final long serialVersionUID = 1L; + + public ShellInvocationException(String s, Throwable cause) { + super(s, cause); + } + + public ShellInvocationException(String s) { + super(s); + } + + public ShellInvocationException(Throwable cause) { + super(cause); + } + +} Added: trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,19 @@ +package org.jnode.shell; + +public class ShellSyntaxException extends ShellException { + + private static final long serialVersionUID = 1L; + + public ShellSyntaxException(String s, Throwable cause) { + super(s, cause); + } + + public ShellSyntaxException(String s) { + super(s); + } + + public ShellSyntaxException(Throwable cause) { + super(cause); + } + +} Added: trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,7 @@ +package org.jnode.shell; + +public interface ThreadExitListener { + + void notifyThreadExitted(CommandThread thread); + +} Modified: trunk/shell/src/shell/org/jnode/shell/help/Argument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/Argument.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/Argument.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -25,6 +25,7 @@ import javax.naming.NameNotFoundException; +import org.jnode.shell.CommandLine; import org.jnode.shell.ShellUtils; /** Modified: trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -28,4 +28,8 @@ public CompletionException(String message) { super(message); } + + public CompletionException(String message, Throwable cause) { + super(message, cause); + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/HelpException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/HelpException.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/HelpException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -28,7 +28,12 @@ HelpException() { super(); } + HelpException(String message) { super(message); } + + public HelpException(String message, Throwable cause) { + super(message, cause); + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -114,7 +114,14 @@ list.add(name); } } - return complete(partial, list); + String completed = complete(partial, list); + if (completed.endsWith(" ")) { + String path = completed.substring(0, completed.length() - 1); + if (new File(path).isDirectory()) { + completed = path + File.separatorChar; + } + } + return completed; } } } Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -6,6 +6,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; + +import org.jnode.shell.CommandThread; import org.jnode.vm.VmSystem; import org.jnode.vm.VmExit; @@ -188,7 +190,7 @@ * @param target the new Thread's Runnable object. * @return the new Thread */ - public static Thread createProclet(Runnable target) { + public static CommandThread createProclet(Runnable target) { return createProclet(target, null, null, null, null, 0); } @@ -206,7 +208,7 @@ * @param target the new Thread's Runnable object. * @return the new Thread */ - public static Thread createProclet(Runnable target, Properties properties, + public static CommandThread createProclet(Runnable target, Properties properties, Map<String, String> environment, Object[] streams) { return createProclet(target, properties, environment, streams, null, 0); } @@ -227,7 +229,7 @@ * @param name an optional Thread name. * @return the new Thread */ - public static Thread createProclet(Runnable target, Properties properties, + public static CommandThread createProclet(Runnable target, Properties properties, Map<String, String> environment, Object[] streams, String name) { return createProclet(target, properties, environment, streams, name, 0); } @@ -249,7 +251,7 @@ * @param size the new Thread's stack size; zero denotes the default thread stack size. * @return the new Thread */ - public static Thread createProclet(Runnable target, Properties properties, + public static CommandThread createProclet(Runnable target, Properties properties, Map<String, String> environment, Object[] streams, String name, long size) { ProcletContext procletContext = @@ -258,7 +260,7 @@ if (name == null) { name = procletContext.autoThreadName(); } - return new Thread(procletContext, target, name, size); + return new CommandThread(procletContext, target, name, size); } /** Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -68,7 +68,6 @@ return getRealStream(); } catch (ProxyStreamException ex) { - setError(); return getNullPrintStream(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-10-26 21:30:15
|
Revision: 3571 http://jnode.svn.sourceforge.net/jnode/?rev=3571&view=rev Author: lsantha Date: 2007-10-26 14:30:12 -0700 (Fri, 26 Oct 2007) Log Message: ----------- Improved support for pipes, command completion for piped commands, introduced jnode.interpreter, jnode.debug, jnode.invoker and jnode.history system properties for controlling the shell command interpreter, detailed exception reporting of shell commands, shell command invoker and shell command history, by crawley. Modified Paths: -------------- trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java trunk/shell/src/shell/org/jnode/shell/CommandInvoker.java trunk/shell/src/shell/org/jnode/shell/CommandLine.java trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/CommandThread.java trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/NullInputStream.java trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/ShellManager.java trunk/shell/src/shell/org/jnode/shell/ShellUtils.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java trunk/shell/src/shell/org/jnode/shell/def/DefaultShellManager.java trunk/shell/src/shell/org/jnode/shell/help/Argument.java trunk/shell/src/shell/org/jnode/shell/help/Help.java trunk/shell/src/shell/org/jnode/shell/help/Parameter.java trunk/shell/src/shell/org/jnode/shell/help/Syntax.java trunk/shell/src/shell/org/jnode/shell/help/argument/StringArgument.java Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java Modified: trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -42,6 +42,7 @@ import javax.naming.NameNotFoundException; import org.jnode.shell.CommandShell; import org.jnode.shell.Shell; +import org.jnode.shell.ShellException; import org.jnode.shell.ShellUtils; /** @@ -414,8 +415,13 @@ public void invoke( String command ) { if( shell != null ) { if( shell instanceof CommandShell ) { - CommandShell cs = (CommandShell)shell; - cs.getDefaultCommandInvoker().invoke( command ); + CommandShell cs = (CommandShell) shell; + try { + cs.invokeCommand( command ); + } + catch (ShellException ex) { + System.err.println( "Command invocation failed: " + ex.getMessage() ); + } } else { System.err.println( "Shell wasn't a CommandShell: " + shell.getClass() ); Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -67,7 +67,7 @@ String[] fileNames = ARG_FILE.getValues(cmdLine); boolean ok = true; try { - if (fileNames.length == 0) { + if (fileNames == null || fileNames.length == 0) { process(in, out); } else { Modified: trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -21,29 +21,19 @@ package org.jnode.shell; -import gnu.java.security.action.InvokeAction; import java.awt.event.KeyEvent; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; +import java.io.Closeable; import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintStream; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; import org.jnode.driver.input.KeyboardEvent; import org.jnode.driver.input.KeyboardListener; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.HelpException; -import org.jnode.shell.help.SyntaxErrorException; -import org.jnode.vm.VmExit; /** * User: Sam Reid Date: Dec 20, 2003 Time: 1:20:33 AM Copyright (c) Dec 20, 2003 @@ -72,11 +62,10 @@ boolean blocking; Thread blockingThread; - Thread threadProcess = null; - String cmdName; + public AsyncCommandInvoker(CommandShell commandShell) { this.commandShell = commandShell; this.err = commandShell.getErrorStream(); @@ -84,153 +73,147 @@ // ctrl-c } - public void invoke(String cmdLineStr) { - commandShell.addCommandToHistory(cmdLineStr); + public int invoke(CommandLine cmdLine) throws ShellException { + CommandInfo cmdInfo = lookupCommand(cmdLine); + if (cmdInfo == null) { + return 0; + } + Runnable cr = setup(cmdLine, cmdInfo); + return runIt(cmdLine, cmdInfo, cr); + } - InputStream inputStream = commandShell.getInputStream(); - InputStream nextInputStream = null; - PrintStream errStream = commandShell.getErrorStream(); - PrintStream outputStream = null; - boolean mustCloseOutputStream = false; + public CommandThread invokeAsynchronous(CommandLine cmdLine) + throws ShellException { + CommandInfo cmdInfo = lookupCommand(cmdLine); + if (cmdInfo == null) { + return null; + } + Runnable cr = setup(cmdLine, cmdInfo); + return forkIt(cmdLine, cmdInfo, cr); + } - CommandLine cmdLine; - Method method; - Runnable cr; - CommandInfo cmdInfo; - - String[] commands = cmdLineStr.split("\\|"); - String command; - ByteArrayOutputStream byteArrayOutputStream = null; - - for (int i = 0; i < commands.length; i++) { - command = commands[i].trim(); - cmdLine = new CommandLine(command); - - if (!cmdLine.hasNext()) - continue; - - cmdName = cmdLine.next(); - - try { - cmdInfo = commandShell.getCommandClass(cmdName); - - if (cmdLine.sendToOutFile()) { - File file = new File(cmdLine.getOutFileName()); - + private CommandInfo lookupCommand(CommandLine cmdLine) throws ShellInvocationException { + String cmdName = cmdLine.getCommandName(); + if (cmdName == null) { + return null; + } try { - FileOutputStream fileOutputStream = new FileOutputStream( - file); - outputStream = new PrintStream(fileOutputStream); - mustCloseOutputStream = true; - } catch (SecurityException e) { - e.printStackTrace(); - return; // FIXME - } catch (FileNotFoundException e) { - e.printStackTrace(); - return; // FIXME - } - } else if (i + 1 < commands.length) { - byteArrayOutputStream = new ByteArrayOutputStream(); - outputStream = new PrintStream(byteArrayOutputStream); - } else { - outputStream = commandShell.getOutputStream(); + return commandShell.getCommandClass(cmdName); + } + catch (ClassNotFoundException ex) { + throw new ShellInvocationException("Cannot resolve command '" + cmdName + "'"); } - - if (byteArrayOutputStream != null) { - nextInputStream = new ByteArrayInputStream( - byteArrayOutputStream.toByteArray()); } - if (nextInputStream != null) - inputStream = nextInputStream; + private Runnable setup(CommandLine cmdLine, CommandInfo cmdInfo) throws ShellException { + Method method; + Runnable cr = null; - CommandLine commandLine = null; - - if (inputStream.available() > 0) { - // FIXME we shouldn't do this. It consumes keyboard typeahead - // that should be delivered to the command's standard input!! - commandLine = new CommandLine(inputStream); - } else { - commandLine = cmdLine.getRemainder(); + Closeable[] streams = cmdLine.getStreams(); + InputStream in; + PrintStream out, err; + try { + in = (InputStream) ((streams[0] == null) ? commandShell.getInputStream() : streams[0]); + OutputStream tmp = (OutputStream) + ((streams[1] == null) ? commandShell.getOutputStream() : streams[1]); + out = (tmp instanceof PrintStream) ? (PrintStream) tmp : new PrintStream(tmp); + tmp = (OutputStream) ((streams[2] == null) ? commandShell.getErrorStream() : streams[2]); + err = (tmp instanceof PrintStream) ? (PrintStream) tmp : new PrintStream(tmp); + } + catch (ClassCastException ex) { + throw new ShellFailureException("streams array broken", ex); } - - commandLine.setOutFileName(cmdLine.getOutFileName()); try { method = cmdInfo.getCommandClass().getMethod( EXECUTE_METHOD, EXECUTE_ARG_TYPES); - + if ((method.getModifiers() & Modifier.STATIC) == 0) { cr = createRunner(cmdInfo.getCommandClass(), method, - new Object[] { commandLine, inputStream, - outputStream, errStream }, - inputStream, outputStream, errStream); + new Object[]{cmdLine, in, out, err}, + in, out, err); + } } catch (NoSuchMethodException e) { - method = cmdInfo.getCommandClass().getMethod(MAIN_METHOD, - MAIN_ARG_TYPES); + // continue; + } + if (cr == null) { + try { + method = cmdInfo.getCommandClass().getMethod(MAIN_METHOD, MAIN_ARG_TYPES); + if ((method.getModifiers() & Modifier.STATIC) != 0) { + if (streams[0] != null || streams[1] != null || streams[2] != null) { + throw new ShellInvocationException( + "Entry point method for " + cmdInfo.getCommandClass() + + " does not allow redirection or pipelining"); + } cr = createRunner(cmdInfo.getCommandClass(), method, - new Object[] { cmdLine.getRemainder().toStringArray() }, - commandShell.getInputStream(), commandShell.getOutputStream(), - commandShell.getErrorStream()); + new Object[]{cmdLine.getArguments()}, + in, out, err); } + } catch (NoSuchMethodException e) { + // continue; + } + } + if (cr == null) { + throw new ShellInvocationException( + "No suitable entry point method for " + cmdInfo.getCommandClass()); + } + if (streams == null) { + cmdLine.setStreams(new Closeable[]{in, out, err}); + } + return cr; + } + + public int runIt(CommandLine cmdLine, CommandInfo cmdInfo, Runnable cr) + throws ShellInvocationException { try { if (cmdInfo.isInternal()) { cr.run(); } else { - threadProcess = createThread(cr, inputStream, - outputStream, errStream); + try { + threadProcess = createThread(cmdLine, cr); + } catch (Exception ex) { + throw new ShellInvocationException("Exception while creating command thread", ex); + } threadProcess.start(); this.blocking = true; this.blockingThread = Thread.currentThread(); - while (blocking) { + this.cmdName = cmdLine.getCommandName(); + while (this.blocking) { try { Thread.sleep(6000); } catch (InterruptedException interrupted) { if (!blocking) { // interruption was okay, break normally. } else { - // abnormal interruption - interrupted.printStackTrace(); - return; // FIXME + throw new ShellFailureException("unexpected interrupt", interrupted); } } } } + return 0; } catch (Exception ex) { - err.println("Exception in command"); - ex.printStackTrace(err); - return; // FIXME + throw new ShellInvocationException("Uncaught Exception in command", ex); } catch (Error ex) { - err.println("Fatal error in command"); - ex.printStackTrace(err); - return; // FIXME - } - } catch (NoSuchMethodException ex) { - err.println("Alias class has no main method " + cmdName); - return; // FIXME - } catch (ClassNotFoundException ex) { - err.println("Unknown alias class " + ex.getMessage()); - return; // FIXME - } catch (ClassCastException ex) { - err.println("Invalid command " + cmdName); - return; // FIXME - } catch (Exception ex) { - err.println("Unknown error: " + ex.getMessage()); - ex.printStackTrace(err); - return; // FIXME + throw new ShellInvocationException("Fatal Error in command", ex); } finally { - if (mustCloseOutputStream) { - outputStream.close(); - mustCloseOutputStream = false; - } + this.blockingThread = null; + this.blocking = false; } } - nextInputStream = null; + public CommandThread forkIt(CommandLine cmdLine, CommandInfo cmdInfo, Runnable cr) + throws ShellInvocationException { + if (cmdInfo.isInternal()) { + throw new ShellFailureException("unexpected internal command"); + } + try { + return createThread(cmdLine, cr); + } catch (Exception ex) { + throw new ShellInvocationException("Exception while creating command thread", ex); + } } - abstract Thread createThread(Runnable cr, InputStream inputStream, - PrintStream outputStream, PrintStream errStream); + abstract CommandThread createThread(CommandLine cmdLine, Runnable cr); public void keyPressed(KeyboardEvent ke) { //disabling Ctrl-C since currently we have no safe method for killing a thread @@ -247,7 +230,7 @@ } private void doCtrlZ() { - if(blockingThread != null && blockingThread.isAlive()) { + if (blockingThread != null && blockingThread.isAlive()) { System.err.println("ctrl-z: Returning focus to console. (" + cmdName + " is still running)"); unblock(); @@ -260,7 +243,6 @@ blockingThread != null && blockingThread.isAlive()) { System.err.println("ctrl-c: Returning focus to console. (" + cmdName + " has been killed)"); - unblock(); AccessController.doPrivileged(new PrivilegedAction<Void>(){ @@ -286,4 +268,18 @@ abstract Runnable createRunner(Class cx, Method method, Object[] args, InputStream commandIn, PrintStream commandOut, PrintStream commandErr); + + abstract class CommandRunner implements Runnable { + + boolean isDebugEnabled() { + return commandShell.isDebugEnabled(); + } + + void stackTrace(Throwable ex) { + if (ex != null && isDebugEnabled()) { + ex.printStackTrace(err); + } + } + + } } Modified: trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -27,6 +27,12 @@ * @author cr...@jn... */ public interface CommandInterpreter { + + public interface Factory { + CommandInterpreter create(); + String getName(); + } + /** * Parse and execute a command line, and return the resulting return code. * Modified: trunk/shell/src/shell/org/jnode/shell/CommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandInvoker.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/shell/src/shell/org/jnode/shell/CommandInvoker.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -21,12 +21,54 @@ package org.jnode.shell; -/** +/* * User: Sam Reid * Date: Dec 20, 2003 * Time: 1:18:31 AM * Copyright (c) Dec 20, 2003 by Sam Reid */ + +/** + * This is the common API for the various mechanisms for running 'commands'. + * + * @author Sam Reid + * @author cr...@jn... + */ public interface CommandInvoker { - void invoke(String cmdLineStr); + + public interface Factory { + CommandInvoker create(CommandShell shell); + String getName(); + } + + /** + * Run a command synchronously, passing back the resulting return code. + * + * @param commandLine this provides the command name (alias), the command arguments and + * (where relevant) the command's i/o stream context. + * @return an integer return code, with zero indicating command success, non-zero indicating + * command failure. + * @throws ShellException if there was some problem launching the command. + */ + int invoke(CommandLine commandLine) throws ShellException; + + /** + * Create a thread for running a command asynchronously. This can be used for running + * and for assembling command pipelines. + * + * @param commandLine this provides the command name (alias), the command arguments and + * (where relevant) the command's i/o stream context. + * @return the thread for the command. Calling {@link java.lang.Thread.start()} will + * cause the command to execute. + * @throws ShellException if there was some problem launching the command. + */ + CommandThread invokeAsynchronous(CommandLine commandLine) + throws ShellException; + + + /** + * Get the invoker's name. + * @return the name. + */ + String getName(); } Modified: trunk/shell/src/shell/org/jnode/shell/CommandLine.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -21,21 +21,29 @@ package org.jnode.shell; -import java.util.ArrayList; -import java.util.List; +import java.io.Closeable; +import java.util.Iterator; import java.util.NoSuchElementException; -import java.io.InputStream; -import java.io.IOException; +import org.jnode.driver.console.CompletionInfo; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.CompletionException; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.HelpException; +import org.jnode.shell.help.Parameter; +import org.jnode.shell.help.argument.AliasArgument; +import org.jnode.shell.help.argument.FileArgument; + /** - * This class represents the command line as an iterator. A trailing space leads - * to an empty token to be appended. + * This class represents the command line as command name and a sequence + * of argument strings. It also can carry the i/o stream environment for + * launching the command. * - * @author epr - * @author qades - * @author Martin Husted Hartvig (ha...@jn...) + * TODO This class needs to be "syntax agnostic". + * + * @author cr...@jn... */ -public class CommandLine { +public class CommandLine implements Completable, Iterator<String> { public static final int LITERAL = 0; @@ -43,6 +51,8 @@ public static final int CLOSED = 2; + public static final int SPECIAL = 4; + public static final char ESCAPE_CHAR = '\\'; public static final char FULL_ESCAPE_CHAR = '\''; @@ -71,76 +81,73 @@ private static final char T = 't'; - private String s; + private static final String[] NO_ARGS = new String[0]; - private int pos = 0; + private final Help.Info defaultParameter = new Help.Info("file", + "default parameter for command line completion", + new Parameter(new FileArgument("file", "a file", Argument.MULTI), Parameter.OPTIONAL) + ); - private int type = LITERAL; + private final Argument defaultArg = new AliasArgument("command", + "the command to be called"); + + private String commandName; - private static final char linebreak = "\n".charAt(0); + private String[] arguments; - // private boolean inEscape = false; - private boolean inFullEscape = false; + private Closeable[] streams; - private boolean inQuote = false; + private int pos = 0; - private String outFileName = null; + private int type = LITERAL; - private void setCommandLine(String s) { - int send_to_file = s.indexOf(SEND_OUTPUT_TO_CHAR); + private boolean argumentAnticipated = false; - if (send_to_file != -1) { - if (send_to_file < s.length()) { - setOutFileName((s.substring(send_to_file + 1)).trim()); - this.s = s.substring(0, send_to_file); - } else { - this.s = s.substring(send_to_file); + /** + * Create a new instance encapsulating a command name, argument list and io stream array. + * If 'arguments' is <code>null</code>, a zero length String array is substituted. + * If 'streams' is <code>null</code> , an array of length 3 is substituted. A non-null + * 'streams' argument must have a length of at least 3. + * + * @param commandName the command name or <code>null</code>. + * @param arguments the argument list or <code>null</code>. + * @param streams the io stream array or <code>null</code>. + */ + public CommandLine(String commandName, String[] arguments, Closeable[] streams) { + this.commandName = commandName; + this.arguments = (arguments == null || arguments.length == 0) ? NO_ARGS : arguments.clone(); + if (streams == null) { + this.streams = new Closeable[3]; + } + else if (streams.length < 3) { + throw new IllegalArgumentException("streams.length < 3"); } - } else { - this.s = s; + else { + this.streams = streams.clone(); } } /** - * Creates a new instance. + * Create a new instance. Equivalent to CommandLine(commandName, arguments, null); + * + * @param commandName the command name or <code>null</code>. + * @param arguments the argument list or <code>null</code>. */ - public CommandLine(String s) { - setCommandLine(s); + public CommandLine(String commandName, String[] arguments) { + this(commandName, arguments, null); } /** - * Create a new instance. + * Create a new instance. Equivalent to CommandLine(null, arguments, null); * - * @param args + * @param arguments the argument list or <code>null</code>. + * @deprecated It is a bad idea to leave out the command name. */ - public CommandLine(String[] args) { - this(escape(args)); + public CommandLine(String[] arguments) { + this(null, arguments, null); } - public CommandLine(InputStream in) { - try { - int avaliable = in.available(); - StringBuilder stringBuilder = new StringBuilder(avaliable); - - if (avaliable > 0) { - int data = in.read(); - char ch; - while (data > -1) { - ch = (char) data; - if (ch != linebreak) - stringBuilder.append(ch); - - data = in.read(); - } - } - - setCommandLine(stringBuilder.toString()); - } catch (IOException e) { - e.printStackTrace(); - } - } - /** * Reset, so a call to nextToken will retreive the first token. */ @@ -149,13 +156,13 @@ } /** - * Returns if there is another token on the command list. + * Returns if there is another argument on the command list. * * @return <code>true</code> if there is another token; <code>false</code> * otherwise */ public boolean hasNext() { - return pos < s.length(); + return pos < arguments.length; } /** @@ -176,79 +183,12 @@ * @return the next token */ public String next() throws NoSuchElementException { - if (!hasNext()) + if (!hasNext()) { throw new NoSuchElementException(); - - type = LITERAL; - - StringBuilder token = new StringBuilder(5); - char currentChar; - - boolean finished = false; - - while (!finished && pos < s.length()) { - currentChar = s.charAt(pos++); - - switch (currentChar) { - case ESCAPE_CHAR: - if(pos >= s.length()) - { - throw new IllegalArgumentException("escape char ('\\') not followed by a character"); } - token.append(CommandLine.unescape(s.charAt(pos++))); - break; - - case FULL_ESCAPE_CHAR: - if (inQuote) { - token.append(currentChar); - } else { - inFullEscape = !inFullEscape; // just a toggle - type = STRING; - if (!inFullEscape) - type |= CLOSED; - } - break; - case QUOTE_CHAR: - if (inFullEscape) { - token.append(currentChar); - } else { - inQuote = !inQuote; - type = STRING; - if (!inQuote) - type |= CLOSED; - } - break; - case SPACE_CHAR: - if (inFullEscape || inQuote) { - token.append(currentChar); - } else { - if (token.length() != 0) { // don't return an empty token - finished = true; - pos--; // to return trailing space as empty last token - } - } - break; - case COMMENT_CHAR: - if (inFullEscape || inQuote) { - token.append(currentChar); - } else { - finished = true; - pos = s.length(); // ignore EVERYTHING - } - break; - /* - * case SEND_OUTPUT_TO_CHAR: next(); break; - */ - default: - token.append(currentChar); - } - } - - String collectedToken = token.toString(); - token = null; - - return collectedToken; + type = LITERAL; + return arguments[pos++]; } /** @@ -261,29 +201,31 @@ } /** - * Get the remaining CommandLine. + * Get the command name * - * @return the remainder + * @return the command name */ - public CommandLine getRemainder() { - return new CommandLine(s.substring(pos)); + public String getCommandName() { + return commandName; } /** - * Get the entire command line as String[]. + * Get the arguments as String[]. * - * @return the command line as String[] + * @return the arguments as String[] */ - public String[] toStringArray() { - final List<String> res = new ArrayList<String>(); - CommandLine line = new CommandLine(s); - - while (line.hasNext()) { - res.add(line.next()); + public String[] getArguments() { + return arguments.clone(); } - String[] result = (String[]) res.toArray(new String[res.size()]); - return result; + /** + * Get the arguments as String[]. + * + * @return the arguments as String[] + * @deprecated this method name is wrong. + */ + public String[] toStringArray() { + return arguments.clone(); } /** @@ -292,7 +234,12 @@ * @return the entire command line */ public String toString() { - return escape(toStringArray()); // perform all possible conversions + StringBuilder sb = new StringBuilder(escape(commandName)); + for (String argument : arguments) { + sb.append(' '); + sb.append(escape(argument)); + } + return sb.toString(); } /** @@ -304,7 +251,7 @@ if (!hasNext()) { return ""; } - return getRemainder().next(); + return arguments[pos]; } /** @@ -313,16 +260,15 @@ * @return the remaining number of parts */ public int getLength() { - if (!hasNext()) - return 0; + return arguments.length; + } - CommandLine remainder = getRemainder(); - int result = 0; - while (remainder.hasNext()) { - result++; - remainder.next(); + public boolean isArgumentAnticipated() { + return argumentAnticipated; } - return result; + + public void setArgumentAnticipated(boolean newValue) { + argumentAnticipated = newValue; } public static class Token { @@ -359,8 +305,8 @@ * the unescaped argument * @return the escaped argument */ - public static String escape(String arg) { - return escape(arg, false); // don't force quotation + public String escape(String arg) { + return doEscape(arg, false); // don't force quotation } /** @@ -372,96 +318,110 @@ * if <code>true</code>, forces the argument to be returned in * quotes even if not necessary * @return the escaped argument + * @deprecated This method does not belong here. Escaping is an interpretter + * concern, and this class needs to be interpretter specific. */ - public static String escape(String arg, boolean forceQuote) { - String s = null; - StringBuilder stringBuilder = new StringBuilder(arg.length() > 0 ? 5 - : 0); + public static String doEscape(String arg, boolean forceQuote) { + int length = arg.length(); + if (length == 0) { + return "" + QUOTE_CHAR + QUOTE_CHAR; + } + StringBuilder sb = new StringBuilder(length); - // one-character escapes + // insert escape sequences for (int i = 0; i < arg.length(); i++) { char c = arg.charAt(i); - for (int j = 0; j < escapes.length; j++) + for (int j = 0; j < escapes.length; j++) { if (escapes[j].plain == c) { - stringBuilder.append(ESCAPE_CHAR); + sb.append(ESCAPE_CHAR); c = escapes[j].escaped; break; } - stringBuilder.append(c); } - - s = stringBuilder.toString(); - - if (s.indexOf(QUOTE_CHAR) != -1) { // full escape needed - stringBuilder.insert(0, FULL_ESCAPE_CHAR); - stringBuilder.append(FULL_ESCAPE_CHAR); - s = stringBuilder.toString(); - } else if (forceQuote || (s.indexOf(SPACE_CHAR) != -1)) { // normal - // quote if - // needed or - // forced - stringBuilder.insert(0, QUOTE_CHAR); - stringBuilder.append(QUOTE_CHAR); - s = stringBuilder.toString(); + forceQuote |= (c == SPACE_CHAR || c == QUOTE_CHAR); + sb.append(c); } - // debug output do show how escapes are translated - // System.out.println(); - // System.out.println("escaped \"" + arg + "\" as \"" + s + "\""); - return s; - } - /** - * Escape a command line for the Shell. - * - * @param args - * the unescaped command line - * @return the escaped argument - */ - public static String escape(String[] args) { - StringBuilder stringBuilder = new StringBuilder(args.length > 0 ? 5 : 0); - - for (int i = 0; i < args.length; i++) { - stringBuilder.append(escape(args[i])); // escape the argument - if (i != args.length - 1) - stringBuilder.append(SPACE_CHAR); // escape the argument + if (forceQuote) { + sb.insert(0, FULL_ESCAPE_CHAR); + sb.append(FULL_ESCAPE_CHAR); } - return stringBuilder.toString(); + return sb.toString(); } - public boolean sendToOutFile() { - return outFileName != null; + public String escape(String arg, boolean forceQuote) { + return CommandLine.doEscape(arg, forceQuote); } - public String getOutFileName() { - return outFileName; - } + private static class Escape { + final char plain; - void setOutFileName(String outFileName) { - this.outFileName = outFileName; + final char escaped; + + Escape(char plain, char escaped) { + this.plain = plain; + this.escaped = escaped; + } } /** - * Unescape a single character + * Get the IO stream context for executing the command. The result + * is guaranteed to be non-null and to have at least 3 entries, but + * these entries may be <code>null</code>. The implied meaning of + * <code>null</code> is: + * <ul> + * <li> offset 0: the invoking context's 'standard input' stream + * <li> offset 1: the invoking context's 'standard output' stream + * <li> offset 2: the invoking context's 'standard error' stream + * </ul> + * + * @return stream context as described above. */ - private static char unescape(char arg) { - // one-character escapes - for (int i = 0; i < escapes.length; i++) { - Escape e = escapes[i]; - if (e.escaped == arg) - return e.plain; + public Closeable[] getStreams() { + return streams.clone(); } - return arg; + + /** + * Set the IO stream context for executing the command. + * + * @param the new tream context. + */ + public void setStreams(Closeable[] streams) { + this.streams = streams.clone(); } - private static class Escape { - final char plain; + public void complete(CompletionInfo completion, CommandShell shell) throws CompletionException { + String cmd = (commandName == null) ? "" : commandName.trim(); + String result = null; + if (!cmd.equals("") && (arguments.length > 0 || argumentAnticipated)) { + try { + // get command's help info + CommandInfo cmdClass = shell.getCommandClass(cmd); - final char escaped; + Help.Info info; + try { + info = Help.getInfo(cmdClass.getCommandClass()); + } catch (HelpException ex) { + //assuming default syntax; i.e. multiple file arguments + info = defaultParameter; + } - Escape(char plain, char escaped) { - this.plain = plain; - this.escaped = escaped; + // perform completion of the command arguments based on the command's + // help info / syntax ... if any. + result = info.complete(this); + + } catch (ClassNotFoundException ex) { + throw new CompletionException("Command class not found", ex); + } } + else { + // do completion on the command name + result = defaultArg.complete(cmd); + } + completion.setCompleted(result); } + public void remove() { + throw new UnsupportedOperationException("remove not supported"); + } } Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -21,9 +21,6 @@ package org.jnode.shell; -import gnu.java.security.action.GetPropertyAction; -import gnu.java.security.action.SetPropertyAction; - import java.io.File; import java.io.FilterInputStream; import java.io.InputStream; @@ -53,13 +50,7 @@ import org.jnode.naming.InitialNaming; import org.jnode.shell.alias.AliasManager; import org.jnode.shell.alias.NoSuchAliasException; -import org.jnode.shell.help.Argument; import org.jnode.shell.help.CompletionException; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.HelpException; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.argument.AliasArgument; -import org.jnode.shell.help.argument.FileArgument; import org.jnode.util.SystemInputStream; import org.jnode.vm.VmSystem; @@ -71,7 +62,23 @@ public class CommandShell implements Runnable, Shell, ConsoleListener { public static final String PROMPT_PROPERTY_NAME = "jnode.prompt"; + public static final String INTERPRETER_PROPERTY_NAME = "jnode.interpreter"; + public static final String INVOKER_PROPERTY_NAME = "jnode.invoker"; + public static final String CMDLINE_PROPERTY_NAME = "jnode.cmdline"; + public static final String DEBUG_PROPERTY_NAME = "jnode.debug"; + public static final String HISTORY_PROPERTY_NAME = "jnode.history"; + + public static final String HOME_PROPERTY_NAME = "user.home"; + public static final String DIRECTORY_PROPERTY_NAME = "user.dir"; + public static final String INITIAL_INVOKER = "thread"; + public static final String INITIAL_INTERPRETER = "redirecting"; + public static final String FALLBACK_INVOKER = "default"; + public static final String FALLBACK_INTERPRETER = "default"; + + private static String DEFAULT_PROMPT = "JNode $P$G"; + private static final String COMMAND_KEY = "cmd="; + /** * My logger */ @@ -119,27 +126,23 @@ */ private volatile boolean threadSuspended = false; - private static String DEFAULT_PROMPT = "JNode $P$G"; + private CommandInvoker invoker; + private String invokerName; - private static final String command = "cmd="; + private CommandInterpreter interpreter; + private String interpreterName; - // private static final Class[] MAIN_ARG_TYPES = new Class[] { - // String[].class }; - - private CommandInvoker commandInvoker; - - private ThreadCommandInvoker threadCommandInvoker; - - private DefaultCommandInvoker defaultCommandInvoker; + private CompletionInfo completion; - private ProcletCommandInvoker procletCommandInvoker; + private boolean historyEnabled; - private boolean historyEnabled = true; + private boolean debugEnabled; private boolean exitted = false; private Thread ownThread; + public TextConsole getConsole() { return console; } @@ -149,27 +152,6 @@ shell.run(); } - public void setThreadCommandInvoker() { - if (this.commandInvoker != threadCommandInvoker) { - err.println("Switched to thread invoker"); - this.commandInvoker = threadCommandInvoker; - } - } - - public void setDefaultCommandInvoker() { - if (this.commandInvoker != defaultCommandInvoker) { - err.println("Switched to default invoker"); - this.commandInvoker = defaultCommandInvoker; - } - } - - public void setProcletCommandInvoker() { - if (this.commandInvoker != procletCommandInvoker) { - err.println("Switched to proclet invoker"); - this.commandInvoker = procletCommandInvoker; - } - } - /** * Create a new instance * @@ -189,16 +171,11 @@ SystemInputStream.getInstance().initialize(this.in); cons.setCompleter(this); - defaultCommandInvoker = new DefaultCommandInvoker(this); - threadCommandInvoker = new ThreadCommandInvoker(this); - procletCommandInvoker = new ProcletCommandInvoker(this); - setThreadCommandInvoker(); // default to separate this.console.addConsoleListener(this); // threads for commands. aliasMgr = ((AliasManager) InitialNaming.lookup(AliasManager.NAME)) .createAliasManager(); - AccessController.doPrivileged(new SetPropertyAction( - PROMPT_PROPERTY_NAME, DEFAULT_PROMPT)); + System.setProperty(PROMPT_PROPERTY_NAME, DEFAULT_PROMPT); // ShellUtils.getShellManager().registerShell(this); } catch (NameNotFoundException ex) { throw new ShellException("Cannot find required resource", ex); @@ -214,62 +191,70 @@ * @see java.lang.Runnable#run() */ public void run() { - ownThread = Thread.currentThread(); // Here, we are running in the CommandShell (main) Thread // so, we can register ourself as the current shell // (it will also be the current shell for all children Thread) + + // FIXME - At one point, the 'current shell' had something to do with + // dispatching keyboard input to the right application. Now this is + // handled by the console layer. Is 'current shell' a meaningful / + // useful concept anymore? try { ShellUtils.getShellManager().registerShell(this); + + ShellUtils.registerCommandInvoker(DefaultCommandInvoker.FACTORY); + ShellUtils.registerCommandInvoker(ThreadCommandInvoker.FACTORY); + ShellUtils.registerCommandInvoker(ProcletCommandInvoker.FACTORY); + ShellUtils.registerCommandInterpreter(DefaultInterpreter.FACTORY); + ShellUtils.registerCommandInterpreter(RedirectingInterpreter.FACTORY); } catch (NameNotFoundException e1) { e1.printStackTrace(); } + // Configure the shell based on Syetsm properties. + setupFromProperties(); + + // Now become interactive + ownThread = Thread.currentThread(); + // Run commands from the JNode commandline first - final String cmdLine = (String) AccessController - .doPrivileged(new GetPropertyAction("jnode.cmdline", "")); + final String cmdLine = System.getProperty(CMDLINE_PROPERTY_NAME, ""); final StringTokenizer tok = new StringTokenizer(cmdLine); while (tok.hasMoreTokens()) { final String e = tok.nextToken(); try { - if (e.startsWith(command)) { - final String cmd = e.substring(command.length()); + if (e.startsWith(COMMAND_KEY)) { + final String cmd = e.substring(COMMAND_KEY.length()); out.println(prompt() + cmd); processCommand(cmd, false); } } catch (Throwable ex) { - ex.printStackTrace(err); + err.println("Error while processing bootarg commands: " + ex.getMessage()); + stackTrace(ex); } } - final String user_home = (String) AccessController.doPrivileged(new GetPropertyAction("user.home", "")); + final String user_home = System.getProperty(HOME_PROPERTY_NAME, ""); + AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { + final File shell_ini = new File(user_home + "/shell.ini"); try { - final File shell_ini = new File(user_home + "/shell.ini"); - if(shell_ini.exists()) + if (shell_ini.exists()) { executeFile(shell_ini); - } catch(IOException ioe){ - ioe.printStackTrace(); + } + } catch (IOException ex) { + err.println("Error while reading " + shell_ini + ": " + ex.getMessage()); + stackTrace(ex); } return null; } }); - // Now become interactive while (!isExitted()) { try { - // Temporary mechanism for switching invokers - String invokerName = System.getProperty("jnode.invoker", ""); - if (invokerName.equalsIgnoreCase("default")) { - setDefaultCommandInvoker(); - } - else if (invokerName.equalsIgnoreCase("thread")) { - setThreadCommandInvoker(); - } - else if (invokerName.equalsIgnoreCase("proclet")) { - setProcletCommandInvoker(); - } + refreshFromProperties(); clearEof(); out.print(prompt()); @@ -283,11 +268,76 @@ exitted = true; } } catch (Throwable ex) { - ex.printStackTrace(err); + err.println("Uncaught exception while processing command(s): " + ex.getMessage()); + stackTrace(ex); } } } + private void setupFromProperties() { + debugEnabled = Boolean.parseBoolean(System.getProperty(DEBUG_PROPERTY_NAME, "true")); + historyEnabled = Boolean.parseBoolean(System.getProperty(HISTORY_PROPERTY_NAME, "true")); + try { + setCommandInvoker(System.getProperty(INVOKER_PROPERTY_NAME, INITIAL_INVOKER)); + } catch (Exception ex) { + err.println(ex.getMessage()); + stackTrace(ex); + setCommandInvoker(FALLBACK_INVOKER); // fallback to default + } + try { + setCommandInterpreter(System.getProperty(INTERPRETER_PROPERTY_NAME, INITIAL_INTERPRETER)); + } catch (Exception ex) { + err.println(ex.getMessage()); + stackTrace(ex); + setCommandInterpreter(FALLBACK_INTERPRETER); // fallback to default + } + } + + private void refreshFromProperties() { + debugEnabled = Boolean.parseBoolean(System.getProperty(DEBUG_PROPERTY_NAME, "true")); + historyEnabled = Boolean.parseBoolean(System.getProperty(HISTORY_PROPERTY_NAME, "true")); + try { + setCommandInterpreter(System.getProperty(INTERPRETER_PROPERTY_NAME, "")); + } + catch (Exception ex) { + err.println(ex.getMessage()); + stackTrace(ex); + } + try { + setCommandInvoker(System.getProperty(INVOKER_PROPERTY_NAME, "")); + } + catch (Exception ex) { + err.println(ex.getMessage()); + stackTrace(ex); + } + } + + public synchronized void setCommandInvoker(String name) + throws IllegalArgumentException { + if (!name.equals(this.invokerName)) { + this.invoker = ShellUtils.createInvoker(name, this); + err.println("Switched to " + name + " invoker"); + this.invokerName = name; + System.setProperty(INVOKER_PROPERTY_NAME, name); + } + } + + public synchronized void setCommandInterpreter(String name) + throws IllegalArgumentException { + if (!name.equals(this.interpreterName)) { + this.interpreter = ShellUtils.createInterpreter(name); + err.println("Switched to " + name + " interpreter"); + this.interpreterName = name; + System.setProperty(INTERPRETER_PROPERTY_NAME, name); + } + } + + private void stackTrace(Throwable ex) { + if (this.debugEnabled) { + ex.printStackTrace(err); + } + } + private String readInputLine() throws IOException { StringBuffer sb = new StringBuffer(40); Reader r = new InputStreamReader(in); @@ -314,16 +364,55 @@ // for input completion applicationHistory.set(new InputHistory()); } - commandInvoker.invoke(cmdLineStr); + try { + interpreter.interpret(this, cmdLineStr); + } + catch (ShellException ex) { + err.println("Shell exception: " + ex.getMessage()); + stackTrace(ex); + } + if (interactive) { applicationHistory.set(null); } } - public void invokeCommand(String command) { + /** + * Parse and run a command line using the CommandShell's current interpreter. + * @param command the command line. + * @throws ShellException + */ + public void invokeCommand(String command) throws ShellException { processCommand(command, false); } + /** + * Run a command encoded as a CommandLine object. The command line + * will give the command name (alias), the argument list and the + * IO stream. The command is run using the CommandShell's current invoker. + * + * @param cmdLine the CommandLine object. + * @return the command's return code + * @throws ShellException + */ + public int invoke(CommandLine cmdLine) throws ShellException { + return this.invoker.invoke(cmdLine); + } + + /** + * Prepare a CommandThread to run a command encoded as a CommandLine object. + * When the thread's "start" method is called, the command will be executed + * using the CommandShell's current (now) invoker. + * + * @param cmdLine the CommandLine object. + * @return the command's return code + * @throws ShellException + */ + public CommandThread invokeAsynchronous(CommandLine cmdLine) + throws ShellException { + return this.invoker.invokeAsynchronous(cmdLine); + } + protected CommandInfo getCommandClass(String cmd) throws ClassNotFoundException { try { @@ -336,6 +425,10 @@ } } + boolean isDebugEnabled() { + return debugEnabled; + } + /** * Gets the alias manager of this shell */ @@ -366,8 +459,7 @@ * Gets the expanded prompt */ protected String prompt() { - String prompt = (String) AccessController.doPrivileged( - new GetPropertyAction(PROMPT_PROPERTY_NAME)); + String prompt = System.getProperty(PROMPT_PROPERTY_NAME, DEFAULT_PROMPT); final StringBuffer result = new StringBuffer(); boolean commandMode = false; try { @@ -378,16 +470,15 @@ if (commandMode) { switch (c) { case 'P': - result.append(new File((String) AccessController - .doPrivileged(new GetPropertyAction("user.dir")))); + result.append(new File( + System.getProperty(DIRECTORY_PROPERTY_NAME, ""))); break; case 'G': result.append("> "); break; case 'D': final Date now = new Date(); - DateFormat.getDateTimeInstance().format(now, result, - null); + DateFormat.getDateTimeInstance().format(now, result, null); break; default: result.append(c); @@ -410,15 +501,10 @@ return result.toString(); } - private final Help.Info defaultParameter = new Help.Info("file", - "default parameter for command line completion", - new Parameter(new FileArgument("file", "a file", Argument.MULTI), Parameter.OPTIONAL) - ); - private final Argument defaultArg = new AliasArgument("command", - "the command to be called"); + public Completable parseCommandLine(String cmdLineStr) throws ShellSyntaxException { + return interpreter.parsePartial(this, cmdLineStr); + } - private CompletionInfo completion; - public CompletionInfo complete(String partial) { if (!readingCommand) { // dummy completion behavior for application input. @@ -435,65 +521,47 @@ } // do command completion - String result = null; completion = new CompletionInfo(); + boolean success = false; try { - CommandLine cl = new CommandLine(partial); - String cmd = ""; - if (cl.hasNext()) { - cmd = cl.next(); - if (!cmd.trim().equals("") && cl.hasNext()) - try { - // get command's help info - CommandInfo cmdClass = getCommandClass(cmd); - - Help.Info info = defaultParameter; - try { - info = Help.getInfo(cmdClass - .getCommandClass()); - }catch (HelpException ex) { - /*ex.printStackTrace(); - throw new CompletionException("Command class not found");*/ - - //assuming default completion which is multiple files - } - - // perform completion - result = cmd + " " + info.complete(cl); // prepend - completion.setCompleted(result); - // command - // name and - // space - // again - } catch (ClassNotFoundException ex) { - throw new CompletionException("Command class not found"); - } - } - if (result == null) // assume this is the alias to be called - result = defaultArg.complete(cmd); - - if (!partial.equals(result) && !completion.hasItems()) { - // performed direct - // completion without listing - completion.setCompleted(result); + Completable cl = parseCommandLine(partial); + if (cl != null) { + cl.complete(completion, this); + if (!partial.equals(completion.getCompleted()) && !completion.hasItems()) { + // we performed direct completion without listing completion.setNewPrompt(false); } + success = true; + } + } catch (ShellSyntaxException ex) { + out.println(); // next line + err.println("Cannot parse: " + ex.getMessage()); // print the error (optional) + } catch (CompletionException ex) { out.println(); // next line - err.println(ex.getMessage()); // print the error (optional) - // this debug output is to trace where the Exception came from - // ex.printStackTrace(err); - // restore old value and need a new prompt + err.println("Problem in completer: " + ex.getMessage()); // print the error (optional) + } + + if (!success) { + // Make sure the caller knows to repaint the prompt completion.setCompleted(partial); completion.setNewPrompt(true); } - return completion; + // Make sure that the shell's completion context gets nulled. + CompletionInfo myCompletion = completion; + completion = null; + return myCompletion; } public void list(String[] items) { + if (completion == null) { + throw new ShellFailureException("list called when no completion is in progress"); + } + else { completion.setItems(items); } + } public void addCommandToHistory(String cmdLineStr) { // Add this command to the command history. @@ -525,6 +593,10 @@ } } + /** + * This class subtypes FilterInputStream to capture console input to an + * application in the application input history. + */ private class HistoryInputStream extends FilterInputStream { // TODO - revisit for support of multi-byte character encodings. private StringBuilder line = new StringBuilder(); @@ -579,50 +651,54 @@ return err; } - public DefaultCommandInvoker getDefaultCommandInvoker() { - return defaultCommandInvoker; + public CommandInvoker getDefaultCommandInvoker() { + return ShellUtils.createInvoker("default", this); } public void executeFile(File file) throws IOException { - if(!file.exists()){ - System.err.println( "File does not exist: " + file); + if (!file.exists()) { + err.println( "File does not exist: " + file); return; } - try{ + try { setHistoryEnabled(false); final BufferedReader br = new BufferedReader(new FileReader(file)); - for(String line = br.readLine(); line != null; line = br.readLine()){ + for (String line = br.readLine(); line != null; line = br.readLine()) { line = line.trim(); - if(line.startsWith("#") || line.equals("")) + if (line.startsWith("#") || line.equals("")) { continue; - + } + try { invokeCommand(line); } + catch (ShellException ex) { + err.println("Shell exception: " + ex.getMessage()); + stackTrace(ex); + } + } br.close(); - }finally{ + } finally { setHistoryEnabled(true); } } public void exit(){ - exit0(); console.close(); - } public void consoleClosed(ConsoleEvent event) { - if(!exitted) - if(Thread.currentThread() == ownThread){ + if (!exitted) { + if (Thread.currentThread() == ownThread){ exit0(); } else { - synchronized(this){ + synchronized(this) { exit0(); notifyAll(); } } - + } } private void exit0() { @@ -630,7 +706,7 @@ threadSuspended = false; } - private synchronized boolean isExitted(){ + private synchronized boolean isExitted() { return exitted; } Modified: trunk/shell/src/shell/org/jnode/shell/CommandThread.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandThread.java 2007-10-26 21:17:14 UTC (rev 3570) +++ trunk/shell/src/shell/org/jnode/shell/CommandThread.java 2007-10-26 21:30:12 UTC (rev 3571) @@ -63,11 +63,15 @@ @Override public void run() { + try { super.run(); + } + finally { if (listener != null) { listener.notifyThreadExitted(this);... [truncated message content] |