Search in sources :

Example 1 with CommandLine

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

the class MainTest method testRetrieveOverwriteMode.

/**
 * Tests that the {@code overwriteMode} passed for the retrieve command works as expected
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testRetrieveOverwriteMode() throws Exception {
    final String[] args = new String[] { "-settings", "test/repositories/ivysettings.xml", "-retrieve", "build/test/main/retrieve/overwrite-test/[artifact].[ext]", "-overwriteMode", "different", "-ivy", "test/repositories/1/org/mod1/ivys/ivy-5.0.xml" };
    final CommandLine parsedCommand = Main.getParser().parse(args);
    final String parsedOverwriteMode = parsedCommand.getOptionValue("overwriteMode");
    assertEquals("Unexpected overwriteMode parsed", RetrieveOptions.OVERWRITEMODE_DIFFERENT, parsedOverwriteMode);
    // create a dummy file which we expect the retrieve task to overwrite
    final Path retrieveArtifactPath = Paths.get("build/test/main/retrieve/overwrite-test/foo-bar.jar");
    Files.createDirectories(retrieveArtifactPath.getParent());
    Files.write(retrieveArtifactPath, new byte[0]);
    assertEquals("Unexpected content at " + retrieveArtifactPath, 0, Files.readAllBytes(retrieveArtifactPath).length);
    // issue the retrieve (which retrieves the org:foo-bar:2.3.4 artifact)
    run(args);
    // expect the existing jar to be overwritten
    assertTrue("Content at " + retrieveArtifactPath + " was not overwritten by retrieve task", Files.readAllBytes(retrieveArtifactPath).length > 0);
}
Also used : Path(java.nio.file.Path) CommandLine(org.apache.ivy.util.cli.CommandLine) Test(org.junit.Test)

Example 2 with CommandLine

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

the class MainTest method testMakePom.

/**
 * Tests that the {@code makepom} option works as expected
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testMakePom() throws Exception {
    final String pomFilePath = this.tempDir.getRoot().getAbsolutePath() + File.separator + "testmakepom.xml";
    final String[] args = new String[] { "-settings", "test/repositories/ivysettings.xml", "-makepom", pomFilePath, "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml" };
    final CommandLine parsedCommand = Main.getParser().parse(args);
    final String parsedMakePomPath = parsedCommand.getOptionValue("makepom");
    assertEquals("Unexpected makepom parsed", pomFilePath, parsedMakePomPath);
    assertFalse("pom file " + pomFilePath + " already exists", new File(pomFilePath).exists());
    // run the command
    run(args);
    assertTrue("pom file hasn't been generated at " + pomFilePath, new File(pomFilePath).isFile());
}
Also used : CommandLine(org.apache.ivy.util.cli.CommandLine) File(java.io.File) Test(org.junit.Test)

Example 3 with CommandLine

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

the class MainTest method testExtraParams1.

@Test
public void testExtraParams1() throws Exception {
    String[] params = new String[] { "-settings", "test/repositories/ivysettings.xml", "-confs", "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml", "foo1", "foo2" };
    CommandLine line = Main.getParser().parse(params);
    String[] leftOver = line.getLeftOverArgs();
    assertNotNull(leftOver);
    assertEquals(2, leftOver.length);
    assertEquals("foo1", leftOver[0]);
    assertEquals("foo2", leftOver[1]);
}
Also used : CommandLine(org.apache.ivy.util.cli.CommandLine) Test(org.junit.Test)

Example 4 with CommandLine

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

the class MainTest method testExtraParams3.

@Test
public void testExtraParams3() throws Exception {
    String[] params = new String[] { "-settings", "test/repositories/ivysettings.xml", "-confs", "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml" };
    CommandLine line = Main.getParser().parse(params);
    String[] leftOver = line.getLeftOverArgs();
    assertNotNull(leftOver);
    assertEquals(0, leftOver.length);
}
Also used : CommandLine(org.apache.ivy.util.cli.CommandLine) Test(org.junit.Test)

Example 5 with CommandLine

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

the class MainTest method testExtraParams2.

@Test
public void testExtraParams2() throws Exception {
    String[] params = new String[] { "-settings", "test/repositories/ivysettings.xml", "-confs", "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml", "--", "foo1", "foo2" };
    CommandLine line = Main.getParser().parse(params);
    String[] leftOver = line.getLeftOverArgs();
    assertNotNull(leftOver);
    assertEquals(2, leftOver.length);
    assertEquals("foo1", leftOver[0]);
    assertEquals("foo2", leftOver[1]);
}
Also used : CommandLine(org.apache.ivy.util.cli.CommandLine) Test(org.junit.Test)

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