Search in sources :

Example 6 with CommandLine

use of org.apache.ivy.util.cli.CommandLine in project ant-ivy by apache.

the class MainTest method testTypes.

/**
 * Test case for IVY-1355.
 * {@code types} argument to the command line must be parsed correctly when it's passed
 * more than one value for the argument.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1355">IVY-1355</a>
 */
@Test
public void testTypes() throws Exception {
    final String[] params = new String[] { "-settings", "test/repositories/ivysettings.xml", "-retrieve", "build/test/main/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", "-types", "jar", "source" };
    final CommandLine parsedCommand = Main.getParser().parse(params);
    final String[] parsedTypes = parsedCommand.getOptionValues("types");
    assertNotNull("Values for types argument is missing", parsedTypes);
    assertEquals("Unexpected number of values parsed for types argument", 2, parsedTypes.length);
    final Set<String> uniqueParsedTypes = new HashSet<>(Arrays.asList(parsedTypes));
    assertTrue("jar type is missing from the parsed types argument", uniqueParsedTypes.contains("jar"));
    assertTrue("jar type is missing from the parsed types argument", uniqueParsedTypes.contains("source"));
}
Also used : CommandLine(org.apache.ivy.util.cli.CommandLine) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with CommandLine

use of org.apache.ivy.util.cli.CommandLine in project ant-ivy by apache.

the class Main method run.

private static ResolveReport run(String[] args, boolean isCli) throws Exception {
    CommandLineParser parser = getParser();
    // parse the command line arguments
    CommandLine line;
    try {
        line = parser.parse(args);
    } catch (ParseException pe) {
        // display usage and and rethrow
        usage(parser, false);
        throw new ParseException(pe.getMessage());
    }
    if (line.hasOption("?")) {
        usage(parser, line.hasOption("deprecated"));
        return null;
    }
    return run(line, isCli);
}
Also used : CommandLine(org.apache.ivy.util.cli.CommandLine) CommandLineParser(org.apache.ivy.util.cli.CommandLineParser) ParseException(org.apache.ivy.util.cli.ParseException)

Aggregations

CommandLine (org.apache.ivy.util.cli.CommandLine)7 Test (org.junit.Test)6 File (java.io.File)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 CommandLineParser (org.apache.ivy.util.cli.CommandLineParser)1 ParseException (org.apache.ivy.util.cli.ParseException)1