result = new ArrayList<>();
diff --git a/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java b/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java
index fea6b0f8a..a5d224d9f 100644
--- a/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java
+++ b/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java
@@ -15,15 +15,10 @@
* limitations under the License.
*
*/
-
package org.apache.ivy.core.module.descriptor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -32,59 +27,61 @@
import org.apache.ivy.TestHelper;
import org.apache.ivy.ant.IvyMakePom;
import org.apache.ivy.util.TestXmlHelper;
+
import org.apache.tools.ant.Project;
-import org.junit.Before;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import static org.apache.commons.io.FileUtils.readFileToString;
+import static org.apache.commons.io.FileUtils.writeLines;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
/**
- * Tests {@link IvyMakePom}
+ * Tests {@link IvyMakePom}.
*/
public class IvyMakePomTest {
- private Project project;
+ private Project project = TestHelper.newProject();
@Rule
public TemporaryFolder workdir = new TemporaryFolder();
- @Before
- public void beforeTest() {
- this.project = TestHelper.newProject();
- }
-
/**
- * Test case for IVY-1528. An Ivy file containing a classifier extra attribute in
- * its dependency, must retain the classifier in the generated POM when converted
- * to a POM file through {@link IvyMakePom}.
- *
- * @throws Exception if something goes wrong
- * @see IVY-1528
+ * Test case for IVY-1528.
+ *
+ * An Ivy file containing a classifier extra attribute in its
+ * dependency, must retain the classifier in the generated POM
+ * when converted to a POM file through {@link IvyMakePom}.
*/
@Test
- public void testClassifier() throws Exception {
- final File ivyFile = new File(IvyMakePomTest.class.getResource("ivy-to-pom-classifier.xml").toURI());
+ public void testMakePom1528() throws Exception {
+ File ivyFile = new File(IvyMakePomTest.class.getResource("ivy-to-pom-classifier.xml").toURI());
assertTrue(ivyFile + " is either missing or not a file", ivyFile.isFile());
- final IvyMakePom makepom = new IvyMakePom();
- makepom.setProject(project);
- final File generatedPomFile = workdir.newFile("test-ivy-to-pom-classifier.pom");
- makepom.setPomFile(generatedPomFile);
- makepom.setIvyFile(ivyFile);
- // run the task
- makepom.execute();
-
- // read the generated pom
- final NodeList dependencies = (NodeList) TestXmlHelper.evaluateXPathExpr(generatedPomFile, "/project/dependencies/dependency", XPathConstants.NODESET);
+ File pomFile = workdir.newFile("test-ivy-to-pom-classifier.pom");
+
+ IvyMakePom task = new IvyMakePom();
+ task.setIvyFile(ivyFile);
+ task.setPomFile(pomFile);
+ task.setProject(project);
+ task.execute();
+
+ NodeList dependencies = (NodeList) TestXmlHelper.evaluateXPathExpr(pomFile, "/project/dependencies/dependency", XPathConstants.NODESET);
assertNotNull("Dependencies element wasn't found in the generated POM file", dependencies);
assertEquals("Unexpected number of dependencies in the generated POM file", 2, dependencies.getLength());
- final Set expectedPomArtifactIds = new HashSet<>();
+ Set expectedPomArtifactIds = new HashSet<>();
expectedPomArtifactIds.add("foo");
expectedPomArtifactIds.add("bar");
for (int i = 0; i < dependencies.getLength(); i++) {
- final PomDependency pomDependency = PomDependency.parse(dependencies.item(i));
+ PomDependency pomDependency = PomDependency.parse(dependencies.item(i));
assertNotNull("Dependency generated was null", pomDependency);
assertTrue("Unexpected dependency " + pomDependency, expectedPomArtifactIds.contains(pomDependency.artifactId));
// we no longer expect this, so remove it
@@ -103,6 +100,225 @@ public void testClassifier() throws Exception {
assertTrue("Some expected dependencies " + expectedPomArtifactIds + " were not found in the generated POM file", expectedPomArtifactIds.isEmpty());
}
+ /**
+ * Test case for IVY-1653.
+ */
+ @Test
+ public void testMakePom1653() throws Exception {
+ File ivyFile = workdir.newFile("ivy-1653.xml");
+ writeLines(ivyFile, "UTF-8", Arrays.asList(
+ "",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ ""
+ ));
+
+ File pomFile = workdir.newFile("ivy-1653.pom");
+
+ IvyMakePom task = new IvyMakePom();
+ task.setIvyFile(ivyFile);
+ task.setPomFile(pomFile);
+ task.setPrintIvyInfo(false);
+ task.setProject(project);
+
+ IvyMakePom.Mapping mapping = task.createMapping();
+ mapping.setConf("default");
+ mapping.setScope("compile");
+
+ task.execute();
+
+ String[] expect = {
+ "",
+ "",
+ "",
+ " 4.0.0",
+ " org",
+ " name",
+ " jar",
+ " 1.0.0-SNAPSHOT",
+ " ",
+ " ",
+ " org.springframework",
+ " spring-aop",
+ " 6.2.9",
+ " compile",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " org.aspectj",
+ " aspectjrt",
+ " 1.9.24",
+ " ",
+ " ",
+ " ",
+ "",
+ ""
+ };
+
+ assertEquals(String.join(System.lineSeparator(), expect), readFileToString(pomFile, "UTF-8"));
+ }
+
+ @Test
+ public void testMakePomWithTemplate() throws Exception {
+ File ivyFile = workdir.newFile("ivy.xml");
+ writeLines(ivyFile, "UTF-8", Arrays.asList(
+ "",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ ""
+ ));
+
+ File pomFile = workdir.newFile("ivy.pom");
+
+ File templateFile = workdir.newFile("the.pom");
+ writeLines(templateFile, "UTF-8", Arrays.asList(
+ "",
+ " ${ivy.pom.groupId}",
+ " ${ivy.pom.artifactId}",
+ " ${ivy.pom.version}",
+ " ",
+ " ",
+ " org.springframework",
+ " spring-core",
+ " 6.2.9",
+ " compile",
+ " ",
+ " ",
+ ""
+ ));
+
+ IvyMakePom task = new IvyMakePom();
+ task.setIvyFile(ivyFile);
+ task.setPomFile(pomFile);
+ task.setPrintIvyInfo(false);
+ task.setProject(project);
+ task.setTemplateFile(templateFile);
+
+ IvyMakePom.Mapping mapping = task.createMapping();
+ mapping.setConf("default");
+ mapping.setScope("compile");
+
+ task.execute();
+
+ String[] expect = {
+ "",
+ " org",
+ " name",
+ " 1.0.0-SNAPSHOT",
+ " ",
+ " ",
+ " org.springframework",
+ " spring-core",
+ " 6.2.9",
+ " compile",
+ " ",
+ " ",
+ " org.springframework",
+ " spring-aop",
+ " 6.2.9",
+ " compile",
+ " ",
+ " ",
+ "",
+ ""
+ };
+
+ assertEquals(String.join(System.lineSeparator(), expect), readFileToString(pomFile, "UTF-8"));
+ }
+
+ @Test
+ public void testMakePomWithTemplate2() throws Exception {
+ File ivyFile = workdir.newFile("ivy.xml");
+ writeLines(ivyFile, "UTF-8", Arrays.asList(
+ "",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ ""
+ ));
+
+ File pomFile = workdir.newFile("ivy.pom");
+
+ File templateFile = workdir.newFile("the.pom");
+ writeLines(templateFile, "UTF-8", Arrays.asList(
+ "",
+ " ${ivy.pom.groupId}",
+ " ${ivy.pom.artifactId}",
+ " ${ivy.pom.version}",
+ " ",
+ " ",
+ " ",
+ " org.aspectj",
+ " aspectjrt",
+ " 1.9.24",
+ " ",
+ " ",
+ " ",
+ ""
+ ));
+
+ IvyMakePom task = new IvyMakePom();
+ task.setIvyFile(ivyFile);
+ task.setPomFile(pomFile);
+ task.setPrintIvyInfo(false);
+ task.setProject(project);
+ task.setTemplateFile(templateFile);
+
+ IvyMakePom.Mapping mapping = task.createMapping();
+ mapping.setConf("default");
+ mapping.setScope("compile");
+
+ task.execute();
+
+ String[] expect = {
+ "",
+ " org",
+ " name",
+ " 1.0.0-SNAPSHOT",
+ " ",
+ " ",
+ " ",
+ " org.aspectj",
+ " aspectjrt",
+ " 1.9.24",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " org.springframework",
+ " spring-aop",
+ " 6.2.9",
+ " compile",
+ " ",
+ " ",
+ "",
+ ""
+ };
+
+ assertEquals(String.join(System.lineSeparator(), expect), readFileToString(pomFile, "UTF-8"));
+ }
+
+ //--------------------------------------------------------------------------
+
private static final class PomDependency {
private final String groupId;
private final String artifactId;