From 1a89989477047546285718922b74d1c821e7d153 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Sat, 12 May 2007 10:37:26 +0000 Subject: [PATCH] FIX: packaging data not parsed in maven 2 pom (IVY-500) (thanks to Jeffrey Blatttman) git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/core/trunk@537380 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../parser/m2/PomModuleDescriptorParser.java | 17 ++++++++-- .../m2/PomModuleDescriptorParserTest.java | 20 ++++++++++++ .../ivy/plugins/parser/m2/test-packaging.pom | 32 +++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 test/java/org/apache/ivy/plugins/parser/m2/test-packaging.pom diff --git a/CHANGES.txt b/CHANGES.txt index ff31a3f9..b2930a50 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -51,6 +51,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br - IMPROVEMENT: Allow "main" parameters to be passed directly (instead of using -args flag) (IVY-480) (thanks to Archie Cobbs) +- FIX: packaging data not parsed in maven 2 pom (IVY-500) (thanks to Jeffrey Blatttman) - FIX: install ant task: requires default resolver in ivy settings (IVY-477) - FIX: Ant project reference lost from context on multiple ant calls in single thread (IVY-497) (thanks to Jaroslaw Wypychowski) - FIX: EOL in the doc pages (IVY-470) diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java index 39a0f0fb..c757df06 100644 --- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java +++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java @@ -85,6 +85,8 @@ public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { private String _revision; private String _scope; private String _classifier; + private String _type; + private String _ext; private boolean _optional = false; private List _exclusions = new ArrayList(); private DefaultDependencyDescriptor _dd; @@ -138,7 +140,10 @@ public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { _properties.put("project.version", _revision); _properties.put("pom.version", _revision); _md.setModuleRevisionId(mrid); - _md.addArtifact("master", new DefaultArtifact(mrid, getDefaultPubDate(),_module, "jar", "jar")); + if (_type == null) { + _type = _ext = "jar"; + } + _md.addArtifact("master", new DefaultArtifact(mrid, getDefaultPubDate(),_module, _type, _ext)); _organisation = null; _module = null; _revision = null; @@ -177,7 +182,7 @@ public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { _dd.addDependencyArtifact( confs[i], new DefaultDependencyArtifactDescriptor( - _dd.getDependencyId().getName(), + _dd.getDependencyId().getName(), "jar", "jar", // here we have to assume a type and ext for the artifact, so this is a limitation compared to how m2 behave with classifiers null, @@ -232,6 +237,11 @@ public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { _revision = txt; return; } + if (context.equals("project/parent/packaging") && _type == null) { + _type = txt; + _ext = txt; + return; + } if (context.startsWith("project/parent")) { return; } @@ -247,6 +257,9 @@ public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { _revision = txt; } else if (_revision == null && context.endsWith("version")) { _revision = txt; + } else if (_type == null && context.endsWith("packaging")) { + _type = txt; + _ext = txt; } else if (_scope == null && context.endsWith("scope")) { _scope = txt; } else if (_classifier == null && context.endsWith("dependency/classifier")) { diff --git a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java index ef9704c5..3642282d 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java +++ b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java @@ -58,6 +58,26 @@ public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParse assertEquals(1, artifact.length); assertEquals(mrid, artifact[0].getModuleRevisionId()); assertEquals("test", artifact[0].getName()); + assertEquals("jar", artifact[0].getExt()); + assertEquals("jar", artifact[0].getType()); + } + + public void testPackaging() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), getClass().getResource("test-packaging.pom"), false); + assertNotNull(md); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays.asList(md.getConfigurations())); + + Artifact[] artifact = md.getArtifacts("master"); + assertEquals(1, artifact.length); + assertEquals(mrid, artifact[0].getModuleRevisionId()); + assertEquals("test", artifact[0].getName()); + assertEquals("war", artifact[0].getExt()); + assertEquals("war", artifact[0].getType()); } public void testParent() throws Exception { diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-packaging.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-packaging.pom new file mode 100644 index 00000000..7e8438d7 --- /dev/null +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-packaging.pom @@ -0,0 +1,32 @@ + + + + 4.0.0 + org.apache + test + war + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + +