japi-cvs Mailing List for JAPI (Page 47)
Status: Beta
Brought to you by:
christianhujer
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
(115) |
May
(11) |
Jun
(5) |
Jul
(2) |
Aug
(10) |
Sep
(35) |
Oct
(14) |
Nov
(49) |
Dec
(27) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(57) |
Feb
(1) |
Mar
|
Apr
(2) |
May
(25) |
Jun
(134) |
Jul
(76) |
Aug
(34) |
Sep
(27) |
Oct
(5) |
Nov
|
Dec
(1) |
2008 |
Jan
(3) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(63) |
Nov
(30) |
Dec
(43) |
2009 |
Jan
(10) |
Feb
(420) |
Mar
(67) |
Apr
(3) |
May
(61) |
Jun
(21) |
Jul
(19) |
Aug
|
Sep
(6) |
Oct
(16) |
Nov
(1) |
Dec
|
2010 |
Jan
(1) |
Feb
|
Mar
|
Apr
(7) |
May
(3) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
From: <chr...@us...> - 2006-12-14 23:09:12
|
Revision: 258 http://svn.sourceforge.net/japi/?rev=258&view=rev Author: christianhujer Date: 2006-12-14 15:09:06 -0800 (Thu, 14 Dec 2006) Log Message: ----------- Improvements on BasicCommand. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java libs/argparser/trunk/src/net/sf/japi/io/args/Command.java libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-14 23:05:41 UTC (rev 257) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-14 23:09:06 UTC (rev 258) @@ -19,34 +19,37 @@ /** The ResourceBundle for locale-specific output. */ private final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.japi.io.args.messages"); - /** The maximum width of the option type field. */ - private final int maxOptionTypeWidth; - /** * Whether to exit or not. - * @see Command#isExiting() + * @see Command#isExiting() */ private boolean exiting; /** Create a BasicCommand. */ protected BasicCommand() { - int tmpMaxOptionTypeWidth = 0; - for (final OptionType optionType : OptionType.values()) { - tmpMaxOptionTypeWidth = Math.max(tmpMaxOptionTypeWidth, optionType.toString().length()); - } - maxOptionTypeWidth = tmpMaxOptionTypeWidth; } /** * Exit Option. + * Normally you wouldn't override this method. + * The default behaviour is to not exit. + * This prevents {@link System#exit(int)} from being invoked when BasicCommand resp. ArgParser is invoked from a running VM. + * If you invoke a command from a batch, setting the <code>exiting</code> property to <code>true</code> makes sense. + * This usually should always be determined by the user of a program, not the programmer. * @param exiting <code>true</code> if {@link System#exit(int)} should be invoked, otherwise <code>false</code>. + * @see System#exit(int) + * @see #isExiting() */ @Option(value = {"exit"}) public void setExiting(@NotNull final Boolean exiting) { this.exiting = exiting; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * @see System#exit(int) + * @see #setExiting(Boolean) + */ public Boolean isExiting() { return exiting; } @@ -106,11 +109,50 @@ /** * Get the ResourceBundle for the default locale. - * If you override this method be sure to declare the bundle returned by the overridden method as parent of your bundle. + * If you override this method, the methods of BasicCommand will still use BasicCommand's own ResourceBundle as a backup. + * That means overriding this method will not break any default behaviour of BasicCommand. * @return ResourceBundle for default locale. */ public ResourceBundle getBundle() { return resourceBundle; } + /** + * Get the help header. + * The default implementation returns a bundle String (see {@link #getBundle()}) for the key "helpHeader". + * The default String for "helpHeader" is the empty String. + * @return Help header. + */ + public String getHelpHeader() { + return getString("helpHeader"); + } + + /** + * Get the help footer. + * The default implementation returns a bundle String (see {@link #getBundle()}) for the key "helpFooter". + * The default String for "helpFooter" is the empty String. + * @return Help footer. + */ + public String getHelpFooter() { + return getString("helpFooter"); + } + + /** + * Returns a String from the ResourceBundles. + * This method first tries the subclass's ResourceBundle. + * If that fails, the String is returned from BasicCommand's own resource bundle. + * If that fails too, a MissingResourceException is thrown. + * If that fails, the String is returned from the subclass's ResourceBundle. + * @param key Name of the key to look up + * @return String from the ResourceBundles. + * @throws MissingResourceException In case all tries for retrieving a value for <var>key</var> failed. + */ + private String getString(final String key) throws MissingResourceException { + try { + return getBundle().getString(key); + } catch (MissingResourceException e) { + return resourceBundle.getString(key); + } + } + } // class BasicCommand Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-12-14 23:05:41 UTC (rev 257) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-12-14 23:09:06 UTC (rev 258) @@ -27,7 +27,7 @@ /** * Shell commands can implement this interface and make use of ArgParser. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @see BasicCommand BasicCommand for a convenient implementation of this interface + * @see BasicCommand BasicCommand for a very convenient implementation of this interface */ public interface Command { Modified: libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties 2006-12-14 23:05:41 UTC (rev 257) +++ libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties 2006-12-14 23:09:06 UTC (rev 258) @@ -7,3 +7,5 @@ help=Display this help and exit. setExiting=Quit Java VM with error code. setNotExiting=Don't quit Java VM (default). +helpHeader= +helpFooter= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-14 23:05:43
|
Revision: 257 http://svn.sourceforge.net/japi/?rev=257&view=rev Author: christianhujer Date: 2006-12-14 15:05:41 -0800 (Thu, 14 Dec 2006) Log Message: ----------- Improved build, fixed some errors. Modified Paths: -------------- libs/argparser/trunk/build.xml Modified: libs/argparser/trunk/build.xml =================================================================== --- libs/argparser/trunk/build.xml 2006-12-06 22:00:00 UTC (rev 256) +++ libs/argparser/trunk/build.xml 2006-12-14 23:05:41 UTC (rev 257) @@ -3,6 +3,7 @@ <property name="module.version" value="0.1" /> <property name="module.name" value="japi-lib-argparser" /> + <property name="module.shortname" value="argparser" /> <property name="module.title" value="ArgParser" /> <taskdef name="pack200" classpath="lib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" /> @@ -19,11 +20,11 @@ name = "compile" description = "Compiles production classes" > - <mkdir dir="classes/production/argparser" /> - <mkdir dir="classes/test/argparser" /> + <mkdir dir="classes/production/${module.shortname}" /> + <mkdir dir="classes/test/${module.shortname}" /> <javac srcdir="src" - destdir="classes/production" + destdir="classes/production/${module.shortname}" encoding="utf-8" source="1.5" target="1.5" @@ -33,6 +34,12 @@ </classpath> <exclude name="test/**/*.java" /> </javac> + <copy + todir="classes/production/${module.shortname}" + > + <fileset dir="src" includes="**/*.properties" /> + <fileset dir="src" includes="META-INF/services/**" /> + </copy> </target> <target @@ -67,7 +74,7 @@ <jar destfile="${distName}.jar"> <zipfileset dir="classes" excludes="production/**,test/**"/> <manifest> - <attribute name="Implementation-Title" value="JAPI" /> + <attribute name="Implementation-Title" value="${module.name}" /> <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" /> <attribute name="Implementation-Version" value="${module.version}" /> <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-06 22:00:06
|
Revision: 256 http://svn.sourceforge.net/japi/?rev=256&view=rev Author: christianhujer Date: 2006-12-06 14:00:00 -0800 (Wed, 06 Dec 2006) Log Message: ----------- Improved argument passing mechanism. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-06 21:48:26 UTC (rev 255) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-06 22:00:00 UTC (rev 256) @@ -48,6 +48,9 @@ * </pre> * Note that because of Reflection this Action is slightly slower than implementing your own Action instance, but in most cases this really does not matter at all. * Usually you won't use ReflectionAction yourself. Instead you'll let {@link ActionFactory} create an instance for you. + * <p /> + * You can use {@link #REFLECTION_ARGUMENTS} for providing arguments for the action method that's called via Reflection. + * Because that Object[] is not cloned, you can keep the reference and dynamically change the arguments of the invoked method. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @todo ReflectionAction should be able to invoke methods with parameters, three variants: Object..., ActionEvent or void */ @@ -141,7 +144,14 @@ putValue(REFLECTION_METHOD, null); } } - super.putValue(key, newValue); + if (REFLECTION_ARGUMENTS.equals(key)) { + if (newValue != null && !(newValue instanceof Object[])) { + throw new IllegalArgumentException("Value for key REFLECTION_ARGUMENTS must be of type " + Object[].class.getName() + " but was " + newValue.getClass().getName()); + } + super.putValue(key, newValue == null ? NO_ARGUMENTS : newValue); + } else { + super.putValue(key, newValue); + } } /** {@inheritDoc} @@ -158,6 +168,10 @@ if (!isEnabled()) { return; } final Object instance = getValue(REFLECTION_TARGET); try { + // TODO: Special value for REFLECTION_ARGUMENTS which determines whether to use ActionEvent. + final Method method = getMethod(instance); + final Object[] arguments = getArguments(method, e); + method.invoke(instance, arguments); getMethod(instance).invoke(instance, (Object[]) getValue(REFLECTION_ARGUMENTS)); } catch (final IllegalAccessException ex) { throw new IllegalAccessError(ACTION_FACTORY.format("ReflectionAction.nonPublicMethod", ex)); @@ -184,6 +198,20 @@ } } + /** + * Returns the arguments suited for invoking the specified method. + * @param method Method to invoke + * @param e ActionEvent which eventually might be used as method argument. + * @return Argument array. + */ + @NotNull private Object[] getArguments(@NotNull final Method method, @NotNull final ActionEvent e) { + final Class<?>[] parameterTypes = method.getParameterTypes(); + if (parameterTypes.length == 1 && parameterTypes[0].equals(ActionEvent.class)) { + return new Object[] { e }; + } + return (Object[]) getValue(REFLECTION_ARGUMENTS); + } + /** Get the method associated with this action. * @param instance Instance to get method for * @return associated method or <code>null</code> if no method could be found This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-06 21:48:35
|
Revision: 255 http://svn.sourceforge.net/japi/?rev=255&view=rev Author: christianhujer Date: 2006-12-06 13:48:26 -0800 (Wed, 06 Dec 2006) Log Message: ----------- Implemented support for ActionMethods which use different keys than their name and take arguments. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-06 21:40:33 UTC (rev 254) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-06 21:48:26 UTC (rev 255) @@ -53,6 +53,9 @@ */ public final class ReflectionAction extends AbstractAction { + /** The empty object array used to denote zero arguments. */ + private static final Object[] NO_ARGUMENTS = new Object[0]; + /** Action Factory for reading strings. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing"); @@ -61,7 +64,7 @@ */ public static final String REFLECTION_TARGET = "ReflectionTarget"; - /** The key used for storing the method name to use when searching for a method using reflection. + /** The key used for storing the method key to use when searching for a method using reflection. * Value Type: {@link String} (checked). */ public static final String REFLECTION_METHOD_NAME = "ReflectionMethodName"; @@ -71,6 +74,12 @@ */ public static final String REFLECTION_METHOD = "ReflectionMethod"; + /** + * The key used for storing the method arguments to use when invoking the method. + * Value Type: {@link Object[]} (checked). + */ + public static final String REFLECTION_ARGUMENTS = "ReflectionArguments"; + /** The key used for storing the action factory that provides access to error handlers strings. */ public static final String REFLECTION_MESSAGE_PROVIDER = "ActionFactory"; @@ -80,6 +89,7 @@ /** Create an uninitialized ReflectionAction. */ public ReflectionAction() { + putValue(REFLECTION_ARGUMENTS, NO_ARGUMENTS); } /** Create a ReflectionAction with method and target. @@ -87,6 +97,7 @@ * @param target Target object to invoke method at */ public ReflectionAction(final String methodName, final Object target) { + putValue(REFLECTION_ARGUMENTS, NO_ARGUMENTS); putValue(REFLECTION_METHOD_NAME, methodName); putValue(REFLECTION_TARGET, target); } @@ -99,6 +110,7 @@ */ public ReflectionAction(final String name, final Icon icon, final String methodName, final Object target) { super(name, icon); + putValue(REFLECTION_ARGUMENTS, NO_ARGUMENTS); putValue(REFLECTION_METHOD_NAME, methodName); putValue(REFLECTION_TARGET, target); } @@ -146,7 +158,7 @@ if (!isEnabled()) { return; } final Object instance = getValue(REFLECTION_TARGET); try { - getMethod(instance).invoke(instance); + getMethod(instance).invoke(instance, (Object[]) getValue(REFLECTION_ARGUMENTS)); } catch (final IllegalAccessException ex) { throw new IllegalAccessError(ACTION_FACTORY.format("ReflectionAction.nonPublicMethod", ex)); } catch (final InvocationTargetException ex) { @@ -187,8 +199,7 @@ return null; } try { - final Class<? extends Object> clazz = instance.getClass(); - method = clazz.getMethod(methodName); + method = getActionMethod(instance, methodName); putValue(REFLECTION_METHOD, method); } catch (final NoSuchMethodException ex) { assert false : "Action Method not found: " + ex; @@ -198,6 +209,31 @@ return method; } + /** Get the named action method from the target class. + * @param clazz Class to search for method + * @param methodName Method name to get + * @return Method found + * @throws NoSuchMethodException In case the method was not found. + */ + @Nullable public static Method getActionMethod(@NotNull final Class<?> clazz, @NotNull final String methodName) throws NoSuchMethodException { + for (final Method method : clazz.getMethods()) { + if (method.getName().equals(methodName) || method.isAnnotationPresent(ActionMethod.class) && method.getAnnotation(ActionMethod.class).value().equals(methodName)) { + return method; + } + } + throw new NoSuchMethodException(methodName + " (error: no public method named " + methodName + " and annotated as @ActionMethod found)"); + } + + /** Get the named action method from the target object. + * @param target Object to search for method + * @param methodName Method name to get + * @return Method found + * @throws NoSuchMethodException In case the method was not found or is not annotated as @{@link ActionMethod}. + */ + @Nullable public static Method getActionMethod(@NotNull final Object target, @NotNull final String methodName) throws NoSuchMethodException { + return getActionMethod(target.getClass(), methodName); + } + /** {@inheritDoc} */ @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-06 21:40:46
|
Revision: 254 http://svn.sourceforge.net/japi/?rev=254&view=rev Author: christianhujer Date: 2006-12-06 13:40:33 -0800 (Wed, 06 Dec 2006) Log Message: ----------- Added support for methods that use different keys than their name. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ActionMethod.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ActionMethod.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ActionMethod.java 2006-12-05 22:42:20 UTC (rev 253) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionMethod.java 2006-12-06 21:40:33 UTC (rev 254) @@ -26,6 +26,7 @@ import java.lang.annotation.Target; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import org.jetbrains.annotations.NotNull; /** Annotation for methods that are Actions. * {@link ActionFactory} in future will automatically configure and store Actions with properties for methods that are annotated with this Annotation. @@ -38,4 +39,12 @@ @Retention(RUNTIME) @Target(METHOD) public @interface ActionMethod { + + /** + * Determines the Action key. + * Defaults to the method name. + * @return The Action key for this ActionMethod or <code>""</code> if the method name should be used. + */ + @NotNull String value() default ""; + } // @interface ActionMethod This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-05 22:42:22
|
Revision: 253 http://svn.sourceforge.net/japi/?rev=253&view=rev Author: christianhujer Date: 2006-12-05 14:42:20 -0800 (Tue, 05 Dec 2006) Log Message: ----------- Fixed javadoc issue. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/DummyAction.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/DummyAction.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/DummyAction.java 2006-12-05 22:40:52 UTC (rev 252) +++ libs/swing-action/trunk/src/net/sf/japi/swing/DummyAction.java 2006-12-05 22:42:20 UTC (rev 253) @@ -21,6 +21,7 @@ package net.sf.japi.swing; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.AbstractAction; /** Dummy Action implementation, an Action implementation which does nothing and only serves as an Action Property container. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-05 22:40:54
|
Revision: 252 http://svn.sourceforge.net/japi/?rev=252&view=rev Author: christianhujer Date: 2006-12-05 14:40:52 -0800 (Tue, 05 Dec 2006) Log Message: ----------- Some test improvement: throwing exceptions is now tested as well. Modified Paths: -------------- libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java Modified: libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java =================================================================== --- libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java 2006-12-03 23:57:11 UTC (rev 251) +++ libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java 2006-12-05 22:40:52 UTC (rev 252) @@ -4,6 +4,7 @@ import java.lang.reflect.Method; import net.sf.japi.swing.ActionMethod; import net.sf.japi.swing.ReflectionAction; +import net.sf.japi.swing.ActionFactory; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -16,13 +17,20 @@ */ public class ReflectionActionTest { + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("test.net.sf.japi.swing"); + /** The testling: A ReflectionAction. */ private ReflectionAction testling; + /** The Action Mock. */ + private ActionMock actionMock; + /** Create the testling. */ @Before public void setUpTestling() { - testling = new ReflectionAction(); + actionMock = new ActionMock(); + testling = (ReflectionAction) ACTION_FACTORY.createAction(false, "someAction", actionMock); } /** Remove the testling. */ @@ -86,9 +94,8 @@ */ @Test public void testPutValueMethod() throws Exception { - final ActionMock actionDummy = new ActionMock(); - testling.putValue(ReflectionAction.REFLECTION_METHOD, actionDummy.getMethod()); - Assert.assertEquals(actionDummy.getMethod(), testling.getValue(ReflectionAction.REFLECTION_METHOD)); + testling.putValue(ReflectionAction.REFLECTION_METHOD, actionMock.getMethod()); + Assert.assertEquals(actionMock.getMethod(), testling.getValue(ReflectionAction.REFLECTION_METHOD)); } /** @@ -97,9 +104,8 @@ */ @Test public void testPutValueTarget() throws Exception { - final ActionMock actionDummy = new ActionMock(); testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, "foo"); - testling.putValue(ReflectionAction.REFLECTION_METHOD, actionDummy.getMethod()); + testling.putValue(ReflectionAction.REFLECTION_METHOD, actionMock.getMethod()); testling.putValue(ReflectionAction.REFLECTION_TARGET, null); Assert.assertNull("After setting REFLECTION_TARGET to null, REFLECTION_METHOD must be reset to null.", testling.getValue(ReflectionAction.REFLECTION_METHOD)); Assert.assertEquals("After setting REFLECTION_TARGET to null, REFLECTION_METHOD_NAME must be unchanged.", testling.getValue(ReflectionAction.REFLECTION_METHOD_NAME), "foo"); @@ -111,14 +117,26 @@ */ @Test public void testActionPerformed() throws Exception { - final ActionMock mock = new ActionMock(); - testling.putValue(ReflectionAction.REFLECTION_TARGET, mock); + testling.putValue(ReflectionAction.REFLECTION_TARGET, actionMock); testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, "someAction"); testling.actionPerformed(new ActionEvent(this, 0, null)); - Assert.assertEquals("actionPerformed() must lead to the target method being invoked exactly once.", mock.getInvocationCount(), 1); + Assert.assertEquals("actionPerformed() must lead to the target method being invoked exactly once.", actionMock.getInvocationCount(), 1); } /** + * Tests whether {@link ReflectionAction#actionPerformed(ActionEvent)} works. + * @throws Exception (unexpected) + */ + @Test(expected=Exception.class) + public void testActionPerformedException() throws Exception { + actionMock.setThrowException(true); + testling.putValue(ReflectionAction.REFLECTION_TARGET, actionMock); + testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, "someAction"); + testling.actionPerformed(new ActionEvent(this, 0, null)); + Assert.assertEquals("actionPerformed() must lead to the target method being invoked exactly once.", actionMock.getInvocationCount(), 1); + } + + /** * ActionMock. * Provides a counter that counts how often the action was invoked. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> @@ -131,11 +149,20 @@ private int invocationCount; /** + * Whether to throw an exception during the execution of {@link #someAction()}. + */ + private boolean throwException; + + /** * The ActionMethod. * Increments the invocation counter. + * @throws Exception If {@link #throwException} is true. */ @ActionMethod - public void someAction() { + public void someAction() throws Exception { + if (isThrowException()) { + throw new Exception(); + } invocationCount++; } @@ -159,6 +186,22 @@ } } + /** + * Returns whether an exception will be thrown when executing {@link #someAction()}. + * @return <code>true</code> if an exception will be thrown, otherwise <code>false</code>. + */ + public boolean isThrowException() { + return throwException; + } + + /** + * Sets whether an exception should be thrown when executing {@link #someAction()}. + * @param throwException <code>true</code> for throwing an exception, otherwise <code>false</code>. + */ + public void setThrowException(boolean throwException) { + this.throwException = throwException; + } + } // class ActionMock } // class ReflectionActionTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-03 23:57:13
|
Revision: 251 http://svn.sourceforge.net/japi/?rev=251&view=rev Author: christianhujer Date: 2006-12-03 15:57:11 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Added unit test for ReflectionAction. Added Paths: ----------- libs/swing-action/trunk/src/test/ libs/swing-action/trunk/src/test/net/ libs/swing-action/trunk/src/test/net/sf/ libs/swing-action/trunk/src/test/net/sf/japi/ libs/swing-action/trunk/src/test/net/sf/japi/swing/ libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java Added: libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java =================================================================== --- libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java (rev 0) +++ libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java 2006-12-03 23:57:11 UTC (rev 251) @@ -0,0 +1,164 @@ +package test.net.sf.japi.swing; + +import java.awt.event.ActionEvent; +import java.lang.reflect.Method; +import net.sf.japi.swing.ActionMethod; +import net.sf.japi.swing.ReflectionAction; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Test for {@link ReflectionAction}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class ReflectionActionTest { + + /** The testling: A ReflectionAction. */ + private ReflectionAction testling; + + /** Create the testling. */ + @Before + public void setUpTestling() { + testling = new ReflectionAction(); + } + + /** Remove the testling. */ + @After + public void tearDown() { + testling = null; + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test(expected = IllegalArgumentException.class) + public void testPutValueMethodNameThrows() throws Exception { + testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, new Object()); + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test + public void testPutValueMethodNameNull() throws Exception { + testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, null); + Assert.assertNull("After setting the method name to null method name must be null.", testling.getValue(ReflectionAction.REFLECTION_METHOD_NAME)); + Assert.assertNull("After setting the method name to null method must be null.", testling.getValue(ReflectionAction.REFLECTION_METHOD)); + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test + public void testPutValueMethodName() throws Exception { + testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, "foo"); + Assert.assertEquals("After setting the method name method name must be stored.", testling.getValue(ReflectionAction.REFLECTION_METHOD_NAME), "foo"); + Assert.assertNull("After setting the method name method must be null.", testling.getValue(ReflectionAction.REFLECTION_METHOD)); + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test(expected = IllegalArgumentException.class) + public void testPutValueMethodThrowsString() throws Exception { + testling.putValue(ReflectionAction.REFLECTION_METHOD, "foo"); + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test(expected = IllegalArgumentException.class) + public void testPutValueMethodThrowsOther() throws Exception { + testling.putValue(ReflectionAction.REFLECTION_METHOD, new Object()); + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test + public void testPutValueMethod() throws Exception { + final ActionMock actionDummy = new ActionMock(); + testling.putValue(ReflectionAction.REFLECTION_METHOD, actionDummy.getMethod()); + Assert.assertEquals(actionDummy.getMethod(), testling.getValue(ReflectionAction.REFLECTION_METHOD)); + } + + /** + * Tests whether {@link ReflectionAction#putValue(String, Object)} works. + * @throws Exception (unexpected) + */ + @Test + public void testPutValueTarget() throws Exception { + final ActionMock actionDummy = new ActionMock(); + testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, "foo"); + testling.putValue(ReflectionAction.REFLECTION_METHOD, actionDummy.getMethod()); + testling.putValue(ReflectionAction.REFLECTION_TARGET, null); + Assert.assertNull("After setting REFLECTION_TARGET to null, REFLECTION_METHOD must be reset to null.", testling.getValue(ReflectionAction.REFLECTION_METHOD)); + Assert.assertEquals("After setting REFLECTION_TARGET to null, REFLECTION_METHOD_NAME must be unchanged.", testling.getValue(ReflectionAction.REFLECTION_METHOD_NAME), "foo"); + } + + /** + * Tests whether {@link ReflectionAction#actionPerformed(ActionEvent)} works. + * @throws Exception (unexpected) + */ + @Test + public void testActionPerformed() throws Exception { + final ActionMock mock = new ActionMock(); + testling.putValue(ReflectionAction.REFLECTION_TARGET, mock); + testling.putValue(ReflectionAction.REFLECTION_METHOD_NAME, "someAction"); + testling.actionPerformed(new ActionEvent(this, 0, null)); + Assert.assertEquals("actionPerformed() must lead to the target method being invoked exactly once.", mock.getInvocationCount(), 1); + } + + /** + * ActionMock. + * Provides a counter that counts how often the action was invoked. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ + public static class ActionMock { + + /** + * Counter for counting the number of invocations of {@link #someAction()}. + */ + private int invocationCount; + + /** + * The ActionMethod. + * Increments the invocation counter. + */ + @ActionMethod + public void someAction() { + invocationCount++; + } + + /** + * Returns the invocation counter. + * @return The invocation counter. + */ + public int getInvocationCount() { + return invocationCount; + } + + /** + * Returns the Action method. + * @return The Action method. + */ + public Method getMethod() { + try { + return getClass().getMethod("someAction"); + } catch (final NoSuchMethodException e) { + throw new Error(e); + } + } + + } // class ActionMock + +} // class ReflectionActionTest Property changes on: libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-03 22:16:24
|
Revision: 250 http://svn.sourceforge.net/japi/?rev=250&view=rev Author: christianhujer Date: 2006-12-03 14:16:22 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Minor improvements. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-03 16:23:37 UTC (rev 249) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-03 22:16:22 UTC (rev 250) @@ -26,9 +26,10 @@ import java.lang.reflect.Method; import javax.swing.AbstractAction; import javax.swing.Icon; -import org.jetbrains.annotations.Nullable; import net.sf.japi.lang.SuperClassIterator; import static net.sf.japi.swing.ActionFactory.ACTION_ID; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; /** Action implementation which invokes the desired method using Reflection. * Usage example: @@ -90,6 +91,18 @@ putValue(REFLECTION_TARGET, target); } + /** Defines an <code>Action</code> object with the specified description string and a the specified icon. + * @param name description string + * @param icon icon + * @param methodName Name of method to invoke + * @param target Target object to invoke method at + */ + public ReflectionAction(final String name, final Icon icon, final String methodName, final Object target) { + super(name, icon); + putValue(REFLECTION_METHOD_NAME, methodName); + putValue(REFLECTION_TARGET, target); + } + /** {@inheritDoc} * This implementation checks the type of <var>newValue</var> if the <var>key</var> is {@link #REFLECTION_METHOD_NAME} or {@link * #REFLECTION_METHOD}, so you'll know of errors quite soon. @@ -119,18 +132,6 @@ super.putValue(key, newValue); } - /** Defines an <code>Action</code> object with the specified description string and a the specified icon. - * @param name description string - * @param icon icon - * @param methodName Name of method to invoke - * @param target Target object to invoke method at - */ - public ReflectionAction(final String name, final Icon icon, final String methodName, final Object target) { - super(name, icon); - putValue(REFLECTION_METHOD_NAME, methodName); - putValue(REFLECTION_TARGET, target); - } - /** {@inheritDoc} * The implementation of this method first looks whether the Action is enabled. * If it isn't, the method simply returns. @@ -156,7 +157,8 @@ final String dialogKey = getValue(ACTION_ID) + ".exception." + c.getName(); final String title = actionFactory.getString(dialogKey + ".title"); if (title != null) { - final Object source = e.getSource(); + // source cannot be null because the ActionEvent constructor will not allow a null source. + @NotNull final Object source = e.getSource(); final Component parent = source instanceof Component ? (Component) source : null; // TODO: find better alternative to null actionFactory.showMessageDialog(parent, dialogKey, cause.getLocalizedMessage()); return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-03 16:23:39
|
Revision: 249 http://svn.sourceforge.net/japi/?rev=249&view=rev Author: christianhujer Date: 2006-12-03 08:23:37 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Improved error handling: Replaced assert with IllegalAccessError. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-03 14:10:26 UTC (rev 248) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ReflectionAction.java 2006-12-03 16:23:37 UTC (rev 249) @@ -139,14 +139,15 @@ * If the method is null, it is reflected upon the instance usign the method name. If the method name is null, the method returns. * Finally the method is invoked upon the instance, which may be null for static methods. * @throws RuntimeException with cause in case the invocation of the method threw an exception and there was no handler for that exception. + * @throws IllegalAccessError In case the target method is non-public. */ - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(final ActionEvent e) throws RuntimeException { if (!isEnabled()) { return; } final Object instance = getValue(REFLECTION_TARGET); try { getMethod(instance).invoke(instance); } catch (final IllegalAccessException ex) { - assert false : ACTION_FACTORY.format("ReflectionAction.nonPublicMethod", ex); + throw new IllegalAccessError(ACTION_FACTORY.format("ReflectionAction.nonPublicMethod", ex)); } catch (final InvocationTargetException ex) { final ActionFactory actionFactory = (ActionFactory) getValue(REFLECTION_MESSAGE_PROVIDER); final Throwable cause = ex.getCause(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-03 14:10:28
|
Revision: 248 http://svn.sourceforge.net/japi/?rev=248&view=rev Author: christianhujer Date: 2006-12-03 06:10:26 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Added support for singular / plural titles. Modified Paths: -------------- libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java libs/taglets/trunk/src/net/sf/japi/taglets/InvariantTaglet.java libs/taglets/trunk/src/net/sf/japi/taglets/NoteTaglet.java libs/taglets/trunk/src/net/sf/japi/taglets/PostconditionTaglet.java libs/taglets/trunk/src/net/sf/japi/taglets/PreconditionTaglet.java libs/taglets/trunk/src/net/sf/japi/taglets/WarningTaglet.java Modified: libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java 2006-12-03 14:05:18 UTC (rev 247) +++ libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java 2006-12-03 14:10:26 UTC (rev 248) @@ -2,31 +2,47 @@ import com.sun.javadoc.Tag; import com.sun.tools.doclets.Taglet; +import org.jetbrains.annotations.NotNull; /** * Base class for Taglets that are simple blocks transforming into lists. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @todo add user definable background colour - * @todo auto-detect singular / plural of heading */ public abstract class BlockListTaglet implements Taglet { /** The name of this Taglet. */ private final String name; - /** The title of this Taglet. */ - private final String title; + /** The singular title of this Taglet. */ + private final String singularTitle; + /** The plural title of this Taglet. */ + private final String pluralTitle; + /** * Create a BLockListTaglet. * @param name Name of this Taglet (e.g. "todo"). - * @param title Title of this Taglet (e.g. "Todo"). + * @param title Title of this Taglet (e.g. "Todo") for both, singular and plural. */ - protected BlockListTaglet(final String name, final String title) { + protected BlockListTaglet(@NotNull final String name, @NotNull final String title) { this.name = name; - this.title = title; + this.singularTitle = title; + this.pluralTitle = title; } + /** + * Create a BLockListTaglet. + * @param name Name of this Taglet (e.g. "note"). + * @param singularTitle Singular title of this taglet (e.g. "note"). + * @param pluralTitle Plural title of this taglet (e.g. "notes"). + */ + protected BlockListTaglet(@NotNull final String name, @NotNull final String singularTitle, @NotNull final String pluralTitle) { + this.name = name; + this.singularTitle = singularTitle; + this.pluralTitle = pluralTitle; + } + /** {@inheritDoc} */ public String getName() { return name; @@ -71,7 +87,7 @@ public String toString(final Tag tag) { final StringBuilder sb = new StringBuilder(); sb.append("<DL><DT><B>"); - sb.append(title); + sb.append(singularTitle); sb.append("</B></DT><DD><UL><LI>"); sb.append(tag.text()); sb.append("</LI></UL></DD></DL>"); @@ -88,7 +104,7 @@ } final StringBuilder sb = new StringBuilder(); sb.append("<DL><DT><B>"); - sb.append(title); + sb.append(pluralTitle); sb.append("</B></DT><DD><UL>"); for (final Tag tag : tags) { sb.append("<LI>"); Modified: libs/taglets/trunk/src/net/sf/japi/taglets/InvariantTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/InvariantTaglet.java 2006-12-03 14:05:18 UTC (rev 247) +++ libs/taglets/trunk/src/net/sf/japi/taglets/InvariantTaglet.java 2006-12-03 14:10:26 UTC (rev 248) @@ -16,7 +16,7 @@ * Create a InvariantTaglet. */ private InvariantTaglet() { - super("invariant", "Invariants"); + super("invariant", "Invariant", "Invariants"); } /** Modified: libs/taglets/trunk/src/net/sf/japi/taglets/NoteTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/NoteTaglet.java 2006-12-03 14:05:18 UTC (rev 247) +++ libs/taglets/trunk/src/net/sf/japi/taglets/NoteTaglet.java 2006-12-03 14:10:26 UTC (rev 248) @@ -5,7 +5,7 @@ import java.util.Map; /** - * Taglet for entries in a warnings list. + * Taglet for entries in a notes list. * A warning states that somebody must take care of something when using the symbol documented with the warning. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @see NoteTaglet for less severe notes @@ -13,10 +13,10 @@ public class NoteTaglet extends BlockListTaglet { /** - * Create a WarningTaglet. + * Create a NoteTaglet. */ private NoteTaglet() { - super("note", "Notes"); + super("note", "Note", "Notes"); } /** Modified: libs/taglets/trunk/src/net/sf/japi/taglets/PostconditionTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/PostconditionTaglet.java 2006-12-03 14:05:18 UTC (rev 247) +++ libs/taglets/trunk/src/net/sf/japi/taglets/PostconditionTaglet.java 2006-12-03 14:10:26 UTC (rev 248) @@ -16,7 +16,7 @@ * Create a PostconditionTaglet. */ private PostconditionTaglet() { - super("postcondition", "Postconditions"); + super("postcondition", "Postcondition", "Postconditions"); } /** {@inheritDoc} */ Modified: libs/taglets/trunk/src/net/sf/japi/taglets/PreconditionTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/PreconditionTaglet.java 2006-12-03 14:05:18 UTC (rev 247) +++ libs/taglets/trunk/src/net/sf/japi/taglets/PreconditionTaglet.java 2006-12-03 14:10:26 UTC (rev 248) @@ -16,7 +16,7 @@ * Create a PreconditionTaglet. */ private PreconditionTaglet() { - super("precondition", "Preconditions"); + super("precondition", "Precondition", "Preconditions"); } /** {@inheritDoc} */ Modified: libs/taglets/trunk/src/net/sf/japi/taglets/WarningTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/WarningTaglet.java 2006-12-03 14:05:18 UTC (rev 247) +++ libs/taglets/trunk/src/net/sf/japi/taglets/WarningTaglet.java 2006-12-03 14:10:26 UTC (rev 248) @@ -16,7 +16,7 @@ * Create a WarningTaglet. */ private WarningTaglet() { - super("warning", "Warnings"); + super("warning", "Warning", "Warnings"); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-03 14:05:19
|
Revision: 247 http://svn.sourceforge.net/japi/?rev=247&view=rev Author: christianhujer Date: 2006-12-03 06:05:18 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Added cases where tags == null or tags.length == 1. Modified Paths: -------------- libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java Modified: libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java =================================================================== --- libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java 2006-12-03 13:56:51 UTC (rev 246) +++ libs/taglets/trunk/src/net/sf/japi/taglets/BlockListTaglet.java 2006-12-03 14:05:18 UTC (rev 247) @@ -80,9 +80,12 @@ /** {@inheritDoc} */ public String toString(final Tag[] tags) { - if (tags.length == 0) { + if (tags == null || tags.length == 0) { return null; } + if (tags.length == 1) { + return toString(tags[0]); + } final StringBuilder sb = new StringBuilder(); sb.append("<DL><DT><B>"); sb.append(title); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-03 13:56:52
|
Revision: 246 http://svn.sourceforge.net/japi/?rev=246&view=rev Author: christianhujer Date: 2006-12-03 05:56:51 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Whitespace change to build.xml Modified Paths: -------------- libs/argparser/trunk/build.xml Modified: libs/argparser/trunk/build.xml =================================================================== --- libs/argparser/trunk/build.xml 2006-12-02 23:27:43 UTC (rev 245) +++ libs/argparser/trunk/build.xml 2006-12-03 13:56:51 UTC (rev 246) @@ -167,4 +167,5 @@ <tag enabled="true" name="xxx" description="XXX:" /> </javadoc> </target> + </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-02 23:27:45
|
Revision: 245 http://svn.sourceforge.net/japi/?rev=245&view=rev Author: christianhujer Date: 2006-12-02 15:27:43 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Fixed Javadoc issues. Modified Paths: -------------- libs/argparser/trunk/src/doc/examples/Head.java libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java Modified: libs/argparser/trunk/src/doc/examples/Head.java =================================================================== --- libs/argparser/trunk/src/doc/examples/Head.java 2006-12-02 22:52:52 UTC (rev 244) +++ libs/argparser/trunk/src/doc/examples/Head.java 2006-12-02 23:27:43 UTC (rev 245) @@ -109,6 +109,7 @@ /** * Copies the configured number of items from the specified InputStream to System.out. * @param in InputStream to run on + * @throws IOException In case of I/O problems. */ private void copyItems(final InputStream in) throws IOException { if (printBytes) { Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-02 22:52:52 UTC (rev 244) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-02 23:27:43 UTC (rev 245) @@ -22,7 +22,10 @@ /** The maximum width of the option type field. */ private final int maxOptionTypeWidth; - /** @see Command#isExiting() */ + /** + * Whether to exit or not. + * @see Command#isExiting() + */ private boolean exiting; /** Create a BasicCommand. */ @@ -34,7 +37,10 @@ maxOptionTypeWidth = tmpMaxOptionTypeWidth; } - /** Exit Option. */ + /** + * Exit Option. + * @param exiting <code>true</code> if {@link System#exit(int)} should be invoked, otherwise <code>false</code>. + */ @Option(value = {"exit"}) public void setExiting(@NotNull final Boolean exiting) { this.exiting = exiting; Modified: libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java 2006-12-02 22:52:52 UTC (rev 244) +++ libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java 2006-12-02 23:27:43 UTC (rev 245) @@ -57,6 +57,7 @@ * @param delim delimiter to use for joining the strings * @param strings Strings to join * @return Appendable + * @throws IOException In case of I/O problems on <var>dest</var>. */ public static Appendable join(final Appendable dest, final CharSequence delim, final CharSequence... strings) throws IOException { for (int i = 0; i < strings.length; i++) { @@ -74,6 +75,7 @@ * @param delim delimiter to use for joining the strings * @param strings Strings to join * @return Appendable + * @throws IOException In case of I/O problems on <var>dest</var>. */ public static Appendable join(final Appendable dest, final CharSequence delim, final Iterable<? extends CharSequence> strings) throws IOException { return join(dest, delim, strings.iterator()); @@ -85,6 +87,7 @@ * @param delim delimiter to use for joining the strings * @param strings Strings to join * @return Appendable + * @throws IOException In case of I/O problems on <var>dest</var>. */ public static Appendable join(final Appendable dest, final CharSequence delim, final Iterator<? extends CharSequence> strings) throws IOException { if (strings.hasNext()) { Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2006-12-02 22:52:52 UTC (rev 244) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2006-12-02 23:27:43 UTC (rev 245) @@ -39,7 +39,7 @@ } /** - * Tests whether convert throws a NullPointerException if invoked with <code>null</code> + * Tests whether convert throws a NullPointerException if invoked with <code>null</code>. * @throws Exception In case of test problems. */ @SuppressWarnings({"ConstantConditions"}) Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java 2006-12-02 22:52:52 UTC (rev 244) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java 2006-12-02 23:27:43 UTC (rev 245) @@ -12,7 +12,6 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class ConverterRegistryTest { - ConverterRegistry converterRegistry; /** * Tests that creating a new ConverterRegistry works. @@ -20,6 +19,7 @@ */ @Test public void testConverterRegistry() throws Exception { + //noinspection UnusedDeclaration final ConverterRegistry converterRegistry = new ConverterRegistry(); } Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java 2006-12-02 22:52:52 UTC (rev 244) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java 2006-12-02 23:27:43 UTC (rev 245) @@ -6,6 +6,7 @@ /** * Test for {@link NoConverterFoundException}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class NoConverterFoundExceptionTest { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-02 22:52:54
|
Revision: 244 http://svn.sourceforge.net/japi/?rev=244&view=rev Author: christianhujer Date: 2006-12-02 14:52:52 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Added some more tests. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Added Paths: ----------- libs/argparser/trunk/src/test/net/sf/japi/io/args/BasicCommandTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/CommandDummy.java libs/argparser/trunk/src/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/OptionTypeTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/RequiredOptionsMissingExceptionTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/TerminalExceptionTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java Removed Paths: ------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java 2006-12-02 19:01:29 UTC (rev 243) +++ libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java 2006-12-02 22:52:52 UTC (rev 244) @@ -23,6 +23,7 @@ import java.util.ResourceBundle; import java.util.MissingResourceException; import java.util.Locale; +import org.jetbrains.annotations.NotNull; /** * The type of an option. @@ -54,7 +55,7 @@ * Returns the localized name of this OptionType in the default locale if available, otherwise the lowercase enum constant name. * @return The localized name of this OptionType. */ - public String getName() { + @NotNull public String getName() { String name; try { name = ResourceBundle.getBundle("net.sf.japi.io.args.messages").getString(getClass().getName() + "." + name()); @@ -69,7 +70,7 @@ * @param locale Locale * @return The localized name of this OptionType. */ - public String getName(final Locale locale) { + @NotNull public String getName(@NotNull final Locale locale) { String name; try { name = ResourceBundle.getBundle("net.sf.japi.io.args.messages", locale).getString(getClass().getName() + "." + name()); @@ -83,7 +84,7 @@ * {@inheritDoc} * Returns the same as {@link #getName()}. */ - @Override public String toString() { + @NotNull @Override public String toString() { return getName(); } @@ -91,7 +92,7 @@ * Returns the command line description of this option type. * @return The command line description of this option type. */ - public String getDescription() { + @NotNull public String getDescription() { String description; try { description = ResourceBundle.getBundle("net.sf.japi.io.args.messages").getString(getClass().getName() + "." + name() + ".description"); @@ -101,4 +102,19 @@ return description.length() == 0 ? description : " (" + description + ")"; } + /** + * Returns the command line description of this option type. + * @param locale Locale + * @return The command line description of this option type. + */ + @NotNull public String getDescription(@NotNull final Locale locale) { + String description; + try { + description = ResourceBundle.getBundle("net.sf.japi.io.args.messages", locale).getString(getClass().getName() + "." + name() + ".description"); + } catch (final MissingResourceException e) { + description = name(); + } + return description.length() == 0 ? description : " (" + description + ")"; + } + } // OptionType Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-12-02 19:01:29 UTC (rev 243) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -1,5 +1,8 @@ package test.net.sf.japi.io.args; +import java.util.List; +import java.util.Set; +import java.lang.reflect.Method; import net.sf.japi.io.args.ArgParser; import net.sf.japi.io.args.BasicCommand; import net.sf.japi.io.args.MissingArgumentException; @@ -8,10 +11,10 @@ import net.sf.japi.io.args.RequiredOptionsMissingException; import net.sf.japi.io.args.TerminalException; import net.sf.japi.io.args.UnknownOptionException; -import java.util.List; +import net.sf.japi.io.args.Command; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; import org.junit.Test; -import org.junit.Assert; -import org.jetbrains.annotations.NotNull; /** * Test for {@link ArgParser}. @@ -20,72 +23,46 @@ public class ArgParserTest { /** - * This MockCommand serves as a command for performing simple tests. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * Tests whether {@link ArgParser#getOptionMethods(Command)} works. + * @throws Exception (unexpected) */ - public static class MockCommand extends BasicCommand { + @Test + public void testGetOptionMethodsCommand() throws Exception { + final CommandDummy commandDummy = new CommandDummy(); + final Set<Method> optionMethods = ArgParser.getOptionMethods(commandDummy); + Assert.assertFalse(optionMethods.isEmpty()); + } - /** The input option value. */ - private String input; + /** + * Tests whether {@link ArgParser#getOptionMethods(Class)} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetOptionMethodsClass() throws Exception { + final Set<Method> optionMethods = ArgParser.getOptionMethods(CommandDummy.class); + Assert.assertFalse(optionMethods.isEmpty()); + } - /** Remembers whether {@link #run(java.util.List<java.lang.String>)} was called. */ - private boolean runCalled; + /** + * Tests whether {@link ArgParser#simpleParseAndRun(Command, String[])} works. + * @throws Exception (unexpected) + */ + @Test + public void testSimpleParseAndRun() throws Exception { + final CommandDummy commandDummy = new CommandDummy(); + ArgParser.simpleParseAndRun(commandDummy); + } - /** The command line arguments received from the parser. */ - private List<String> args; + /** + * Tests whether {@link ArgParser#parseAndRun(Command, String[])} works. + * @throws Exception (unexpected) + */ + @Test + public void testParseAndRun() throws Exception { + final CommandDummy commandDummy = new CommandDummy(); + ArgParser.parseAndRun(commandDummy); + } - /** {@inheritDoc} */ - @SuppressWarnings({"InstanceMethodNamingConvention"}) - public int run(@NotNull final List<String> args) { - runCalled = true; - this.args = args; - return 0; - } - - /** - * Get the command line arguments. - * @return Command line arguments. - */ - private List<String> getArgs() { - return args; - } - - /** - * Set the value of the input option. - * @param input Value of the input option. - */ - @Option(value = {"i", "input"}, type = OptionType.REQUIRED) - public void setInput(final String input) { - this.input = input; - } - - /** - * Set the value of the foo option. - * @param foo Value of the foo option. - */ - @Option({"f", "b", "foo", "bar", "buzz"}) - public void setFoo(final String foo) { - // ignored - } - - /** - * Get the value of the input option. - * @return Value of the input option. - */ - private String getInput() { - return input; - } - - /** - * Return whether run was called. - * @return whether run was called. - */ - private boolean isRunCalled() { - return runCalled; - } - - } // class MockCommand - /** * Tests whether supplying a required option with argument in short form works. * @throws RequiredOptionsMissingException (unexpected) @@ -141,7 +118,7 @@ * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) */ - @Test(expected=RequiredOptionsMissingException.class) + @Test(expected = RequiredOptionsMissingException.class) public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); try { @@ -158,7 +135,7 @@ * @throws UnknownOptionException (expected) * @throws MissingArgumentException (unexpected) */ - @Test(expected=UnknownOptionException.class) + @Test(expected = UnknownOptionException.class) public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); try { @@ -175,7 +152,7 @@ * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (expected) */ - @Test(expected=MissingArgumentException.class) + @Test(expected = MissingArgumentException.class) public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); try { @@ -214,4 +191,71 @@ ArgParser.parseAndRun(command, "-h"); } + /** + * This MockCommand serves as a command for performing simple tests. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ + public static class MockCommand extends BasicCommand { + + /** The input option value. */ + private String input; + + /** Remembers whether {@link #run(java.util.List<java.lang.String>)} was called. */ + private boolean runCalled; + + /** The command line arguments received from the parser. */ + private List<String> args; + + /** {@inheritDoc} */ + @SuppressWarnings({"InstanceMethodNamingConvention"}) + public int run(@NotNull final List<String> args) { + runCalled = true; + this.args = args; + return 0; + } + + /** + * Get the command line arguments. + * @return Command line arguments. + */ + private List<String> getArgs() { + return args; + } + + /** + * Set the value of the input option. + * @param input Value of the input option. + */ + @Option(value = {"i", "input"}, type = OptionType.REQUIRED) + public void setInput(final String input) { + this.input = input; + } + + /** + * Set the value of the foo option. + * @param foo Value of the foo option. + */ + @Option({"f", "b", "foo", "bar", "buzz"}) + public void setFoo(final String foo) { + // ignored + } + + /** + * Get the value of the input option. + * @return Value of the input option. + */ + private String getInput() { + return input; + } + + /** + * Return whether run was called. + * @return whether run was called. + */ + private boolean isRunCalled() { + return runCalled; + } + + } // class MockCommand + } // class ArgParserTest Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/BasicCommandTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/BasicCommandTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/BasicCommandTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,69 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.BasicCommand; +import org.junit.Assert; +import org.junit.Test; +import java.util.ArrayList; +import java.util.ResourceBundle; + +/** + * Test for {@link BasicCommand}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class BasicCommandTest { + + /** + * Tests whether {@link BasicCommand#BasicCommand()} works. + * @throws Exception (unexpected) + */ + @Test + public void testBasicCommand() throws Exception { + final BasicCommand basicCommand = new CommandDummy(); + Assert.assertEquals(0, basicCommand.run(new ArrayList<String>())); + } + + /** + * Tests whether {@link BasicCommand#setExiting(Boolean)} works. + * @throws Exception (unexpected) + */ + @Test + public void testSetExiting() throws Exception { + final BasicCommand basicCommand = new CommandDummy(); + basicCommand.setExiting(false); + Assert.assertFalse(basicCommand.isExiting()); + basicCommand.setExiting(true); + Assert.assertTrue(basicCommand.isExiting()); + } + + /** + * Tests whether {@link BasicCommand#isExiting()} works. + * @throws Exception (unexpected) + */ + @Test + public void testIsExiting() throws Exception { + testSetExiting(); + } + + /** + * Tests whether {@link BasicCommand#help()} works. + * @throws Exception (unexpected) + */ + @Test + public void testHelp() throws Exception { + final BasicCommand basicCommand = new CommandDummy(); + basicCommand.help(); + } + + /** + * Tests whether {@link BasicCommand#getBundle()} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetBundle() throws Exception { + final BasicCommand basicCommand = new CommandDummy(); + final ResourceBundle bundle = basicCommand.getBundle(); + Assert.assertNotNull(bundle); + } + +} // class BasicCommandTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/BasicCommandTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/CommandDummy.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/CommandDummy.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/CommandDummy.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,19 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.BasicCommand; +import org.jetbrains.annotations.NotNull; +import java.util.List; + +/** + * A simple BasicCommand implementation as a test mock. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +class CommandDummy extends BasicCommand { + + /** {@inheritDoc} */ + @SuppressWarnings({"InstanceMethodNamingConvention"}) + public int run(@NotNull List<String> args) throws Exception { + return 0; + } + +} // class CommandDummy Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/CommandDummy.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,33 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.MissingArgumentException; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link MissingArgumentException}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class MissingArgumentExceptionTest { + + /** + * Tests whether {@link MissingArgumentException#MissingArgumentException(String)} works. + * @throws Exception (unexpected) + */ + @Test + public void testMissingArgumentException() throws Exception { + final MissingArgumentException exception = new MissingArgumentException("foo"); + Assert.assertEquals(exception.getOption(), "foo"); + } + + /** + * Tests whether {@link MissingArgumentException#getOption()} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetOption() throws Exception { + testMissingArgumentException(); + } + +} // class MissingArgumentExceptionTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/OptionTypeTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/OptionTypeTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/OptionTypeTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,54 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.OptionType; +import org.junit.Assert; +import org.junit.Test; +import java.util.Locale; + +/** + * Test for {@link OptionType}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class OptionTypeTest { + + /** + * Tests whether {@link OptionType#getName()} and {@link OptionType#getName(Locale)} work. + * @throws Exception (unexpected) + */ + @Test + public void testGetName() throws Exception { + for (final OptionType optionType : OptionType.values()) { + Assert.assertNotNull(optionType.getName()); + } + for (final OptionType optionType : OptionType.values()) { + Assert.assertNotNull(optionType.getName(Locale.getDefault())); + } + } + + /** + * Tests whether {@link OptionType#toString()} works. + * @throws Exception (unexpected) + */ + @Test + public void testToString() throws Exception { + for (final OptionType optionType : OptionType.values()) { + Assert.assertNotNull(optionType.toString()); + } + } + + /** + * Tests whether {@link OptionType#getDescription()} and {@link OptionType#getDescription(Locale)} work. + * @throws Exception (unexpected) + */ + @Test + public void testGetDescription() throws Exception { + for (final OptionType optionType : OptionType.values()) { + Assert.assertNotNull(optionType.getDescription()); + } + for (final OptionType optionType : OptionType.values()) { + Assert.assertNotNull(optionType.getDescription(Locale.getDefault())); + } + } + +} // class OptionTypeTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/OptionTypeTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/RequiredOptionsMissingExceptionTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/RequiredOptionsMissingExceptionTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/RequiredOptionsMissingExceptionTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,35 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.RequiredOptionsMissingException; +import org.junit.Assert; +import org.junit.Test; +import java.util.Arrays; + +/** + * Test for {@link RequiredOptionsMissingException}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class RequiredOptionsMissingExceptionTest { + + /** + * Tests whether {@link RequiredOptionsMissingException#RequiredOptionsMissingException(String[])} works. + * @throws Exception (unexpected) + */ + @Test + public void testRequiredOptionsMissingException() throws Exception { + final String[] options = { "foo", "bar" }; + final RequiredOptionsMissingException exception = new RequiredOptionsMissingException(options.clone()); + Assert.assertTrue(Arrays.equals(exception.getMissingOptions(), options)); + } + + /** + * Tests whether {@link RequiredOptionsMissingException#getMissingOptions()} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetMissingOptions() throws Exception { + testRequiredOptionsMissingException(); + } + +} // class RequiredOptionsMissingExceptionTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/RequiredOptionsMissingExceptionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,59 @@ +package test.net.sf.japi.io.args; + +import java.util.Arrays; +import net.sf.japi.io.args.StringJoiner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +/** + * Test for {@link StringJoiner}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class StringJoinerTest { + + /** + * Expected String. + */ + private static final String EXPECTED = "foo, bar, buzz"; + + /** + * Argument values. + */ + private static final String[] ARGS = {"foo", "bar", "buzz"}; + + /** + * Tests whether {@link StringJoiner#join(CharSequence,CharSequence...)} works. + */ + @Test + public void testJoinCSCS() { + final String[] nargs = ARGS.clone(); + final String actual = StringJoiner.join(", ", nargs); + assertEquals("arguments must be joined correctly.", EXPECTED, actual); + assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); + } + + /** + * Tests whether {@link StringJoiner#join(CharSequence,Iterable<? extends java.lang.CharSequence>)} works. + */ + @Test + public void testJoinCSIe() { + final String[] nargs = ARGS.clone(); + final String actual = StringJoiner.join(", ", Arrays.asList(nargs)); + assertEquals("arguments must be joined correctly.", EXPECTED, actual); + assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); + } + + /** + * Tests whether {@link StringJoiner#join(CharSequence,java.util.Iterator<? extends java.lang.CharSequence>)} works. + */ + @Test + public void testJoinCSIr() { + final String[] nargs = ARGS.clone(); + final String actual = StringJoiner.join(", ", Arrays.asList(nargs).iterator()); + assertEquals("arguments must be joined correctly.", EXPECTED, actual); + assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); + } + +} // class StringJoinerTest Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Deleted: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-12-02 19:01:29 UTC (rev 243) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-12-02 22:52:52 UTC (rev 244) @@ -1,58 +0,0 @@ -package test.net.sf.japi.io.args; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; -import net.sf.japi.io.args.StringJoiner; -import org.junit.Test; - -import java.util.Arrays; - -/** - * TestCase for {@link StringJoiner}. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class StringJoinerTestCase { - - /** Expected String. */ - private static final String EXPECTED = "foo, bar, buzz"; - - /** Argument values. */ - private static final String[] ARGS = { "foo", "bar", "buzz" }; - - /** - * Empty constructor for JUnit. - */ - public StringJoinerTestCase() { - } - - /** - * Tests whether {@link StringJoiner#join(CharSequence, CharSequence...)} works. - */ - @Test public void testJoinCSCS() { - final String[] nargs = ARGS.clone(); - final String actual = StringJoiner.join(", ", nargs); - assertEquals("arguments must be joined correctly.", EXPECTED, actual); - assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); - } - - /** - * Tests whether {@link StringJoiner#join(CharSequence, Iterable<? extends java.lang.CharSequence>)} works. - */ - @Test public void testJoinCSIe() { - final String[] nargs = ARGS.clone(); - final String actual = StringJoiner.join(", ", Arrays.asList(nargs)); - assertEquals("arguments must be joined correctly.", EXPECTED, actual); - assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); - } - - /** - * Tests whether {@link StringJoiner#join(CharSequence, java.util.Iterator<? extends java.lang.CharSequence>)} works. - */ - @Test public void testJoinCSIr() { - final String[] nargs = ARGS.clone(); - final String actual = StringJoiner.join(", ", Arrays.asList(nargs).iterator()); - assertEquals("arguments must be joined correctly.", EXPECTED, actual); - assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); - } - -} // class StringJoinerTestCase Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/TerminalExceptionTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/TerminalExceptionTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/TerminalExceptionTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,34 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.TerminalException; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link TerminalException}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class TerminalExceptionTest { + + /** + * Tests whether {@link TerminalException#TerminalException()} works. + * @throws Exception (unexpected) + */ + @Test + public void testTerminalException() throws Exception { + final TerminalException exception = new TerminalException(); + Assert.assertEquals(exception.getReturnCode(), 0); + } + + /** + * Tests whether {@link TerminalException#getReturnCode()} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetReturnCode() throws Exception { + final TerminalException exception = new TerminalException(1); + Assert.assertEquals(exception.getReturnCode(), 1); + } + +} // class TerminalExceptionTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/TerminalExceptionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java 2006-12-02 22:52:52 UTC (rev 244) @@ -0,0 +1,35 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.UnknownOptionException; +import org.junit.Assert; +import org.junit.Test; +import java.util.Arrays; + +/** + * Test for {@link UnknownOptionException}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class UnknownOptionExceptionTest { + + /** + * Tests whether {@link UnknownOptionException#UnknownOptionException(String[])} works. + * @throws Exception (unexpected) + */ + @Test + public void testUnknownOptionException() throws Exception { + final String[] options = { "foo", "bar" }; + final UnknownOptionException exception = new UnknownOptionException(options.clone()); + Assert.assertTrue(Arrays.equals(options, exception.getUnknownOptions())); + } + + /** + * Tests whether {@link UnknownOptionException#getUnknownOptions()} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetUnknownOptions() throws Exception { + testUnknownOptionException(); + } + +} // class UnknownOptionExceptionTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-02 19:01:38
|
Revision: 243 http://svn.sourceforge.net/japi/?rev=243&view=rev Author: christianhujer Date: 2006-12-02 11:01:29 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Added more tests, improved existing tests. Now all non-deprecated converter classes have 100% method coverage in unit test. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java Added Paths: ----------- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2006-12-02 19:01:29 UTC (rev 243) @@ -31,15 +31,29 @@ } /** + * Tests whether creating a Converter works. + * @throws Exception (unexpected) + */ + public void testAbstractConverter() throws Exception { + // Tested by the constructor. + } + + /** * Tests whether convert throws a NullPointerException if invoked with <code>null</code> - * @throws NullPointerException Expected exception that's thrown if the test case is successful. * @throws Exception In case of test problems. */ @SuppressWarnings({"ConstantConditions"}) - @Test(expected=NullPointerException.class) - public void testThrowsNPE() throws Exception { - converter.convert(null); + public void testConvertThrowsNPE() throws Exception { + try { + converter.convert(null); + Assert.fail("Expected exception IllegalArgumentException or NullPointerException but got no exception when invoking convert(null)."); + } catch (final IllegalArgumentException ignore) { + // expected Exception if compiled with @NotNull support + } catch (final NullPointerException ignore) { + // expected Exception if compiled without @NotNull support + } } + /** * Tests whether getting the target class works. * @throws Exception In case of test problems. @@ -54,7 +68,7 @@ * @throws Exception In case of unexpected errors. */ @Test - public void testDescription() throws Exception { + public void testGetDescription() throws Exception { final String description = converter.getDescription(); Assert.assertNotNull(description); Assert.assertTrue(description.length() > 0); @@ -66,7 +80,7 @@ * @throws Exception In case of unexpected errors. */ @Test - public void testDisplayName() throws Exception { + public void testGetDisplayName() throws Exception { final String displayName = converter.getDisplayName(); Assert.assertNotNull(displayName); Assert.assertTrue(displayName.length() > 0); Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java 2006-12-02 19:01:29 UTC (rev 243) @@ -19,6 +19,15 @@ } /** + * Tests whether instanciating a BooleanConverter works. + * @throws Exception (unexpected) + */ + @Test + public void testBooleanConverter() throws Exception { + // Tested by this test class's superclass constructor. + } + + /** * Tests whether convert works for true. * @throws Exception In case of unexpected errors. */ Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java 2006-12-02 19:01:29 UTC (rev 243) @@ -0,0 +1,129 @@ +package test.net.sf.japi.io.args.converter; + +import net.sf.japi.io.args.converter.ConverterRegistry; +import net.sf.japi.io.args.converter.Converter; +import org.junit.Test; +import org.junit.Assert; +import org.jetbrains.annotations.NotNull; +import java.util.Locale; + +/** + * Test for {@link ConverterRegistry}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class ConverterRegistryTest { + ConverterRegistry converterRegistry; + + /** + * Tests that creating a new ConverterRegistry works. + * @throws Exception (unexpected) + */ + @Test + public void testConverterRegistry() throws Exception { + final ConverterRegistry converterRegistry = new ConverterRegistry(); + } + + /** + * Tests whether {@link ConverterRegistry#getInstance()} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetInstance() throws Exception { + final ConverterRegistry converterRegistry = ConverterRegistry.getInstance(); + Assert.assertNotNull("ConverterRegistry.getInstance() must not return null.", converterRegistry); + } + + /** + * Tests whether {@link ConverterRegistry#getConverter(Class)} works. + * @throws Exception (unexpected) + */ + @Test + public void testGetConverter() throws Exception { + final ConverterRegistry converterRegistry = new ConverterRegistry(); + final Converter<String> converter = new DummyConverter<String>(String.class); + converterRegistry.register(converter); + Assert.assertSame(converterRegistry.getConverter(String.class), converter); + } + + /** + * Tests whether {@link ConverterRegistry#register(Converter)} works. + * @throws Exception (unexpected) + */ + @Test + public void testRegister() throws Exception { + // see #testGetConverter(); + } + + /** + * Tests whether {@link ConverterRegistry#convert(Class, String)} and {@link ConverterRegistry#convert(Class, Locale, String)} work. + * @throws Exception (unexpected) + */ + @Test + public void testConvert() throws Exception { + Assert.assertEquals("foo", ConverterRegistry.convert(String.class, "foo")); + Assert.assertEquals("foo", ConverterRegistry.convert(String.class, Locale.GERMANY, "foo")); + } + + /** + * Dummy Converter. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ + @SuppressWarnings({"ConstantConditions"}) + private static class DummyConverter<T> implements Converter<T> { + + /** Class for this converter. */ + private final Class<T> targetClass; + + /** + * Create a DummyConverter. + * @param targetClass Target class. + */ + private DummyConverter(final Class<T> targetClass) { + this.targetClass = targetClass; + } + + /** {@inheritDoc} */ + @NotNull + public T convert(@NotNull String arg) throws Exception { + return null; + } + + /** {@inheritDoc} */ + @NotNull + public T convert(@NotNull Locale locale, @NotNull String arg) throws Exception { + return null; + } + + /** {@inheritDoc} */ + @NotNull + public Class<T> getTargetClass() { + return targetClass; + } + + /** {@inheritDoc} */ + @NotNull + public String getDisplayName() { + return null; + } + + /** {@inheritDoc} */ + @NotNull + public String getDisplayName(@NotNull Locale locale) { + return null; + } + + /** {@inheritDoc} */ + @NotNull + public String getDescription() { + return null; + } + + /** {@inheritDoc} */ + @NotNull + public String getDescription(@NotNull Locale locale) { + return null; + } + + } // class DummyConverter + +} // class ConverterRegistryTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java 2006-12-02 19:01:29 UTC (rev 243) @@ -19,11 +19,20 @@ } /** + * Tests whether instanciating a IntegerConverter works. + * @throws Exception (unexpected) + */ + @Test + public void testIntegerConverter() throws Exception { + // Tested by this test class's superclass constructor. + } + + /** * Tests whether converting an arbitrary text throws a NumberFormatException. * @throws NumberFormatException Expected exception that's thrown if the test case is successful. */ @Test(expected=NumberFormatException.class) - public void convertWithText() throws Exception { + public void testConvertWithText() throws Exception { converter.convert("foo"); } @@ -32,7 +41,7 @@ * @throws Exception In case of unexpected errors. */ @Test - public void convertDecimalNumbers() throws Exception { + public void testConvertDecimalNumbers() throws Exception { for (final int number : new int[] { Integer.MIN_VALUE, -100, -1, 0, 1, 100, Integer.MAX_VALUE }) { Assert.assertEquals(number, converter.convert(Integer.toString(number))); } @@ -43,7 +52,7 @@ * @throws Exception In case of unexpected errors. */ @Test - public void convertHexadecimalNumbers() throws Exception { + public void testConvertHexadecimalNumbers() throws Exception { Assert.assertEquals(0x50000, converter.convert("0x50000")); Assert.assertEquals(0x50000, converter.convert("0X50000")); Assert.assertEquals(0x50000, converter.convert("#50000")); @@ -54,7 +63,7 @@ * @throws Exception In case of unexpected errors. */ @Test - public void convertOctalNumbers() throws Exception { + public void testConvertOctalNumbers() throws Exception { Assert.assertEquals(0x1ff, converter.convert("0777")); } Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java 2006-12-02 19:01:29 UTC (rev 243) @@ -0,0 +1,31 @@ +package test.net.sf.japi.io.args.converter; + +import net.sf.japi.io.args.converter.NoConverterFoundException; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link NoConverterFoundException}. + */ +public class NoConverterFoundExceptionTest { + + /** + * Tests whether the target type is stored correctly. + * @throws Exception (unexpected) + */ + @Test + public void testGetTargetType() throws Exception { + final NoConverterFoundException exception = new NoConverterFoundException(Object.class); + Assert.assertSame(exception.getTargetType(), Object.class); + } + + /** + * Tests whether the target type is stored correctly. + * @throws Exception (unexpected) + */ + @Test + public void testNoConverterFoundException() throws Exception { + testGetTargetType(); + } + +} // class NoConverterFoundExceptionTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/NoConverterFoundExceptionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java 2006-12-02 19:01:29 UTC (rev 243) @@ -19,11 +19,20 @@ } /** + * Tests whether instanciating a StringConverter works. + * @throws Exception (unexpected) + */ + @Test + public void testStringConverter() throws Exception { + // Tested by this test class's superclass constructor. + } + + /** * Tests whether {@link StringConverter} has a public default constructor. * @throws Exception In case of unexpected errors. */ @Test - public void testOperation() throws Exception { + public void testConvert() throws Exception { final String foo = converter.convert("foo"); Assert.assertEquals("StringConverter.convert(\"foo\") must return \"foo\".", "foo", foo); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-02 16:15:13
|
Revision: 242 http://svn.sourceforge.net/japi/?rev=242&view=rev Author: christianhujer Date: 2006-12-02 08:15:10 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Improved converters, added some test cases. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Added Paths: ----------- libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.properties libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter_de.properties libs/argparser/trunk/src/net/sf/japi/io/args/converter/NoConverterFoundException.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/OututStreamConverter.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Option.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-12-02 16:15:10 UTC (rev 242) @@ -37,6 +37,7 @@ /** * The option type. * Default is {@link OptionType#OPTIONAL}. + * Normally you wouldn't change this. * @return option type */ OptionType type() default OptionType.OPTIONAL; Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -2,37 +2,53 @@ import java.util.Locale; import java.util.ResourceBundle; +import org.jetbrains.annotations.NotNull; /** * Base class for the default converters. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -abstract class AbstractConverter<T> implements Converter<T> { +public abstract class AbstractConverter<T> implements Converter<T> { /** The target class. */ - private final Class<T> targetClass; + @NotNull private final Class<T> targetClass; /** * Create an AbstractConverter. * @param targetClass TargetClass */ - AbstractConverter(final Class<T> targetClass) { + AbstractConverter(@NotNull final Class<T> targetClass) { this.targetClass = targetClass; } /** {@inheritDoc} */ - public final Class<T> getTargetClass() { + @NotNull public final Class<T> getTargetClass() { return targetClass; } /** {@inheritDoc} */ - public final String getDisplayName() { - return ResourceBundle.getBundle("net.sf.japi.io.args.converter.names").getString(targetClass.getName()); + @NotNull public final T convert(@NotNull final String arg) throws Exception { + return convert(Locale.getDefault(), arg); } /** {@inheritDoc} */ - public final String getDisplayName(final Locale locale) { - return ResourceBundle.getBundle("net.sf.japi.io.args.converter.names", locale).getString(targetClass.getName()); + @NotNull public final String getDisplayName() { + return getDisplayName(Locale.getDefault()); } + /** {@inheritDoc} */ + @NotNull public final String getDisplayName(@NotNull final Locale locale) { + return ResourceBundle.getBundle("net.sf.japi.io.args.converter.Converter", locale).getString(targetClass.getName() + ".displayName"); + } + + /** {@inheritDoc} */ + @NotNull public final String getDescription() { + return getDescription(Locale.getDefault()); + } + + /** {@inheritDoc} */ + @NotNull public final String getDescription(@NotNull final Locale locale) { + return ResourceBundle.getBundle("net.sf.japi.io.args.converter.Converter", locale).getString(targetClass.getName() + ".description"); + } + } // class AbstractConverter Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -1,11 +1,21 @@ package net.sf.japi.io.args.converter; +import org.jetbrains.annotations.NotNull; +import java.util.Locale; +import java.util.ResourceBundle; + /** * Converter which converts a String into a Boolean. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class BooleanConverter extends AbstractConverter<Boolean> { + /** Strings for true. */ + private static final String[] TRUE_STRINGS = { "true", "yes", "on", "1" }; + + /** Strings for true. */ + private static final String[] FALSE_STRINGS = { "false", "no", "off", "0" }; + /** * Create a BooleanConverter. */ @@ -14,8 +24,29 @@ } /** {@inheritDoc} */ - public Boolean convert(final String arg) throws Exception { - return Boolean.valueOf(arg); + @NotNull + public Boolean convert(@NotNull final Locale locale, @NotNull final String arg) throws Exception { + for (final String s : TRUE_STRINGS) { + if (s.equalsIgnoreCase(arg)) { + return Boolean.TRUE; + } + } + for (final String s : FALSE_STRINGS) { + if (s.equalsIgnoreCase(arg)) { + return Boolean.FALSE; + } + } + for (final String s : ResourceBundle.getBundle("net.sf.japi.io.args.converter.Converter", locale).getString("java.lang.Boolean.true").split("\\s+")) { + if (s.equalsIgnoreCase(arg)) { + return Boolean.TRUE; + } + } + for (final String s : ResourceBundle.getBundle("net.sf.japi.io.args.converter.Converter", locale).getString("java.lang.Boolean.false").split("\\s+")) { + if (s.equalsIgnoreCase(arg)) { + return Boolean.TRUE; + } + } + throw new IllegalArgumentException(arg + " is not a valid String for a boolean."); } } // class BooleanConverter Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -1,6 +1,7 @@ package net.sf.japi.io.args.converter; import java.util.Locale; +import org.jetbrains.annotations.NotNull; /** * The Converter interface is used for converters that convert Strings into other types. @@ -13,26 +14,50 @@ * @param arg Argument to convert * @return Argument converted to T. * @throws Exception In case of conversion failure. + * @throws NullPointerException In case <code><var>arg</var> == null</code>. */ - T convert(final String arg) throws Exception; + @NotNull T convert(@NotNull final String arg) throws Exception; /** + * Convert the given argument to the desired return type. + * @param arg Argument to convert + * @param locale Locale to get perform conversion for. + * @return Argument converted to T. + * @throws Exception In case of conversion failure. + * @throws NullPointerException In case <code><var>arg</var> == null</code>. + */ + @NotNull T convert(@NotNull final Locale locale, @NotNull final String arg) throws Exception; + + /** * Returns the Class this Converter is for. * @return The Class this Converter is for. */ - Class<T> getTargetClass(); + @NotNull Class<T> getTargetClass(); /** * Returns a display name for the type of this Converter. * @return A display name for the type of this Converter. */ - String getDisplayName(); + @NotNull String getDisplayName(); /** * Returns a display name for the type of this Converter. * @param locale Locale to get display name for. * @return A display name for the type of this Converter in the specified locale. */ - String getDisplayName(final Locale locale); + @NotNull String getDisplayName(@NotNull final Locale locale); + /** + * Returns a description for this Converter. + * @return A description for this Converter. + */ + @NotNull String getDescription(); + + /** + * Returns a description for this Converter. + * @param locale Locale to get the description for. + * @return A description for this Converter in the specified locale. + */ + @NotNull String getDescription(@NotNull final Locale locale); + } // interface Convert Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.properties =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.properties (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.properties 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,12 @@ +java.io.InputStream.displayName=uri|filename|- +java.io.InputStream.description=Input file (URI, filename or - for STDIN). +java.io.OutputStream.displayName=filename|- +java.io.OutputStream.description=Output file (filename or - for STDOUT). +java.lang.Boolean.displayName=boolean +java.lang.Boolean.description=Valid values are: {0} for true and {1} for false. +java.lang.Boolean.true= +java.lang.Boolean.false= +java.lang.Integer.displayName=integer +java.lang.Integer.description=Integer number (decimal, 0... octal, 0x... 0X... #... hexadecimal) +java.lang.String.displayName=string +java.lang.String.description=Simple text \ No newline at end of file Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.properties ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java 2006-12-02 16:15:10 UTC (rev 242) @@ -3,7 +3,10 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Locale; import sun.misc.Service; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Registry for Converters. @@ -11,15 +14,15 @@ */ public class ConverterRegistry { - /** Singleton instance. */ - private static final ConverterRegistry instance = createSingletonInstance(); + /** Singleton INSTANCE. */ + private static final ConverterRegistry INSTANCE = createSingletonInstance(); /** Map for converters. */ private final Map<Class<?>, Converter<?>> converters = new HashMap<Class<?>, Converter<?>>(); /** * Creates a ConverterRegistry. - * Usually you want a shared global ConverterRegistry and use {@link #getInstance()} instead of creating your own ConverterRegistry instance. + * Usually you want a shared global ConverterRegistry and use {@link #getInstance()} instead of creating your own ConverterRegistry INSTANCE. * @see #getInstance() */ public ConverterRegistry() { @@ -29,6 +32,7 @@ * Creates the global shared instance of ConverterRegistry. * @return The global shared instance of ConverterRegistry. */ + @SuppressWarnings({"unchecked"}) private static ConverterRegistry createSingletonInstance() { final ConverterRegistry instance = new ConverterRegistry(); for (final Iterator<Converter<?>> converters = Service.providers(Converter.class); converters.hasNext();) { @@ -42,7 +46,7 @@ * @return The global shared instance of ConverterRegistry. */ public static ConverterRegistry getInstance() { - return instance; + return INSTANCE; } /** @@ -50,7 +54,8 @@ * @param clazz Class to get Converter for. * @return <code>null</code> if no suited converter was found. */ - public <T> Converter<T> getConverter(final Class<T> clazz) { + @Nullable public <T> Converter<T> getConverter(@NotNull final Class<T> clazz) { + //noinspection unchecked return (Converter<T>) converters.get(clazz); } @@ -58,7 +63,7 @@ * Register a Converter for a specific class. * @param converter Converter to register */ - public <T> void register(final Converter<T> converter) { + public <T> void register(@NotNull final Converter<T> converter) { converters.put(converter.getTargetClass(), converter); for (Class<?> superClass = converter.getTargetClass(); (superClass = superClass.getSuperclass()) != null;) { if (!converters.containsKey(superClass)) { @@ -79,8 +84,30 @@ * @return Converted String in the desired target type. * @throws Exception in case the conversion failed. */ - public static <T> T convert(final Class<T> targetType, final String s) throws Exception { - return getInstance().getConverter(targetType).convert(s); + @NotNull public static <T> T convert(@NotNull final Class<T> targetType, @NotNull final String s) throws Exception { + final Converter<T> converter = getInstance().getConverter(targetType); + if (converter != null) { + return converter.convert(s); + } else { + throw new NoConverterFoundException(targetType); + } } + /** + * Convenience method to convert a String to the desired target type using the default ConverterRegistry. + * @param targetType target type to convert to. + * @param locale Locale to perform the conversion in. + * @param s String to convert. + * @return Converted String in the desired target type. + * @throws Exception in case the conversion failed. + */ + @NotNull public static <T> T convert(@NotNull final Class<T> targetType, @NotNull final Locale locale, @NotNull final String s) throws Exception { + final Converter<T> converter = getInstance().getConverter(targetType); + if (converter != null) { + return converter.convert(locale, s); + } else { + throw new NoConverterFoundException(targetType); + } + } + } // class ConverterRegistry Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter_de.properties =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter_de.properties (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter_de.properties 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,7 @@ +java.io.InputStream.description=Eingabedatei (als URI, Dateiname oder - f\xFCr STDIN). +java.io.OutputStream.description=Ausgabedatei (Dateiname oder - f\xFCr STDOUT). +java.lang.Boolean.description=G\xFCltige Werte: {0} f\xFCr wahr und {1} f\xFCr falsch. +java.lang.Boolean.true=wahr ja an +java.lang.Boolean.false=falsch nein aus +java.lang.Integer.description=Ganzzahl (dezimal, 0... oktal, 0x... 0X... #... hexadezimal) +java.lang.String.description=Einfacher Text. Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter_de.properties ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -5,12 +5,16 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Locale; +import org.jetbrains.annotations.NotNull; /** * Converter that converts a String into an InputStream. + * @note This converter always behaves the same independently of the {@link Locale}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @deprecated The concept of this class is not yet mature. Please don't use it. */ -public class InputStreamConverter extends AbstractConverter<InputStream> { +@Deprecated public class InputStreamConverter extends AbstractConverter<InputStream> { /** * Create an InputStreamConverter. @@ -20,11 +24,19 @@ } /** {@inheritDoc} */ - public InputStream convert(final String arg) throws FileNotFoundException { + @NotNull public InputStream convert(@NotNull final Locale locale, @NotNull final String arg) throws FileNotFoundException { try { return new URL(arg).openStream(); } catch (final IOException ignore) { - return new FileInputStream(arg); + try { + return new FileInputStream(arg); + } catch (final FileNotFoundException e) { + if ("-".equals(arg)) { + return System.in; + } else { + throw e; + } + } } } Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -1,8 +1,15 @@ package net.sf.japi.io.args.converter; +import org.jetbrains.annotations.NotNull; +import java.util.Locale; + /** * Converter which converts a String into a an Integer. + * The Converter uses a method that at minimum supports the same conversions as {@link Integer#decode(String)}. + * That means the following formats are supported: + * @note This converter always behaves the same independently of the {@link Locale}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @see Integer#decode(String) Minimum grammar supported. */ public class IntegerConverter extends AbstractConverter<Integer> { @@ -14,8 +21,8 @@ } /** {@inheritDoc} */ - public Integer convert(final String arg) throws Exception { - return Integer.valueOf(arg); + @NotNull public Integer convert(@NotNull final Locale locale, @NotNull final String arg) throws NumberFormatException { + return Integer.decode(arg); } } // class IntegerConverter Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/NoConverterFoundException.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/NoConverterFoundException.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/NoConverterFoundException.java 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,30 @@ +package net.sf.japi.io.args.converter; + +/** + * Exception that is thrown in case no matching converter for a conversion was found. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class NoConverterFoundException extends Exception { + + /** + * The type for that no Converter was found. + */ + private final Class<?> targetType; + + /** + * Create a NoConverterFoundException. + * @param targetType Type for that no Converter was found. + */ + public NoConverterFoundException(final Class<?> targetType) { + this.targetType = targetType; + } + + /** + * Returns the type for that no Converter was found. + * @return The type for that no Converter was found. + */ + public Class<?> getTargetType() { + return targetType; + } + +} // class NoConverterFoundException Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/NoConverterFoundException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/OututStreamConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/OututStreamConverter.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/OututStreamConverter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,34 @@ +package net.sf.japi.io.args.converter; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.Locale; +import org.jetbrains.annotations.NotNull; + +/** + * Converter that converts a String into an InputStream. + * @note This converter always behaves the same independently of the {@link Locale}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @deprecated The concept of this class is not yet mature. Please don't use it. + */ +@Deprecated public class OututStreamConverter extends AbstractConverter<OutputStream> { + + /** + * Create an InputStreamConverter. + */ + public OututStreamConverter() { + super(OutputStream.class); + } + + /** {@inheritDoc} */ + @NotNull public OutputStream convert(@NotNull final Locale locale, @NotNull final String arg) throws FileNotFoundException { + if ("-".equals(arg) && !new File("-").exists()) { + return System.out; + } else { + return new FileOutputStream(arg); + } + } + +} // class InputStreamConverter Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/OututStreamConverter.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java 2006-12-02 16:15:10 UTC (rev 242) @@ -1,7 +1,12 @@ package net.sf.japi.io.args.converter; +import org.jetbrains.annotations.NotNull; +import java.util.Locale; + /** - * Dummy Converter which "converts" a String into a String by simply returning it. + * Simple Converter which "converts" a String into a String by simply returning it. + * It exists to be able to apply the same conversion pattern for all types including Strings. + * @note This converter always behaves the same independently of the {@link Locale}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class StringConverter extends AbstractConverter<String> { @@ -14,7 +19,7 @@ } /** {@inheritDoc} */ - public String convert(final String arg) throws Exception { + @NotNull public String convert(@NotNull final Locale locale, @NotNull final String arg) throws Exception { return arg; } Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-29 23:09:22 UTC (rev 241) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-12-02 16:15:10 UTC (rev 242) @@ -54,7 +54,7 @@ * Set the value of the input option. * @param input Value of the input option. */ - @Option(type = OptionType.REQUIRED, value = {"i", "input"}) + @Option(value = {"i", "input"}, type = OptionType.REQUIRED) public void setInput(final String input) { this.input = input; } @@ -63,7 +63,7 @@ * Set the value of the foo option. * @param foo Value of the foo option. */ - @Option(value = {"f", "b", "foo", "bar", "buzz"}) + @Option({"f", "b", "foo", "bar", "buzz"}) public void setFoo(final String foo) { // ignored } Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,76 @@ +package test.net.sf.japi.io.args.converter; + +import java.util.Locale; +import net.sf.japi.io.args.converter.Converter; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; +import org.junit.Test; + +/** + * Base class for tests for Converters. + * Provides some basic testing methods. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class AbstractConverterTest<V, T extends Converter<V>> { + + /** The target class. */ + private Class<V> targetClass; + + /** The converter testling. */ + protected T converter; + + /** + * Create an AbstractConverterTest. + * @param targetClass Class of the Converter's target to test. + * @param converterClass Class of the Converter to test. + * @throws Exception in case of setup problems. + */ + protected AbstractConverterTest(@NotNull final Class<V> targetClass, @NotNull final Class<T> converterClass) throws Exception { + this.targetClass = targetClass; + converter = converterClass.newInstance(); + } + + /** + * Tests whether convert throws a NullPointerException if invoked with <code>null</code> + * @throws NullPointerException Expected exception that's thrown if the test case is successful. + * @throws Exception In case of test problems. + */ + @SuppressWarnings({"ConstantConditions"}) + @Test(expected=NullPointerException.class) + public void testThrowsNPE() throws Exception { + converter.convert(null); + } + /** + * Tests whether getting the target class works. + * @throws Exception In case of test problems. + */ + @Test + public void testGetTargetClass() throws Exception { + Assert.assertSame(targetClass, converter.getTargetClass()); + } + + /** + * Tests whether the testling has a proper description for the default locale. + * @throws Exception In case of unexpected errors. + */ + @Test + public void testDescription() throws Exception { + final String description = converter.getDescription(); + Assert.assertNotNull(description); + Assert.assertTrue(description.length() > 0); + Assert.assertEquals(description, converter.getDescription(Locale.getDefault())); + } + + /** + * Tests whether the testling has a proper display name. + * @throws Exception In case of unexpected errors. + */ + @Test + public void testDisplayName() throws Exception { + final String displayName = converter.getDisplayName(); + Assert.assertNotNull(displayName); + Assert.assertTrue(displayName.length() > 0); + Assert.assertEquals(displayName, converter.getDisplayName(Locale.getDefault())); + } + +} // class AbstractConverterTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/AbstractConverterTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,55 @@ +package test.net.sf.japi.io.args.converter; + +import net.sf.japi.io.args.converter.BooleanConverter; +import org.junit.Test; +import org.junit.Assert; + +/** + * Tests for {@link BooleanConverter}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class BooleanConverterTest extends AbstractConverterTest<Boolean, BooleanConverter> { + + /* + * Create an BooleanConverterTest. + * @throws Exception in case of setup problems. + */ + public BooleanConverterTest() throws Exception { + super(Boolean.class, BooleanConverter.class); + } + + /** + * Tests whether convert works for true. + * @throws Exception In case of unexpected errors. + */ + @Test + public void testConvertTrue() throws Exception { + Assert.assertTrue(converter.convert("true")); + Assert.assertTrue(converter.convert("TRUE")); + Assert.assertTrue(converter.convert("True")); + Assert.assertTrue(converter.convert("1")); + } + + /** + * Tests whether convert works for true. + * @throws Exception In case of unexpected errors. + */ + @Test + public void testConvertFalse() throws Exception { + Assert.assertFalse(converter.convert("false")); + Assert.assertFalse(converter.convert("FALSE")); + Assert.assertFalse(converter.convert("False")); + Assert.assertFalse(converter.convert("0")); + } + + /** + * Tests whether convert works for other Strings (IllegalArgumentException must be thrown). + * @throws IllegalArgumentException Expected exception that's thrown if the test case is successful. + * @throws Exception In case of unexpected errors. + */ + @Test(expected=IllegalArgumentException.class) + public void testConvertOther() throws Exception { + converter.convert("foobarbuzz"); + } + +} // class BooleanConverterTest Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/BooleanConverterTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,61 @@ +package test.net.sf.japi.io.args.converter; + +import net.sf.japi.io.args.converter.IntegerConverter; +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests for {@link IntegerConverter}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class IntegerConverterTest extends AbstractConverterTest<Integer, IntegerConverter> { + + /** + * Create an IntegerConverterTest. + * @throws Exception in case of setup problems. + */ + public IntegerConverterTest() throws Exception { + super(Integer.class, IntegerConverter.class); + } + + /** + * Tests whether converting an arbitrary text throws a NumberFormatException. + * @throws NumberFormatException Expected exception that's thrown if the test case is successful. + */ + @Test(expected=NumberFormatException.class) + public void convertWithText() throws Exception { + converter.convert("foo"); + } + + /** + * Tests whether converting decimal (10-base) integer numbers works correclty. + * @throws Exception In case of unexpected errors. + */ + @Test + public void convertDecimalNumbers() throws Exception { + for (final int number : new int[] { Integer.MIN_VALUE, -100, -1, 0, 1, 100, Integer.MAX_VALUE }) { + Assert.assertEquals(number, converter.convert(Integer.toString(number))); + } + } + + /** + * Tests whether converting hexadecimal (16-base) integer numbers works correctly. + * @throws Exception In case of unexpected errors. + */ + @Test + public void convertHexadecimalNumbers() throws Exception { + Assert.assertEquals(0x50000, converter.convert("0x50000")); + Assert.assertEquals(0x50000, converter.convert("0X50000")); + Assert.assertEquals(0x50000, converter.convert("#50000")); + } + + /** + * Tests whether converting octal (8-base) integer numbers works correctly. + * @throws Exception In case of unexpected errors. + */ + @Test + public void convertOctalNumbers() throws Exception { + Assert.assertEquals(0x1ff, converter.convert("0777")); + } + +} // class IntegerConverterTest \ No newline at end of file Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/IntegerConverterTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java 2006-12-02 16:15:10 UTC (rev 242) @@ -0,0 +1,31 @@ +package test.net.sf.japi.io.args.converter; + +import net.sf.japi.io.args.converter.StringConverter; +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests for {@link StringConverter}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class StringConverterTest extends AbstractConverterTest<String, StringConverter> { + + /** + * Create a StringConverterTest. + * @throws Exception in case of setup problems. + */ + public StringConverterTest() throws Exception { + super(String.class, StringConverter.class); + } + + /** + * Tests whether {@link StringConverter} has a public default constructor. + * @throws Exception In case of unexpected errors. + */ + @Test + public void testOperation() throws Exception { + final String foo = converter.convert("foo"); + Assert.assertEquals("StringConverter.convert(\"foo\") must return \"foo\".", "foo", foo); + } + +} // class StringConverterTest Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/converter/StringConverterTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-29 23:09:23
|
Revision: 241 http://svn.sourceforge.net/japi/?rev=241&view=rev Author: christianhujer Date: 2006-11-29 15:09:22 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Fixed bug: missing argument didn't throw MissingArgumentException. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-29 22:26:59 UTC (rev 240) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-29 23:09:22 UTC (rev 241) @@ -196,8 +196,9 @@ * Invoke the argument method for the current option. * @throws TerminalException in case the invoked exception was terminal * @throws UnknownOptionException In case a given option is not known. + * @throws MissingArgumentException In case the required argument for an option was missing. */ - private void invokeMethod() throws TerminalException, UnknownOptionException { + private void invokeMethod() throws TerminalException, UnknownOptionException, MissingArgumentException { final Method method = argumentMethods.get(currentOption); if (method == null) { throw new UnknownOptionException(currentOption); @@ -223,6 +224,8 @@ throw (TerminalException) cause; } System.err.println(e.getCause()); + } catch (final NoSuchElementException e) { + throw new MissingArgumentException(currentOption); } catch (final Exception e) { e.printStackTrace(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-29 22:27:01
|
Revision: 240 http://svn.sourceforge.net/japi/?rev=240&view=rev Author: christianhujer Date: 2006-11-29 14:26:59 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Renamed var to match code style. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-11-29 22:26:05 UTC (rev 239) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-11-29 22:26:59 UTC (rev 240) @@ -17,7 +17,7 @@ private static final String EXPECTED = "foo, bar, buzz"; /** Argument values. */ - private static final String[] args = { "foo", "bar", "buzz" }; + private static final String[] ARGS = { "foo", "bar", "buzz" }; /** * Empty constructor for JUnit. @@ -29,30 +29,30 @@ * Tests whether {@link StringJoiner#join(CharSequence, CharSequence...)} works. */ @Test public void testJoinCSCS() { - final String[] nargs = args.clone(); + final String[] nargs = ARGS.clone(); final String actual = StringJoiner.join(", ", nargs); assertEquals("arguments must be joined correctly.", EXPECTED, actual); - assertTrue("arguments must not be changed by join().", Arrays.equals(args, nargs)); + assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); } /** * Tests whether {@link StringJoiner#join(CharSequence, Iterable<? extends java.lang.CharSequence>)} works. */ @Test public void testJoinCSIe() { - final String[] nargs = args.clone(); + final String[] nargs = ARGS.clone(); final String actual = StringJoiner.join(", ", Arrays.asList(nargs)); assertEquals("arguments must be joined correctly.", EXPECTED, actual); - assertTrue("arguments must not be changed by join().", Arrays.equals(args, nargs)); + assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); } /** * Tests whether {@link StringJoiner#join(CharSequence, java.util.Iterator<? extends java.lang.CharSequence>)} works. */ @Test public void testJoinCSIr() { - final String[] nargs = args.clone(); + final String[] nargs = ARGS.clone(); final String actual = StringJoiner.join(", ", Arrays.asList(nargs).iterator()); assertEquals("arguments must be joined correctly.", EXPECTED, actual); - assertTrue("arguments must not be changed by join().", Arrays.equals(args, nargs)); + assertTrue("arguments must not be changed by join().", Arrays.equals(ARGS, nargs)); } } // class StringJoinerTestCase This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-29 22:26:09
|
Revision: 239 http://svn.sourceforge.net/japi/?rev=239&view=rev Author: christianhujer Date: 2006-11-29 14:26:05 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Removed warnings. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-29 21:17:00 UTC (rev 238) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-29 22:26:05 UTC (rev 239) @@ -11,6 +11,7 @@ import java.util.List; import org.junit.Test; import org.junit.Assert; +import org.jetbrains.annotations.NotNull; /** * Test for {@link ArgParser}. @@ -35,7 +36,7 @@ /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) - public int run(final List<String> args) { + public int run(@NotNull final List<String> args) { runCalled = true; this.args = args; return 0; @@ -87,10 +88,10 @@ /** * Tests whether supplying a required option with argument in short form works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandWithShortOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -103,10 +104,10 @@ /** * Tests whether supplying a required option with argument in long form with separate argument works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandWithLongOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -119,10 +120,10 @@ /** * Tests whether supplying a required option with argument in long form with integrated argument works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandWithLongOptEq() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -135,10 +136,10 @@ /** * Tests whether it's detected that a required option is missing. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (expected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test(expected=RequiredOptionsMissingException.class) public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { @@ -152,10 +153,10 @@ /** * Tests whether it's detected that an unknown option was given. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (expected) + * @throws MissingArgumentException (unexpected) */ @Test(expected=UnknownOptionException.class) public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { @@ -169,10 +170,10 @@ /** * Tests whether it's detected that the argument of an option that requires an argument is missing. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (expected) */ @Test(expected=MissingArgumentException.class) public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { @@ -186,10 +187,10 @@ /** * Tests whether specifying an option twice works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandDuplicateOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -202,10 +203,10 @@ /** * Tests whether help works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (expected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test(expected = TerminalException.class) public void testHelp() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-29 21:17:06
|
Revision: 238 http://svn.sourceforge.net/japi/?rev=238&view=rev Author: christianhujer Date: 2006-11-29 13:17:00 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Improved converter feature. Integrated converter with ArgParser. Changed option names to value so it's default annotation argument. Modified Paths: -------------- libs/argparser/trunk/src/doc/examples/Head.java libs/argparser/trunk/src/doc/examples/Tail.java libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java libs/argparser/trunk/src/net/sf/japi/io/args/Command.java libs/argparser/trunk/src/net/sf/japi/io/args/Option.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Added Paths: ----------- libs/argparser/trunk/src/META-INF/ libs/argparser/trunk/src/META-INF/services/ libs/argparser/trunk/src/META-INF/services/net.sf.japi.io.args.converter.Converter libs/argparser/trunk/src/doc/examples/Uniq.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java Added: libs/argparser/trunk/src/META-INF/services/net.sf.japi.io.args.converter.Converter =================================================================== --- libs/argparser/trunk/src/META-INF/services/net.sf.japi.io.args.converter.Converter (rev 0) +++ libs/argparser/trunk/src/META-INF/services/net.sf.japi.io.args.converter.Converter 2006-11-29 21:17:00 UTC (rev 238) @@ -0,0 +1,4 @@ +net.sf.japi.io.args.converter.BooleanConverter +net.sf.japi.io.args.converter.InputStreamConverter +net.sf.japi.io.args.converter.IntegerConverter +net.sf.japi.io.args.converter.StringConverter Property changes on: libs/argparser/trunk/src/META-INF/services/net.sf.japi.io.args.converter.Converter ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/doc/examples/Head.java =================================================================== --- libs/argparser/trunk/src/doc/examples/Head.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/doc/examples/Head.java 2006-11-29 21:17:00 UTC (rev 238) @@ -43,9 +43,9 @@ * Sets the number of lines to print. * @param lines number of lines to print */ - @Option(names = {"n", "lines"}) - public void setLines(final String lines) { - numItems = Integer.parseInt(lines); + @Option({"n", "lines"}) + public void setLines(final Integer lines) { + numItems = lines; printBytes = false; } @@ -53,16 +53,16 @@ * Sets the number of bytes to print. * @param bytes number of bytes to print. */ - @Option(names = {"c", "bytes"}) - public void setBytes(final String bytes) { - numItems = Integer.parseInt(bytes); + @Option({"c", "bytes"}) + public void setBytes(final Integer bytes) { + numItems = bytes; printBytes = true; } /** * Sets the command to be quiet. */ - @Option(names = {"q", "quiet", "silent"}) + @Option({"q", "quiet", "silent"}) public void setQuiet() { verbose = 0; } @@ -70,7 +70,7 @@ /** * Sets the command to be verbose. */ - @Option(names = {"v", "verbose"}) + @Option({"v", "verbose"}) public void setVerbose() { verbose = 2; } Modified: libs/argparser/trunk/src/doc/examples/Tail.java =================================================================== --- libs/argparser/trunk/src/doc/examples/Tail.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/doc/examples/Tail.java 2006-11-29 21:17:00 UTC (rev 238) @@ -40,9 +40,9 @@ * Sets the number of lines to print. * @param lines number of lines to print */ - @Option(names = {"n", "lines"}) - public void setLines(final String lines) { - numItems = Integer.parseInt(lines); + @Option({"n", "lines"}) + public void setLines(final Integer lines) { + numItems = lines; printBytes = false; } @@ -50,16 +50,16 @@ * Sets the number of bytes to print. * @param bytes number of bytes to print. */ - @Option(names = {"c", "bytes"}) - public void setBytes(final String bytes) { - numItems = Integer.parseInt(bytes); + @Option({"c", "bytes"}) + public void setBytes(final Integer bytes) { + numItems = bytes; printBytes = true; } /** * Sets the command to be quiet. */ - @Option(names = {"q", "quiet", "silent"}) + @Option({"q", "quiet", "silent"}) public void setQuiet() { verbose = 0; } @@ -67,7 +67,7 @@ /** * Sets the command to be verbose. */ - @Option(names = {"v", "verbose"}) + @Option({"v", "verbose"}) public void setVerbose() { verbose = 2; } Added: libs/argparser/trunk/src/doc/examples/Uniq.java =================================================================== --- libs/argparser/trunk/src/doc/examples/Uniq.java (rev 0) +++ libs/argparser/trunk/src/doc/examples/Uniq.java 2006-11-29 21:17:00 UTC (rev 238) @@ -0,0 +1,110 @@ +package examples; + +import net.sf.japi.io.args.BasicCommand; +import net.sf.japi.io.args.Option; +import org.jetbrains.annotations.NotNull; +import java.util.List; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.BufferedReader; + +/** + * Java implementation of the UNIX command <q>uniq</q> to demonstrate how to use the argparser library. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class Uniq extends BasicCommand { + + /** Whether to prefix lines with the count of their occurrence. */ + private boolean count; + + /** Whether to only print lines that occurred more than once. */ + private boolean repeated; + + /** Whether to ignore case. */ + private boolean ignoreCase; + + /** + * Sets that lines should prefixed with the count of their occurrence. + */ + @Option({"c", "count"}) + public void setCount() { + count = true; + } + + /** + * Sets that only lines that occurred more than once will be printed. + */ + @Option({"d", "repeated"}) + public void setRepeated() { + repeated = true; + } + + /** + * Sets that the case should be ignored. + */ + @Option({"i", "ignore-case"}) + public void setIgnoreCase() { + ignoreCase = true; + } + + /** {@inheritDoc} */ + @SuppressWarnings({"InstanceMethodNamingConvention"}) + public int run(final @NotNull List<String> args) throws Exception { + int returnCode = 0; + for (final String arg : args) { + try { + final InputStream in = new BufferedInputStream(new FileInputStream(arg)); + try { + uniq(in); + } finally { + in.close(); + } + } catch (final IOException e) { + returnCode = 1; + System.err.println(e); + } + } + return returnCode; + } + + /** + * Prints unique lines from the specified InputStream. + * @param in InputStream to print unique lines from. + * @throws IOException In case of I/O problems. + */ + private void uniq(@NotNull final InputStream in) throws IOException { + uniq(new InputStreamReader(in)); + } + + /** + * Prints unique lines from the specified Reader. + * @param in Reader to print unique lines from. + * @throws IOException In case of I/O problems. + */ + private void uniq(@NotNull final Reader in) throws IOException { + final BufferedReader bin = in instanceof BufferedReader ? (BufferedReader) in : new BufferedReader(in); + String previousLine = bin.readLine(); + if (previousLine != null) { + String line; + int lineCount = 1; + do { + line = bin.readLine(); + if (!(ignoreCase ? previousLine.equalsIgnoreCase(line) : previousLine.equals(line)) && (!repeated || lineCount > 1)) { + if (count) { + System.out.format("%7d %s%n", lineCount, previousLine); + } else { + System.out.println(previousLine); + } + lineCount = 0; + } + previousLine = line; + lineCount++; + } while (line != null); + } + } + +} // class Uniq Property changes on: libs/argparser/trunk/src/doc/examples/Uniq.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-29 21:17:00 UTC (rev 238) @@ -25,6 +25,7 @@ import java.lang.reflect.Method; import java.util.*; import java.io.Closeable; +import net.sf.japi.io.args.converter.ConverterRegistry; /** * Parser for command line arguments. @@ -97,7 +98,7 @@ for (final Method requiredMethod : requiredMethods) { final Option option = requiredMethod.getAnnotation(Option.class); assert option != null; - missingOptions.add(option.names()[0]); + missingOptions.add(option.value()[0]); } throw new RequiredOptionsMissingException(missingOptions.toArray(new String[missingOptions.size()])); } @@ -112,7 +113,7 @@ for (final Method method : getOptionMethods(commandClass)) { final Option option = method.getAnnotation(Option.class); assert option != null; - for (final String optionName : option.names()) { + for (final String optionName : option.value()) { if (argumentMethods.containsKey(optionName)) { throw new IllegalArgumentException(commandClass.getName() + " declared option " + optionName + " twice."); } @@ -207,8 +208,8 @@ final int parameterCount = parameterTypes.length; if (parameterCount == 1) { final String arg = argIterator.next(); - method.invoke(command, arg); argIterator.remove(); + method.invoke(command, ConverterRegistry.convert(parameterTypes[0], arg)); } else if (parameterCount == 0) { method.invoke(command); } else { @@ -222,6 +223,8 @@ throw (TerminalException) cause; } System.err.println(e.getCause()); + } catch (final Exception e) { + e.printStackTrace(); } if (method.getAnnotation(Option.class).type() == OptionType.TERMINAL) { throw new TerminalException(); Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-11-29 21:17:00 UTC (rev 238) @@ -8,6 +8,7 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; +import org.jetbrains.annotations.NotNull; /** * BasicCommand is a base class for commands that provides the options --help, --exit and --noexit. @@ -34,24 +35,18 @@ } /** Exit Option. */ - @Option(names = {"exit"}) - public void setExiting() { - exiting = true; + @Option(value = {"exit"}) + public void setExiting(@NotNull final Boolean exiting) { + this.exiting = exiting; } - /** No Exit Option. */ - @Option(names = {"noexit"}) - public void setNotExiting() { - exiting = false; - } - /** {@inheritDoc} */ - public boolean isExiting() { + public Boolean isExiting() { return exiting; } /** Help Option. */ - @Option(type = OptionType.TERMINAL, names = {"h", "help"}) + @Option(type = OptionType.TERMINAL, value = {"h", "help"}) public void help() { final Set<Method> optionMethods = ArgParser.getOptionMethods(this); final Set<Class<?>> parameterTypes = new HashSet<Class<?>>(); @@ -59,7 +54,7 @@ int maxShort = 0; for (final Method optionMethod : optionMethods) { final Option option = optionMethod.getAnnotation(Option.class); - final String[] names = option.names(); + final String[] names = option.value(); int currentLong = 0; int currentShort = 0; for (final String name : names) { @@ -80,7 +75,7 @@ for (final Method optionMethod : optionMethods) { final Option option = optionMethod.getAnnotation(Option.class); final OptionType optionType = option.type(); - final String[] names = option.names(); + final String[] names = option.value(); final List<String> shortNames = new ArrayList<String>(); final List<String> longNames = new ArrayList<String>(); for (final String name : names) { Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-11-29 21:17:00 UTC (rev 238) @@ -45,6 +45,6 @@ * Return whether after running this Command, {@link System#exit(int)} should be invoked. * @return <code>true</code> if {@link ArgParser} should invoke {@link System#exit(int)} after this command, otherwise <code>false</code>. */ - boolean isExiting(); + Boolean isExiting(); } // interface Command Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Option.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-11-29 21:17:00 UTC (rev 238) @@ -48,7 +48,7 @@ * @note the supplied string values MUST consist of ASCII-letters only (match regex <code>[a-zA-Z]+</code>). * @return option names */ - String[] names(); + String[] value(); /** * The option key, used for i18n/l10n. Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java 2006-11-29 21:17:00 UTC (rev 238) @@ -0,0 +1,38 @@ +package net.sf.japi.io.args.converter; + +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Base class for the default converters. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +abstract class AbstractConverter<T> implements Converter<T> { + + /** The target class. */ + private final Class<T> targetClass; + + /** + * Create an AbstractConverter. + * @param targetClass TargetClass + */ + AbstractConverter(final Class<T> targetClass) { + this.targetClass = targetClass; + } + + /** {@inheritDoc} */ + public final Class<T> getTargetClass() { + return targetClass; + } + + /** {@inheritDoc} */ + public final String getDisplayName() { + return ResourceBundle.getBundle("net.sf.japi.io.args.converter.names").getString(targetClass.getName()); + } + + /** {@inheritDoc} */ + public final String getDisplayName(final Locale locale) { + return ResourceBundle.getBundle("net.sf.japi.io.args.converter.names", locale).getString(targetClass.getName()); + } + +} // class AbstractConverter Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/AbstractConverter.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java 2006-11-29 21:17:00 UTC (rev 238) @@ -4,8 +4,15 @@ * Converter which converts a String into a Boolean. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class BooleanConverter implements Converter<Boolean> { +public class BooleanConverter extends AbstractConverter<Boolean> { + /** + * Create a BooleanConverter. + */ + public BooleanConverter() { + super(Boolean.class); + } + /** {@inheritDoc} */ public Boolean convert(final String arg) throws Exception { return Boolean.valueOf(arg); Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java 2006-11-29 21:17:00 UTC (rev 238) @@ -1,5 +1,7 @@ package net.sf.japi.io.args.converter; +import java.util.Locale; + /** * The Converter interface is used for converters that convert Strings into other types. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> @@ -14,4 +16,23 @@ */ T convert(final String arg) throws Exception; + /** + * Returns the Class this Converter is for. + * @return The Class this Converter is for. + */ + Class<T> getTargetClass(); + + /** + * Returns a display name for the type of this Converter. + * @return A display name for the type of this Converter. + */ + String getDisplayName(); + + /** + * Returns a display name for the type of this Converter. + * @param locale Locale to get display name for. + * @return A display name for the type of this Converter in the specified locale. + */ + String getDisplayName(final Locale locale); + } // interface Convert Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/ConverterRegistry.java 2006-11-29 21:17:00 UTC (rev 238) @@ -1,10 +1,9 @@ package net.sf.japi.io.args.converter; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; -import java.util.HashMap; -import java.util.Enumeration; -import java.net.URL; -import java.io.IOException; +import sun.misc.Service; /** * Registry for Converters. @@ -32,14 +31,8 @@ */ private static ConverterRegistry createSingletonInstance() { final ConverterRegistry instance = new ConverterRegistry(); - try { - for (final Enumeration<URL> urls = ConverterRegistry.class.getClassLoader().getResources("META-INF/services/net.sf.japi.io.args.ConverterRegistry"); urls.hasMoreElements() ; ) { - final URL url = urls.nextElement(); - // TODO - } - } catch (final IOException e) { - // TODO - e.printStackTrace(); + for (final Iterator<Converter<?>> converters = Service.providers(Converter.class); converters.hasNext();) { + instance.register(converters.next()); } return instance; } @@ -63,21 +56,31 @@ /** * Register a Converter for a specific class. - * @param clazz Class Class to register converter for * @param converter Converter to register */ - public <T> void register(final Class<T> clazz, final Converter<T> converter) { - converters.put(clazz, converter); - for (Class<?> superClass = clazz; (superClass = superClass.getSuperclass()) != null;) { + public <T> void register(final Converter<T> converter) { + converters.put(converter.getTargetClass(), converter); + for (Class<?> superClass = converter.getTargetClass(); (superClass = superClass.getSuperclass()) != null;) { if (!converters.containsKey(superClass)) { converters.put(superClass, converter); } } - for (final Class<?> interf : clazz.getInterfaces()) { + for (final Class<?> interf : converter.getTargetClass().getInterfaces()) { if (!converters.containsKey(interf)) { converters.put(interf, converter); } } } + /** + * Convenience method to convert a String to the desired target type using the default ConverterRegistry. + * @param targetType target type to convert to. + * @param s String to convert + * @return Converted String in the desired target type. + * @throws Exception in case the conversion failed. + */ + public static <T> T convert(final Class<T> targetType, final String s) throws Exception { + return getInstance().getConverter(targetType).convert(s); + } + } // class ConverterRegistry Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java 2006-11-29 21:17:00 UTC (rev 238) @@ -10,8 +10,15 @@ * Converter that converts a String into an InputStream. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class InputStreamConverter implements Converter<InputStream> { +public class InputStreamConverter extends AbstractConverter<InputStream> { + /** + * Create an InputStreamConverter. + */ + public InputStreamConverter() { + super(InputStream.class); + } + /** {@inheritDoc} */ public InputStream convert(final String arg) throws FileNotFoundException { try { Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java 2006-11-29 21:17:00 UTC (rev 238) @@ -0,0 +1,21 @@ +package net.sf.japi.io.args.converter; + +/** + * Converter which converts a String into a an Integer. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class IntegerConverter extends AbstractConverter<Integer> { + + /** + * Create an IntegerConverter. + */ + public IntegerConverter() { + super(Integer.class); + } + + /** {@inheritDoc} */ + public Integer convert(final String arg) throws Exception { + return Integer.valueOf(arg); + } + +} // class IntegerConverter Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/IntegerConverter.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/StringConverter.java 2006-11-29 21:17:00 UTC (rev 238) @@ -4,8 +4,15 @@ * Dummy Converter which "converts" a String into a String by simply returning it. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class StringConverter implements Converter<String> { +public class StringConverter extends AbstractConverter<String> { + /** + * Create a StringConverter. + */ + public StringConverter() { + super(String.class); + } + /** {@inheritDoc} */ public String convert(final String arg) throws Exception { return arg; Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-26 23:47:21 UTC (rev 237) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-29 21:17:00 UTC (rev 238) @@ -53,7 +53,7 @@ * Set the value of the input option. * @param input Value of the input option. */ - @Option(type = OptionType.REQUIRED, names = {"i", "input"}) + @Option(type = OptionType.REQUIRED, value = {"i", "input"}) public void setInput(final String input) { this.input = input; } @@ -62,7 +62,7 @@ * Set the value of the foo option. * @param foo Value of the foo option. */ - @Option(names = {"f", "b", "foo", "bar", "buzz"}) + @Option(value = {"f", "b", "foo", "bar", "buzz"}) public void setFoo(final String foo) { // ignored } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-26 23:47:22
|
Revision: 237 http://svn.sourceforge.net/japi/?rev=237&view=rev Author: christianhujer Date: 2006-11-26 15:47:21 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Added todo about default option values. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-26 23:46:28 UTC (rev 236) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-26 23:47:21 UTC (rev 237) @@ -32,6 +32,7 @@ * @todo automatic argument conversion for option method invocation. * @todo better handling of boolean arguments * @todo Handling of - for STDIN as input argument filestream + * @todo automatic printout of default values if property getter available. */ public class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-26 23:46:29
|
Revision: 236 http://svn.sourceforge.net/japi/?rev=236&view=rev Author: christianhujer Date: 2006-11-26 15:46:28 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Improved documentation. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-11-26 23:41:33 UTC (rev 235) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-11-26 23:46:28 UTC (rev 236) @@ -27,6 +27,7 @@ /** * Shell commands can implement this interface and make use of ArgParser. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @see BasicCommand BasicCommand for a convenient implementation of this interface */ public interface Command { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-26 23:41:33
|
Revision: 235 http://svn.sourceforge.net/japi/?rev=235&view=rev Author: christianhujer Date: 2006-11-26 15:41:33 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Made module title a parameter. Modified Paths: -------------- libs/argparser/trunk/build.xml Modified: libs/argparser/trunk/build.xml =================================================================== --- libs/argparser/trunk/build.xml 2006-11-26 23:39:59 UTC (rev 234) +++ libs/argparser/trunk/build.xml 2006-11-26 23:41:33 UTC (rev 235) @@ -3,6 +3,7 @@ <property name="module.version" value="0.1" /> <property name="module.name" value="japi-lib-argparser" /> + <property name="module.title" value="ArgParser" /> <taskdef name="pack200" classpath="lib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" /> @@ -125,10 +126,10 @@ locale = "en_US" use = "yes" splitindex = "yes" - windowtitle = "JAPI Library ArgParser ${module.version} API documentation" - doctitle = "JAPI<br />Yet another Java API<br />Library ArgParser ${module.version} API documentation" - header = "JAPI Library ArgParser ${module.version}<br />API Documentation" - footer = "JAPI<br />Yet another Java API<br />Library ArgParser ${module.version} API documentation" + windowtitle = "JAPI Library ${module.title} ${module.version} API documentation" + doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation" + header = "JAPI Library ${module.title} ${module.version}<br />API Documentation" + footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation" bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>" serialwarn = "yes" charset = "utf-8" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-26 23:40:00
|
Revision: 234 http://svn.sourceforge.net/japi/?rev=234&view=rev Author: christianhujer Date: 2006-11-26 15:39:59 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Removed old IntelliJ IDEA module files. Removed Paths: ------------- libs/argparser/trunk/argparser-examples.iml libs/argparser/trunk/argparser.iml Deleted: libs/argparser/trunk/argparser-examples.iml =================================================================== --- libs/argparser/trunk/argparser-examples.iml 2006-11-26 23:38:21 UTC (rev 233) +++ libs/argparser/trunk/argparser-examples.iml 2006-11-26 23:39:59 UTC (rev 234) @@ -1,190 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4" relativePaths="true" type="JAVA_MODULE"> - <component name="DependecySynchronizer" /> - <component name="ModuleRootManager" /> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$/src/doc/examples"> - <sourceFolder url="file://$MODULE_DIR$/src/doc/examples" isTestSource="false" packagePrefix="examples" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="module" module-name="argparser" /> - <orderEntry type="library" name="annotations" level="project" /> - <orderEntryProperties /> - </component> - <component name="copyright"> - <Base> - <setting name="state" value="2" /> - </Base> - <LanguageOptions name="$TEMPLATE$"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="4" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="CSS"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="HTML"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="JAVA"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="JSP"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="JavaScript"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="Properties"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="XML"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - </component> -</module> - Deleted: libs/argparser/trunk/argparser.iml =================================================================== --- libs/argparser/trunk/argparser.iml 2006-11-26 23:38:21 UTC (rev 233) +++ libs/argparser/trunk/argparser.iml 2006-11-26 23:39:59 UTC (rev 234) @@ -1,191 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4" relativePaths="true" type="JAVA_MODULE"> - <component name="DependecySynchronizer" /> - <component name="ModuleRootManager" /> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src/net" isTestSource="false" packagePrefix="net" /> - <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" packagePrefix="test" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="library" name="annotations" level="project" /> - <orderEntry type="library" name="junit" level="project" /> - <orderEntryProperties /> - </component> - <component name="copyright"> - <Base> - <setting name="state" value="2" /> - </Base> - <LanguageOptions name="$TEMPLATE$"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="4" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="CSS"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="HTML"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="JAVA"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="JSP"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="JavaScript"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="Properties"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - <LanguageOptions name="XML"> - <option name="templateOptions"> - <value> - <option name="block" value="true" /> - <option name="separateBefore" value="false" /> - <option name="separateAfter" value="false" /> - <option name="prefixLines" value="true" /> - <option name="lenBefore" value="80" /> - <option name="lenAfter" value="80" /> - <option name="box" value="false" /> - <option name="filler" value=" " /> - </value> - </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> - <option name="keyword" value="Copyright" /> - <option name="fileTypeOverride" value="2" /> - <option name="relativeBefore" value="true" /> - <option name="addBlankAfter" value="true" /> - <option name="fileLocation" value="1" /> - <option name="useAlternate" value="false" /> - </LanguageOptions> - </component> -</module> - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |