Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 7420 invoked from network); 29 Aug 2007 02:18:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Aug 2007 02:18:14 -0000 Received: (qmail 69847 invoked by uid 500); 29 Aug 2007 02:18:09 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 69792 invoked by uid 500); 29 Aug 2007 02:18:09 -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 69777 invoked by uid 99); 29 Aug 2007 02:18:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Aug 2007 19:18:09 -0700 X-ASF-Spam-Status: No, hits=-99.1 required=10.0 tests=ALL_TRUSTED,URIBL_RHS_DOB X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2007 02:18:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 074DE1A9842; Tue, 28 Aug 2007 19:17:35 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r570606 [3/5] - in /geronimo/sandbox/gshell/trunk: ./ gshell-api/ gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-api/src/main/java/org/apache/geronimo/gshell/console/ gshell-api/src/main/java/org/apache/geronimo/gshell/... Date: Wed, 29 Aug 2007 02:17:20 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070829021735.074DE1A9842@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,72 @@ +/* + * 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.clp.setter; + +import java.lang.reflect.Field; + +/** + * Setter for fields. + * + * @version $Rev$ $Date$ + */ +public class FieldSetter + implements Setter +{ + protected final Field field; + + protected final Object bean; + + public FieldSetter(final Object bean, final Field field) { + assert bean != null; + assert field != null; + + this.bean = bean; + this.field = field; + } + + public Class getType() { + return field.getType(); + } + + public boolean isMultiValued() { + return false; + } + + public void set(final Object value) { + try { + doSet(value); + } + catch (IllegalAccessException ignore) { + // try again + field.setAccessible(true); + + try { + doSet(value); + } + catch (IllegalAccessException e) { + throw new IllegalAccessError(e.getMessage()); + } + } + } + + protected void doSet(Object value) throws IllegalAccessException { + field.set(bean, value); + } +} Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,51 @@ +/* + * 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.clp.setter; + +import java.text.MessageFormat; +import java.util.ResourceBundle; + +/** + * Messages for the {@link org.apache.geronimo.gshell.clp.setter} package. + * + * @version $Rev$ $Date$ + */ +enum Messages +{ + ILLEGAL_OPERAND, + ILLEGAL_BOOLEAN, + ILLEGAL_METHOD_SIGNATURE, + ILLEGAL_FIELD_SIGNATURE, + ; + + private static ResourceBundle bundle; + + String format(Object... args) { + assert args != null; + + synchronized (Messages.class) { + if (bundle == null) { + bundle = ResourceBundle.getBundle(Messages.class.getName()); + } + + return MessageFormat.format(bundle.getString(name()), args); + } + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Messages.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,98 @@ +/* + * 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.clp.setter; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.geronimo.gshell.clp.IllegalAnnotationError; +import org.apache.geronimo.gshell.clp.ProcessingException; + +/** + * Setter for methods. + * + * @version $Rev$ $Date$ + */ +public class MethodSetter + implements Setter +{ + private final Object bean; + + private final Method method; + + public MethodSetter(final Object bean, final Method method) { + assert bean != null; + assert method != null; + + this.bean = bean; + this.method = method; + + if (method.getParameterTypes().length != 1) { + throw new IllegalAnnotationError(Messages.ILLEGAL_METHOD_SIGNATURE.format(method)); + } + } + + public Class getType() { + return method.getParameterTypes()[0]; + } + + public boolean isMultiValued() { + return false; + } + + public void set(final Object value) throws ProcessingException { + try { + try { + method.invoke(bean, value); + } + catch (IllegalAccessException ignore) { + method.setAccessible(true); + + try { + method.invoke(bean, value); + } + catch (IllegalAccessException e) { + throw new IllegalAccessError(e.getMessage()); + } + } + } + catch (InvocationTargetException e) { + // Decode or wrap the target exception + Throwable t = e.getTargetException(); + + if (t instanceof RuntimeException) { + throw (RuntimeException)t; + } + if (t instanceof Error) { + throw (Error)t; + } + if (t instanceof ProcessingException) { + throw (ProcessingException)t; + } + + if (t != null) { + throw new ProcessingException(t); + } + else { + throw new ProcessingException(e); + } + } + } +} Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,49 @@ +/* + * 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.clp.setter; + +import org.apache.geronimo.gshell.clp.ProcessingException; + +/** + * Provides the basic mechanism to set values. + * + * @version $Rev$ $Date$ + */ +public interface Setter +{ + /** + * Adds/sets a value to the property of the option bean. + * + *

+ * A {@link Setter} object has an implicit knowledge about the property it's setting, + * and the instance of the option bean. + */ + void set(T value) throws ProcessingException; + + /** + * Gets the type of the underlying method/field. + */ + Class getType(); + + /** + * Whether this setter is instrinsically multi-valued. + */ + boolean isMultiValued(); +} Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +/** + * Provides support for setting option and argument values. + * + * @version $Rev$ $Date$ + */ +package org.apache.geronimo.gshell.clp.setter; Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/package-info.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties Tue Aug 28 19:17:11 2007 @@ -0,0 +1,34 @@ +## +## 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. +## + +## +## $Rev$ $Date$ +## + +MISSING_OPERAND=Option "{0}" takes an operand + +UNDEFINED_OPTION="{0}" is not a valid option + +NO_ARGUMENT_ALLOWED=No argument is allowed: {0} + +REQUIRED_OPTION_MISSING=Option "{0}" is required + +REQUIRED_ARGUMENT_MISSING=Argument "{0}" is required + +TOO_MANY_ARGUMENTS=Too many arguments: {0} Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/Messages.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties Tue Aug 28 19:17:11 2007 @@ -0,0 +1,26 @@ +## +## 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. +## + +## +## $Rev$ $Date$ +## + +ILLEGAL_OPERAND="{1}" is not a valid value for "{0}" + +ILLEGAL_BOOLEAN="{0}" is not a legal boolean value \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/handler/Messages.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties Tue Aug 28 19:17:11 2007 @@ -0,0 +1,26 @@ +## +## 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. +## + +## +## $Rev$ $Date$ +## + +ILLEGAL_METHOD_SIGNATURE=Method {0} takes more than one parameter + +ILLEGAL_FIELD_SIGNATURE=Field of type {0} isn't supported \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,72 @@ +/* + * 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.clp; + +import java.util.List; + +import junit.framework.TestCase; + +/** + * Tests for the {@link CommandLineProcessor} class. + * + * @version $Rev$ $Date$ + */ +public class CommandLineProcessorTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(1, clp.getOptionHandlers().size()); + assertEquals(1, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void testStopAtNonOption() throws Exception { + clp.setStopAtNonOption(true); + clp.process("-1", "test", "foo", "-bar", "baz"); + + assertEquals("test", bean.s); + assertNotNull(bean.args); + assertEquals(3, bean.args.size()); + assertEquals("foo", bean.args.get(0)); + assertEquals("-bar", bean.args.get(1)); + assertEquals("baz", bean.args.get(2)); + + } + + private static class TestBean + { + @Option(name="-1") + String s; + + @Argument + List args; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/CommandLineProcessorTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,69 @@ +/* + * 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.clp; + +import java.io.StringWriter; +import java.util.List; + +import junit.framework.TestCase; + +/** + * Tests for the {@link Printer} class. + * + * @version $Rev$ $Date$ + */ +public class PrinterTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + Printer printer = new Printer(clp); + + StringWriter out = new StringWriter(); + printer.printUsage(out); + + System.out.println(out.getBuffer()); + } + + private static class TestBean + { + @Option(name="-1", aliases={"--foo", "-bar"}, description="this is a test") + String a; + + @Option(name="-2", aliases={"--2", "-2"}, description="this is a really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really long description") + String b; + + @Argument(description="these are arguments") + List args; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/PrinterTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,100 @@ +/* + * 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.clp; + +import junit.framework.TestCase; + +/** + * Some simple tests to validate basic functionality. + * + * @version $Rev$ $Date$ + */ +public class SimpleTest + extends TestCase +{ + Simple bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new Simple(); + clp = new CommandLineProcessor(bean); + + assertEquals(2, clp.getOptionHandlers().size()); + assertEquals(1, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void testSimple0() throws Exception { + clp.process("-v"); + + assertFalse(bean.help); + } + + public void testSimple1() throws Exception { + clp.process("--help"); + + assertTrue(bean.help); + } + + public void testSimple2() throws Exception { + clp.process("-h"); + + assertTrue(bean.help); + } + + public void testSimple3() throws Exception { + try { + clp.process("-f"); + fail(); + } + catch (ProcessingException ignore) {} + + assertFalse(bean.help); + } + + public void testSimple4() throws Exception { + clp.process("-h"); + + assertFalse(bean.verbose); + } + + public void testSimple5() throws Exception { + clp.process("foo"); + + assertEquals(bean.arg1, "foo"); + } + + private static class Simple + { + @Option(name="-h", aliases={"--help"}) + boolean help; + + @Option(name="-v", aliases={"--verbose"}) + boolean verbose; + + @Argument + String arg1; + } +} Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/SimpleTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,75 @@ +/* + * 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.clp.handler; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link BooleanHandler} class. + * + * @version $Rev$ $Date$ + */ +public class BooleanHandlerTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(2, clp.getOptionHandlers().size()); + assertEquals(0, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1"); + + assertTrue(bean.flag); + } + + public void test2() throws Exception { + clp.process("-2", "false"); + + assertFalse(bean.flag2); + + clp.process("-2", "true"); + + assertTrue(bean.flag2); + } + + private static class TestBean + { + @Option(name="-1") + boolean flag; + + @Option(name="-2", argumentRequired=true) + boolean flag2; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/BooleanHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,68 @@ +/* + * 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.clp.handler; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link DoubleHandler} class. + * + * @version $Rev$ $Date$ + */ +public class DoubleHandlerTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(1, clp.getOptionHandlers().size()); + assertEquals(0, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1", "1"); + + assertEquals(1.0, bean.d); + } + + public void test2() throws Exception { + clp.process("-1", "1.1"); + + assertEquals(1.1, bean.d); + } + + private static class TestBean + { + @Option(name="-1") + double d; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/DoubleHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,66 @@ +/* + * 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.clp.handler; + +import java.io.File; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link FileHandler} class. + * + * @version $Rev$ $Date$ + */ +public class FileHandlerTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(1, clp.getOptionHandlers().size()); + assertEquals(0, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1", "/tmp"); + + File f = new File("/tmp"); + + assertEquals(f, bean.f); + } + + private static class TestBean + { + @Option(name="-1") + File f; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/FileHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,71 @@ +/* + * 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.clp.handler; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link IntegerHandler} class. + * + * @version $Rev$ $Date$ + */ +public class IntegerHandlerTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(2, clp.getOptionHandlers().size()); + assertEquals(0, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1", "1"); + + assertEquals(1, bean.n); + } + + public void test2() throws Exception { + clp.process("-2", "1"); + + assertEquals(new Integer(1), bean.i); + } + + private static class TestBean + { + @Option(name="-1") + int n; + + @Option(name="-2") + Integer i; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/IntegerHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,76 @@ +/* + * 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.clp.handler; + +import java.util.List; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link StopHandler} class. + * + * @version $Rev$ $Date$ + */ +public class StopHandlerTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(2, clp.getOptionHandlers().size()); + assertEquals(1, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1", "test", "--", "-foo", "bar"); + + assertEquals("test", bean.s); + assertNotNull(bean.args); + assertEquals(2, bean.args.size()); + assertEquals("-foo", bean.args.get(0)); + assertEquals("bar", bean.args.get(1)); + + } + + private static class TestBean + { + @Option(name="-1") + String s; + + @Option(name="--", handler=StopHandler.class) + boolean stop; + + @Argument + List args; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StopHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java Tue Aug 28 19:17:11 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.clp.handler; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link StringHandler} class. + * + * @version $Rev$ $Date$ + */ +public class StringHandlerTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(1, clp.getOptionHandlers().size()); + assertEquals(0, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1", "test"); + + assertEquals("test", bean.s); + } + + private static class TestBean + { + @Option(name="-1") + String s; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/handler/StringHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java Tue Aug 28 19:17:11 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.clp.setter; + +import java.util.List; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; + +/** + * Tests for the {@link CollectionFieldSetter} class. + * + * @version $Rev$ $Date$ + */ +public class CollectionFieldSetterTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(0, clp.getOptionHandlers().size()); + assertEquals(1, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("foo", "bar"); + + assertNotNull(bean.args); + assertEquals(2, bean.args.size()); + assertEquals("foo", bean.args.get(0)); + assertEquals("bar", bean.args.get(1)); + } + + private static class TestBean + { + @Argument + List args; + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetterTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java?rev=570606&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java Tue Aug 28 19:17:11 2007 @@ -0,0 +1,78 @@ +/* + * 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.clp.setter; + +import junit.framework.TestCase; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.CommandLineProcessor; +import org.apache.geronimo.gshell.clp.Option; + +/** + * Tests for the {@link MethodSetter} class. + * + * @version $Rev$ $Date$ + */ +public class MethodSetterTest + extends TestCase +{ + TestBean bean; + + CommandLineProcessor clp; + + protected void setUp() throws Exception { + bean = new TestBean(); + clp = new CommandLineProcessor(bean); + + assertEquals(1, clp.getOptionHandlers().size()); + assertEquals(1, clp.getArgumentHandlers().size()); + } + + protected void tearDown() throws Exception { + bean = null; + clp = null; + } + + public void test1() throws Exception { + clp.process("-1", "test"); + + assertEquals("test", bean.o); + } + + public void test2() throws Exception { + clp.process("test"); + + assertEquals("test", bean.a); + } + + private static class TestBean + { + String o, a; + + @Option(name="-1") + public void setOption(String value) { + this.o = value; + } + + @Argument + public void setArgument(String value) { + this.a = value; + } + } +} \ No newline at end of file Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/test/java/org/apache/geronimo/gshell/clp/setter/MethodSetterTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/PumpStreamHandler.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/PumpStreamHandler.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/PumpStreamHandler.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/PumpStreamHandler.java Tue Aug 28 19:17:11 2007 @@ -20,8 +20,8 @@ package org.apache.geronimo.gshell.commands.standard.util; import org.apache.geronimo.gshell.console.IO; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; @@ -38,7 +38,7 @@ */ public class PumpStreamHandler { - private static final Log log = LogFactory.getLog(PumpStreamHandler.class); + private static final Logger log = LoggerFactory.getLogger(PumpStreamHandler.class); private InputStream in; Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/StreamPumper.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/StreamPumper.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/StreamPumper.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/util/StreamPumper.java Tue Aug 28 19:17:11 2007 @@ -19,8 +19,8 @@ package org.apache.geronimo.gshell.commands.standard.util; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; @@ -38,7 +38,7 @@ public class StreamPumper implements Runnable { - private static final Log log = LogFactory.getLog(StreamPumper.class); + private static final Logger log = LoggerFactory.getLogger(StreamPumper.class); private InputStream in; Modified: geronimo/sandbox/gshell/trunk/gshell-core/pom.xml URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/pom.xml?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/pom.xml (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/pom.xml Tue Aug 28 19:17:11 2007 @@ -60,6 +60,18 @@ commons-jexl commons-jexl + + + org.slf4j + jcl104-over-slf4j + runtime + + + + org.slf4j + slf4j-simple + test + Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/CommandLineParser.jjt Tue Aug 28 19:17:11 2007 @@ -36,10 +36,8 @@ import java.io.Reader; import java.io.StringReader; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.commons.lang.NullArgumentException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Command line parser. @@ -49,16 +47,14 @@ public class CommandLineParser extends CommandLineParserSupport { - private static final Log log = LogFactory.getLog(CommandLineParser.class); + private static final Logger log = LoggerFactory.getLogger(CommandLineParser.class); public CommandLineParser() { this(new StringReader("")); } public ASTCommandLine parse(final Reader reader) throws ParseException { - if (reader == null) { - throw new NullArgumentException("reader"); - } + assert reader != null; if (log.isDebugEnabled()) { log.debug("Parsing from reader: " + reader); Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/SyntaxParser.jtb URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/SyntaxParser.jtb?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/SyntaxParser.jtb (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/grammar/SyntaxParser.jtb Tue Aug 28 19:17:11 2007 @@ -32,8 +32,8 @@ import java.io.Reader; import java.io.StringReader; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.commons.lang.NullArgumentException; @@ -44,7 +44,7 @@ */ public class SyntaxParser { - private static final Log log = LogFactory.getLog(SyntaxParser.class); + private static final Logger log = LoggerFactory.getLogger(SyntaxParser.class); public SyntaxParser() { this(new StringReader("")); Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CompletionHandlerImpl.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CompletionHandlerImpl.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CompletionHandlerImpl.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CompletionHandlerImpl.java Tue Aug 28 19:17:11 2007 @@ -19,22 +19,20 @@ package org.apache.geronimo.gshell; -import jline.CompletionHandler; -import jline.ConsoleReader; -import jline.CursorBuffer; - -import java.util.List; +import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; -import java.util.ArrayList; -import java.io.IOException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import jline.CompletionHandler; +import jline.ConsoleReader; +import jline.CursorBuffer; import org.apache.geronimo.gshell.command.MessageSource; import org.apache.geronimo.gshell.command.MessageSourceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; // // NOTE: Based on jline.CandidateListCompletionHandler. CLCH that comes with @@ -53,7 +51,7 @@ public class CompletionHandlerImpl implements CompletionHandler { - private static final Log log = LogFactory.getLog(CompletionHandlerImpl.class); + private static final Logger log = LoggerFactory.getLogger(CompletionHandlerImpl.class); private static MessageSource messages = new MessageSourceImpl(CompletionHandlerImpl.class.getName()); Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java Tue Aug 28 19:17:11 2007 @@ -19,17 +19,16 @@ package org.apache.geronimo.gshell; -import org.apache.geronimo.gshell.console.InteractiveConsole; -import org.apache.geronimo.gshell.console.Console; -import org.apache.geronimo.gshell.console.JLineConsole; -import org.apache.geronimo.gshell.command.StandardVariables; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.io.IOException; import jline.ConsoleReader; import jline.SimpleCompletor; +import org.apache.geronimo.gshell.command.StandardVariables; +import org.apache.geronimo.gshell.console.Console; +import org.apache.geronimo.gshell.console.InteractiveConsole; +import org.apache.geronimo.gshell.console.JLineConsole; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides the user-interaction bits for Shell. @@ -39,7 +38,7 @@ public class InteractiveShell extends InteractiveConsole { - private static final Log log = LogFactory.getLog(InteractiveConsole.class); + private static final Logger log = LoggerFactory.getLogger(InteractiveConsole.class); // // TODO: Refactor InteractiveConsole to use method overides for extention 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=570606&r1=570605&r2=570606&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 Tue Aug 28 19:17:11 2007 @@ -19,27 +19,25 @@ package org.apache.geronimo.gshell; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.lang.time.StopWatch; -import org.apache.commons.lang.NullArgumentException; -import org.apache.geronimo.gshell.console.IO; +import java.util.Iterator; + import org.apache.geronimo.gshell.command.Command; -import org.apache.geronimo.gshell.command.CommandManager; import org.apache.geronimo.gshell.command.CommandContext; -import org.apache.geronimo.gshell.command.Variables; -import org.apache.geronimo.gshell.command.VariablesImpl; -import org.apache.geronimo.gshell.command.CommandException; import org.apache.geronimo.gshell.command.CommandDefinition; +import org.apache.geronimo.gshell.command.CommandException; +import org.apache.geronimo.gshell.command.CommandManager; import org.apache.geronimo.gshell.command.CommandManagerImpl; import org.apache.geronimo.gshell.command.MessageSource; import org.apache.geronimo.gshell.command.MessageSourceImpl; import org.apache.geronimo.gshell.command.StandardVariables; -import org.apache.geronimo.gshell.commandline.CommandLineBuilder; +import org.apache.geronimo.gshell.command.Variables; +import org.apache.geronimo.gshell.command.VariablesImpl; import org.apache.geronimo.gshell.commandline.CommandLine; +import org.apache.geronimo.gshell.commandline.CommandLineBuilder; +import org.apache.geronimo.gshell.console.IO; import org.apache.geronimo.gshell.util.Arguments; - -import java.util.Iterator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is the primary interface to executing named commands. @@ -52,7 +50,7 @@ // TODO: Introduce Shell interface? // - private static final Log log = LogFactory.getLog(Shell.class); + private static final Logger log = LoggerFactory.getLogger(Shell.class); private final IO io; @@ -65,10 +63,8 @@ private final Variables variables = new VariablesImpl(); public Shell(final IO io) throws CommandException { - if (io == null) { - throw new NullArgumentException("io"); - } - + assert io != null; + this.io = io; shellContainer.registerComponentInstance(this); @@ -188,20 +184,26 @@ } }); + // FIXME: + /* // Setup command timings StopWatch watch = null; if (debug) { watch = new StopWatch(); watch.start(); } + */ Object result; try { result = cmd.execute(args); + // FIXME: + /* if (debug) { log.debug("Command completed in " + watch); } + */ } finally { cmd.destroy(); Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java Tue Aug 28 19:17:11 2007 @@ -19,8 +19,8 @@ package org.apache.geronimo.gshell; -import org.picocontainer.defaults.DefaultPicoContainer; import org.picocontainer.PicoContainer; +import org.picocontainer.defaults.DefaultPicoContainer; /** * ??? Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java Tue Aug 28 19:17:11 2007 @@ -19,14 +19,9 @@ package org.apache.geronimo.gshell.builtins; -import org.apache.commons.cli.CommandLine; - -import org.apache.geronimo.gshell.command.CommandSupport; -import org.apache.geronimo.gshell.command.MessageSource; -import org.apache.geronimo.gshell.command.CommandException; -import org.apache.geronimo.gshell.console.IO; import org.apache.geronimo.gshell.ExitNotification; -import org.apache.geronimo.gshell.util.Arguments; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.command.CommandSupport; /** * Exit the current shell. @@ -36,6 +31,7 @@ public class ExitCommand extends CommandSupport { + @Argument private int exitCode = 0; public ExitCommand() { @@ -46,29 +42,7 @@ return super.getUsage() + " [code]"; } - protected boolean processCommandLine(final CommandLine line) throws CommandException { - assert line != null; - - String[] args = line.getArgs(); - - IO io = getIO(); - MessageSource messages = getMessageSource(); - - if (args.length > 1) { - io.err.println(messages.getMessage("info.unexpected_args", Arguments.asString(args))); - io.err.println(); - return true; - } - if (args.length == 1) { - exitCode = Integer.parseInt(args[0]); - } - - return false; - } - - protected Object doExecute(Object[] args) throws Exception { - assert args != null; - + protected Object doExecute() throws Exception { log.info("Exiting w/code: " + exitCode); // 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=570606&r1=570605&r2=570606&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 Tue Aug 28 19:17:11 2007 @@ -19,14 +19,11 @@ package org.apache.geronimo.gshell.builtins; -import org.apache.commons.cli.CommandLine; - +import org.apache.geronimo.gshell.clp.Argument; import org.apache.geronimo.gshell.command.Command; -import org.apache.geronimo.gshell.command.CommandSupport; -import org.apache.geronimo.gshell.command.CommandManager; import org.apache.geronimo.gshell.command.CommandDefinition; -import org.apache.geronimo.gshell.command.MessageSource; -import org.apache.geronimo.gshell.command.CommandException; +import org.apache.geronimo.gshell.command.CommandManager; +import org.apache.geronimo.gshell.command.CommandSupport; import org.apache.geronimo.gshell.console.IO; import org.apache.geronimo.gshell.util.Arguments; @@ -40,7 +37,8 @@ { private CommandManager commandManager; - private String topic; + @Argument + private String topic = "topics"; public HelpCommand(final CommandManager commandManager) { super("help"); @@ -71,33 +69,7 @@ return super.getUsage() + " [topic|command]"; } - protected boolean processCommandLine(final CommandLine line) throws CommandException { - assert line != null; - - String[] args = line.getArgs(); - - IO io = getIO(); - MessageSource messages = getMessageSource(); - - if (args.length == 0) { - // No args, so help - return true; - } - else if (args.length > 1) { - // more than 1 arg complain - io.err.println(messages.getMessage("info.unexpected_args", Arguments.asString(args))); - return true; - } - else if (args.length == 1) { - // first arg becomes help topic name - topic = args[0]; - } - - return false; - } - - protected Object doExecute(final Object[] args) throws Exception { - assert args != null; + protected Object doExecute() throws Exception { IO io = getIO(); CommandManager manager = getCommandManager(); 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=570606&r1=570605&r2=570606&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 Tue Aug 28 19:17:11 2007 @@ -19,21 +19,18 @@ package org.apache.geronimo.gshell.builtins; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option; import org.apache.geronimo.gshell.command.Command; import org.apache.geronimo.gshell.command.CommandSupport; import org.apache.geronimo.gshell.command.Variables; -import org.apache.geronimo.gshell.command.MessageSource; import org.apache.geronimo.gshell.command.VariablesImpl; -import org.apache.geronimo.gshell.command.CommandException; import org.apache.geronimo.gshell.console.IO; -import java.util.Iterator; -import java.util.Properties; - /** * Set a variable or property. * @@ -48,53 +45,25 @@ PROPERTY } - private boolean display; - + @Option(name="-m", aliases={"--mode"}) private Mode mode = Mode.VARIABLE; + @Argument + private List args; + public SetCommand() { super("set"); } - protected Options getOptions() { - MessageSource messages = getMessageSource(); - - Options options = super.getOptions(); - - options.addOption(OptionBuilder.withLongOpt("property") - .withDescription(messages.getMessage("cli.option.property")) - .create('p')); - - return options; - } - protected String getUsage() { return super.getUsage() + " (])*"; } - protected boolean processCommandLine(final CommandLine line) throws CommandException { - assert line != null; - - String[] args = line.getArgs(); - - if (args.length == 0) { - display = true; - } - - if (line.hasOption('p')) { - mode = Mode.PROPERTY; - } - - return false; - } - - protected Object doExecute(Object[] args) throws Exception { - assert args != null; - + protected Object doExecute() throws Exception { IO io = getIO(); // No args... list all properties or variables - if (display) { + if (args == null || args.size() == 0) { switch (mode) { case PROPERTY: { Properties props = System.getProperties(); Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SourceCommand.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SourceCommand.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SourceCommand.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SourceCommand.java Tue Aug 28 19:17:11 2007 @@ -19,22 +19,18 @@ package org.apache.geronimo.gshell.builtins; -import java.io.File; import java.io.BufferedReader; -import java.io.InputStreamReader; +import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.net.URL; +import java.io.InputStreamReader; import java.net.MalformedURLException; +import java.net.URL; -import org.apache.commons.cli.CommandLine; - -import org.apache.geronimo.gshell.command.CommandSupport; -import org.apache.geronimo.gshell.command.CommandException; -import org.apache.geronimo.gshell.command.MessageSource; -import org.apache.geronimo.gshell.command.Command; -import org.apache.geronimo.gshell.console.IO; import org.apache.geronimo.gshell.Shell; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.command.Command; +import org.apache.geronimo.gshell.command.CommandSupport; /** * Read and execute commands from a file/url in the current shell environment. @@ -46,6 +42,9 @@ { private Shell shell; + @Argument(required=true) + private File file; + public SourceCommand(final Shell shell) { super("source"); @@ -56,30 +55,8 @@ return super.getUsage() + " "; } - protected boolean processCommandLine(final CommandLine line) throws CommandException { - assert line != null; - - String[] args = line.getArgs(); - - IO io = getIO(); - MessageSource messages = getMessageSource(); - - if (args.length == 0) { - io.err.println(messages.getMessage("cli.error.missing_source")); - - return true; - } - else if (args.length > 1) { - io.err.println(messages.getMessage("cli.error.unexpected_args", args)); - - return true; - } - - return false; - } - - protected Object doExecute(final Object[] args) throws Exception { - BufferedReader reader = openReader(args[0]); + protected Object doExecute() throws Exception { + BufferedReader reader = openReader(file); String line; while ((line = reader.readLine()) != null) { Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java?rev=570606&r1=570605&r2=570606&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java Tue Aug 28 19:17:11 2007 @@ -19,16 +19,14 @@ package org.apache.geronimo.gshell.builtins; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; +import java.util.List; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option; import org.apache.geronimo.gshell.command.Command; import org.apache.geronimo.gshell.command.CommandSupport; import org.apache.geronimo.gshell.command.Variables; import org.apache.geronimo.gshell.command.VariablesImpl; -import org.apache.geronimo.gshell.command.MessageSource; -import org.apache.geronimo.gshell.command.CommandException; /** * Unset a variable or property. @@ -44,48 +42,22 @@ PROPERTY } + @Option(name="-m", aliases={"--mode"}) private Mode mode = Mode.VARIABLE; + @Argument(required=true) + private List args; + public UnsetCommand() { super("unset"); } - protected Options getOptions() { - MessageSource messages = getMessageSource(); - - Options options = super.getOptions(); - - options.addOption(OptionBuilder.withLongOpt("property") - .withDescription(messages.getMessage("cli.option.property")) - .create('p')); - - return options; - } - protected String getUsage() { return super.getUsage() + " ()+"; } - protected boolean processCommandLine(final CommandLine line) throws CommandException { - assert line != null; - - String[] args = line.getArgs(); - - if (args.length == 0) { - return true; - } - - if (line.hasOption('p')) { - mode = Mode.PROPERTY; - } - - return false; - } - - protected Object doExecute(Object[] args) throws Exception { - assert args != null; - - for (Object arg : args) { + protected Object doExecute() throws Exception { + for (String arg : args) { String namevalue = String.valueOf(arg); switch (mode) {