ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r657658 - in /ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2: PomModuleDescriptorBuilder.java PomModuleDescriptorParser.java PomReader.java
Date Sun, 18 May 2008 22:25:23 GMT
Author: maartenc
Date: Sun May 18 15:25:23 2008
New Revision: 657658

URL: http://svn.apache.org/viewvc?rev=657658&view=rev
Log:
Added quick-fix for IVY-633. I think it will solve most of the packaging problems, but we
should work on a better solution.

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java?rev=657658&r1=657657&r2=657658&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
Sun May 18 15:25:23 2008
@@ -18,11 +18,14 @@
 package org.apache.ivy.plugins.parser.m2;
 
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 import java.util.Map.Entry;
 
 import org.apache.ivy.Ivy;
@@ -43,8 +46,10 @@
 import org.apache.ivy.plugins.matcher.PatternMatcher;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
 import org.apache.ivy.plugins.parser.m2.PomReader.PomDependencyData;
+import org.apache.ivy.plugins.parser.m2.PomReader.PomPluginElement;
 import org.apache.ivy.plugins.repository.Resource;
 import org.apache.ivy.util.Message;
+import org.w3c.dom.Element;
 
 
 /**
@@ -202,8 +207,25 @@
 
 
     public void addArtifact(String artifactId, String packaging) {
+        String ext = packaging;
+
+        // TODO: we should refactor the following code into something more configurable
+
+        // if 'packaging == bundle' and if we use the 'maven-bundle-plugin', the
+        // type must be 'jar'
+        if ("bundle".equals(packaging)) {
+            for (Iterator it = getPlugins(ivyModuleDescriptor).iterator(); it.hasNext();)
{
+                PomDependencyMgt plugin = (PomDependencyMgt) it.next();
+                if ("org.apache.felix".equals(plugin.getGroupId())
+                        && "maven-bundle-plugin".equals(plugin.getArtifaceId()))
{
+                    ext = "jar";
+                    break;
+                }
+            }
+        }
+
         ivyModuleDescriptor.addArtifact("master", 
-                new DefaultArtifact(mrid, new Date(), artifactId, packaging, packaging));
+                new DefaultArtifact(mrid, new Date(), artifactId, ext, ext));
     }
 
 
@@ -267,6 +289,57 @@
             ExactPatternMatcher.INSTANCE,
             new OverrideDependencyDescriptorMediator(null, dep.getVersion()));
     }
+    
+    public void addPlugin(PomDependencyMgt plugin) {
+        String pluginValue = plugin.getGroupId() + EXTRA_INFO_DELIMITER + plugin.getArtifaceId()

+                + EXTRA_INFO_DELIMITER + plugin.getVersion();
+        String pluginExtraInfo = (String) ivyModuleDescriptor.getExtraInfo().get("maven.plugins");
+        if (pluginExtraInfo == null) {
+            pluginExtraInfo = pluginValue;
+        } else {
+            pluginExtraInfo = pluginExtraInfo + "|" + pluginValue;
+        }
+        ivyModuleDescriptor.getExtraInfo().put("m:maven.plugins", pluginExtraInfo);
+    }
+    
+    public static List /*<PomDependencyMgt>*/ getPlugins(ModuleDescriptor md) {
+        List result = new ArrayList();
+        String plugins = (String) md.getExtraInfo().get("m:maven.plugins");
+        if (plugins == null) {
+            return new ArrayList();
+        }
+        String[] pluginsArray = plugins.split("\\|");
+        for (int i = 0; i < pluginsArray.length; i++) {
+            String[] parts = pluginsArray[i].split(EXTRA_INFO_DELIMITER);
+            result.add(new PomPluginElement(parts[0], parts[1], parts[2]));
+        }
+        
+        return result;
+    }
+    
+    private static class PomPluginElement implements PomDependencyMgt {
+        private String groupId;
+        private String artifactId;
+        private String version;
+        
+        public PomPluginElement(String groupId, String artifactId, String version) {
+            this.groupId = groupId;
+            this.artifactId = artifactId;
+            this.version = version;
+        }
+        
+        public String getGroupId() {
+            return groupId;
+        }
+
+        public String getArtifaceId() {
+            return artifactId;
+        }
+
+        public String getVersion() {
+            return version;
+        }
+    }
 
     private String getDefaultVersion(PomDependencyData dep) {
         String key = getDependencyMgtExtraInfoKey(dep.getGroupId(), dep.getArtifaceId());
       

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java?rev=657658&r1=657657&r2=657658&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
Sun May 18 15:25:23 2008
@@ -24,6 +24,7 @@
 import java.text.ParseException;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.ivy.core.IvyContext;
@@ -215,6 +216,12 @@
                         mdBuilder.addDependencyMgt(
                             new DefaultPomDependencyMgt(mid.getOrganisation(), mid.getName(),
v));
                     }
