ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1368709 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/osgi/core/ src/java/org/apache/ivy/osgi/obr/xml/ src/java/org/apache/ivy/osgi/repo/ test/java/org/apache/ivy/osgi/obr/
Date Thu, 02 Aug 2012 21:22:44 GMT
Author: hibou
Date: Thu Aug  2 21:22:44 2012
New Revision: 1368709

URL: http://svn.apache.org/viewvc?rev=1368709&view=rev
Log:
add support for source URI from OBR repositories

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfo.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/Requirement.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/BundleRepoDescriptor.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/obr/OBRParserTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu Aug  2 21:22:44 2012
@@ -135,6 +135,7 @@ for detailed view of each issue, please 
 - FIX: buildlist task chokes on absolute path to parent Ivy module (IVY-1364) (thanks to
Mitch Gitman and Jean-Louis Boudart)
 
 - IMPROVEMENT: add support for source bundles from p2 repositories
+- IMPROVEMENT: add support for source URI from OBR repositories
 
    2.3.0-rc1
 =====================================

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfo.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfo.java?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfo.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfo.java Thu Aug  2 21:22:44
2012
@@ -72,6 +72,8 @@ public class BundleInfo {
     /** the version of the bundle it is source of */
     private Version versionTarget;
 
+    private URI sourceURI;
+
     public BundleInfo(String name, Version version) {
         this.symbolicName = name;
         this.version = version;
@@ -191,6 +193,14 @@ public class BundleInfo {
         this.executionEnvironments = executionEnvironment;
     }
 
+    public void setSourceURI(URI sourceURI) {
+        this.sourceURI = sourceURI;
+    }
+
+    public URI getSourceURI() {
+        return sourceURI;
+    }
+
     public void setSource(boolean isSource) {
         this.isSource = isSource;
     }
@@ -228,6 +238,7 @@ public class BundleInfo {
         result = prime * result
                 + ((symbolicNameTarget == null) ? 0 : symbolicNameTarget.hashCode());
         result = prime * result + ((versionTarget == null) ? 0 : versionTarget.hashCode());
+        result = prime * result + ((sourceURI == null) ? 0 : sourceURI.hashCode());
         return result;
     }
 
@@ -294,6 +305,13 @@ public class BundleInfo {
         } else if (!versionTarget.equals(other.versionTarget)) {
             return false;
         }
+        if (sourceURI == null) {
+            if (other.sourceURI != null) {
+                return false;
+            }
+        } else if (!sourceURI.equals(other.sourceURI)) {
+            return false;
+        }
         return true;
     }
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java Thu Aug  2
21:22:44 2012
@@ -116,6 +116,11 @@ public class BundleInfoAdapter {
             DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, "jar");
             md.addArtifact(CONF_NAME_DEFAULT, artifact);
         }
+        URI sourceURI = bundle.getSourceURI();
+        if (sourceURI != null) {
+            DefaultArtifact artifact = buildArtifact(mrid, baseUri, sourceURI, "source");
+            md.addArtifact(CONF_NAME_DEFAULT, artifact);
+        }
 
         if (profileProvider != null) {
             Iterator itEnv = bundle.getExecutionEnvironments().iterator();

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java Thu Aug  2 21:22:44
2012
@@ -78,13 +78,7 @@ public class OBRXMLParser {
 
             repo.setName(atts.getValue(NAME));
 
-            try {
-                Long lastModified = getOptionalLongAttribute(atts, LASTMODIFIED, null);
-                repo.setLastModified(lastModified);
-            } catch (SAXParseException e) {
-                log(Message.MSG_WARN, e.getMessage() + ". It will be ignored.");
-            }
-
+            repo.setLastModified(atts.getValue(LASTMODIFIED));
         }
     }
 
