geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r411612 - in /geronimo/sandbox/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/
Date Sun, 04 Jun 2006 22:32:45 GMT
Author: jdillon
Date: Sun Jun  4 15:32:44 2006
New Revision: 411612

URL: http://svn.apache.org/viewvc?rev=411612&view=rev
Log:
Force name of variables to be proper java identifiers

Added:
    geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/SetCommandTest.java
  (with props)
Modified:
    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/CommandManager.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java

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=411612&r1=411611&r2=411612&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 15:32:44 2006
@@ -35,6 +35,8 @@
 
     private final boolean enabled;
 
+    private final String category;
+
     public CommandDefinition(final Properties props) throws InvalidDefinitionException {
         if (props == null) {
             throw new IllegalArgumentException("Properties is null");
@@ -53,6 +55,19 @@
         this.aliases = loadAliasesFrom(props);
 
         this.enabled = Boolean.getBoolean(props.getProperty("enable"));
+
+        this.category = props.getProperty("category");
+        if (category == null) {
+            throw new MissingPropertyException("category", props);
+        }
+    }
+
+    public String toString() {
+        return getName() + "=" + getClassName() +
+                "{ aliases=" + Arguments.asString(getAliases()) +
+                ", enabled=" + enabled +
+                ", category=" + category +
+                " }";
     }
 
     //
@@ -91,10 +106,8 @@
         return enabled;
     }
 
-    public String toString() {
-        return getName() + "=" + getClassName() + "{ aliases=" +
-                Arguments.asString(getAliases()) +
-                " }";
+    public String getCategory() {
+        return category;
     }
 
     public Class loadClass() throws ClassNotFoundException {

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java?rev=411612&r1=411611&r2=411612&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
Sun Jun  4 15:32:44 2006
@@ -20,8 +20,8 @@
 import java.util.Collection;
 
 /**
- * Interface for manager of command definitions and provides access to command instances.
- *
+ * Interface for manager of command definitions.
+ * 
  * @version $Id$
  */
 public interface CommandManager

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java?rev=411612&r1=411611&r2=411612&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
Sun Jun  4 15:32:44 2006
@@ -55,7 +55,7 @@
     public void setCommandManager(final CommandManager commandManager) {
         this.commandManager = commandManager;
     }
-    
+
     */
 
     private CommandManager getCommandManager() {
@@ -163,6 +163,7 @@
             //
 
             io.err.println("Pending... sorry");
+            io.err.println();
         }
 
         return Command.SUCCESS;

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java?rev=411612&r1=411611&r2=411612&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
Sun Jun  4 15:32:44 2006
@@ -176,11 +176,39 @@
         return nv;
     }
 
+    private boolean isIdentifier(final String name) {
+        if (name == null || name.length() == 0) {
+            return false;
+        }
+
+        char[] chars = name.toCharArray();
+
+        if (!Character.isJavaIdentifierStart(chars[0])) {
+            return false;
+        }
+
+        for (int i=1; i<chars.length; i++) {
+            if (!Character.isJavaIdentifierPart(chars[i])) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    private void ensureIsIdentifier(final String name) {
+        if (!isIdentifier(name)) {
+            throw new RuntimeException("Invalid identifer name: " + name);
+        }
+    }
+
     private void setProperty(final String namevalue) {
         NameValue nv = parse(namevalue);
 
         log.info("Setting system property: " + nv.name + "=" + nv.value);
 
+        ensureIsIdentifier(nv.name);
+        
         System.setProperty(nv.name, nv.value);
     }
 
@@ -188,6 +216,8 @@
         NameValue nv = parse(namevalue);
 
         log.info("Setting variable: " + nv.name + "=" + nv.value);
+
+        ensureIsIdentifier(nv.name);
 
         // Command vars always has a parent, set only makes sence when setting in parent's
scope
         Variables vars = this.getVariables().parent();

Added: geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/SetCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/SetCommandTest.java?rev=411612&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/SetCommandTest.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-testsuite/src/test/java/org/apache/geronimo/gshell/testsuite/SetCommandTest.java
Sun Jun  4 15:32:44 2006
@@ -0,0 +1,45 @@
+/*
+ * 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.testsuite;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gshell.Shell;
+import org.apache.geronimo.gshell.console.IO;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+
+/**
+ * ???
+ *
+ * @version $Id$
+ */
+public class SetCommandTest
+    extends TestCase
+{
+    public void testSimple() throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        IO io = new IO(System.in, out);
+
+        Shell shell = new Shell(io);
+        shell.execute("set", "a=b");
+
+        assertEquals("b", shell.getVariables().get("a"));
+    }
+}

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

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

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



Mime
View raw message