servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r605911 - in /servicemix/smx4/runtime/trunk/gshell/gshell-core: ./ src/main/java/org/apache/geronimo/gshell/commands/builtins/ src/main/java/org/apache/geronimo/gshell/spring/ src/main/java/org/apache/geronimo/gshell/whisper/transport/ssl/ ...
Date Thu, 20 Dec 2007 12:42:18 GMT
Author: gnodet
Date: Thu Dec 20 04:42:18 2007
New Revision: 605911

URL: http://svn.apache.org/viewvc?rev=605911&view=rev
Log:
Fix builtins statefull commands by inheriting OsgiCommandSupport

Added:
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
      - copied, changed from r604789, servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ExitCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
      - copied, changed from r604789, servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/HelpCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java
Removed:
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ExitCommand.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/HelpCommand.java
Modified:
    servicemix/smx4/runtime/trunk/gshell/gshell-core/pom.xml
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/ssl/SpringSslTransportFactory.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/vm/SpringVmTransportFactory.java
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml

Modified: servicemix/smx4/runtime/trunk/gshell/gshell-core/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/pom.xml?rev=605911&r1=605910&r2=605911&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/pom.xml (original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/pom.xml Thu Dec 20 04:42:18 2007
@@ -88,11 +88,6 @@
             <version>${gshell.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.geronimo.gshell.commands</groupId>
-            <artifactId>gshell-builtins</artifactId>
-            <version>${gshell.version}</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.geronimo.gshell</groupId>
             <artifactId>gshell-command-api</artifactId>
             <version>${gshell.version}</version>

Added: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearCommand.java?rev=605911&view=auto
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearCommand.java
(added)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearCommand.java
Thu Dec 20 04:42:18 2007
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.commands.builtins;
+
+import java.io.PrintWriter;
+
+import jline.ConsoleReader;
+import jline.Terminal;
+import org.apache.geronimo.gshell.ansi.ANSI;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.command.annotation.Requirement;
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+
+/**
+ * Clear the terminal screen.
+ *
+ * @version $Rev: 595891 $ $Date: 2007-11-17 02:23:47 +0100 (Sat, 17 Nov 2007) $
+ */
+@CommandComponent(id="gshell-builtins:clear", description="Clear the terminal screen")
+public class ClearCommand
+    extends OsgiCommandSupport
+{
+    @Requirement
+    private Terminal terminal;
+
+    public ClearCommand() {
+    }
+
+    public ClearCommand(Terminal terminal) {
+        this.terminal = terminal;
+    }
+
+    protected OsgiCommandSupport createCommand() throws Exception {
+        return new ClearCommand(terminal);
+    }
+
+    protected Object doExecute() throws Exception {
+        ConsoleReader reader = new ConsoleReader(io.inputStream, new PrintWriter(io.outputStream,
true), /*bindings*/ null, terminal);
+
+        if (!ANSI.isEnabled()) {
+        	io.out.println("ANSI is not enabled.  The clear command is not functional");
+        }
+        else {
+        	reader.clearScreen();
+        	return SUCCESS;
+        }
+
+        return SUCCESS;
+    }
+}

Added: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java?rev=605911&view=auto
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java
(added)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java
Thu Dec 20 04:42:18 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.commands.builtins;
+
+import java.util.List;
+
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+
+/**
+ * A simple command to <em>echo</em> all given arguments to the commands standard
output.
+ *
+ * @version $Rev: 593392 $ $Date: 2007-11-09 03:14:15 +0100 (Fri, 09 Nov 2007) $
+ */
+@CommandComponent(id="gshell-builtins:echo", description="Echo or print arguments to STDOUT")
+public class EchoCommand
+    extends CommandSupport
+{
+    @Option(name="-n", description="Do not print the trailing newline character")
+    private boolean trailingNewline = true;
+
+    @Argument(description="Arguments")
+    private List<String> args;
+
+    protected Object doExecute() throws Exception {
+        if (args != null) {
+            int c=0;
+
+            for (String arg : args) {
+                io.out.print(arg);
+                if (++c + 1 < args.size()) {
+                    io.out.print(" ");
+                }
+            }
+        }
+
+        if (trailingNewline) {
+            io.out.println();
+        }
+
+        return SUCCESS;
+    }
+}
\ No newline at end of file

Copied: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
(from r604789, servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ExitCommand.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java?p2=servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java&p1=servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ExitCommand.java&r1=604789&r2=605911&rev=605911&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ExitCommand.java
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
Thu Dec 20 04:42:18 2007
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.geronimo.gshell.spring;
+package org.apache.geronimo.gshell.commands.builtins;
 
 import org.apache.geronimo.gshell.ExitNotification;
 import org.apache.geronimo.gshell.clp.Argument;

Copied: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
(from r604789, servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/HelpCommand.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?p2=servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java&p1=servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/HelpCommand.java&r1=604789&r2=605911&rev=605911&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/HelpCommand.java
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
Thu Dec 20 04:42:18 2007
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.geronimo.gshell.spring;
+package org.apache.geronimo.gshell.commands.builtins;
 
 import java.util.Comparator;
 import java.util.List;

Added: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java?rev=605911&view=auto
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java
(added)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java
Thu Dec 20 04:42:18 2007
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.commands.builtins;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.geronimo.gshell.DefaultVariables;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+
+/**
+ * Set a variable or property.
+ *
+ * @version $Rev: 593392 $ $Date: 2007-11-09 03:14:15 +0100 (Fri, 09 Nov 2007) $
+ */
+@CommandComponent(id="gshell-builtins:set", description="Set a variable")
+public class SetCommand
+    extends OsgiCommandSupport
+{
+    enum Mode
+    {
+        VARIABLE,
+        PROPERTY
+    }
+
+    @Option(name="-m", aliases={"--mode"}, description="Set mode")
+    private Mode mode = Mode.VARIABLE;
+
+    @Argument(description="Variable definition")
+    private List<String> args;
+
+    protected Object doExecute() throws Exception {
+        // No args... list all properties or variables
+        if (args == null || args.size() == 0) {
+            switch (mode) {
+                case PROPERTY: {
+                    Properties props = System.getProperties();
+
+                    for (Object o : props.keySet()) {
+                        String name = (String) o;
+                        String value = props.getProperty(name);
+
+                        io.out.print(name);
+                        io.out.print("=");
+                        io.out.print(value);
+                        io.out.println();
+                    }
+                    break;
+                }
+
+                case VARIABLE: {
+                    Iterator<String> iter = variables.names();
+
+                    while (iter.hasNext()) {
+                        String name = iter.next();
+                        Object value = variables.get(name);
+
+                        io.out.print(name);
+                        io.out.print("=");
+                        io.out.print(value);
+                        io.out.println();
+                    }
+                    break;
+                }
+            }
+
+            return SUCCESS;
+        }
+
+        //
+        // FIXME: This does not jive well with the parser, and stuff like foo = "b a r"
+        //
+
+        //
+        // NOTE: May want to make x=b part of the CL grammar
+        //
+
+        for (Object arg : args) {
+            String namevalue = String.valueOf(arg);
+
+            switch (mode) {
+                case PROPERTY:
+                    setProperty(namevalue);
+                    break;
+
+                case VARIABLE:
+                    setVariable(namevalue);
+                    break;
+            }
+        }
+
+        return SUCCESS;
+    }
+
+    class NameValue
+    {
+        String name;
+        String value;
+    }
+
+    private NameValue parse(final String input) {
+        NameValue nv = new NameValue();
+
+        int i = input.indexOf("=");
+
+        if (i == -1) {
+            nv.name = input;
+            nv.value = "true";
+        }
+        else {
+            nv.name = input.substring(0, i);
+            nv.value = input.substring(i + 1, input.length());
+        }
+
+        nv.name = nv.name.trim();
+
+        return nv;
+    }
+
+    private void ensureIsIdentifier(final String name) {
+        if (!DefaultVariables.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);
+    }
+
+    private void setVariable(final String namevalue) {
+        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 = variables.parent();
+
+        vars.set(nv.name, nv.value);
+    }
+}

Added: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java?rev=605911&view=auto
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java
(added)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java
Thu Dec 20 04:42:18 2007
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.commands.builtins;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.command.CommandExecutor;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.command.annotation.Requirement;
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Read and execute commands from a file/url in the current shell environment.
+ *
+ * @version $Rev: 600779 $ $Date: 2007-12-04 04:55:33 +0100 (Tue, 04 Dec 2007) $
+ */
+@CommandComponent(id="gshell-builtins:source", description="Load a file/url into the current
shell")
+public class SourceCommand
+    extends OsgiCommandSupport
+{
+    @Requirement
+    private CommandExecutor executor;
+
+    @Argument(required=true, description="Source file")
+    private String source;
+
+    protected Object doExecute() throws Exception {
+        URL url;
+
+        try {
+            url = new URL(source);
+        }
+        catch (MalformedURLException e) {
+            url = new File(source).toURI().toURL();
+        }
+
+        BufferedReader reader = openReader(url);
+        try {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                String tmp = line.trim();
+
+                // Ignore empty lines and comments
+                if (tmp.length() == 0 || tmp.startsWith("#")) {
+                    continue;
+                }
+
+                executor.execute(line);
+            }
+        }
+        finally {
+            IOUtil.close(reader);
+        }
+
+        return SUCCESS;
+    }
+
+    private BufferedReader openReader(final Object source) throws IOException {
+        BufferedReader reader;
+
+        if (source instanceof File) {
+            File file = (File)source;
+            log.info("Using source file: {}", file);
+
+            reader = new BufferedReader(new FileReader(file));
+        }
+        else if (source instanceof URL) {
+            URL url = (URL)source;
+            log.info("Using source URL: {}", url);
+
+            reader = new BufferedReader(new InputStreamReader(url.openStream()));
+        }
+        else {
+            String tmp = String.valueOf(source);
+
+            // First try a URL
+            try {
+                URL url = new URL(tmp);
+                log.info("Using source URL: {}", url);
+
+                reader = new BufferedReader(new InputStreamReader(url.openStream()));
+            }
+            catch (MalformedURLException ignore) {
+                // They try a file
+                File file = new File(tmp);
+                log.info("Using source file: {}", file);
+
+                reader = new BufferedReader(new FileReader(tmp));
+            }
+        }
+
+        return reader;
+    }
+}

Added: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java?rev=605911&view=auto
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java
(added)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java
Thu Dec 20 04:42:18 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.commands.builtins;
+
+import java.util.List;
+
+import org.apache.geronimo.gshell.DefaultVariables;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+
+/**
+ * Unset a variable or property.
+ *
+ * @version $Rev: 593392 $ $Date: 2007-11-09 03:14:15 +0100 (Fri, 09 Nov 2007) $
+ */
+@CommandComponent(id="gshell-builtins:unset", description="Unset a variable")
+public class UnsetCommand
+    extends OsgiCommandSupport
+{
+    enum Mode
+    {
+        VARIABLE,
+        PROPERTY
+    }
+
+    @Option(name="-m", aliases={"--mode"}, description="Unset mode")
+    private Mode mode = Mode.VARIABLE;
+
+    @Argument(required=true, description="Variable name")
+    private List<String> args;
+
+    protected Object doExecute() throws Exception {
+        for (String arg : args) {
+            String namevalue = String.valueOf(arg);
+
+            switch (mode) {
+                case PROPERTY:
+                    unsetProperty(namevalue);
+                    break;
+
+                case VARIABLE:
+                    unsetVariable(namevalue);
+                    break;
+            }
+        }
+
+        return SUCCESS;
+    }
+
+    private void ensureIsIdentifier(final String name) {
+        if (!DefaultVariables.isIdentifier(name)) {
+            throw new RuntimeException("Invalid identifer name: " + name);
+        }
+    }
+
+    private void unsetProperty(final String name) {
+        log.info("Unsetting system property: {}", name);
+
+        ensureIsIdentifier(name);
+
+        System.getProperties().remove(name);
+    }
+
+    private void unsetVariable(final String name) {
+        log.info("Unsetting variable: {}", name);
+
+        ensureIsIdentifier(name);
+
+        // Command vars always has a parent, set only makes sence when setting in parent's
scope
+        Variables vars = variables.parent();
+
+        vars.unset(name);
+    }
+}

Modified: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/ssl/SpringSslTransportFactory.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/ssl/SpringSslTransportFactory.java?rev=605911&r1=605910&r2=605911&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/ssl/SpringSslTransportFactory.java
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/ssl/SpringSslTransportFactory.java
Thu Dec 20 04:42:18 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.geronimo.gshell.whisper.transport.ssl;
 
-import org.apache.geronimo.gshell.whisper.transport.tcp.TcpTransport;
-import org.apache.geronimo.gshell.whisper.transport.tcp.TcpTransportServer;
 import org.apache.geronimo.gshell.whisper.transport.base.SpringBaseTransportFactory;
 import org.apache.geronimo.gshell.whisper.transport.base.BaseTransport;
 import org.apache.geronimo.gshell.whisper.transport.base.BaseTransportServer;

Modified: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/vm/SpringVmTransportFactory.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/vm/SpringVmTransportFactory.java?rev=605911&r1=605910&r2=605911&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/vm/SpringVmTransportFactory.java
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/whisper/transport/vm/SpringVmTransportFactory.java
Thu Dec 20 04:42:18 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.geronimo.gshell.whisper.transport.vm;
 
-import org.apache.geronimo.gshell.whisper.transport.tcp.TcpTransport;
-import org.apache.geronimo.gshell.whisper.transport.tcp.TcpTransportServer;
 import org.apache.geronimo.gshell.whisper.transport.base.SpringBaseTransportFactory;
 import org.apache.geronimo.gshell.whisper.transport.base.BaseTransport;
 import org.apache.geronimo.gshell.whisper.transport.base.BaseTransportServer;

Modified: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml?rev=605911&r1=605910&r2=605911&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
Thu Dec 20 04:42:18 2007
@@ -26,13 +26,15 @@
   http://www.springframework.org/schema/util
   http://www.springframework.org/schema/util/spring-util.xsd">
 
-    <bean id="clear" class="org.apache.geronimo.gshell.commands.builtins.ClearCommand"
/>
+    <bean id="clear" class="org.apache.geronimo.gshell.commands.builtins.ClearCommand">
+        <constructor-arg ref="terminal" />
+    </bean>
 
     <bean id="echo" class="org.apache.geronimo.gshell.commands.builtins.EchoCommand" />
 
-    <bean id="exit" class="org.apache.geronimo.gshell.spring.ExitCommand" />
+    <bean id="exit" class="org.apache.geronimo.gshell.commands.builtins.ExitCommand" />
 
-    <bean id="help" class="org.apache.geronimo.gshell.spring.HelpCommand">
+    <bean id="help" class="org.apache.geronimo.gshell.commands.builtins.HelpCommand">
         <constructor-arg ref="commandRegistry" />
         <constructor-arg ref="commandRegistry" />
         <constructor-arg ref="branding" />



Mime
View raw message