Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 79684 invoked from network); 9 May 2006 04:56:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 May 2006 04:56:05 -0000 Received: (qmail 10980 invoked by uid 500); 9 May 2006 04:56:05 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 10946 invoked by uid 500); 9 May 2006 04:56:04 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 10935 invoked by uid 99); 9 May 2006 04:56:04 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2006 21:56:04 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 08 May 2006 21:56:02 -0700 Received: (qmail 79554 invoked by uid 65534); 9 May 2006 04:55:42 -0000 Message-ID: <20060509045542.79553.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r405303 - in /geronimo/sandbox/gshell/trunk: gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/ gshell-core... Date: Tue, 09 May 2006 04:55:41 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jdillon Date: Mon May 8 21:55:39 2006 New Revision: 405303 URL: http://svn.apache.org/viewcvs?rev=405303&view=rev Log: Added simple command to execute a static method on a class Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java Modified: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java?rev=405303&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java Mon May 8 21:55:39 2006 @@ -0,0 +1,144 @@ +/* + * 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.commands.standard; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.PosixParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.HelpFormatter; + +import org.apache.geronimo.gshell.command.Command; +import org.apache.geronimo.gshell.command.CommandSupport; +import org.apache.geronimo.gshell.console.IO; + +import java.lang.reflect.Method; +import java.util.Arrays; + +/** + * ??? + * + * @version $Id: EchoCommand.java 399599 2006-05-04 08:13:57Z jdillon $ + */ +public class JavaCommand + extends CommandSupport +{ + private String methodName = "main"; + + public JavaCommand() { + super("java"); + } + + protected int doExecute(final String[] args) throws Exception { + assert args != null; + + // + // TODO: Optimize, move common code to CommandSupport + // + + IO io = getIO(); + + Options options = new Options(); + + options.addOption(OptionBuilder.withLongOpt("help") + .withDescription("Display this help message") + .create('h')); + + options.addOption(OptionBuilder.withLongOpt("method") + .withDescription("Invoke a named method") + .withArgName("method") + .create('M')); + + CommandLineParser parser = new PosixParser(); + CommandLine line = parser.parse(options, args); + + if (line.hasOption('h')) { + io.out.println("java -- execute a java application"); + io.out.println(); + + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( + io.out, + 80, // width (FIXME: Should pull from gshell.columns variable) + "java [options] [arguments]", + "", + options, + 4, // left pad + 4, // desc pad + "", + false); // auto usage + + io.out.println(); + + return Command.SUCCESS; + } + + if (line.hasOption('M')) { + methodName = line.getOptionValue('M'); + } + + run(line.getArgs()); + + return Command.SUCCESS; + } + + private void run(final String[] args) throws Exception { + assert args != null; + + if (args.length == 0) { + // + // TODO: Error show usage + // + throw new Exception("Missing classname"); + } + + run(args[0], shift(args)); + } + + private void run(final String classname, final String[] args) throws Exception { + assert classname != null; + assert args != null; + + Class type = Thread.currentThread().getContextClassLoader().loadClass(classname); + log.info("Using type: " + type); + + Method method = type.getMethod(methodName, new Class[] { String[].class }); + log.info("Using method: " + method); + + log.info("Invoking w/arguments: " + Arrays.asList(args)); + Object result = method.invoke(null, args); + + log.info("Result: " + result); + } + + // + // Misc + // + + public static String[] shift(final String[] args) { + return shift(args, 1); + } + + public static String[] shift(final String[] args, int pos) { + assert args.length >= pos; + + String[] _args = new String[args.length - pos]; + System.arraycopy(args, pos, _args, 0, _args.length); + return _args; + } +} Modified: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml?rev=405303&r1=405302&r2=405303&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml (original) +++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml Mon May 8 21:55:39 2006 @@ -4,6 +4,7 @@ + @@ -14,4 +15,8 @@ + + + + Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java?rev=405303&r1=405302&r2=405303&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java Mon May 8 21:55:39 2006 @@ -33,7 +33,7 @@ * * @version $Id$ */ -class GShellImpl +public class GShellImpl implements ApplicationContextAware { private static final Log log = LogFactory.getLog(GShell.class); @@ -102,11 +102,11 @@ // Misc // - private String[] shift(final String[] args) { + public static String[] shift(final String[] args) { return shift(args, 1); } - private String[] shift(final String[] args, int pos) { + public static String[] shift(final String[] args, int pos) { assert args.length >= pos; String[] _args = new String[args.length - pos];