geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r411664 - in /geronimo/sandbox/gshell/trunk: ./ gshell-api/src/main/java/org/apache/geronimo/gshell/ gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-api/src/main/java/org/apache/geronimo/gshell/util/ gshell-api/src/test/...
Date Mon, 05 Jun 2006 04:57:42 GMT
Author: jdillon
Date: Sun Jun  4 21:57:41 2006
New Revision: 411664

URL: http://svn.apache.org/viewvc?rev=411664&view=rev
Log:
Hooked up ${...} post-parsing as a temporary solution until I can get the command line parser
to do this in the first pass
Dropped CommandExecutor interface & related... components that used it really needed a
Shell instance (for variables and execution)
Setting ///CLOVER:OFF on classes which should not be included in the code-coverage calculations

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
  (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
    geronimo/sandbox/gshell/trunk/gshell-api/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDefinition.java
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Variables.java
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/util/Banner.java
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-core/pom.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/ExecutingVisitorTest.java
    geronimo/sandbox/gshell/trunk/pom.xml

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/ExitNotification.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
Sun Jun  4 21:57:41 2006
@@ -27,6 +27,8 @@
 public class ExitNotification
     extends Error
 {
+    ///CLOVER:OFF
+    
     //
     // TODO: Need to find a better home for this...
     //

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDefinition.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDefinition.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDefinition.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDefinition.java
Sun Jun  4 21:57:41 2006
@@ -122,6 +122,8 @@
     public static class InvalidDefinitionException
         extends CommandException
     {
+        ///CLOVER:OFF
+
         public InvalidDefinitionException(String msg) {
             super(msg);
         }
@@ -130,6 +132,8 @@
     public static class MissingPropertyException
         extends InvalidDefinitionException
     {
+        ///CLOVER:OFF
+        
         MissingPropertyException(String name, Properties props) {
             super("Missing '" + name + "' property in command definition: " + props);
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Variables.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Variables.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Variables.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Variables.java
Sun Jun  4 21:57:41 2006
@@ -52,6 +52,8 @@
     class ImmutableVariableException
         extends RuntimeException
     {
+        ///CLOVER:OFF
+        
         public ImmutableVariableException(final String name) {
             super("Variable is immutable: " + name);
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/util/Banner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/util/Banner.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/util/Banner.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/util/Banner.java
Sun Jun  4 21:57:41 2006
@@ -26,6 +26,8 @@
  */
 public class Banner
 {
+    ///CLOVER:OFF
+    
     public static String getBanner() {
         StringWriter writer = new StringWriter();
         PrintWriter out = new PrintWriter(writer);

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
Sun Jun  4 21:57:41 2006
@@ -46,6 +46,8 @@
  */
 public class Main
 {
+    ///CLOVER:OFF
+    
     //
     // NOTE: Do not use logging from this class, as it is used to configure
     //       the logging level with System properties, which will only get

Modified: geronimo/sandbox/gshell/trunk/gshell-core/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/pom.xml?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/pom.xml Sun Jun  4 21:57:41 2006
@@ -46,6 +46,12 @@
             <groupId>picocontainer</groupId>
             <artifactId>picocontainer-gems</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>commons-jexl</groupId>
+            <artifactId>commons-jexl</artifactId>
+            <version>1.0</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -103,7 +109,7 @@
                             <goal>run</goal>
                         </goals>
                     </execution>
-                    
+
                     <!-- Need to put these into a package so that Eclipse does not freak
out -->
                     <execution>
                         <id>move-to-package</id>
@@ -116,7 +122,7 @@
                                         <include name="*.java"/>
                                     </fileset>
                                 </move>
-                                
+
                                 <mkdir dir="${pom.basedir}/target/generated-sources/javacc/org/apache/geronimo/gshell/commandline/parser"/>
                                 <move todir="${pom.basedir}/target/generated-sources/javacc/org/apache/geronimo/gshell/commandline/parser">
                                     <fileset dir="${pom.basedir}/target/generated-sources/javacc">
@@ -125,7 +131,7 @@
                                 </move>
                             </tasks>
                         </configuration>
-                        
+
                         <goals>
                             <goal>run</goal>
                         </goals>

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
Sun Jun  4 21:57:41 2006
@@ -20,7 +20,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.geronimo.gshell.console.IO;
-import org.apache.geronimo.gshell.command.CommandExecutor;
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandManager;
 import org.apache.geronimo.gshell.command.CommandContext;
@@ -43,8 +42,11 @@
  * @version $Id$
  */
 public class Shell
-    implements CommandExecutor
 {
+    //
+    // TODO: Introduce Shell interface?
+    //
+
     private static final Log log = LogFactory.getLog(Shell.class);
 
     private final IO io;

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
Sun Jun  4 21:57:41 2006
@@ -19,7 +19,8 @@
 import org.apache.geronimo.gshell.commandline.parser.CommandLineParser;
 import org.apache.geronimo.gshell.commandline.parser.ASTCommandLine;
 import org.apache.geronimo.gshell.commandline.parser.ParseException;
-import org.apache.geronimo.gshell.command.CommandExecutor;
+import org.apache.geronimo.gshell.Shell;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -35,16 +36,16 @@
 {
     private static final Log log = LogFactory.getLog(CommandLineBuilder.class);
 
-    private final CommandExecutor executor;
+    private final Shell shell;
 
     private final CommandLineParser parser;
 
-    public CommandLineBuilder(final CommandExecutor executor) {
-        if (executor == null) {
-            throw new IllegalArgumentException("Executor is null");
+    public CommandLineBuilder(final Shell shell) {
+        if (shell == null) {
+            throw new IllegalArgumentException("Shell is null");
         }
 
-        this.executor = executor;
+        this.shell = shell;
         this.parser = new CommandLineParser();
     }
 
@@ -73,7 +74,7 @@
         }
 
         final ASTCommandLine root = parse(commandLine);
-        final ExecutingVisitor visitor = new ExecutingVisitor(this.executor);
+        final ExecutingVisitor visitor = new ExecutingVisitor(this.shell);
 
         return new CommandLine() {
             public void execute() throws Exception {

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
Sun Jun  4 21:57:41 2006
@@ -23,9 +23,8 @@
 import org.apache.geronimo.gshell.commandline.parser.ASTQuotedString;
 import org.apache.geronimo.gshell.commandline.parser.ASTOpaqueString;
 import org.apache.geronimo.gshell.commandline.parser.ASTPlainString;
-import org.apache.geronimo.gshell.commandline.parser.StringSupport;
 import org.apache.geronimo.gshell.util.Arguments;
-import org.apache.geronimo.gshell.command.CommandExecutor;
+import org.apache.geronimo.gshell.Shell;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -43,14 +42,17 @@
 {
     private static final Log log = LogFactory.getLog(ExecutingVisitor.class);
 
-    private final CommandExecutor executor;
+    private final Shell shell;
 
-    public ExecutingVisitor(final CommandExecutor executor) {
-        if (executor == null) {
-            throw new IllegalArgumentException("Executor is null");
+    private final VariableExpressionParser exprParser;
+
+    public ExecutingVisitor(final Shell shell) {
+        if (shell == null) {
+            throw new IllegalArgumentException("Shell is null");
         }
 
-        this.executor = executor;
+        this.shell = shell;
+        this.exprParser = new VariableExpressionParser(shell.getVariables());
     }
 
     public Object visit(final SimpleNode node, final Object data) {
@@ -84,7 +86,7 @@
         // assert data != null;
 
         // Create the argument list (cmd name + args)
-        List list = new ArrayList(node.jjtGetNumChildren());
+        List<String> list = new ArrayList<String>(node.jjtGetNumChildren());
         node.childrenAccept(this, list);
 
         String[] args = (String[])list.toArray(new String[list.size()]);
@@ -96,7 +98,7 @@
         int result;
 
         try {
-            result = executor.execute(commandName, args);
+            result = shell.execute(commandName, args);
         }
         catch (Exception e) {
             //
@@ -109,27 +111,31 @@
         return result;
     }
 
-    private Object appendString(final StringSupport node, final Object data) {
-        assert node != null;
+    private Object appendString(final String value, final Object data) {
         assert data != null;
         assert data instanceof List;
 
-        List args = (List)data;
-        String value = node.getValue();
+        List<String> args = (List<String>)data;
         args.add(value);
 
         return value;
     }
 
+    //
+    // TODO: Include parsed ${...} strings?
+    //
+
     public Object visit(final ASTQuotedString node, final Object data) {
-        return appendString(node, data);
+        String value = exprParser.parse(node.getValue());
+        return appendString(value, data);
     }
 
     public Object visit(final ASTOpaqueString node, final Object data) {
-        return appendString(node, data);
+        return appendString(node.getValue(), data);
     }
 
     public Object visit(final ASTPlainString node, final Object data) {
-        return appendString(node, data);
+        String value = exprParser.parse(node.getValue());
+        return appendString(value, data);
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java?rev=411664&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
Sun Jun  4 21:57:41 2006
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.commandline;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.jexl.JexlHelper;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.Expression;
+import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.resolver.FlatResolver;
+import org.apache.commons.lang.NullArgumentException;
+
+import org.apache.geronimo.gshell.command.Variables;
+
+/**
+ * Parser to handle ${...} expressions using
+ * <a href="http://jakarta.apache.org/commons/jexl/">JEXL</a>.
+ *
+ * @version $Id$
+ */
+public class VariableExpressionParser
+{
+    //
+    // NOTE: May want to add the ${...} bits the the CommandLineParser directly.
+    //       This sub-parser is probably only short-term so we can get soemthing working
+    //
+
+    private static final Log log = LogFactory.getLog(VariableExpressionParser.class);
+
+    protected JexlContext context;
+
+    public VariableExpressionParser(final Map vars) {
+        if (vars == null) {
+            throw new NullArgumentException("vars");
+        }
+
+        context = JexlHelper.createContext();
+        context.setVars(vars);
+
+        if (log.isTraceEnabled()) {
+            log.trace("Using variables: " + context.getVars());
+        }
+    }
+
+    private static Map convertToMap(final Variables vars) {
+        if (vars == null) {
+            throw new NullArgumentException("vars");
+        }
+
+        Map map = new HashMap();
+        Iterator<String> iter = vars.names();
+
+        while (iter.hasNext()) {
+            String name = iter.next();
+            map.put(name, vars.get(name));
+        }
+
+        return map;
+    }
+
+    public VariableExpressionParser(final Variables vars) {
+        this(convertToMap(vars));
+    }
+
+    public VariableExpressionParser() {
+        this(System.getProperties());
+    }
+
+    public Map getVariables() {
+        return context.getVars();
+    }
+
+    public Object getVariable(final Object name) {
+        if (name == null) {
+            throw new NullArgumentException("name");
+        }
+
+        return getVariables().get(name);
+    }
+
+    public Object setVariable(final Object name, final Object value) {
+        if (name == null) {
+            throw new NullArgumentException("name");
+        }
+
+        return getVariables().put(name, value);
+    }
+
+    public Object unsetVariable(final Object name) {
+        if (name == null) {
+            throw new NullArgumentException("name");
+        }
+
+        return getVariables().remove(name);
+    }
+
+    public void addVariables(final Map map) {
+        if (map == null) {
+            throw new NullArgumentException("map");
+        }
+
+        getVariables().putAll(map);
+    }
+
+    private final FlatResolver resolver = new FlatResolver(true);
+
+    protected Expression createExpression(final String expression) throws Exception {
+        assert expression != null;
+
+        Expression expr = ExpressionFactory.createExpression(expression);
+        expr.addPreResolver(resolver);
+
+        return expr;
+    }
+
+    public Object evaluate(final String expression) throws Exception {
+        if (expression == null) {
+            throw new NullArgumentException("expression");
+        }
+
+        boolean trace = log.isTraceEnabled();
+        if (trace) {
+            log.trace("Evaluating expression: " + expression);
+        }
+
+        Expression expr = createExpression(expression);
+        Object obj = expr.evaluate(context);
+        if (trace) {
+            log.trace("Result: " + obj);
+        }
+
+        return obj;
+    }
+
+    private static final String PREFIX = "${";
+
+    private static final String SUFFIX = "}";
+
+    public String parse(final String input) throws SyntaxException {
+        if (input == null) {
+            throw new NullArgumentException("input");
+        }
+
+        boolean trace = log.isTraceEnabled();
+        if (trace) {
+            log.trace("Parsing input: " + input);
+        }
+
+        StringBuffer buff = new StringBuffer();
+
+        int cur = 0;
+        int prefixLoc = 0;
+        int suffixLoc = 0;
+
+        while (cur < input.length()) {
+            prefixLoc = input.indexOf(PREFIX, cur);
+
+            if (prefixLoc < 0) {
+                break;
+            }
+
+            suffixLoc = input.indexOf(SUFFIX, prefixLoc);
+            if (suffixLoc < 0) {
+                throw new SyntaxException("Missing '}': " + input);
+            }
+
+            String expr = input.substring(prefixLoc + 2, suffixLoc);
+            buff.append(input.substring(cur, prefixLoc));
+
+            try {
+                buff.append(evaluate(expr));
+            }
+            catch (Exception e) {
+                throw new SyntaxException("Failed to evaluate: " + expr, e);
+            }
+
+            cur = suffixLoc + 1;
+        }
+
+        buff.append(input.substring(cur));
+
+        if (trace) {
+            log.trace("Parsed result: " + buff);
+        }
+
+        return buff.toString();
+    }
+
+    public String parse(final String input, final boolean trim) throws SyntaxException {
+        String output = parse(input);
+        if (trim && output != null) {
+            output = output.trim();
+        }
+
+        return output;
+    }
+
+    //
+    // SyntaxException
+    //
+
+    /**
+     * Thrown to indicate a syntax error while parsing.
+     */
+    public static class SyntaxException
+        extends RuntimeException
+    {
+        ///CLOVER:OFF
+        
+        public SyntaxException(final String msg) {
+            super(msg);
+        }
+
+        public SyntaxException(final String msg, final Throwable cause) {
+            super(msg, cause);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/VariableExpressionParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java?rev=411664&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
Sun Jun  4 21:57:41 2006
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gshell.console.IO;
+import org.apache.geronimo.gshell.command.CommandNotFoundException;
+import org.apache.geronimo.gshell.command.CommandException;
+
+/**
+ * Mock {@link Shell}.
+ *
+ * @version $Id$
+ */
+public class MockShell
+    extends Shell
+{
+    public String[] args;
+
+    public String commandName;
+
+    public MockShell() throws CommandException {
+        super(new IO());
+    }
+
+    public int execute(String... args) throws Exception {
+        this.args = args;
+
+        return 0;
+    }
+
+    public int execute(String commandName, String[] args) throws Exception {
+        this.commandName = commandName;
+        this.args = args;
+
+        return 0;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/MockShell.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/CommandLineBuilderTest.java
Sun Jun  4 21:57:41 2006
@@ -17,7 +17,7 @@
 package org.apache.geronimo.gshell.commandline;
 
 import junit.framework.TestCase;
-import org.apache.geronimo.gshell.command.MockCommandExecutor;
+import org.apache.geronimo.gshell.MockShell;
 
 /**
  * Unit tests for the {@link CommandLineBuilder} class.
@@ -38,16 +38,16 @@
     }
 
     public void testSimple() throws Exception {
-        MockCommandExecutor executor = new MockCommandExecutor();
-        CommandLineBuilder builder = new CommandLineBuilder(executor);
+        MockShell shell = new MockShell();
+        CommandLineBuilder builder = new CommandLineBuilder(shell);
 
         CommandLine cl = builder.create("echo hi");
         assertNotNull(cl);
 
         cl.execute();
 
-        assertEquals("echo", executor.commandName);
-        assertEquals(1, executor.args.length);
-        assertEquals("hi", executor.args[0]);
+        assertEquals("echo", shell.commandName);
+        assertEquals(1, shell.args.length);
+        assertEquals("hi", shell.args[0]);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/ExecutingVisitorTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/ExecutingVisitorTest.java?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/ExecutingVisitorTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/ExecutingVisitorTest.java
Sun Jun  4 21:57:41 2006
@@ -18,7 +18,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.geronimo.gshell.command.MockCommandExecutor;
+import org.apache.geronimo.gshell.MockShell;
 
 /**
  * Unit tests for the {@link ExecutingVisitor} usage.
@@ -38,6 +38,6 @@
         }
 
         // Happy day
-        new ExecutingVisitor(new MockCommandExecutor());
+        new ExecutingVisitor(new MockShell());
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java?rev=411664&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
Sun Jun  4 21:57:41 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.commandline;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for the {@link VariableExpressionParser} class.
+ *
+ * @version $Id$
+ */
+public class VariableExpressionParserTest
+    extends TestCase
+{
+    protected VariableExpressionParser parser;
+
+    protected void setUp() throws Exception {
+        parser = new VariableExpressionParser();
+    }
+
+    protected void tearDown() throws Exception {
+        parser = null;
+    }
+
+    public void testDefault() throws Exception {
+        String value = "${java.home}";
+        String result = parser.parse(value);
+        assertEquals(result, System.getProperty("java.home"));
+    }
+
+    public void testSubst() throws Exception {
+        String value = "BEFORE${java.home}AFTER";
+        String result = parser.parse(value);
+        assertEquals(result, "BEFORE" + System.getProperty("java.home") + "AFTER");
+    }
+
+    public void testVariable() throws Exception {
+        String myvar = "this is my variable";
+        parser.getVariables().put("my.var", myvar);
+
+        String value = "${my.var}";
+        String result = parser.parse(value);
+        assertEquals(result, myvar);
+    }
+
+    public void testFlatVariable() throws Exception {
+        String myvar = "this is my variable";
+        parser.getVariables().put("my.var", myvar);
+        parser.getVariables().put("my", "not used");
+
+        String value = "${my.var}";
+        String result = parser.parse(value);
+        assertEquals(result, myvar);
+    }
+
+    public void testSyntax() throws Exception {
+        String value = "${java.home";
+
+        try {
+            String result = parser.parse(value);
+            fail("Should have thrown an exception");
+        }
+        catch (VariableExpressionParser.SyntaxException expected) {
+            // ignore
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/VariableExpressionParserTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/pom.xml?rev=411664&r1=411663&r2=411664&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/pom.xml Sun Jun  4 21:57:41 2006
@@ -154,6 +154,15 @@
                 <groupId>commons-collections</groupId>
                 <artifactId>commons-collections</artifactId>
                 <version>3.1</version>
+                <type>jar</type>
+                <scope>compile</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>commons-jexl</groupId>
+                <artifactId>commons-jexl</artifactId>
+                <version>1.0</version>
+                <type>jar</type>
                 <scope>compile</scope>
             </dependency>
 
@@ -161,6 +170,7 @@
                 <groupId>classworlds</groupId>
                 <artifactId>classworlds</artifactId>
                 <version>1.1</version>
+                <type>jar</type>
                 <scope>compile</scope>
             </dependency>
 



Mime
View raw message