@@ -112,6 +106,25 @@ public class OBRXMLParser {
             setSkipOnError(true); // if anything bad happen in any children, just ignore
the
                                   // resource
 
+            addChild(new ResourceSourceHandler(), new ChildElementHandler() {
+                public void childHanlded(DelegetingHandler child) {
+                    String uri = child.getBufferedChars().trim();
+                    if (!uri.endsWith(".jar")) {
+                        // the maven plugin is putting some useless source url sometimes...
+                        log(Message.MSG_WARN,
+                            "A source uri is suspect, it is not ending with .jar, it is probably"
+                                    + " a pointer to a download page. Ignoring it.");
+                        return;
+                    }
+                    try {
+                        bundleInfo.setSourceURI(new URI(uri));
+                    } catch (URISyntaxException e) {
+                        log(Message.MSG_WARN, "Incorrect uri " + uri + ". The source of "
+                                + bundleInfo.getSymbolicName() + " is then ignored.");
+                        return;
+                    }
+                }
+            });
             addChild(new ResourceDescriptionHandler(), new ChildElementHandler() {
                 public void childHanlded(DelegetingHandler child) {
                     bundleInfo.setDescription(child.getBufferedChars().trim());
@@ -165,6 +178,11 @@ public class OBRXMLParser {
                     }
                 }
             });
+            addChild(new ExtendHandler(), new ChildElementHandler() {
+                public void childHanlded(DelegetingHandler child) throws SAXParseException
{
+                    // TODO handle fragment host
+                }
+            });
         }
 
         protected void handleAttributes(Attributes atts) throws SAXException {
@@ -208,6 +226,17 @@ public class OBRXMLParser {
 
     }
 
+    static class ResourceSourceHandler extends DelegetingHandler {
+
+        static final String SOURCE = "source";
+
+        public ResourceSourceHandler() {
+            super(SOURCE);
+            setBufferingChar(true);
+        }
+
+    }
+
     static class ResourceDescriptionHandler extends DelegetingHandler {
 
         static final String DESCRIPTION = "description";
@@ -305,9 +334,7 @@ public class OBRXMLParser {
         }
     }
 
-    static class RequireHandler extends DelegetingHandler {
-
-        static final String REQUIRE = "require";
+    static class AbstractRequirementHandler extends DelegetingHandler {
 
         static final String NAME = "name";
 
@@ -315,16 +342,14 @@ public class OBRXMLParser {
 
         static final String MULTIPLE = "multiple";
 
-        static final String EXTEND = "extend";
-
         static final String FILTER = "filter";
 
-        private Requirement requirement;
+        Requirement requirement;
 
-        private RequirementFilter filter;
+        RequirementFilter filter;
 
-        public RequireHandler() {
-            super(REQUIRE);
+        public AbstractRequirementHandler(String name) {
+            super(name);
         }
 
         protected void handleAttributes(Attributes atts) throws SAXException {
@@ -343,7 +368,6 @@ public class OBRXMLParser {
 
             Boolean optional = getOptionalBooleanAttribute(atts, OPTIONAL, null);
             Boolean multiple = getOptionalBooleanAttribute(atts, MULTIPLE, null);
-            Boolean extend = getOptionalBooleanAttribute(atts, EXTEND, null);
 
             requirement = new Requirement(name, filter);
             if (optional != null) {
@@ -352,11 +376,27 @@ public class OBRXMLParser {
             if (multiple != null) {
                 requirement.setMultiple(multiple.booleanValue());
             }
-            if (extend != null) {
-                requirement.setExtend(extend.booleanValue());
-            }
         }
 
     }
 
+    static class RequireHandler extends AbstractRequirementHandler {
+
+        static final String REQUIRE = "require";
+
+        public RequireHandler() {
+            super(REQUIRE);
+        }
+
+    }
+
+    static class ExtendHandler extends AbstractRequirementHandler {
+
+        static final String EXTEND = "extend";
+
+        public ExtendHandler() {
+            super(EXTEND);
+        }
+
+    }
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/Requirement.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/Requirement.java?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/Requirement.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/Requirement.java Thu Aug  2 21:22:44
2012
@@ -27,8 +27,6 @@ public class Requirement {
 
     private boolean multiple = false;
 
-    private boolean extend = false;
-
     public Requirement(String name, RequirementFilter filter) {
         this.name = name;
         this.filter = filter;
@@ -50,14 +48,6 @@ public class Requirement {
         return optional;
     }
 
-    public void setExtend(boolean extend) {
-        this.extend = extend;
-    }
-
-    public boolean isExtend() {
-        return extend;
-    }
-
     public void setMultiple(boolean multiple) {
         this.multiple = multiple;
     }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/BundleRepoDescriptor.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/BundleRepoDescriptor.java?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/BundleRepoDescriptor.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/BundleRepoDescriptor.java Thu Aug
 2 21:22:44 2012
@@ -30,7 +30,7 @@ public class BundleRepoDescriptor extend
 
     private String name;
 
-    private Long lastModified;
+    private String lastModified;
 
     public BundleRepoDescriptor(URI baseUri, ExecutionEnvironmentProfileProvider profileProvider)
{
         super(baseUri, profileProvider);
@@ -44,11 +44,11 @@ public class BundleRepoDescriptor extend
         return name;
     }
 
-    public void setLastModified(Long lastModified) {
+    public void setLastModified(String lastModified) {
         this.lastModified = lastModified;
     }
 
-    public Long getLastModified() {
+    public String getLastModified() {
         return lastModified;
     }
 

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/obr/OBRParserTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/obr/OBRParserTest.java?rev=1368709&r1=1368708&r2=1368709&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/obr/OBRParserTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/obr/OBRParserTest.java Thu Aug  2 21:22:44
2012
@@ -19,10 +19,12 @@ package org.apache.ivy.osgi.obr;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.net.URL;
 import java.util.Iterator;
 
 import junit.framework.TestCase;
 
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.osgi.obr.xml.OBRXMLParser;
 import org.apache.ivy.osgi.repo.BundleRepoDescriptor;
 import org.apache.ivy.util.Message;
@@ -43,6 +45,38 @@ public class OBRParserTest extends TestC
             System.err.println(error);
         }
         assertEquals("OBR/Releases", repo.getName());
-        assertEquals(new Long(1253581430652l), repo.getLastModified());
+        assertEquals("1253581430652", repo.getLastModified());
+    }
+
+    public void testParseSource() throws Exception {
+        BundleRepoDescriptor repo = OBRXMLParser.parse(testObr.toURI(), new FileInputStream(
+                new File(testObr, "sources.xml")));
+        assertNotNull(repo);
+        assertEquals(2, repo.getModules().size());
+        Iterator itModule = repo.getModules().iterator();
+        while (itModule.hasNext()) {
+            ModuleDescriptor md = (ModuleDescriptor) itModule.next();
+            if (md.getModuleRevisionId().getName().equals("org.apache.felix.eventadmin"))
{
+                assertEquals(1, md.getAllArtifacts().length);
+            } else {
+                assertEquals("org.apache.felix.bundlerepository", md.getModuleRevisionId()
+                        .getName());
+                assertEquals(2, md.getAllArtifacts().length);
+                String url0 = md.getAllArtifacts()[0].getUrl().toExternalForm();
+                String url1 = md.getAllArtifacts()[1].getUrl().toExternalForm();
+                String jarUrl = "http://repo1.maven.org/maven2/org/apache/felix/"
+                        + "org.apache.felix.bundlerepository/1.0.3/org.apache.felix.bundlerepository-1.0.3.jar";
+                String srcUrl = "http://oscar-osgi.sf.net/obr2/org.apache.felix.bundlerepository/"
+                        + "org.apache.felix.bundlerepository-1.0.3-src.jar";
+                if (url0.equals(srcUrl)) {
+                    assertEquals(jarUrl, url1);
+                } else {
+                    assertEquals(jarUrl, url0);
+                    assertEquals(srcUrl, url1);
+                }
+            }
+        }
+        assertEquals("Felix-Releases", repo.getName());
+        assertEquals("20120203022437.168", repo.getLastModified());
     }
 }



Mime
View raw message