Added makepom option to main/standalone

This close PR #71 at github.com/apache/ant-ivy
This commit is contained in:
Thomas Pasch 2018-03-27 21:17:01 +02:00 committed by Jaikiran Pai
parent 198af5cdf1
commit 73f7cf413d
4 changed files with 41 additions and 0 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ test/repositories/norevision/ivy-mod1.1.xml
test/repositories/norevision/mod1.1.jar
test/test-repo/bundlerepo/*.jar
test/test-repo/ivyrepo/org.apache.ivy.osgi
out/

View File

@ -93,6 +93,7 @@ For details about the following changes, check our JIRA install at link:https://
- NEW: Lets SSH-based resolvers use an `~/.ssh/config` file to find username/hostname/keyfile options (Thanks to Colin Stanfill)
- NEW: Add ivy.maven.lookup.sources and ivy.maven.lookup.javadoc variables to control the lookup of the additional artifacts. Defaults to true, for backward compatibility (jira:IVY-1529[])
- NEW: Add (conditional) support for SHA-256, SHA-512 and SHA-384 checksum algorithms (jira:IVY-1554[]) (Thanks to Jaikiran Pai)
- NEW: The standalone Ivy jar can now be used to generate a pom file for the resolved module, using the `makepom` option (Thanks to link:https://github.com/aanno[aanno])
////

View File

@ -47,6 +47,8 @@ import org.apache.ivy.core.resolve.ResolveOptions;
import org.apache.ivy.core.resolve.ResolveProcessException;
import org.apache.ivy.core.retrieve.RetrieveOptions;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorWriter;
import org.apache.ivy.plugins.parser.m2.PomWriterOptions;
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
import org.apache.ivy.plugins.report.XmlReportParser;
import org.apache.ivy.util.DefaultMessageLogger;
@ -174,6 +176,10 @@ public final class Main {
new OptionBuilder("overwrite").description(
"overwrite files in the repository if they exist").create())
.addCategory("makepom options")
.addOption(new OptionBuilder("makepom").arg("pomfilepath")
.description("Creates a pom file for the module").create())
.addCategory("http auth options")
.addOption(
new OptionBuilder("realm").arg("realm")
@ -199,6 +205,7 @@ public final class Main {
new OptionBuilder("cp").arg("cp")
.description("extra classpath to use when launching process").create())
.addCategory("message options")
.addOption(
new OptionBuilder("debug").description("set message level to debug").create())
@ -419,6 +426,12 @@ public final class Main {
.setOverwrite(line.hasOption("overwrite")));
}
}
if (line.hasOption("makepom")) {
final String pomFilePath = line.getOptionValue("makepom", "pom.xml");
final File pomFile = new File(pomFilePath);
PomModuleDescriptorWriter.write(md, pomFile, new PomWriterOptions());
Message.debug("Generated a pom file for module at " + pomFile);
}
if (line.hasOption("main")) {
// check if the option cp has been set
List<File> fileList = getExtraClasspathFileList(line);

View File

@ -18,6 +18,8 @@
package org.apache.ivy;
import org.apache.ivy.core.retrieve.RetrieveOptions;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser;
import org.apache.ivy.util.CacheCleaner;
import org.apache.ivy.util.cli.CommandLine;
import org.apache.ivy.util.cli.ParseException;
@ -26,6 +28,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.nio.file.Files;
@ -36,6 +39,7 @@ import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@ -46,6 +50,9 @@ public class MainTest {
@Rule
public ExpectedException expExc = ExpectedException.none();
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();
@Before
public void setUp() {
cache = new File("build/cache");
@ -182,6 +189,25 @@ public class MainTest {
assertTrue("Content at " + retrieveArtifactPath + " was not overwritten by retrieve task", Files.readAllBytes(retrieveArtifactPath).length > 0);
}
/**
* 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());
}
private void run(String[] args) throws Exception {
Main.run(Main.getParser(), args);
}