Author: hibou
Date: Sun Nov 13 19:55:21 2011
New Revision: 1201498

URL: http://svn.apache.org/viewvc?rev=1201498&view=rev
Log:
Fix composite P2 respotory parsing

Added:
    ant/ivy/core/trunk/test/test-p2/composite/
    ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml   (with 
props)
    ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml   (with 
props)
Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2ArtifactParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2CompositeParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2Descriptor.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepoDescriptor.java
    
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoader.java
    
ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoaderTest.java

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2ArtifactParser.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2ArtifactParser.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2ArtifactParser.java 
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2ArtifactParser.java 
Sun Nov 13 19:55:21 2011
@@ -38,12 +38,15 @@ public class P2ArtifactParser implements
 
     private final P2Descriptor p2Descriptor;
 
-    public P2ArtifactParser(P2Descriptor p2Descriptor) {
+    private final String repoUrl;
+
+    public P2ArtifactParser(P2Descriptor p2Descriptor, String repoUrl) {
         this.p2Descriptor = p2Descriptor;
+        this.repoUrl = repoUrl;
     }
 
     public void parse(InputStream in) throws ParseException, IOException, 
SAXException {
-        RepositoryHandler handler = new RepositoryHandler(p2Descriptor);
+        RepositoryHandler handler = new RepositoryHandler(p2Descriptor, 
repoUrl);
         try {
             XMLHelper.parse(in, null, handler, null);
         } catch (ParserConfigurationException e) {
@@ -63,7 +66,7 @@ public class P2ArtifactParser implements
 
         private Map/* <String, String> */patternsByClassifier = new HashMap();
 
-        public RepositoryHandler(final P2Descriptor p2Descriptor) {
+        public RepositoryHandler(final P2Descriptor p2Descriptor, String 
repoUrl) {
             super(REPOSITORY);
             // addChild(new PropertiesHandler(), new ChildElementHandler() {
             // public void childHanlded(DelegetingHandler child) {
@@ -85,7 +88,7 @@ public class P2ArtifactParser implements
                     }
                 }
             });
-            addChild(new ArtifactsHandler(p2Descriptor, patternsByClassifier),
+            addChild(new ArtifactsHandler(p2Descriptor, patternsByClassifier, 
repoUrl),
                 new ChildElementHandler() {
                     public void childHanlded(DelegetingHandler child) {
                         // nothing to do
@@ -153,12 +156,13 @@ public class P2ArtifactParser implements
         // private static final String SIZE = "size";
 
         public ArtifactsHandler(final P2Descriptor p2Descriptor,
-                final Map/* <String, String> */patternsByClassifier) {
+                final Map/* <String, String> */patternsByClassifier, final 
String repoUrl) {
             super(ARTIFACTS);
             addChild(new ArtifactHandler(), new ChildElementHandler() {
                 public void childHanlded(DelegetingHandler child) {
                     P2Artifact a = ((ArtifactHandler) child).p2Artifact;
                     String url = (String) 
patternsByClassifier.get(a.getClassifier());
+                    url = url.replaceAll("\\$\\{repoUrl\\}", repoUrl);
                     p2Descriptor.addArtifactUrl(a.getId(), a.getVersion(), 
url);
                 }
             });

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2CompositeParser.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2CompositeParser.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2CompositeParser.java 
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2CompositeParser.java 
Sun Nov 13 19:55:21 2011
@@ -21,7 +21,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.xml.parsers.ParserConfigurationException;
 
@@ -32,9 +34,9 @@ import org.xml.sax.SAXException;
 
 public class P2CompositeParser implements XMLInputParser {
 
-    private List/* <String> */childLocations;
+    private Set/* <String> */childLocations = new LinkedHashSet();
 
-    public List getChildLocations() {
+    public Set getChildLocations() {
         return childLocations;
     }
 
@@ -45,7 +47,7 @@ public class P2CompositeParser implement
         } catch (ParserConfigurationException e) {
             throw new SAXException(e);
         }
-        childLocations = handler.childLocations;
+        childLocations.addAll(handler.childLocations);
     }
 
     static class RepositoryHandler extends DelegetingHandler {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2Descriptor.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2Descriptor.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2Descriptor.java 
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2Descriptor.java Sun 
Nov 13 19:55:21 2011
@@ -20,7 +20,9 @@ package org.apache.ivy.osgi.p2;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.ivy.osgi.core.BundleInfo;
@@ -51,14 +53,14 @@ public class P2Descriptor extends RepoDe
 
     public void addBundle(BundleInfo bundleInfo) {
         // before transforming it and adding it into the repo, let's add the 
artifacts
+        // and if no artifact, then no bundle
 
         Map/* <Version, String> */urlPatternsByVersion = (Map) 
artifactUrlPatterns.get(bundleInfo
                 .getSymbolicName());
         if (urlPatternsByVersion != null) {
             String urlPattern = (String) 
urlPatternsByVersion.get(bundleInfo.getVersion());
             if (urlPattern != null) {
-                String url = urlPattern.replaceAll("\\$\\{repoUrl\\}", 
repoUrl);
-                url = url.replaceAll("\\$\\{id\\}", 
bundleInfo.getSymbolicName());
+                String url = urlPattern.replaceAll("\\$\\{id\\}", 
bundleInfo.getSymbolicName());
                 url = url.replaceAll("\\$\\{version\\}", 
bundleInfo.getVersion().toString());
                 try {
                     bundleInfo.setUri(new URI(url));
@@ -66,10 +68,9 @@ public class P2Descriptor extends RepoDe
                     throw new RuntimeException("Unable to build the artifact 
uri of " + bundleInfo,
                             e);
                 }
+                super.addBundle(bundleInfo);
             }
         }
-
-        super.addBundle(bundleInfo);
     }
 
     public void addArtifactUrl(String id, Version version, String url) {
@@ -80,4 +81,5 @@ public class P2Descriptor extends RepoDe
         }
         byVersion.put(version, url);
     }
+
 }

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java 
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java 
Sun Nov 13 19:55:21 2011
@@ -187,7 +187,10 @@ public class P2MetadataParser implements
             super(UNITS);
             addChild(new UnitHandler(), new ChildElementHandler() {
                 public void childHanlded(DelegetingHandler child) {
-                    bundles.add(((UnitHandler) child).bundleInfo);
+                    BundleInfo bundleInfo = ((UnitHandler) child).bundleInfo;
+                    if (!bundleInfo.getCapabilities().isEmpty()) {
+                        bundles.add(((UnitHandler) child).bundleInfo);
+                    }
                 }
             });
         }
@@ -207,7 +210,7 @@ public class P2MetadataParser implements
 
         private static final String VERSION = "version";
 
-        private static final String SINGLETON = "singleton";
+        // private static final String SINGLETON = "singleton";
 
         BundleInfo bundleInfo;
 
@@ -350,6 +353,9 @@ public class P2MetadataParser implements
                     String name = ((ProvidedHandler) child).name;
                     Version version = ((ProvidedHandler) child).version;
                     String type = namespace2Type(((ProvidedHandler) 
child).namespace);
+                    if (type == null) {
+                        return;
+                    }
                     BundleCapability capability;
                     if (type == BundleInfo.PACKAGE_TYPE) {
                         capability = new ExportPackage(name, version);
@@ -423,7 +429,7 @@ public class P2MetadataParser implements
 
     static class RequiresHandler extends AbstractRequirementHandler {
 
-        private static final String REQUIRES = "provides";
+        private static final String REQUIRES = "requires";
 
         public RequiresHandler() {
             super(REQUIRES);
@@ -679,7 +685,7 @@ public class P2MetadataParser implements
 
         private static final String CHANGES = "changes";
 
-        private static final String SIZE = "size";
+        // private static final String SIZE = "size";
 
         public ChangesHandler() {
             super(CHANGES);
@@ -690,7 +696,7 @@ public class P2MetadataParser implements
         }
 
         protected void handleAttributes(Attributes atts) {
-            int size = Integer.parseInt(atts.getValue(SIZE));
+            // int size = Integer.parseInt(atts.getValue(SIZE));
         }
     }
 
@@ -727,7 +733,7 @@ public class P2MetadataParser implements
 
         private static final String PATCH_SCOPE = "patchScope";
 
-        private static final String SIZE = "size";
+        // private static final String SIZE = "size";
 
         public PatchScopeHandler() {
             super(PATCH_SCOPE);
@@ -738,7 +744,7 @@ public class P2MetadataParser implements
         }
 
         protected void handleAttributes(Attributes atts) {
-            int size = Integer.parseInt(atts.getValue(SIZE));
+            // int size = Integer.parseInt(atts.getValue(SIZE));
         }
     }
 

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepoDescriptor.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepoDescriptor.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepoDescriptor.java 
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepoDescriptor.java 
Sun Nov 13 19:55:21 2011
@@ -90,7 +90,8 @@ public class RepoDescriptor {
             map.put(value, bundleReferences);
         }
         if (!bundleReferences.add(md)) {
-            Message.warn("The repo did already contains " + md);
+            Message.debug("Duplicate module in the repo " + baseUri + " for " 
+ type + " "
+                    + value + ": " + md.getModuleRevisionId());
         }
     }
 

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoader.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoader.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoader.java
 (original)
+++ 
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoader.java
 Sun Nov 13 19:55:21 2011
@@ -105,15 +105,22 @@ public class UpdateSiteLoader {
 
     private boolean populateP2Descriptor(URI repoUri, P2Descriptor 
p2Descriptor)
             throws IOException, ParseException, SAXException {
-        boolean exist = false;
-
-        exist |= readComposite(repoUri, "compositeContent", p2Descriptor);
-
-        exist |= readComposite(repoUri, "compositeArtifacts", p2Descriptor);
+        Message.verbose("Loading P2 repository " + repoUri);
 
-        exist |= readJarOrXml(repoUri, "artifacts", new 
P2ArtifactParser(p2Descriptor));
+        boolean exist = false;
 
-        exist |= readJarOrXml(repoUri, "content", new 
P2MetadataParser(p2Descriptor));
+        boolean artifactExists = readComposite(repoUri, "compositeArtifacts", 
p2Descriptor);
+        if (!artifactExists) {
+            artifactExists = readJarOrXml(repoUri, "artifacts", new 
P2ArtifactParser(p2Descriptor,
+                    repoUri.toURL().toExternalForm()));
+        }
+        exist |= artifactExists;
+
+        boolean contentExists = readComposite(repoUri, "compositeContent", 
p2Descriptor);
+        if (!contentExists) {
+            contentExists = readJarOrXml(repoUri, "content", new 
P2MetadataParser(p2Descriptor));
+        }
+        exist |= artifactExists;
 
         return exist;
     }

Modified: 
ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoaderTest.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoaderTest.java?rev=1201498&r1=1201497&r2=1201498&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoaderTest.java
 (original)
+++ 
ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/updatesite/UpdateSiteLoaderTest.java
 Sun Nov 13 19:55:21 2011
@@ -79,4 +79,13 @@ public class UpdateSiteLoaderTest extend
         assertTrue(site.getModules().size() > 900);
     }
 
+    public void testComposite() throws Exception {
+        RepoDescriptor site = loader.load(new 
File("test/test-p2/composite/").toURI());
+        assertEquals(18, site.getModules().size());
+
+        // check that the url of the artifact is correctly resolved
+        String path = new 
File("test/test-p2/ivyde-repo/").toURI().toURL().toExternalForm();
+        ModuleDescriptor md = (ModuleDescriptor) 
site.getModules().iterator().next();
+        
assertTrue(md.getAllArtifacts()[0].getUrl().toExternalForm().startsWith(path));
+    }
 }

Added: ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml?rev=1201498&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml (added)
+++ ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml Sun Nov 13 
19:55:21 2011
@@ -0,0 +1,29 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<?compositeArtifactRepository version='1.0.0'?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<repository name='IvyDE test composite Repository' 
type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository'
 version='1.0.0'>
+  <properties size='2'>
+    <property name='p2.timestamp' value='1308747727547'/>
+    <property name='p2.compressed' value='true'/>
+  </properties>
+  <children size='2'>
+    <child location='../ivyde-repo'/>
+  </children>
+</repository>

Propchange: ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/core/trunk/test/test-p2/composite/compositeArtifacts.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml?rev=1201498&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml (added)
+++ ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml Sun Nov 13 
19:55:21 2011
@@ -0,0 +1,29 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<?compositeMetadataRepository version='1.0.0'?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<repository name='IvyDE test composite repository' 
type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository'
 version='1.0.0'>
+  <properties size='2'>
+    <property name='p2.timestamp' value='1308747730658'/>
+    <property name='p2.compressed' value='true'/>
+  </properties>
+  <children size='2'>
+    <child location='../ivyde-repo'/>
+  </children>
+</repository>

Propchange: ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/core/trunk/test/test-p2/composite/compositeContent.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to