Skip to content
Snippets Groups Projects
Commit 3acf86e8 authored by brinn's avatar brinn
Browse files

add: args4j library for parsing the command line

remove: commons-cli library for parsing the command line
change: switch datamover and lims over to use arg4j instead of commons-cli

SVN: 213
parent ea629ced
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="sourceTest/java"/> <classpathentry kind="src" path="sourceTest/java"/>
<classpathentry kind="src" path="source/java"/> <classpathentry kind="src" path="source/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/libraries/activation/activation.jar"/> <classpathentry kind="lib" path="/libraries/activation/activation.jar"/>
<classpathentry kind="lib" path="/libraries/commons-cli/commons-cli.jar" sourcepath="/libraries/commons-cli/src.zip"/> <classpathentry kind="lib" path="/libraries/log4j/log4j.jar" sourcepath="/libraries/log4j/src.zip"/>
<classpathentry kind="lib" path="/libraries/log4j/log4j.jar" sourcepath="/libraries/log4j/src.zip"/> <classpathentry kind="lib" path="/libraries/mail/mail.jar"/>
<classpathentry kind="lib" path="/libraries/mail/mail.jar"/> <classpathentry kind="lib" path="/libraries/testng/testng-jdk15.jar" sourcepath="/libraries/testng/src.zip"/>
<classpathentry kind="lib" path="/libraries/testng/testng-jdk15.jar" sourcepath="/libraries/testng/src.zip"/> <classpathentry combineaccessrules="false" kind="src" path="/common"/>
<classpathentry combineaccessrules="false" kind="src" path="/common"/> <classpathentry kind="lib" path="/libraries/args4j/args4j.jar" sourcepath="/libraries/args4j/args4j-src.jar"/>
<classpathentry kind="output" path="targets/classes"/> <classpathentry kind="output" path="targets/classes"/>
</classpath> </classpath>
...@@ -222,12 +222,6 @@ public class Main ...@@ -222,12 +222,6 @@ public class Main
{ {
initLog(); initLog();
final Parameters parameters = new Parameters(args); final Parameters parameters = new Parameters(args);
if (parameters.hasAllMandatoryOptions() == false)
{
parameters.printVersionAndOptions();
System.err.println("\nThere are mandatory options missing from the command line.");
System.exit(1);
}
printInitialLogMessage(parameters); printInitialLogMessage(parameters);
startupServer(parameters); startupServer(parameters);
operationLog.info("Data mover ready and waiting for data."); operationLog.info("Data mover ready and waiting for data.");
......
...@@ -17,207 +17,167 @@ ...@@ -17,207 +17,167 @@
package ch.systemsx.cisd.datamover; package ch.systemsx.cisd.datamover;
import java.io.File; import java.io.File;
import java.util.regex.PatternSyntaxException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import static org.testng.AssertJUnit.*; import static org.testng.AssertJUnit.*;
/** /**
* Test cases for the {@link Parameters} class. * Test cases for the {@link Parameters} class.
* *
* @author bernd * @author Bernd Rinn
*/ */
public class ParametersTest public class ParametersTest
{ {
@Test() private Parameters parse(String... args)
public void testSetRsyncExecutableLong() throws Exception
{ {
final String RSYNC_EXEC = "/usr/local/bin/rsync"; return parse(true, args);
final Parameters parameters = new Parameters(new String[]
{ "--rsync-executable", RSYNC_EXEC });
assertEquals(RSYNC_EXEC, parameters.getRsyncExecutable());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test() private Parameters parse(boolean suppressMissingMandatoryOptions, String... args)
public void testSetRsyncExecutableShort() throws Exception
{ {
final String RSYNC_EXEC = "/usr/local/bin/rsync"; return new Parameters(args, true, suppressMissingMandatoryOptions);
final Parameters parameters = new Parameters(new String[]
{ "-e", RSYNC_EXEC });
assertEquals(RSYNC_EXEC, parameters.getRsyncExecutable());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test() @Test
public void testSetSshExecutableLong() throws Exception public void testSetRsyncExecutableLong() throws Exception
{ {
final String SSH_EXEC = "/usr/local/bin/ssh"; final String RSYNC_EXEC = "/usr/local/bin/rsync";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--rsync-executable", RSYNC_EXEC);
{ "--ssh-executable", SSH_EXEC }); assertEquals(RSYNC_EXEC, parameters.getRsyncExecutable());
assertEquals(SSH_EXEC, parameters.getSshExecutable());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test() @Test
public void testSetSshExecutableShort() throws Exception public void testSetSshExecutableLong() throws Exception
{ {
final String SSH_EXEC = "/usr/local/bin/ssh"; final String SSH_EXEC = "/usr/local/bin/ssh";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--ssh-executable", SSH_EXEC);
{ "-s", SSH_EXEC });
assertEquals(SSH_EXEC, parameters.getSshExecutable()); assertEquals(SSH_EXEC, parameters.getSshExecutable());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test() @Test
public void testSetCleansingRegexLong() throws Exception public void testSetCleansingRegexLong() throws Exception
{ {
final String CLEANSING_REGEX = "[0-9]+"; final String CLEANSING_REGEX = "[0-9]+";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--cleansing-regex", CLEANSING_REGEX);
{ "--cleansing-regex", CLEANSING_REGEX });
assertEquals(CLEANSING_REGEX, parameters.getCleansingRegex().pattern());
assert parameters.hasAllMandatoryOptions() == false;
}
@Test()
public void testSetCleansingRegexShort() throws Exception
{
final String CLEANSING_REGEX = "[0-9]+";
final Parameters parameters = new Parameters(new String[]
{ "-x", CLEANSING_REGEX });
assertEquals(CLEANSING_REGEX, parameters.getCleansingRegex().pattern()); assertEquals(CLEANSING_REGEX, parameters.getCleansingRegex().pattern());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test(expectedExceptions = @Test(expectedExceptions = UserFailureException.class)
{ PatternSyntaxException.class })
public void testSetInvalidCleansingRegex() throws Exception public void testSetInvalidCleansingRegex() throws Exception
{ {
final String CLEANSING_REGEX = "[0-9}+"; final String CLEANSING_REGEX = "[0-9}+";
new Parameters(new String[] parse("--cleansing-regex", CLEANSING_REGEX);
{ "--cleansing-regex", CLEANSING_REGEX });
} }
@Test @Test
public void testSetLocalDataDirLong() throws Exception public void testSetLocalDataDirLong() throws Exception
{ {
final String LOCAL_DATADIR = ".." + File.separator + "test_it_data"; final String LOCAL_DATADIR = ".." + File.separator + "test_it_data";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--local-datadir", LOCAL_DATADIR);
{ "--local-datadir", LOCAL_DATADIR });
assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath()); assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetLocalDataDirShort() throws Exception public void testSetLocalDataDirShort() throws Exception
{ {
final String LOCAL_DATADIR = ".." + File.separator + "test_it_data2"; final String LOCAL_DATADIR = ".." + File.separator + "test_it_data2";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("-d", LOCAL_DATADIR);
{ "-d", LOCAL_DATADIR });
assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath()); assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetLocalTempDirLong() throws Exception public void testSetLocalTempDirLong() throws Exception
{ {
final String LOCAL_TEMPDIR = "test_it_tmp"; final String LOCAL_TEMPDIR = "test_it_tmp";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--local-tempdir", LOCAL_TEMPDIR);
{ "--local-tempdir", LOCAL_TEMPDIR });
assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath()); assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetLocalTempDirShort() throws Exception public void testSetLocalTempDirShort() throws Exception
{ {
final String LOCAL_TEMPDIR = "test_it_tmp3"; final String LOCAL_TEMPDIR = "test_it_tmp3";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("-t", LOCAL_TEMPDIR);
{ "-t", LOCAL_TEMPDIR });
assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath()); assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetRemoteDirLong() throws Exception public void testSetRemoteDirLong() throws Exception
{ {
final String REMOTE_DATADIR = "test_it_remote"; final String REMOTE_DATADIR = "test_it_remote";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--remotedir", REMOTE_DATADIR);
{ "--remotedir", REMOTE_DATADIR });
assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath()); assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetRemoteDirShort() throws Exception public void testSetRemoteDirShort() throws Exception
{ {
final String REMOTE_DATADIR = "test_it_remote4"; final String REMOTE_DATADIR = "test_it_remote4";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("-r", REMOTE_DATADIR);
{ "-r", REMOTE_DATADIR });
assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath()); assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetRemoteHostLong() throws Exception public void testSetRemoteHostLong() throws Exception
{ {
final String REMOTE_HOST = "test_it_remote"; final String REMOTE_HOST = "test_it_remote";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--remotehost", REMOTE_HOST);
{ "--remotehost", REMOTE_HOST });
assertEquals(REMOTE_HOST, parameters.getRemoteHost()); assertEquals(REMOTE_HOST, parameters.getRemoteHost());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetRemoteHostShort() throws Exception public void testSetRemoteHostShort() throws Exception
{ {
final String REMOTE_HOST = "test_it_remote4"; final String REMOTE_HOST = "test_it_remote4";
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("-h", REMOTE_HOST);
{ "-h", REMOTE_HOST });
assertEquals(REMOTE_HOST, parameters.getRemoteHost()); assertEquals(REMOTE_HOST, parameters.getRemoteHost());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetCheckIntervalLong() throws Exception public void testSetCheckIntervalLong() throws Exception
{ {
final int CHECK_INTERVAL = 5; final int CHECK_INTERVAL = 5;
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--check-interval", Integer.toString(CHECK_INTERVAL));
{ "--check-interval", Integer.toString(CHECK_INTERVAL) });
assertEquals(1000 * CHECK_INTERVAL, parameters.getCheckIntervalMillis()); assertEquals(1000 * CHECK_INTERVAL, parameters.getCheckIntervalMillis());
assert parameters.hasAllMandatoryOptions() == false; }
@Test(expectedExceptions = UserFailureException.class)
public void testSetInvalidCheckInterval() throws Exception
{
parse("--check-interval", "5x");
} }
@Test @Test
public void testSetCheckIntervalShort() throws Exception public void testSetCheckIntervalShort() throws Exception
{ {
final int CHECK_INTERVAL = 11; final int CHECK_INTERVAL = 11;
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("-c", Integer.toString(CHECK_INTERVAL));
{ "-c", Integer.toString(CHECK_INTERVAL) });
assertEquals(1000 * CHECK_INTERVAL, parameters.getCheckIntervalMillis()); assertEquals(1000 * CHECK_INTERVAL, parameters.getCheckIntervalMillis());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetQuietPeriodLong() throws Exception public void testSetQuietPeriodLong() throws Exception
{ {
final int QUIET_PERIOD = 6; final int QUIET_PERIOD = 6;
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("--quiet-period", Integer.toString(QUIET_PERIOD));
{ "--quiet-period", Integer.toString(QUIET_PERIOD) });
assertEquals(1000 * QUIET_PERIOD, parameters.getQuietPeriodMillis()); assertEquals(1000 * QUIET_PERIOD, parameters.getQuietPeriodMillis());
assert parameters.hasAllMandatoryOptions() == false;
} }
@Test @Test
public void testSetQuietPeriodShort() throws Exception public void testSetQuietPeriodShort() throws Exception
{ {
final int QUIET_PERIOD = 17; final int QUIET_PERIOD = 17;
final Parameters parameters = new Parameters(new String[] final Parameters parameters = parse("-q", Integer.toString(QUIET_PERIOD));
{ "-q", Integer.toString(QUIET_PERIOD) });
assertEquals(1000 * QUIET_PERIOD, parameters.getQuietPeriodMillis()); assertEquals(1000 * QUIET_PERIOD, parameters.getQuietPeriodMillis());
assert parameters.hasAllMandatoryOptions() == false; }
@Test(expectedExceptions = UserFailureException.class)
public void testMissingMandatoryOptions() throws Exception
{
parse(false);
} }
@Test @Test
...@@ -226,12 +186,12 @@ public class ParametersTest ...@@ -226,12 +186,12 @@ public class ParametersTest
final String LOCAL_DATADIR = ".." + File.separator + "ldata"; final String LOCAL_DATADIR = ".." + File.separator + "ldata";
final String LOCAL_TEMPDIR = "l" + File.separator + "tmp"; final String LOCAL_TEMPDIR = "l" + File.separator + "tmp";
final String REMOTE_DATADIR = "rrr"; final String REMOTE_DATADIR = "rrr";
final Parameters parameters = new Parameters(new String[] final Parameters parameters =
{ "--local-datadir", LOCAL_DATADIR, "--local-tempdir", LOCAL_TEMPDIR, "--remotedir", REMOTE_DATADIR, }); parse(false, "--local-datadir", LOCAL_DATADIR, "--local-tempdir", LOCAL_TEMPDIR, "--remotedir",
REMOTE_DATADIR);
assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath()); assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath());
assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath()); assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath());
assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath()); assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath());
assert parameters.hasAllMandatoryOptions();
} }
@Test @Test
...@@ -244,17 +204,15 @@ public class ParametersTest ...@@ -244,17 +204,15 @@ public class ParametersTest
final int CHECK_INTERVAL = 22; final int CHECK_INTERVAL = 22;
final int QUIET_PERIOD = 33; final int QUIET_PERIOD = 33;
final Parameters parameters = final Parameters parameters =
new Parameters(new String[] parse(false, "--local-datadir", LOCAL_DATADIR, "--local-tempdir", LOCAL_TEMPDIR, "--remotedir",
{ "--local-datadir", LOCAL_DATADIR, "--local-tempdir", LOCAL_TEMPDIR, "--remotedir", REMOTE_DATADIR, "--remotehost", REMOTE_HOST, "--check-interval", Integer
REMOTE_DATADIR, "--remotehost", REMOTE_HOST, "--check-interval", .toString(CHECK_INTERVAL), "--quiet-period", Integer.toString(QUIET_PERIOD));
Integer.toString(CHECK_INTERVAL), "--quiet-period", Integer.toString(QUIET_PERIOD), });
assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath()); assertEquals(LOCAL_DATADIR, parameters.getLocalDataDirectory().getPath());
assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath()); assertEquals(LOCAL_TEMPDIR, parameters.getLocalTemporaryDirectory().getPath());
assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath()); assertEquals(REMOTE_DATADIR, parameters.getRemoteDataDirectory().getPath());
assertEquals(REMOTE_HOST, parameters.getRemoteHost()); assertEquals(REMOTE_HOST, parameters.getRemoteHost());
assertEquals(1000 * CHECK_INTERVAL, parameters.getCheckIntervalMillis()); assertEquals(1000 * CHECK_INTERVAL, parameters.getCheckIntervalMillis());
assertEquals(1000 * QUIET_PERIOD, parameters.getQuietPeriodMillis()); assertEquals(1000 * QUIET_PERIOD, parameters.getQuietPeriodMillis());
assert parameters.hasAllMandatoryOptions();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment