maartenc commented on code in PR #120:
URL: https://github.com/apache/ant-ivy/pull/120#discussion_r3405291048
##########
test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java:
##########
@@ -103,6 +100,161 @@ public void testClassifier() throws Exception {
assertTrue("Some expected dependencies " + expectedPomArtifactIds + "
were not found in the generated POM file", expectedPomArtifactIds.isEmpty());
}
+ @Test
+ public void testMakePomWithTemplate() throws Exception {
+ File ivyFile = workdir.newFile("ivy.xml");
+ writeLines(ivyFile, "UTF-8", Arrays.asList(
+ "<ivy-module version='2.0'>",
+ " <info module='name' organisation='org'
revision='1.0.0-SNAPSHOT' />",
+ " <configurations>",
+ " <conf name='default' />",
+ " </configurations>",
+ " <dependencies defaultconf='default'
defaultconfmapping='*->master,runtime()'>",
+ " <dependency org='org.springframework' name='spring-aop'
rev='6.2.9' />",
+ " </dependencies>",
+ "</ivy-module>"
+ ));
+
+ File pomFile = workdir.newFile("ivy.pom");
+
+ File templateFile = workdir.newFile("the.pom");
+ writeLines(templateFile, "UTF-8", Arrays.asList(
+ "<project>",
+ " <groupId>${ivy.pom.groupId}</groupId>",
+ " <artifactId>${ivy.pom.artifactId}</artifactId>",
+ " <version>${ivy.pom.version}</version>",
+ " <dependencies>",
+ " <dependency>",
+ " <groupId>org.springframework</groupId>",
+ " <artifactId>spring-core</artifactId>",
+ " <version>6.2.9</version>",
+ " <scope>compile</scope>",
+ " </dependency>",
+ " </dependencies>",
+ "</project>"
+ ));
+
+ 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 = {
+ "<project>",
+ " <groupId>org</groupId>",
+ " <artifactId>name</artifactId>",
+ " <version>1.0.0-SNAPSHOT</version>",
+ " <dependencies>",
+ " <dependency>",
+ " <groupId>org.springframework</groupId>",
+ " <artifactId>spring-core</artifactId>",
+ " <version>6.2.9</version>",
+ " <scope>compile</scope>",
+ " </dependency>",
+ " <dependency>",
+ " <groupId>org.springframework</groupId>",
+ " <artifactId>spring-aop</artifactId>",
+ " <version>6.2.9</version>",
+ " <scope>compile</scope>",
+ " </dependency>",
+ " </dependencies>",
+ "</project>",
+ ""
+ };
+
+ assertEquals(String.join(System.lineSeparator(), expect),
readFileToString(pomFile, "UTF-8"));
+ }
+
+ /**
+ * Test case for <a
href="https://issues.apache.org/jira/browse/IVY-1667">IVY-1667</a>.
+ */
+ @Test
+ public void testMakePomWithTemplate1667() throws Exception {
+ File ivyFile = workdir.newFile("ivy.xml");
+ writeLines(ivyFile, "UTF-8", Arrays.asList(
+ "<ivy-module version='2.0'>",
+ " <info module='name' organisation='org'
revision='1.0.0-SNAPSHOT' />",
+ " <configurations>",
+ " <conf name='default' />",
+ " </configurations>",
+ " <dependencies defaultconf='default'
defaultconfmapping='*->master,runtime()'>",
+ " <dependency org='org.springframework' name='spring-aop'
rev='6.2.9' />",
+ " </dependencies>",
+ "</ivy-module>"
+ ));
+
+ File pomFile = workdir.newFile("ivy.pom");
+
+ File templateFile = workdir.newFile("the.pom");
+ writeLines(templateFile, "UTF-8", Arrays.asList(
+ "<project>",
+ " <groupId>${ivy.pom.groupId}</groupId>",
+ " <artifactId>${ivy.pom.artifactId}</artifactId>",
+ " <version>${ivy.pom.version}</version>",
+ " <dependencyManagement>",
+ " <dependencies>",
+ " <dependency>",
+ " <groupId>org.aspectj</groupId>",
+ " <artifactId>aspectjrt</artifactId>",
+ " <version>1.9.24</version>",
+ " </dependency>",
+ " </dependencies>",
+ " </dependencyManagement>",
+ "</project>"
+ ));
+
+ 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 = {
+ "<project>",
+ " <groupId>org</groupId>",
+ " <artifactId>name</artifactId>",
+ " <version>1.0.0-SNAPSHOT</version>",
+ " <dependencyManagement>",
+ " <dependencies>",
+ " <dependency>",
+ " <groupId>org.aspectj</groupId>",
+ " <artifactId>aspectjrt</artifactId>",
+ " <version>1.9.24</version>",
+ " </dependency>",
+ " </dependencies>",
+ " </dependencyManagement>",
+ " <dependencies>",
+ " <dependency>",
+ " <groupId>org.springframework</groupId>",
+ " <artifactId>spring-aop</artifactId>",
+ " <version>6.2.9</version>",
+ " <scope>compile</scope>",
+ " </dependency>",
+ " </dependencies>",
+ "</project>",
+ ""
+ };
+
+ assertEquals(String.join(System.lineSeparator(), expect),
readFileToString(pomFile, "UTF-8"));
+ }
Review Comment:
Can you also add a test where the template contains both a
<dependencyManagement> and a <dependencies> element?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]