felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r787428 [1/3] - in /felix/trunk/gogo: ./ src/main/java/org/apache/felix/gogo/cpeg/ src/main/java/org/apache/felix/gogo/launcher/ src/main/java/org/apache/felix/gogo/shell/console/ src/main/java/org/apache/felix/gogo/shell/equinox/ src/main/...
Date Mon, 22 Jun 2009 22:27:14 GMT
Author: gnodet
Date: Mon Jun 22 22:27:13 2009
New Revision: 787428

URL: http://svn.apache.org/viewvc?rev=787428&view=rev
Log:
FELIX-1268: Reformat code according to felix conventions

Modified:
    felix/trunk/gogo/pom.xml
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/cpeg/Procedural.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/launcher/Launcher.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/console/Console.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/equinox/Equinox.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/lang/Support.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiCommands.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiShell.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/ServiceCommand.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Closure.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Command.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/CommandSessionImpl.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/CommandShellImpl.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Parser.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Pipe.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Reflective.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/stdio/StdioConsole.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/telnet/Handler.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/telnet/TelnetShell.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/threadio/Marker.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/threadio/ThreadIOImpl.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/threadio/ThreadInputStream.java
    felix/trunk/gogo/src/main/java/org/apache/felix/gogo/threadio/ThreadPrintStream.java
    felix/trunk/gogo/src/main/java/org/osgi/framework/boot/SystemBundle.java
    felix/trunk/gogo/src/main/java/org/osgi/service/command/CommandProcessor.java
    felix/trunk/gogo/src/main/java/org/osgi/service/command/CommandSession.java
    felix/trunk/gogo/src/main/java/org/osgi/service/command/Converter.java
    felix/trunk/gogo/src/main/java/org/osgi/service/command/Function.java
    felix/trunk/gogo/src/main/java/org/osgi/service/threadio/ThreadIO.java
    felix/trunk/gogo/src/test/java/org/apache/felix/gogo/shell/runtime/Context.java
    felix/trunk/gogo/src/test/java/org/apache/felix/gogo/shell/runtime/TestParser.java
    felix/trunk/gogo/src/test/java/org/apache/felix/gogo/threadio/TestThreadIO.java

Modified: felix/trunk/gogo/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/pom.xml?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/pom.xml (original)
+++ felix/trunk/gogo/pom.xml Mon Jun 22 22:27:13 2009
@@ -16,76 +16,77 @@
  specific language governing permissions and limitations
  under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.apache.felix</groupId>
-    <artifactId>felix-parent</artifactId>
-    <version>1.2.0</version>
-    <relativePath>../pom/pom.xml</relativePath>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <packaging>bundle</packaging>
-  <name>Apache Felix Gogo Shell</name>
-  <artifactId>org.apache.felix.gogo</artifactId>
-  <version>1.0.0-SNAPSHOT</version>
-  <dependencies>
-      <dependency>
-        <groupId>${pom.groupId}</groupId>
-        <artifactId>org.osgi.core</artifactId>
-        <version>1.2.0</version>
-        <scope>provided</scope>
-      </dependency>
-      <dependency>
-        <groupId>${pom.groupId}</groupId>
-        <artifactId>org.osgi.compendium</artifactId>
-        <version>1.2.0</version>
-        <scope>provided</scope>
-      </dependency>
-      <dependency>
-          <groupId>junit</groupId>
-          <artifactId>junit</artifactId>
-          <version>4.5</version>
-          <scope>test</scope>
-      </dependency>
-  </dependencies>
-  <build>
-    <plugins>
-      <plugin>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
         <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <version>2.0.0</version>
-        <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Export-Package>org.osgi.service.command; version=1.0.0</Export-Package>
-            <Private-Package>org.apache.felix.gogo.*</Private-Package>
-            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
-            <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
-          </instructions>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>rat-maven-plugin</artifactId>
-        <configuration>
-          <excludeSubProjects>false</excludeSubProjects>
-          <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
-          <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
-          <excludes>
-            <param>doc/*</param>
-            <param>maven-eclipse.xml</param>
-            <param>.checkstyle</param>
-            <param>.externalToolBuilders/*</param>
-          </excludes>
-        </configuration>
-      </plugin>
-      <plugin>
-          <artifactId>maven-compiler-plugin</artifactId>
-          <configuration>
-              <source>1.5</source>
-              <target>1.5</target>
-          </configuration>
-      </plugin>
-    </plugins>
-  </build>
+        <artifactId>felix-parent</artifactId>
+        <version>1.2.0</version>
+        <relativePath>../pom/pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>bundle</packaging>
+    <name>Apache Felix Gogo Shell</name>
+    <artifactId>org.apache.felix.gogo</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <dependencies>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>1.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>1.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.5</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.0.0</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.osgi.service.command; version=1.0.0</Export-Package>
+                        <Private-Package>org.apache.felix.gogo.*</Private-Package>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>rat-maven-plugin</artifactId>
+                <configuration>
+                    <excludeSubProjects>false</excludeSubProjects>
+                    <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+                    <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+                    <excludes>
+                        <param>doc/*</param>
+                        <param>maven-eclipse.xml</param>
+                        <param>.checkstyle</param>
+                        <param>.externalToolBuilders/*</param>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/cpeg/Procedural.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/cpeg/Procedural.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/cpeg/Procedural.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/cpeg/Procedural.java Mon Jun 22 22:27:13 2009
@@ -19,41 +19,60 @@
 package org.apache.felix.gogo.cpeg;
 
 
-import org.osgi.framework.*;
-import org.osgi.service.command.*;
+import org.osgi.framework.Bundle;
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Function;
 
 
-public class Procedural {
-    
-    public Object _if( CommandSession session, Function condition, Function ifTrue, Function ifFalse ) throws Exception {
+public class Procedural
+{
+
+    public Object _if(CommandSession session, Function condition, Function ifTrue, Function ifFalse) throws Exception
+    {
         Object result = condition.execute(session, null);
-        if ( isTrue(result)) {
+        if (isTrue(result))
+        {
             return ifTrue.execute(session, null);
-        } else {
-            if ( ifFalse != null )
-                return ifFalse.execute(session,null);
+        }
+        else
+        {
+            if (ifFalse != null)
+            {
+                return ifFalse.execute(session, null);
+            }
         }
         return null;
     }
-    
-    public Object _new(String name, Bundle bundle) throws Exception {
-        if ( bundle == null)
+
+    public Object _new(String name, Bundle bundle) throws Exception
+    {
+        if (bundle == null)
+        {
             return Class.forName(name).newInstance();
-        else {
+        }
+        else
+        {
             return bundle.loadClass(name).newInstance();
         }
     }
 
-    private boolean isTrue(Object result) {
-        if ( result == null)
+    private boolean isTrue(Object result)
+    {
+        if (result == null)
+        {
             return false;
-        
-        if ( result instanceof String && ((String)result).equals(""))
+        }
+
+        if (result instanceof String && ((String) result).equals(""))
+        {
             return false;
-        
-        if ( result instanceof Boolean )
-            return ((Boolean)result).booleanValue();
-        
+        }
+
+        if (result instanceof Boolean)
+        {
+            return ((Boolean) result).booleanValue();
+        }
+
         return true;
     }
 }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/launcher/Launcher.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/launcher/Launcher.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/launcher/Launcher.java Mon Jun 22 22:27:13 2009
@@ -18,104 +18,143 @@
  */
 package org.apache.felix.gogo.launcher;
 
+import org.apache.felix.gogo.shell.console.Console;
+import org.apache.felix.gogo.shell.osgi.OSGiShell;
+import org.apache.felix.gogo.threadio.ThreadIOImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.service.command.CommandProcessor;
+import org.osgi.service.command.CommandSession;
+
 import java.io.*;
-import java.lang.reflect.*;
-import java.net.*;
+import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.*;
 
