You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2009/02/23 14:30:35 UTC

svn commit: r747011 - in /servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main: java/org/apache/servicemix/kernel/gshell/core/WorkAroundAliasCommand.java resources/META-INF/spring/gshell.xml

Author: gnodet
Date: Mon Feb 23 13:30:33 2009
New Revision: 747011

URL: http://svn.apache.org/viewvc?rev=747011&view=rev
Log:
SMX4KNL-205: aliases commands are not executed with the correct IO

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/WorkAroundAliasCommand.java
Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/WorkAroundAliasCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/WorkAroundAliasCommand.java?rev=747011&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/WorkAroundAliasCommand.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/WorkAroundAliasCommand.java Mon Feb 23 13:30:33 2009
@@ -0,0 +1,118 @@
+/*
+ * 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.servicemix.kernel.gshell.core;
+
+import java.util.List;
+import java.util.Iterator;
+
+import org.apache.geronimo.gshell.wisdom.command.AliasCommand;
+import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
+import org.apache.geronimo.gshell.command.CommandAction;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.command.CommandResult;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.shell.ShellContextHolder;
+import org.apache.geronimo.gshell.shell.ShellContext;
+import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.geronimo.gshell.io.IO;
+
+public class WorkAroundAliasCommand extends AliasCommand {
+
+    private final CommandLineExecutor executor;
+
+    public WorkAroundAliasCommand(CommandLineExecutor executor) {
+        super(executor);
+        this.executor = executor;
+        setAction(new AliasCommandAction());
+    }
+
+    @Override
+    protected void prepareAction(final ShellContext context, final Object[] args) {
+        // HACK: Reset state for proper appendArgs muck
+        assert context != null;
+        assert args != null;
+
+        setAction(new AliasCommandAction());
+        log.trace("Preparing action");
+
+        IO io = context.getIo();
+        CommandAction action = getAction();
+
+        // Setup the command action
+        try {
+            // Process command line options/arguments
+            processArguments(io, action, args);
+        }
+        catch (Exception e) {
+            // Abort if preparation caused a failure
+            throw new AbortExecutionNotification(new CommandResult.FailureResult(e));
+        }
+    }
+
+    private class AliasCommandAction
+        implements CommandAction
+    {
+        @Argument
+        private List<String> appendArgs = null;
+
+        public Object execute(final CommandContext context) throws Exception {
+            assert context != null;
+
+            StringBuilder buff = new StringBuilder();
+            buff.append(getAlias());
+
+            // If we have args to append, then do it
+            if (appendArgs != null && !appendArgs.isEmpty()) {
+                buff.append(" ");
+
+                // Append args quoted as they have already been processed by the parser
+                Iterator iter = appendArgs.iterator();
+                while (iter.hasNext()) {
+                    //
+                    // HACK: Using double quote instead of single quote for now as the parser's handling of single quote is broken
+                    //
+
+                    buff.append('"').append(iter.next()).append('"');
+                    if (iter.hasNext()) {
+                        buff.append(" ");
+                    }
+                }
+            }
+
+            log.debug("Executing alias: {}", buff);
+
+            final Shell shell = ShellContextHolder.get().getShell();
+            ShellContext shellContext = new ShellContext() {
+                public Shell getShell() {
+                    return shell;
+                }
+                public IO getIo() {
+                    return context.getIo();
+                }
+                public Variables getVariables() {
+                    return context.getVariables();
+                }
+            };
+            Object result = executor.execute(shellContext, buff.toString());
+
+            log.debug("Alias result: {}", result);
+
+            return result;
+        }
+    }
+}

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml?rev=747011&r1=747010&r2=747011&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml Mon Feb 23 13:30:33 2009
@@ -92,7 +92,7 @@
         <constructor-arg ref="groupDirResolver"/>
     </bean>
 
-    <bean class="org.apache.geronimo.gshell.wisdom.command.AliasCommand" scope="prototype">
+    <bean class="org.apache.servicemix.kernel.gshell.core.WorkAroundAliasCommand" scope="prototype">
         <constructor-arg ref="commandLineExecutor"/>
     </bean>