+                    
+                    // add plugins from parent
+                    List /*<PomDependencyMgt>*/ plugins = PomModuleDescriptorBuilder.getPlugins(parentDescr);
+                    for (Iterator it = plugins.iterator(); it.hasNext();) {
+                        mdBuilder.addPlugin((PomDependencyMgt) it.next());
+                    }
                 }
                 
                 for (Iterator it = domReader.getDependencyMgt().iterator(); it.hasNext();)
{
@@ -233,6 +240,11 @@
                     }
                 }
                 
+                for (Iterator it = domReader.getPlugins().iterator(); it.hasNext();) {
+                    PomReader.PomPluginElement plugin = (PomReader.PomPluginElement) it.next();
+                    mdBuilder.addPlugin(plugin);
+                }
+                
                 mdBuilder.addArtifact(artifactId , domReader.getPackaging());
             }            
         } catch (SAXException e) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java?rev=657658&r1=657657&r2=657658&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java Sun May 18
15:25:23 2008
@@ -64,8 +64,8 @@
     private static final String DISTRIBUTION_MGT = "distributionManagement";
     private static final String RELOCATION = "relocation";
     private static final String PROPERTIES = "properties";
-    
-    
+    private static final String PLUGINS = "plugins";
+    private static final String PLUGIN = "plugin";
     
 
     private HashMap properties = new HashMap();
@@ -227,7 +227,6 @@
         return dependencies;
     }
 
-    
     public class PomDependencyMgtElement implements PomDependencyMgt {
         private final Element depElement;
         
@@ -261,6 +260,51 @@
         
     }
     
+    public List /* <PomPluginElement> */ getPlugins() {
+        LinkedList plugins = new LinkedList();
+
+        Element buildElement = getFirstChildElement(projectElement, "build");
+        if (buildElement == null) {
+            return plugins;
+        }
+        
+        Element pluginsElement = getFirstChildElement(buildElement, PLUGINS);
+        if (pluginsElement != null) {
+            NodeList childs = pluginsElement.getChildNodes();
+            for (int i = 0; i < childs.getLength(); i++) {
+                Node node = childs.item(i);
+                if (node instanceof Element && PLUGIN.equals(node.getNodeName()))
{
+                    plugins.add(new PomPluginElement((Element) node));
+                }
+            }
+        }
+        return plugins;
+    }
+
+    public class PomPluginElement implements PomDependencyMgt {
+        private Element pluginElement;
+        
+        PomPluginElement(Element pluginElement) {
+            this.pluginElement = pluginElement; 
+        }
+        
+        public String getGroupId() {
+            String val = getFirstChildText(pluginElement , GROUP_ID);
+            return replaceProps(val);
+        }
+
+        public String getArtifaceId() {
+            String val = getFirstChildText(pluginElement , ARTIFACT_ID);
+            return replaceProps(val);
+        }
+
+        public String getVersion() {
+            String val = getFirstChildText(pluginElement , VERSION);
+            return replaceProps(val);
+        }
+        
+    }
+    
     
     public class PomDependencyData extends PomDependencyMgtElement {
         private final Element depElement;



Mime
View raw message