maartenc commented on code in PR #114:
URL: https://github.com/apache/ant-ivy/pull/114#discussion_r2283077210


##########
test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java:
##########
@@ -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 <a 
href="https://issues.apache.org/jira/browse/IVY-1653";>IVY-1653</a>.
+     */
+    @Test
+    public void testMakePom1653() throws Exception {
+        File ivyFile = workdir.newFile("ivy-1653.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' />",
+            "    <override org='org.aspectj' module='aspectjrt' rev='1.9.24' 
/>",
+            "  </dependencies>",
+            "</ivy-module>"
+        ));
+
+        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 = {
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
+            "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"; 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";,
+            "    xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd\";>",
+            "",
+            "  <modelVersion>4.0.0</modelVersion>",
+            "  <groupId>org</groupId>",
+            "  <artifactId>name</artifactId>",
+            "  <packaging>jar</packaging>",
+            "  <version>1.0.0-SNAPSHOT</version>",
+            "  <dependencies>",
+            "    <dependency>",
+            "      <groupId>org.springframework</groupId>",
+            "      <artifactId>spring-aop</artifactId>",
+            "      <version>6.2.9</version>",
+            "      <scope>compile</scope>",
+            "    </dependency>",
+            "  </dependencies>",
+            "  <dependencyManagement>",
+            "    <dependencies>",
+            "      <dependency>",
+            "        <groupId>org.aspectj</groupId>",
+            "        <artifactId>aspectjrt</artifactId>",
+            "        <version>1.9.24</version>",
+            "      </dependency>",
+            "    </dependencies>",
+            "  </dependencyManagement>",
+            "</project>",
+            ""
+        };
+
+        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(
+            "<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
+    public void testMakePomWithTemplate2() 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:
   Could you also add a test case for updating a template pom.xml that already 
has a dependencyManagement section, and we have an ivy.xml with an override 
element. (just to verify that an existing dependencyManagent gets updated 
correctly.



##########
test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java:
##########
@@ -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 <a 
href="https://issues.apache.org/jira/browse/IVY-1653";>IVY-1653</a>.
+     */
+    @Test
+    public void testMakePom1653() throws Exception {
+        File ivyFile = workdir.newFile("ivy-1653.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' />",
+            "    <override org='org.aspectj' module='aspectjrt' rev='1.9.24' 
/>",
+            "  </dependencies>",
+            "</ivy-module>"
+        ));
+
+        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 = {
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
+            "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"; 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";,
+            "    xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd\";>",
+            "",
+            "  <modelVersion>4.0.0</modelVersion>",
+            "  <groupId>org</groupId>",
+            "  <artifactId>name</artifactId>",
+            "  <packaging>jar</packaging>",
+            "  <version>1.0.0-SNAPSHOT</version>",
+            "  <dependencies>",
+            "    <dependency>",
+            "      <groupId>org.springframework</groupId>",
+            "      <artifactId>spring-aop</artifactId>",
+            "      <version>6.2.9</version>",
+            "      <scope>compile</scope>",
+            "    </dependency>",
+            "  </dependencies>",
+            "  <dependencyManagement>",
+            "    <dependencies>",
+            "      <dependency>",
+            "        <groupId>org.aspectj</groupId>",
+            "        <artifactId>aspectjrt</artifactId>",
+            "        <version>1.9.24</version>",
+            "      </dependency>",
+            "    </dependencies>",
+            "  </dependencyManagement>",
+            "</project>",
+            ""
+        };
+
+        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(
+            "<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
+    public void testMakePomWithTemplate2() 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:
   Could you also add a test case for updating a template pom.xml that already 
has a dependencyManagement section, and we have an ivy.xml with an override 
element. (just to verify that an existing dependencyManagent gets updated 
correctly).



-- 
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: dev-unsubscr...@ant.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org

Reply via email to