-import org.osgi.framework.*;
-import org.osgi.service.command.*;
-
-import org.apache.felix.gogo.shell.console.*;
-import org.apache.felix.gogo.shell.osgi.*;
-import org.apache.felix.gogo.threadio.*;
-
-public class Launcher {
-	static List<URL> classpath = new ArrayList<URL>();
-	static File cwd = new File("").getAbsoluteFile();
-	
-	public static void main(String args[]) throws Exception {
-		StringBuffer sb = new StringBuffer();
-		String framework = null;
-		PrintStream		out = System.out;
-		InputStream		in = System.in;
-		boolean console = false;
-		
-		for (int i = 0; i < args.length; i++) {
-			String arg = args[i];
-			if (arg.equals("-f")) {
-				framework = args[++i];
-			} else if (arg.equals("-cp") || arg.equals("-classpath")) {
-				classpath(args[++i]);
-			} else if (arg.equals("-console")) {
-				console = true;
-			} else if (arg.equals("-i")) {
-				in = new FileInputStream(args[++i]);
-			} else if (arg.equals("-o")) {
-				out = new PrintStream(new FileOutputStream(args[++i]));
-			} else {
-				sb.append(' ');
-				sb.append(arg);
-			}
-		}
-
-		if (framework == null) {
-			System.err.println("No framework set");
-			System.exit(1);
-		}
-
-		ThreadIOImpl threadio = new ThreadIOImpl();
-		threadio.start();
-		URL[] urls = classpath.toArray(new URL[classpath.size()]);
-		URLClassLoader urlcl = new URLClassLoader(urls, Launcher.class.getClassLoader());
-		Class<?> fw = urlcl.loadClass(framework);
-		
-		Constructor<?> c = fw.getConstructor(Map.class, List.class );
-		Properties p = new Properties( System.getProperties());
-		p.setProperty("felix.cache.profile", "default");
-		p.setProperty("felix.embedded.execution", "true");
-		Bundle bundle = (Bundle) c.newInstance(p,null);
-		
-		OSGiShell shell = new OSGiShell();
-		shell.setThreadio(threadio);
-		shell.setBundle(bundle);
-		shell.start();
-		
-		
-		CommandSession session = shell.createSession(in, out,
-				System.err);
-		session.put("shell", shell);
-		session.put("threadio", threadio);
-		
-		session.execute(sb);
-		out.flush();
-		
-		if ( bundle.getState() == Bundle.ACTIVE ) {
-			bundle.getBundleContext().registerService(CommandProcessor.class.getName(), shell, null );
-		}
-		if ( console ) {
-			Console cons = new Console();
-			cons.setSession(session);
-			cons.run();
-		}
-	}
-
-
-	private static void classpath(String string) throws MalformedURLException {
-		StringTokenizer st = new StringTokenizer(string, File.pathSeparator);
-		while (st.hasMoreTokens()) {
-			String part = st.nextToken();
-			if ( part.equals("."))
-				classpath.add( cwd.toURL() );
-			
-			File f = new File(part);
-			if ( ! f.isAbsolute() ) {
-				f = new File( cwd, part );
-			}
-			if ( f.exists() )
-				classpath.add( f.toURL());
-			else
-				System.err.println("Can not find " + part );
-		}
-	}	
+public class Launcher
+{
+    static List<URL> classpath = new ArrayList<URL>();
+    static File cwd = new File("").getAbsoluteFile();
+
+    public static void main(String args[]) throws Exception
+    {
+        StringBuffer sb = new StringBuffer();
+        String framework = null;
+        PrintStream out = System.out;
+        InputStream in = System.in;
+        boolean console = false;
+
+        for (int i = 0; i < args.length; i++)
+        {
+            String arg = args[i];
+            if (arg.equals("-f"))
+            {
+                framework = args[++i];
+            }
+            else
+            {
+                if (arg.equals("-cp") || arg.equals("-classpath"))
+                {
+                    classpath(args[++i]);
+                }
+                else
+                {
+                    if (arg.equals("-console"))
+                    {
+                        console = true;
+                    }
+                    else
+                    {
+                        if (arg.equals("-i"))
+                        {
+                            in = new FileInputStream(args[++i]);
+                        }
+                        else
+                        {
+                            if (arg.equals("-o"))
+                            {
+                                out = new PrintStream(new FileOutputStream(args[++i]));
+                            }
+                            else
+                            {
+                                sb.append(' ');
+                                sb.append(arg);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        if (framework == null)
+        {
+            System.err.println("No framework set");
+            System.exit(1);
+        }
+
+        ThreadIOImpl threadio = new ThreadIOImpl();
+        threadio.start();
+        URL[] urls = classpath.toArray(new URL[classpath.size()]);
+        URLClassLoader urlcl = new URLClassLoader(urls, Launcher.class.getClassLoader());
+        Class<?> fw = urlcl.loadClass(framework);
+
+        Constructor<?> c = fw.getConstructor(Map.class, List.class);
+        Properties p = new Properties(System.getProperties());
+        p.setProperty("felix.cache.profile", "default");
+        p.setProperty("felix.embedded.execution", "true");
+        Bundle bundle = (Bundle) c.newInstance(p, null);
+
+        OSGiShell shell = new OSGiShell();
+        shell.setThreadio(threadio);
+        shell.setBundle(bundle);
+        shell.start();
+
+
+        CommandSession session = shell.createSession(in, out, System.err);
+        session.put("shell", shell);
+        session.put("threadio", threadio);
+
+        session.execute(sb);
+        out.flush();
+
+        if (bundle.getState() == Bundle.ACTIVE)
+        {
+            bundle.getBundleContext().registerService(CommandProcessor.class.getName(), shell, null);
+        }
+        if (console)
+        {
+            Console cons = new Console();
+            cons.setSession(session);
+            cons.run();
+        }
+    }
+
+
+    private static void classpath(String string) throws MalformedURLException
+    {
+        StringTokenizer st = new StringTokenizer(string, File.pathSeparator);
+        while (st.hasMoreTokens())
+        {
+            String part = st.nextToken();
+            if (part.equals("."))
+            {
+                classpath.add(cwd.toURL());
+            }
+
+            File f = new File(part);
+            if (!f.isAbsolute())
+            {
+                f = new File(cwd, part);
+            }
+            if (f.exists())
+            {
+                classpath.add(f.toURL());
+            }
+            else
+            {
+                System.err.println("Can not find " + part);
+            }
+        }
+    }
 }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/console/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/console/Console.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/console/Console.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/console/Console.java Mon Jun 22 22:27:13 2009
@@ -19,125 +19,169 @@
 
 package org.apache.felix.gogo.shell.console;
 
-import java.io.*;
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.osgi.service.command.*;
-
-public class Console implements Runnable {
-	StringBuilder		sb;
-	CommandSession		session;
-	List<CharSequence>	history	= new ArrayList<CharSequence>();
-	int					current	= 0;
-	boolean				quit;
-
-	public void setSession(CommandSession session) {
-	    this.session= session;
-	}
-	
-	public void run() {
-		try {
-			while (!quit) {
-				try {
-					CharSequence line = getLine(session.getKeyboard());
-					if (line != null) {
-						history.add(line);
-						if (history.size() > 40)
-							history.remove(0);
-						Object result = session.execute(line);
-						if (result != null)
-							session.getConsole().println(
-									session.format(result, Converter.INSPECT));
-					} else
-						quit = true;
-
-				} catch (InvocationTargetException ite) {
-					session.getConsole().println(
-							"E: " + ite.getTargetException());
-					session.put("exception", ite.getTargetException());
-				} catch (Throwable e) {
-					if (!quit) {
-						session.getConsole().println("E: " + e.getMessage());
-						session.put("exception", e);
-					}
-				}
-			}
-		} catch (Exception e) {
-			if (!quit)
-				e.printStackTrace();
-		}
-	}
-
-	CharSequence getLine(InputStream in) throws IOException {
-		sb = new StringBuilder();
-		session.getConsole().print("$ ");
-		int outer = 0;
-		while (!quit) {
-			session.getConsole().flush();
-			int c = in.read();
-			if (c < 0)
-				quit = true;
-			else {
-				switch (c) {
-				case '\r':
-				    break;
-				case '\n':
-					if (outer == 0 && sb.length() > 0) {
-						return sb;
-					} else {
-					        session.getConsole().print("$ ");
-					}
-					break;
-
-				case '\u001b':
-					c = in.read();
-					if (c == '[') {
-						c = in.read();
-						session.getConsole().print("\b\b\b");
-						switch (c) {
-						case 'A':
-							history(current - 1);
-							break;
-						case 'B':
-							history(current + 1);
-							break;
-						case 'C': // right(); break;
-						case 'D': // left(); break;
-						}
-					}
-					break;
-
-				case '\b':
-					if (sb.length() > 0) {
-						session.getConsole().print("\b \b");
-						sb.deleteCharAt(sb.length() - 1);
-					}
-					break;
-
-				default:
-					sb.append((char) c);
-					break;
-				}
-			}
-		}
-		return null;
-	}
-
-	void history(int n) {
-		if (n < 0 || n > history.size())
-			return;
-		current = n;
-		for (int i = 0; i < sb.length(); i++)
-			session.getConsole().print("\b \b");
-
-		sb = new StringBuilder(history.get(current));
-		session.getConsole().print(sb);
-	}
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Converter;
 
-    public void close() {
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Console implements Runnable
+{
+    StringBuilder sb;
+    CommandSession session;
+    List<CharSequence> history = new ArrayList<CharSequence>();
+    int current = 0;
+    boolean quit;
+
+    public void setSession(CommandSession session)
+    {
+        this.session = session;
+    }
+
+    public void run()
+    {
+        try
+        {
+            while (!quit)
+            {
+                try
+                {
+                    CharSequence line = getLine(session.getKeyboard());
+                    if (line != null)
+                    {
+                        history.add(line);
+                        if (history.size() > 40)
+                        {
+                            history.remove(0);
+                        }
+                        Object result = session.execute(line);
+                        if (result != null)
+                        {
+                            session.getConsole().println(session.format(result, Converter.INSPECT));
+                        }
+                    }
+                    else
+                    {
+                        quit = true;
+                    }
+
+                }
+                catch (InvocationTargetException ite)
+                {
+                    session.getConsole().println("E: " + ite.getTargetException());
+                    session.put("exception", ite.getTargetException());
+                }
+                catch (Throwable e)
+                {
+                    if (!quit)
+                    {
+                        session.getConsole().println("E: " + e.getMessage());
+                        session.put("exception", e);
+                    }
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            if (!quit)
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    CharSequence getLine(InputStream in) throws IOException
+    {
+        sb = new StringBuilder();
+        session.getConsole().print("$ ");
+        int outer = 0;
+        while (!quit)
+        {
+            session.getConsole().flush();
+            int c = in.read();
+            if (c < 0)
+            {
+                quit = true;
+            }
+            else
+            {
+                switch (c)
+                {
+                    case '\r':
+                        break;
+                    case '\n':
+                        if (outer == 0 && sb.length() > 0)
+                        {
+                            return sb;
+                        }
+                        else
+                        {
+                            session.getConsole().print("$ ");
+                        }
+                        break;
+
+                    case '\u001b':
+                        c = in.read();
+                        if (c == '[')
+                        {
+                            c = in.read();
+                            session.getConsole().print("\b\b\b");
+                            switch (c)
+                            {
+                                case 'A':
+                                    history(current - 1);
+                                    break;
+                                case 'B':
+                                    history(current + 1);
+                                    break;
+                                case 'C': // right(); break;
+                                case 'D': // left(); break;
+                            }
+                        }
+                        break;
+
+                    case '\b':
+                        if (sb.length() > 0)
+                        {
+                            session.getConsole().print("\b \b");
+                            sb.deleteCharAt(sb.length() - 1);
+                        }
+                        break;
+
+                    default:
+                        sb.append((char) c);
+                        break;
+                }
+            }
+        }
+        return null;
+    }
+
+    void history(int n)
+    {
+        if (n < 0 || n > history.size())
+        {
+            return;
+        }
+        current = n;
+        for (int i = 0; i < sb.length(); i++)
+        {
+            session.getConsole().print("\b \b");
+        }
+
+        sb = new StringBuilder(history.get(current));
+        session.getConsole().print(sb);
+    }
+
+    public void close()
+    {
         quit = true;
     }
-    
-    public void open() {}
+
+    public void open()
+    {
+    }
 }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/equinox/Equinox.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/equinox/Equinox.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/equinox/Equinox.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/equinox/Equinox.java Mon Jun 22 22:27:13 2009
@@ -1,66 +1,81 @@
 package org.apache.felix.gogo.shell.equinox;
 
-import java.io.*;
-import java.net.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.command.CommandProcessor;
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Converter;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+
+import java.io.IOException;
+import java.net.URL;
 import java.util.*;
 
-import org.osgi.framework.*;
-import org.osgi.service.command.*;
-import org.osgi.service.component.*;
-import org.osgi.service.log.*;
-import org.osgi.service.packageadmin.*;
-import org.osgi.service.startlevel.*;
-
-public class Equinox implements Converter {
-    BundleContext         context;
-    PackageAdmin          pka;
-    LogReaderService      lrs;
-    StartLevel            sls;
-    final static String[] functions = { "active", "bundles", "close", "diag",
-            "exec", "exit", "fork", "gc", "getprop", "headers", "init",
-            "install", "launch", "log", "packages", "packages", "refresh",
-            "services", "setbsl", "setfwsl", "setibsl", "setprop", "shutdown",
-            "sl", "ss", "start", "status", "stop", "uninstall", "update" };
+public class Equinox implements Converter
+{
+    BundleContext context;
+    PackageAdmin pka;
+    LogReaderService lrs;
+    StartLevel sls;
+    final static String[] functions = {"active", "bundles", "close", "diag", "exec", "exit", "fork", "gc", "getprop", "headers", "init", "install", "launch", "log", "packages", "packages", "refresh", "services", "setbsl", "setfwsl", "setibsl", "setprop", "shutdown", "sl", "ss", "start", "status", "stop", "uninstall", "update"};
 
-    protected void activate(ComponentContext context) {
+    protected void activate(ComponentContext context)
+    {
         this.context = context.getBundleContext();
         Dictionary<String, Object> dict = new Hashtable<String, Object>();
         dict.put(CommandProcessor.COMMAND_SCOPE, "eqx");
         dict.put(CommandProcessor.COMMAND_FUNCTION, functions);
-        this.context.registerService( Converter.class.getName(), this, dict);
+        this.context.registerService(Converter.class.getName(), this, dict);
     }
 
-    BundleContext getContext() {
+    BundleContext getContext()
+    {
         return context;
     }
 
-    public void setPka(PackageAdmin pka) {
+    public void setPka(PackageAdmin pka)
+    {
         this.pka = pka;
     }
 
-    public void setLrs(LogReaderService lrs) {
+    public void setLrs(LogReaderService lrs)
+    {
         this.lrs = lrs;
     }
 
-    public void setSls(StartLevel sls) {
+    public void setSls(StartLevel sls)
+    {
         this.sls = sls;
     }
 
     /**
      * - Displays unsatisfied constraints for the specified bundle(s).
      */
-    public void diag() {
+    public void diag()
+    {
     }
 
     /*
      * active - Displays a list of all bundles currently in the ACTIVE state.
      */
-    public List<Bundle> active() {
+    public List<Bundle> active()
+    {
         List<Bundle> result = new ArrayList<Bundle>();
         Bundle[] bundles = getContext().getBundles();
-        for (Bundle b : bundles) {
+        for (Bundle b : bundles)
+        {
             if (b.getState() == Bundle.ACTIVE)
+            {
                 result.add(b);
+            }
         }
         return result;
     }
@@ -70,32 +85,40 @@
      * all of them.
      */
 
-    public Object getprop(CharSequence name) {
+    public Object getprop(CharSequence name)
+    {
         if (name == null)
+        {
             return System.getProperties();
+        }
         else
+        {
             return System.getProperty(name.toString());
+        }
     }
 
     /**
      * launch - start the OSGi Framework
      */
 
-    public void launch() {
+    public void launch()
+    {
         throw new IllegalStateException("Already running");
     }
 
     /**
      * shutdown - shutdown the OSGi Framework
      */
-    public void shutdown() throws BundleException {
+    public void shutdown() throws BundleException
+    {
         getContext().getBundle().stop();
     }
 
     /**
      * close - shutdown and exit
      */
-    public void close(CommandSession session) {
+    public void close(CommandSession session)
+    {
         session.close();
     }
 
@@ -103,14 +126,16 @@
      * exit - exit immediately (System.exit)
      */
 
-    public void exit(int exitValue) {
+    public void exit(int exitValue)
+    {
         exit(exitValue);
     }
 
     /**
      * gc - perform a garbage collection
      */
-    public long gc() {
+    public long gc()
+    {
         Runtime.getRuntime().gc();
         return Runtime.getRuntime().freeMemory();
     }
@@ -119,37 +144,46 @@
      * init - uninstall all bundles
      */
 
-    public void init() throws Exception {
+    public void init() throws Exception
+    {
         Bundle bundles[] = getContext().getBundles();
         for (Bundle b : bundles)
+        {
             if (b.getBundleId() != 0)
+            {
                 b.uninstall();
+            }
+        }
     }
 
     /**
      * setprop <key>=<value> - set the OSGi property
      */
-    public void setprop(CommandSession session, String key, String value) {
+    public void setprop(CommandSession session, String key, String value)
+    {
         session.put(key, value);
     }
 
     /**
      * install - install and optionally start bundle from the given URL
-     * 
+     *
      * @throws BundleException
      */
 
-    public Bundle install(URL url) throws BundleException {
+    public Bundle install(URL url) throws BundleException
+    {
         return getContext().installBundle(url.toExternalForm());
     }
 
     /**
      * uninstall - uninstall the specified bundle(s)
-     * 
+     *
      * @throws BundleException
      */
-    public void uninstall(Bundle[] bundles) throws BundleException {
-        for (Bundle b : bundles) {
+    public void uninstall(Bundle[] bundles) throws BundleException
+    {
+        for (Bundle b : bundles)
+        {
             b.uninstall();
         }
     }
@@ -157,8 +191,10 @@
     /**
      * start - start the specified bundle(s)
      */
-    public void start(Bundle[] bundles) throws BundleException {
-        for (Bundle b : bundles) {
+    public void start(Bundle[] bundles) throws BundleException
+    {
+        for (Bundle b : bundles)
+        {
             b.start();
         }
     }
@@ -166,8 +202,10 @@
     /**
      * stop - stop the specified bundle(s)
      */
-    public void stop(Bundle[] bundles) throws BundleException {
-        for (Bundle b : bundles) {
+    public void stop(Bundle[] bundles) throws BundleException
+    {
+        for (Bundle b : bundles)
+        {
             b.stop();
         }
     }
@@ -175,18 +213,25 @@
     /**
      * refresh - refresh the packages of the specified bundles
      */
-    public void refresh(Bundle[] bundles) throws Exception {
+    public void refresh(Bundle[] bundles) throws Exception
+    {
         if (pka != null)
+        {
             pka.refreshPackages(bundles);
+        }
         else
+        {
             throw new RuntimeException("No PackageAdmin service registered");
+        }
     }
 
     /**
      * update - update the specified bundle(s)
      */
-    public void update(Bundle[] bundles) throws BundleException {
-        for (Bundle b : bundles) {
+    public void update(Bundle[] bundles) throws BundleException
+    {
+        for (Bundle b : bundles)
+        {
             b.update();
         }
     }
@@ -194,25 +239,27 @@
     /**
      * status - display installed bundles and registered services
      */
-    public List<Object> status() throws Exception {
+    public List<Object> status() throws Exception
+    {
         List<Object> status = new ArrayList<Object>();
         status.addAll(Arrays.asList(getContext().getBundles()));
-        status.addAll(Arrays.asList(getContext().getServiceReferences(null,
-                null)));
+        status.addAll(Arrays.asList(getContext().getServiceReferences(null, null)));
         return status;
     }
 
     /**
      * ss - display installed bundles (short status)
      */
-    public Bundle[] ss() {
+    public Bundle[] ss()
+    {
         return getContext().getBundles();
     }
 
     /**
      * services {filter} - display registered service details
      */
-    public ServiceReference[] services(String filter) throws Exception {
+    public ServiceReference[] services(String filter) throws Exception
+    {
         return getContext().getServiceReferences(null, filter);
     }
 
@@ -220,23 +267,32 @@
      * packages {<pkgname>|<id>|<location>} - display imported/exported
      * package details
      */
-    public ExportedPackage[] packages(Bundle bundle) throws Exception {
+    public ExportedPackage[] packages(Bundle bundle) throws Exception
+    {
         if (pka != null)
+        {
             return pka.getExportedPackages(bundle);
+        }
         else
+        {
             throw new RuntimeException("No PackageAdmin service registered");
+        }
     }
 
-    public ExportedPackage[] packages(String packageName) throws Exception {
+    public ExportedPackage[] packages(String packageName) throws Exception
+    {
         if (pka != null)
+        {
             return pka.getExportedPackages(packageName);
+        }
         return null;
     }
 
     /**
      * bundles - display details for all installed bundles
      */
-    public Bundle[] bundles() {
+    public Bundle[] bundles()
+    {
         return ss();
     }
 
@@ -249,7 +305,8 @@
      */
 
     @SuppressWarnings("unchecked")
-    public Dictionary headers(Bundle b, String locale) {
+    public Dictionary headers(Bundle b, String locale)
+    {
         return b.getHeaders(locale);
     }
 
@@ -258,32 +315,42 @@
      */
 
     @SuppressWarnings("unchecked")
-    public Collection<LogEntry> log(Bundle bundle) throws Exception {
+    public Collection<LogEntry> log(Bundle bundle) throws Exception
+    {
         if (lrs != null)
+        {
             return Collections.list((Enumeration<LogEntry>) lrs.getLog());
+        }
         else
+        {
             throw new RuntimeException("LogReader not available");
+        }
     }
 
     /**
      * exec <command> - execute a command in a separate process and wait
-     * 
+     *
      * @throws IOException
      */
 
-    public int exec(Object[] args, boolean fork) throws IOException {
+    public int exec(Object[] args, boolean fork) throws IOException
+    {
         StringBuffer sb = new StringBuffer();
         String del = "";
-        for (Object arg : args) {
+        for (Object arg : args)
+        {
             sb.append(del);
             sb.append(arg);
             del = " ";
         }
         Process p = Runtime.getRuntime().exec(sb.toString());
-        if (fork) {
+        if (fork)
+        {
             int c;
             while ((c = p.getInputStream().read()) > 0)
+            {
                 System.out.print(c);
+            }
         }
         return p.exitValue();
     }
@@ -292,7 +359,8 @@
      * fork <command> - execute a command in a separate process
      */
 
-    public void fork(Object args[]) throws Exception {
+    public void fork(Object args[]) throws Exception
+    {
         exec(args, true);
     }
 
@@ -300,21 +368,31 @@
      * sl {(<id>|<location>)} - display the start level for the specified
      * bundle, or for the framework if no bundle specified
      */
-    public int sl(Bundle b) throws Exception {
+    public int sl(Bundle b) throws Exception
+    {
         if (sls == null)
+        {
             throw new RuntimeException("No StartLevel service registered");
+        }
         if (b == null)
+        {
             return sls.getStartLevel();
+        }
         else
+        {
             return sls.getBundleStartLevel(b);
+        }
     }
 
     /**
      * setfwsl <start level> - set the framework start level
      */
-    public int setfwsl(int n) throws Exception {
+    public int setfwsl(int n) throws Exception
+    {
         if (sls == null)
+        {
             throw new RuntimeException("No StartLevel service registered");
+        }
         int old = sls.getStartLevel();
         sls.setStartLevel(n);
         return old;
@@ -324,9 +402,12 @@
      * setbsl <start level> (<id>|<location>) - set the start level for the
      * bundle(s)
      */
-    public int setbsl(Bundle b, int n) throws Exception {
+    public int setbsl(Bundle b, int n) throws Exception
+    {
         if (sls == null)
+        {
             throw new RuntimeException("No StartLevel service registered");
+        }
         int old = sls.getBundleStartLevel(b);
         sls.setBundleStartLevel(b, n);
         return old;
@@ -335,49 +416,55 @@
     /**
      * setibsl <start level> - set the initial bundle start level
      */
-    public int setibsl(int n) throws Exception {
+    public int setibsl(int n) throws Exception
+    {
         if (sls == null)
+        {
             throw new RuntimeException("No StartLevel service registered");
+        }
         int old = sls.getInitialBundleStartLevel();
         sls.setInitialBundleStartLevel(n);
         return old;
     }
 
-    public Object convert(Class<?> desiredType, Object in) throws Exception {
+    public Object convert(Class<?> desiredType, Object in) throws Exception
+    {
         return null;
     }
 
-    String getLevel(int index) {
-        switch (index) {
-        case LogService.LOG_DEBUG:
-            return "DEBUG";
-        case LogService.LOG_INFO:
-            return "INFO ";
-        case LogService.LOG_WARNING:
-            return "WARNI";
-        case LogService.LOG_ERROR:
-            return "ERROR";
-        default:
-            return "<" + index + ">";
+    String getLevel(int index)
+    {
+        switch (index)
+        {
+            case LogService.LOG_DEBUG:
+                return "DEBUG";
+            case LogService.LOG_INFO:
+                return "INFO ";
+            case LogService.LOG_WARNING:
+                return "WARNI";
+            case LogService.LOG_ERROR:
+                return "ERROR";
+            default:
+                return "<" + index + ">";
         }
     }
 
-    public CharSequence format(Object target, int level, Converter escape) {
-        if (target instanceof LogEntry) {
+    public CharSequence format(Object target, int level, Converter escape)
+    {
+        if (target instanceof LogEntry)
+        {
             LogEntry entry = (LogEntry) target;
-            switch (level) {
-            case LINE:
-                Formatter f = new Formatter();
-                f.format("%tT %04d %s %s", entry.getTime(), entry.getBundle()
-                        .getBundleId(), getLevel(entry.getLevel())+"", entry
-                        .getMessage()+"");
-                return f.toString();
-                
-            case PART:
-                Formatter f2 = new Formatter();
-                f2.format("%tT %s", entry.getTime(), entry
-                        .getMessage());
-                return f2.toString();
+            switch (level)
+            {
+                case LINE:
+                    Formatter f = new Formatter();
+                    f.format("%tT %04d %s %s", entry.getTime(), entry.getBundle().getBundleId(), getLevel(entry.getLevel()) + "", entry.getMessage() + "");
+                    return f.toString();
+
+                case PART:
+                    Formatter f2 = new Formatter();
+                    f2.format("%tT %s", entry.getTime(), entry.getMessage());
+                    return f2.toString();
             }
         }
         return null;

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/lang/Support.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/lang/Support.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/lang/Support.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/lang/Support.java Mon Jun 22 22:27:13 2009
@@ -18,32 +18,38 @@
  */
 package org.apache.felix.gogo.shell.lang;
 
-import java.lang.reflect.*;
-import java.util.*;
+import org.osgi.service.command.Converter;
+import org.osgi.service.command.Function;
 
-import org.osgi.service.command.*;
-
-
-
-public class Support implements Converter {
-
-    public Object convert(Class<?> desiredType, final Object in) throws Exception {
-        if ( in instanceof Function  && desiredType.isInterface() && desiredType.getDeclaredMethods().length == 1) {
-            return Proxy.newProxyInstance(desiredType.getClassLoader(), new Class[] {desiredType}, new InvocationHandler() {
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+
+public class Support implements Converter
+{
+
+    public Object convert(Class<?> desiredType, final Object in) throws Exception
+    {
+        if (in instanceof Function && desiredType.isInterface() && desiredType.getDeclaredMethods().length == 1)
+        {
+            return Proxy.newProxyInstance(desiredType.getClassLoader(), new Class[]{desiredType}, new InvocationHandler()
+            {
                 Function command = ((Function) in);
 
-                public Object invoke(Object proxy, Method method, Object[] args)
-                        throws Throwable {
-                    return command.execute(null,Arrays.asList(args));
+                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+                {
+                    return command.execute(null, Arrays.asList(args));
                 }
-                
+
             });
         }
         return null;
     }
 
-    public CharSequence format(Object target, int level, Converter escape)
-            throws Exception {
+    public CharSequence format(Object target, int level, Converter escape) throws Exception
+    {
         return null;
     }
 }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiCommands.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiCommands.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiCommands.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiCommands.java Mon Jun 22 22:27:13 2009
@@ -20,293 +20,396 @@
 // DWB2: ClassNotFoundException should be caught in convert() method
 package org.apache.felix.gogo.shell.osgi;
 
-import java.io.*;
-import java.util.*;
-import java.util.regex.*;
-
 import org.osgi.framework.*;
-import org.osgi.service.command.*;
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Converter;
+import org.osgi.service.command.Function;
 
-public class OSGiCommands implements Converter {
-	Bundle	bundle;
-	String	COLUMN	= "%40s %s\n";
-
-	protected OSGiCommands(Bundle bundle) {
-		this.bundle = bundle;
-	}
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Formatter;
+import java.util.List;
+import java.util.regex.Pattern;
+
+public class OSGiCommands implements Converter
+{
+    Bundle bundle;
+    String COLUMN = "%40s %s\n";
+
+    protected OSGiCommands(Bundle bundle)
+    {
+        this.bundle = bundle;
+    }
 
 //	Bundle[] getBundles() {
 //		return getContext().getBundles();
 //	}
 
-	public BundleContext getContext() {
-		if ( bundle.getState() != Bundle.ACTIVE )
-			throw new IllegalStateException("Framework is not started yet");
-		return bundle.getBundleContext();
-	}
-	
-	CharSequence print(Bundle bundle) {
-	    String version = (String) bundle.getHeaders().get("Bundle-Version");
-	    if ( version == null )
-	        version = "0.0.0";
-		return String.format("%06d %s %s-%s", bundle.getBundleId(),
-				getState(bundle), bundle.getSymbolicName(), version);
-	}
-
-	CharSequence print(ServiceReference ref) {
-		StringBuilder sb = new StringBuilder();
-		Formatter f = new Formatter(sb);
-
-		String spid = "";
-		Object pid = ref.getProperty("service.pid");
-		if (pid != null) {
-			spid = pid.toString();
-		}
-
-		f.format("%06d %3s %-40s %s", ref.getProperty("service.id"), ref
-				.getBundle().getBundleId(), getShortNames((String[]) ref
-				.getProperty("objectclass")), spid);
-		return sb;
-	}
-
-	CharSequence getShortNames(String[] list) {
-		StringBuilder sb = new StringBuilder();
-		String del = "";
-		for (String s : list) {
-			sb.append(del + getShortName(s));
-			del = " | ";
-		}
-		return sb;
-	}
-
-	CharSequence getShortName(String name) {
-		int n = name.lastIndexOf('.');
-		if (n < 0)
-			n = 0;
-		else
-			n++;
-		return name.subSequence(n, name.length());
-	}
-
-	private String getState(Bundle bundle) {
-		switch (bundle.getState()) {
-		case Bundle.ACTIVE:
-			return "ACT";
-
-		case Bundle.INSTALLED:
-			return "INS";
-
-		case Bundle.RESOLVED:
-			return "RES";
-
-		case Bundle.STARTING:
-			return "STA";
-
-		case Bundle.STOPPING:
-			return "STO";
-
-		case Bundle.UNINSTALLED:
-			return "UNI ";
-		}
-		return null;
-	}
-
-	public void grep(String match) throws IOException {
-		Pattern p = Pattern.compile(match);
-		BufferedReader rdr = new BufferedReader(
-				new InputStreamReader(System.in));
-		String s = rdr.readLine();
-		while (s != null) {
-			if (p.matcher(s).find()) {
-				System.out.println(s);
-			}
-			s = rdr.readLine();
-		}
-	}
-
-	public String tac() throws IOException {
-		StringWriter sw = new StringWriter();
-		BufferedReader rdr = new BufferedReader(
-				new InputStreamReader(System.in));
-		String s = rdr.readLine();
-		while (s != null) {
-			sw.write(s);
-			s = rdr.readLine();
-		}
-		return sw.toString();
-	}
-
-	public CharSequence echo(CommandSession session, Object args[]) {
-		StringBuilder sb = new StringBuilder();
-		String del = "";
-		for (Object arg : args) {
-			sb.append(del);
-			if (arg != null) {
-				sb.append(arg);
-				del = " ";
-			}
-		}
-		return sb;
-	}
-
-	public void each(CommandSession session, Collection<Object> list, Function closure) throws Exception {
-		List<Object> args = new ArrayList<Object>();
-		args.add(null);
-		for (Object x : list) {
-			args.set(0, x);
-			//Object result = closure.execute(session, args);
-			// System.out.println(session.format(result,Converter.INSPECT));
-			// derek: this is way too noisy
-			closure.execute(session, args);
-		}
-	}
-
-	public Bundle bundle(Bundle i) {
-		return i;
-	}
-
-	public String[] ls(CommandSession session, File f) throws Exception{
-		File cwd = (File) session.get("_cwd");
-		if (cwd == null)
-			cwd = new File("").getAbsoluteFile();
-		
-		if (  f == null )
-			f = cwd;
-		else if (!f.isAbsolute())
-			f = new File(cwd, f.getPath());
-
-		if ( f.isDirectory() )
-			return f.list();
-
-		if ( f.isFile() ) {
-			cat(session,f);
-		}
-		
-		return null;
-	}
-
-	public Object cat(CommandSession session, File f ) throws Exception {
-		File cwd = (File) session.get("_cwd");
-		if (cwd == null)
-			cwd = new File("").getAbsoluteFile();
-		
-		if ( !f.isAbsolute() )
-			f = new File(cwd,f.getPath());
-		
-		ByteArrayOutputStream bout = new ByteArrayOutputStream();
-		FileInputStream in = new FileInputStream(f);
-		byte [] buffer = new byte[ (int) (f.length() % 100000) ];
-		int size = in.read(buffer);
-		while ( size > 0 ) {
-			bout.write(buffer,0,size);
-			size = in.read(buffer);
-		}
-		return new String(bout.toByteArray());
-	}
-	public Object convert(Class<?> desiredType, Object in) throws Exception {
-		if (desiredType == Bundle.class)
-			return convertBundle(in);
-        else if (desiredType == ServiceReference.class)
-            return convertServiceReference(in);
-        else if (desiredType == Class.class) {
-            // derek.baum@paremus.com - added try/catch
-            try {
-                return Class.forName(in.toString());
-            } catch (ClassNotFoundException e) {
-                return null;
+    public BundleContext getContext()
+    {
+        if (bundle.getState() != Bundle.ACTIVE)
+        {
+            throw new IllegalStateException("Framework is not started yet");
+        }
+        return bundle.getBundleContext();
+    }
+
+    CharSequence print(Bundle bundle)
+    {
+        String version = (String) bundle.getHeaders().get("Bundle-Version");
+        if (version == null)
+        {
+            version = "0.0.0";
+        }
+        return String.format("%06d %s %s-%s", bundle.getBundleId(), getState(bundle), bundle.getSymbolicName(), version);
+    }
+
+    CharSequence print(ServiceReference ref)
+    {
+        StringBuilder sb = new StringBuilder();
+        Formatter f = new Formatter(sb);
+
+        String spid = "";
+        Object pid = ref.getProperty("service.pid");
+        if (pid != null)
+        {
+            spid = pid.toString();
+        }
+
+        f.format("%06d %3s %-40s %s", ref.getProperty("service.id"), ref.getBundle().getBundleId(), getShortNames((String[]) ref.getProperty("objectclass")), spid);
+        return sb;
+    }
+
+    CharSequence getShortNames(String[] list)
+    {
+        StringBuilder sb = new StringBuilder();
+        String del = "";
+        for (String s : list)
+        {
+            sb.append(del + getShortName(s));
+            del = " | ";
+        }
+        return sb;
+    }
+
+    CharSequence getShortName(String name)
+    {
+        int n = name.lastIndexOf('.');
+        if (n < 0)
+        {
+            n = 0;
+        }
+        else
+        {
+            n++;
+        }
+        return name.subSequence(n, name.length());
+    }
+
+    private String getState(Bundle bundle)
+    {
+        switch (bundle.getState())
+        {
+            case Bundle.ACTIVE:
+                return "ACT";
+
+            case Bundle.INSTALLED:
+                return "INS";
+
+            case Bundle.RESOLVED:
+                return "RES";
+
+            case Bundle.STARTING:
+                return "STA";
+
+            case Bundle.STOPPING:
+                return "STO";
+
+            case Bundle.UNINSTALLED:
+                return "UNI ";
+        }
+        return null;
+    }
+
+    public void grep(String match) throws IOException
+    {
+        Pattern p = Pattern.compile(match);
+        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
+        String s = rdr.readLine();
+        while (s != null)
+        {
+            if (p.matcher(s).find())
+            {
+                System.out.println(s);
             }
+            s = rdr.readLine();
         }
-        else if (desiredType.isAssignableFrom(String.class) && in instanceof InputStream)
-            return read(((InputStream) in));
+    }
 
-		return null;
-	}
+    public String tac() throws IOException
+    {
+        StringWriter sw = new StringWriter();
+        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
+        String s = rdr.readLine();
+        while (s != null)
+        {
+            sw.write(s);
+            s = rdr.readLine();
+        }
+        return sw.toString();
+    }
+
+    public CharSequence echo(CommandSession session, Object args[])
+    {
+        StringBuilder sb = new StringBuilder();
+        String del = "";
+        for (Object arg : args)
+        {
+            sb.append(del);
+            if (arg != null)
+            {
+                sb.append(arg);
+                del = " ";
+            }
+        }
+        return sb;
+    }
+
+    public void each(CommandSession session, Collection<Object> list, Function closure) throws Exception
+    {
+        List<Object> args = new ArrayList<Object>();
+        args.add(null);
+        for (Object x : list)
+        {
+            args.set(0, x);
+            //Object result = closure.execute(session, args);
+            // System.out.println(session.format(result,Converter.INSPECT));
+            // derek: this is way too noisy
+            closure.execute(session, args);
+        }
+    }
+
+    public Bundle bundle(Bundle i)
+    {
+        return i;
+    }
+
+    public String[] ls(CommandSession session, File f) throws Exception
+    {
+        File cwd = (File) session.get("_cwd");
+        if (cwd == null)
+        {
+            cwd = new File("").getAbsoluteFile();
+        }
+
+        if (f == null)
+        {
+            f = cwd;
+        }
+        else
+        {
+            if (!f.isAbsolute())
+            {
+                f = new File(cwd, f.getPath());
+            }
+        }
+
+        if (f.isDirectory())
+        {
+            return f.list();
+        }
+
+        if (f.isFile())
+        {
+            cat(session, f);
+        }
+
+        return null;
+    }
+
+    public Object cat(CommandSession session, File f) throws Exception
+    {
+        File cwd = (File) session.get("_cwd");
+        if (cwd == null)
+        {
+            cwd = new File("").getAbsoluteFile();
+        }
+
+        if (!f.isAbsolute())
+        {
+            f = new File(cwd, f.getPath());
+        }
+
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        FileInputStream in = new FileInputStream(f);
+        byte[] buffer = new byte[(int) (f.length() % 100000)];
+        int size = in.read(buffer);
+        while (size > 0)
+        {
+            bout.write(buffer, 0, size);
+            size = in.read(buffer);
+        }
+        return new String(bout.toByteArray());
+    }
+
+    public Object convert(Class<?> desiredType, Object in) throws Exception
+    {
+        if (desiredType == Bundle.class)
+        {
+            return convertBundle(in);
+        }
+        else
+        {
+            if (desiredType == ServiceReference.class)
+            {
+                return convertServiceReference(in);
+            }
+            else
+            {
+                if (desiredType == Class.class)
+                {
+                    // derek.baum@paremus.com - added try/catch
+                    try
+                    {
+                        return Class.forName(in.toString());
+                    }
+                    catch (ClassNotFoundException e)
+                    {
+                        return null;
+                    }
+                }
+                else
+                {
+                    if (desiredType.isAssignableFrom(String.class) && in instanceof InputStream)
+                    {
+                        return read(((InputStream) in));
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private Object convertServiceReference(Object in) throws InvalidSyntaxException
+    {
+        String s = in.toString();
+        if (s.startsWith("(") && s.endsWith(")"))
+        {
+            ServiceReference refs[] = getContext().getServiceReferences(null, String.format("(|(service.id=%s)(service.pid=%s))", in, in));
+            if (refs != null && refs.length > 0)
+            {
+                return refs[0];
+            }
+        }
+
+        ServiceReference refs[] = getContext().getServiceReferences(null, String.format("(|(service.id=%s)(service.pid=%s))", in, in));
+        if (refs != null && refs.length > 0)
+        {
+            return refs[0];
+        }
+        return null;
+    }
+
+    private Object convertBundle(Object in)
+    {
+        String s = in.toString();
+        try
+        {
+            long id = Long.parseLong(s);
+            return getContext().getBundle(id);
+        }
+        catch (NumberFormatException nfe)
+        {
+            // Ignore
+        }
+
+        Bundle bundles[] = getContext().getBundles();
+        for (Bundle b : bundles)
+        {
+            if (b.getLocation().equals(s))
+            {
+                return b;
+            }
+
+            if (b.getSymbolicName().equals(s))
+            {
+                return b;
+            }
+        }
+
+        return null;
+    }
+
+    public CharSequence format(Object target, int level, Converter converter) throws IOException
+    {
+        if (level == INSPECT && target instanceof InputStream)
+        {
+            return read(((InputStream) target));
+        }
+        if (level == LINE && target instanceof Bundle)
+        {
+            return print((Bundle) target);
+        }
+        if (level == LINE && target instanceof ServiceReference)
+        {
+            return print((ServiceReference) target);
+        }
+        if (level == PART && target instanceof Bundle)
+        {
+            return ((Bundle) target).getSymbolicName();
+        }
+        if (level == PART && target instanceof ServiceReference)
+        {
+            return getShortNames((String[]) ((ServiceReference) target).getProperty("objectclass"));
+        }
+        return null;
+    }
+
+    public CharSequence read(InputStream in) throws IOException
+    {
+        int c;
+        StringBuffer sb = new StringBuffer();
+        while ((c = in.read()) > 0)
+        {
+            if (c >= 32 && c <= 0x7F || c == '\n' || c == '\r')
+            {
+                sb.append((char) c);
+            }
+            else
+            {
+                String s = Integer.toHexString(c).toUpperCase();
+                sb.append("\\");
+                if (s.length() < 1)
+                {
+                    sb.append(0);
+                }
+                sb.append(s);
+            }
+        }
+        return sb;
+    }
+
+    public void start(Bundle b) throws BundleException
+    {
+        b.start();
+    }
+
+    public void stop(Bundle b) throws BundleException
+    {
+        b.stop();
+    }
+
+    public Object service(String clazz, String filter) throws InvalidSyntaxException
+    {
+        ServiceReference ref[] = getContext().getServiceReferences(clazz, filter);
+        if (ref == null)
+        {
+            return null;
+        }
+
+        return getContext().getService(ref[0]);
+    }
 
-	private Object convertServiceReference(Object in)
-			throws InvalidSyntaxException {
-		String s = in.toString();
-		if (s.startsWith("(") && s.endsWith(")")) {
-			ServiceReference refs[] = getContext().getServiceReferences(null, String
-					.format("(|(service.id=%s)(service.pid=%s))", in, in));
-			if (refs != null && refs.length > 0)
-				return refs[0];
-		}
-
-		ServiceReference refs[] = getContext().getServiceReferences(null, String
-				.format("(|(service.id=%s)(service.pid=%s))", in, in));
-		if (refs != null && refs.length > 0)
-			return refs[0];
-		return null;
-	}
-
-	private Object convertBundle(Object in) {
-		String s = in.toString();
-		try {
-			long id = Long.parseLong(s);
-			return getContext().getBundle(id);
-		} catch (NumberFormatException nfe) {
-			// Ignore
-		}
-
-		Bundle bundles[] = getContext().getBundles();
-		for (Bundle b : bundles) {
-			if (b.getLocation().equals(s))
-				return b;
-
-			if (b.getSymbolicName().equals(s))
-				return b;
-		}
-
-		return null;
-	}
-
-	public CharSequence format(Object target, int level, Converter converter ) throws IOException {
-	    if ( level == INSPECT && target instanceof InputStream ) {
-	        return read(((InputStream)target));   
-	    }
-		if (level == LINE && target instanceof Bundle)
-			return print((Bundle) target);
-		if (level == LINE && target instanceof ServiceReference)
-			return print((ServiceReference) target);
-		if (level == PART && target instanceof Bundle)
-			return ((Bundle) target).getSymbolicName();
-		if (level == PART && target instanceof ServiceReference)
-			return getShortNames((String[]) ((ServiceReference) target)
-					.getProperty("objectclass"));
-		return null;
-	}	
-
-	public CharSequence read(InputStream in) throws IOException {
-	    int c;
-	    StringBuffer sb = new StringBuffer();
-	    while ( (c=in.read())> 0 ) {
-	        if ( c >=32 && c <= 0x7F || c=='\n' || c=='\r') {
-	            sb.append( (char) c);
-	        } else {
-	            String s = Integer.toHexString(c).toUpperCase();
-	            sb.append("\\");
-	            if ( s.length() < 1)
-	                sb.append(0);
-	            sb.append(s);
-	        }
-	    }
-	    return sb;
-    }
-
-    public void start(Bundle b) throws BundleException {
-		b.start();
-	}
-	
-	public void stop(Bundle b) throws BundleException {
-		b.stop();
-	}
-	
-	public Object service(String clazz, String filter) throws InvalidSyntaxException {
-		ServiceReference ref[] = getContext().getServiceReferences(clazz,filter);
-		if (ref == null )
-			return null;
-		
-		return getContext().getService(ref[0]);
-	}
-	
 }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiShell.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiShell.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiShell.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/OSGiShell.java Mon Jun 22 22:27:13 2009
@@ -20,109 +20,137 @@
 // DWB4: get() with trailing colon causes org.osgi.framework.InvalidSyntaxException
 package org.apache.felix.gogo.shell.osgi;
 
-import org.osgi.framework.*;
-import org.osgi.service.command.*;
-import org.osgi.service.component.*;
-import org.osgi.service.packageadmin.*;
-import org.osgi.service.threadio.*;
-
-import org.apache.felix.gogo.shell.runtime.*;
-
-public class OSGiShell extends CommandShellImpl {
-    Bundle       bundle;
+import org.apache.felix.gogo.shell.runtime.CommandShellImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.command.Converter;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.threadio.ThreadIO;
+
+public class OSGiShell extends CommandShellImpl
+{
+    Bundle bundle;
     OSGiCommands commands;
 
-    protected void activate(ComponentContext context) throws Exception {
+    protected void activate(ComponentContext context) throws Exception
+    {
         this.bundle = context.getBundleContext().getBundle();
         if (threadIO == null)
+        {
             threadIO = (ThreadIO) context.locateService("x");
+        }
         start();
     }
 
-    public void start() throws Exception {
+    public void start() throws Exception
+    {
         commands = new OSGiCommands(bundle);
         addCommand("osgi", this.bundle);
         addCommand("osgi", commands);
         setConverter(commands);
-        if (bundle.getState() == Bundle.ACTIVE) {
-            addCommand("osgi", commands.service(PackageAdmin.class.getName(),
-                    null), PackageAdmin.class);
+        if (bundle.getState() == Bundle.ACTIVE)
+        {
+            addCommand("osgi", commands.service(PackageAdmin.class.getName(), null), PackageAdmin.class);
             addCommand("osgi", commands.getContext(), BundleContext.class);
-            
-            try {
+
+            try
+            {
                 // derek - dynamically load StartLevel to avoid import dependency
                 String sl = "org.osgi.service.startlevel.StartLevel";
                 Class<?> slClass = bundle.loadClass(sl);
                 addCommand("osgi", commands.service(sl, null), slClass);
-            } catch (ClassNotFoundException e) {
             }
-            
-            try {
+            catch (ClassNotFoundException e)
+            {
+            }
+
+            try
+            {
                 // derek - dynamically load PermissionAdmin to avoid import dependency
                 String pa = "org.osgi.service.permissionadmin.PermissionAdmin";
                 Class<?> paClass = bundle.loadClass(pa);
                 addCommand("osgi", commands.service(pa, null), paClass);
-            } catch (ClassNotFoundException e) {
+            }
+            catch (ClassNotFoundException e)
+            {
             }
         }
-        else {
+        else
+        {
             System.err.println("eek! bundle not active: " + bundle);
         }
     }
 
-    protected void deactivate(ComponentContext context) {
+    protected void deactivate(ComponentContext context)
+    {
         System.out.println("Deactivating");
     }
 
-    public Object get(String name) {
-        if (bundle.getBundleContext() != null) {
+    public Object get(String name)
+    {
+        if (bundle.getBundleContext() != null)
+        {
             BundleContext context = bundle.getBundleContext();
-            try {
+            try
+            {
                 Object cmd = super.get(name);
                 if (cmd != null)
+                {
                     return cmd;
+                }
 
                 int n = name.indexOf(':');
                 if (n < 0)
+                {
                     return null;
+                }
 
                 String service = name.substring(0, n);
                 String function = name.substring(n + 1);
-                
+
                 // derek - fix org.osgi.framework.InvalidSyntaxException
                 if (service.length() == 0 || function.length() == 0)
+                {
                     return null;
+                }
 
-                String filter = String.format(
-                        "(&(osgi.command.scope=%s)(osgi.command.function=%s))",
-                        service, function);
-                ServiceReference refs[] = context.getServiceReferences(null,
-                        filter);
+                String filter = String.format("(&(osgi.command.scope=%s)(osgi.command.function=%s))", service, function);
+                ServiceReference refs[] = context.getServiceReferences(null, filter);
                 if (refs == null || refs.length == 0)
+                {
                     return null;
+                }
 
                 if (refs.length > 1)
-                    throw new IllegalArgumentException(
-                            "Command name is not unambiguous: " + name
-                                    + ", found multiple impls");
+                {
+                    throw new IllegalArgumentException("Command name is not unambiguous: " + name + ", found multiple impls");
+                }
 
                 return new ServiceCommand(this, refs[0], function);
-            } catch (InvalidSyntaxException ise) {
+            }
+            catch (InvalidSyntaxException ise)
+            {
                 ise.printStackTrace();
             }
         }
         return super.get(name);
     }
 
-    public void setThreadio(Object t) {
+    public void setThreadio(Object t)
+    {
         super.setThreadio((ThreadIO) t);
     }
 
-    public void setBundle(Bundle bundle) {
+    public void setBundle(Bundle bundle)
+    {
         this.bundle = bundle;
     }
 
-    public void setConverter(Converter c) {
+    public void setConverter(Converter c)
+    {
         super.setConverter(c);
     }
 

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/ServiceCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/ServiceCommand.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/ServiceCommand.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/osgi/ServiceCommand.java Mon Jun 22 22:27:13 2009
@@ -18,34 +18,43 @@
  */
 package org.apache.felix.gogo.shell.osgi;
 
-import java.util.*;
+import org.apache.felix.gogo.shell.runtime.CommandShellImpl;
+import org.apache.felix.gogo.shell.runtime.Reflective;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Function;
 
-import org.osgi.framework.*;
-import org.osgi.service.command.*;
+import java.util.List;
 
-import org.apache.felix.gogo.shell.runtime.*;
+public class ServiceCommand extends Reflective implements Function
+{
+    ServiceReference ref;
+    OSGiShell shell;
+    String name;
 
-public class ServiceCommand extends Reflective implements Function {
-	ServiceReference	ref;
-	OSGiShell			shell;
-	String				name;
-	
-	public ServiceCommand(OSGiShell shell, ServiceReference ref, String name) {
-		this.shell =shell;
-		this.ref = ref;
-		this.name = name;
-	}
-
-	public Object execute(CommandSession session, List<Object> arguments) throws Exception {
-		try {
-			Object target = shell.bundle.getBundleContext().getService(ref);
-			Object result = method(session,target, name, arguments);
-			if ( result != CommandShellImpl.NO_SUCH_COMMAND )
-				return result;
-			
-			throw new IllegalArgumentException("Service does not implement promised command " + ref + " " + name );
-		} finally {
-			shell.bundle.getBundleContext().ungetService(ref);
-		}
-	}
+    public ServiceCommand(OSGiShell shell, ServiceReference ref, String name)
+    {
+        this.shell = shell;
+        this.ref = ref;
+        this.name = name;
+    }
+
+    public Object execute(CommandSession session, List<Object> arguments) throws Exception
+    {
+        try
+        {
+            Object target = shell.bundle.getBundleContext().getService(ref);
+            Object result = method(session, target, name, arguments);
+            if (result != CommandShellImpl.NO_SUCH_COMMAND)
+            {
+                return result;
+            }
+
+            throw new IllegalArgumentException("Service does not implement promised command " + ref + " " + name);
+        }
+        finally
+        {
+            shell.bundle.getBundleContext().ungetService(ref);
+        }
+    }
 }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Closure.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Closure.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Closure.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Closure.java Mon Jun 22 22:27:13 2009
@@ -21,97 +21,123 @@
 // DWB7: removing variable via 'execute("name=") throws OutOfBoundsException
 package org.apache.felix.gogo.shell.runtime;
 
-import java.util.*;
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Function;
 
-import org.osgi.service.command.*;
+import java.util.*;
 
-public class Closure extends Reflective implements Function {
+public class Closure extends Reflective implements Function
+{
     private static final long serialVersionUID = 1L;
-    final CharSequence        source;
-    final Closure             parent;
-    CommandSessionImpl        session;
-    List<Object>              parms;
+    final CharSequence source;
+    final Closure parent;
+    CommandSessionImpl session;
+    List<Object> parms;
 
-    Closure(CommandSessionImpl session, Closure parent, CharSequence source) {
+    Closure(CommandSessionImpl session, Closure parent, CharSequence source)
+    {
         this.session = session;
         this.parent = parent;
         this.source = source;
     }
 
-    public Object execute(CommandSession x, List<Object> values)
-            throws Exception {
+    public Object execute(CommandSession x, List<Object> values) throws Exception
+    {
         parms = values;
         Parser parser = new Parser(source);
         ArrayList<Pipe> pipes = new ArrayList<Pipe>();
         List<List<List<CharSequence>>> program = parser.program();
 
-        for (List<List<CharSequence>> statements : program) {
+        for (List<List<CharSequence>> statements : program)
+        {
             Pipe current = new Pipe(this, statements);
 
-            if (pipes.isEmpty()) {
+            if (pipes.isEmpty())
+            {
                 current.setIn(session.in);
                 current.setOut(session.out);
                 current.setErr(session.err);    // XXX: derek.baum@paremus.com
-            } else {
+            }
+            else
+            {
                 Pipe previous = pipes.get(pipes.size() - 1);
                 previous.connect(current);
             }
             pipes.add(current);
         }
         if (pipes.size() == 0)
+        {
             return null;
+        }
 
-        if (pipes.size() == 1) {
+        if (pipes.size() == 1)
+        {
             pipes.get(0).run();
-        } else {
-            for (Pipe pipe : pipes) {
+        }
+        else
+        {
+            for (Pipe pipe : pipes)
+            {
                 pipe.start();
             }
-            for (Pipe pipe : pipes) {
+            for (Pipe pipe : pipes)
+            {
                 pipe.join();
             }
         }
 
         Pipe last = pipes.get(pipes.size() - 1);
         if (last.exception != null)
+        {
             throw last.exception;
+        }
 
-        if (last.result instanceof Object[]) {
+        if (last.result instanceof Object[])
+        {
             return Arrays.asList((Object[]) last.result);
         }
         return last.result;
     }
 
-    Object executeStatement(List<CharSequence> statement) throws Exception {
+    Object executeStatement(List<CharSequence> statement) throws Exception
+    {
         Object result;
         List<Object> values = new ArrayList<Object>();
         CharSequence statement0 = statement.remove(0);
-        
+
         // derek: FEATURE: add set -x facility if echo is set
         StringBuilder buf = new StringBuilder("+ ");
         buf.append(statement0);
-        
+
         Object cmd = eval(statement0);
-        for (CharSequence token : statement) {
+        for (CharSequence token : statement)
+        {
             buf.append(' ');
             buf.append(token);
             values.add(eval(token));
         }
-        
+
         if (Boolean.TRUE.equals(session.get("echo")))
+        {
             System.err.println(buf);
+        }
 
         result = execute(cmd, values);
         return result;
     }
 
-    private Object execute(Object cmd, List<Object> values) throws Exception {
-        if (cmd == null) {
+    private Object execute(Object cmd, List<Object> values) throws Exception
+    {
+        if (cmd == null)
+        {
             if (values.isEmpty())
+            {
                 return null;
+            }
             else
-                throw new IllegalArgumentException(
-                        "Command name evaluates to null");
+            {
+                throw new IllegalArgumentException("Command name evaluates to null");
+            }
         }
 
         // Now there are the following cases
@@ -120,130 +146,179 @@
         // <object> // value of <object>
         // <object> statement // method call
 
-        if (cmd instanceof CharSequence) {
+        if (cmd instanceof CharSequence)
+        {
             String scmd = cmd.toString();
 
-            if (values.size() > 0 && "=".equals(values.get(0))) {
+            if (values.size() > 0 && "=".equals(values.get(0)))
+            {
                 //if (values.size() == 0)
                 if (values.size() == 1)            // derek: BUGFIX
+                {
                     return session.variables.remove(scmd);
-                else {
-                    Object value = execute(values.get(1), values.subList(2,
-                            values.size()));
+                }
+                else
+                {
+                    Object value = execute(values.get(1), values.subList(2, values.size()));
                     return assignment(scmd, value);
                 }
-            } else {
+            }
+            else
+            {
                 String scopedFunction = scmd;
                 Object x = get(scmd);
-                if ( !(x instanceof Function) ) {
-                    if (scmd.indexOf(':') < 0) {
+                if (!(x instanceof Function))
+                {
+                    if (scmd.indexOf(':') < 0)
+                    {
                         scopedFunction = "*:" + scmd;
                     }
                     x = get(scopedFunction);
-                    if (x == null || !(x instanceof Function)) {
+                    if (x == null || !(x instanceof Function))
+                    {
                         if (values.isEmpty())
+                        {
                             return scmd;
-                        throw new IllegalArgumentException("Command not found:  "
-                                + scopedFunction);
-                    } 
-                 }
+                        }
+                        throw new IllegalArgumentException("Command not found:  " + scopedFunction);
+                    }
+                }
                 return ((Function) x).execute(session, values);
             }
-        } else {
+        }
+        else
+        {
             if (values.isEmpty())
+            {
                 return cmd;
+            }
             else
+            {
                 return method(session, cmd, values.remove(0).toString(), values);
+            }
         }
     }
 
-    private Object assignment(Object name, Object value) {
+    private Object assignment(Object name, Object value)
+    {
         session.variables.put(name, value);
         return value;
     }
 
-    private Object eval(CharSequence seq) throws Exception {
+    private Object eval(CharSequence seq) throws Exception
+    {
         int end = seq.length();
-        switch (seq.charAt(0)) {
-        case '$':
-            return var(seq);
-        case '<':
-            Closure c = new Closure(session, this, seq.subSequence(1, end - 1));
-            return c.execute(session, parms);
-        case '[':
-            return array(seq.subSequence(1, end - 1));
-
-        case '{':
-            return new Closure(session, this, seq.subSequence(1, end - 1));
-
-        default:
-            String result = new Parser(seq).unescape();
-            if ("null".equals(result))
-                return null;
-            if ("true".equalsIgnoreCase(result))
-                return true;
-            if ("false".equalsIgnoreCase(result))
-                return false;
-            return seq;
+        switch (seq.charAt(0))
+        {
+            case '$':
+                return var(seq);
+            case '<':
+                Closure c = new Closure(session, this, seq.subSequence(1, end - 1));
+                return c.execute(session, parms);
+            case '[':
+                return array(seq.subSequence(1, end - 1));
+
+            case '{':
+                return new Closure(session, this, seq.subSequence(1, end - 1));
+
+            default:
+                String result = new Parser(seq).unescape();
+                if ("null".equals(result))
+                {
+                    return null;
+                }
+                if ("true".equalsIgnoreCase(result))
+                {
+                    return true;
+                }
+                if ("false".equalsIgnoreCase(result))
+                {
+                    return false;
+                }
+                return seq;
         }
     }
 
-    private Object array(CharSequence array) throws Exception {
+    private Object array(CharSequence array) throws Exception
+    {
         List<Object> list = new ArrayList<Object>();
         Map<Object, Object> map = new LinkedHashMap<Object, Object>();
         Parser p = new Parser(array);
 
-        while (!p.eof()) {
+        while (!p.eof())
+        {
             CharSequence token = p.value();
 
             p.ws();
-            if (p.peek() == '=') {
+            if (p.peek() == '=')
+            {
                 p.next();
                 p.ws();
-                if (!p.eof()) {
+                if (!p.eof())
+                {
                     CharSequence value = p.messy();
                     map.put(eval(token), eval(value));
                 }
-            } else
+            }
+            else
+            {
                 list.add(eval(token));
+            }
 
             if (p.peek() == ',')
+            {
                 p.next();
+            }
             p.ws();
         }
         p.ws();
         if (!p.eof())
+        {
             throw new IllegalArgumentException("Invalid array syntax: " + array);
+        }
 
         if (map.size() != 0 && list.size() != 0)
-            throw new IllegalArgumentException(
-                    "You can not mix maps and arrays: " + array);
+        {
+            throw new IllegalArgumentException("You can not mix maps and arrays: " + array);
+        }
 
         if (map.size() > 0)
+        {
             return map;
+        }
         else
+        {
             return list;
+        }
     }
 
-    private Object var(CharSequence var) throws Exception {
+    private Object var(CharSequence var) throws Exception
+    {
         String name = eval(var.subSequence(1, var.length())).toString();
         return get(name);
     }
 
     /**
-     * 
      * @param name
      * @return
      */
-    private Object get(String name) {
-        if (parms != null) {
+    private Object get(String name)
+    {
+        if (parms != null)
+        {
             if ("it".equals(name))
+            {
                 return parms.get(0);
+            }
             if ("args".equals(name))
+            {
                 return parms;
+            }
 
             if (name.length() == 1 && Character.isDigit(name.charAt(0)))
+            {
                 return parms.get(name.charAt(0) - '0');
+            }
         }
         return session.get(name);
     }

Modified: felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Command.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Command.java?rev=787428&r1=787427&r2=787428&view=diff
==============================================================================
--- felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Command.java (original)
+++ felix/trunk/gogo/src/main/java/org/apache/felix/gogo/shell/runtime/Command.java Mon Jun 22 22:27:13 2009
@@ -18,21 +18,25 @@
  */
 package org.apache.felix.gogo.shell.runtime;
 
-import java.util.*;
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Function;
 
-import org.osgi.service.command.*;
+import java.util.List;
 
-public class Command extends Reflective implements Function {
-	Object target;
-	String function;
-
-	public Command(Object target, String function) {
-		this.function = function;
-		this.target = target;
-	}
-
-	public Object execute(CommandSession session, List<Object> arguments) throws Exception {
-		return method(session,target, function, arguments);
-	}
+public class Command extends Reflective implements Function
+{
+    Object target;
+    String function;
+
+    public Command(Object target, String function)
+    {
+        this.function = function;
+        this.target = target;
+    }
+
+    public Object execute(CommandSession session, List<Object> arguments) throws Exception
+    {
+        return method(session, target, function, arguments);
+    }
 
 }



Mime
View raw message