geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1167021 - in /geronimo/xbean/trunk/xbean-bundleutils/src: main/java/org/apache/xbean/osgi/bundle/util/HeaderParser.java test/java/org/apache/xbean/osgi/bundle/util/HeaderParserTest.java
Date Fri, 09 Sep 2011 07:01:22 GMT
Author: xuhaihong
Date: Fri Sep  9 07:01:22 2011
New Revision: 1167021

URL: http://svn.apache.org/viewvc?rev=1167021&view=rev
Log:
XBEAN-188 multiple import packages separate with semicolon could not be parsed correctly

Modified:
    geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/HeaderParser.java
    geronimo/xbean/trunk/xbean-bundleutils/src/test/java/org/apache/xbean/osgi/bundle/util/HeaderParserTest.java

Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/HeaderParser.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/HeaderParser.java?rev=1167021&r1=1167020&r2=1167021&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/HeaderParser.java
(original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/HeaderParser.java
Fri Sep  9 07:01:22 2011
@@ -49,6 +49,7 @@ public class HeaderParser  {
             }
             HeaderElement elem = new HeaderElement(tokens[0].trim());
             elements.add(elem);
+            int beginIndex = elements.size() - 1;
             for (int i = 1; i < tokens.length; i++) {
                 int pos = tokens[i].indexOf('=');
                 if (pos != -1) {
@@ -66,12 +67,17 @@ public class HeaderParser  {
                     elements.add(elem);
                 }
             }
+            for (; beginIndex < elements.size() - 1; beginIndex++) {
+                HeaderElement headerElement = elements.get(beginIndex);
+                headerElement.getAttributes().putAll(elem.getAttributes());
+                headerElement.getDirectives().putAll(elem.getDirectives());
+            }
         }
         return elements;
     }
 
-    private static List<String> parseDelimitedString(String value, String delim, boolean
includeQuotes) {   
-        if (value == null) {       
+    private static List<String> parseDelimitedString(String value, String delim, boolean
includeQuotes) {
+        if (value == null) {
             value = "";
         }
 
@@ -86,76 +92,76 @@ public class HeaderParser  {
 
         int expecting = (CHAR | DELIMITER | STARTQUOTE);
 
-        for (int i = 0; i < value.length(); i++) {        
+        for (int i = 0; i < value.length(); i++) {
             char c = value.charAt(i);
 
             boolean isDelimiter = (delim.indexOf(c) >= 0);
             boolean isQuote = (c == '"');
 
-            if (isDelimiter && ((expecting & DELIMITER) > 0)) {          
 
+            if (isDelimiter && ((expecting & DELIMITER) > 0)) {
                 list.add(sb.toString().trim());
                 sb.delete(0, sb.length());
                 expecting = (CHAR | DELIMITER | STARTQUOTE);
-            } else if (isQuote && ((expecting & STARTQUOTE) > 0)) { 
+            } else if (isQuote && ((expecting & STARTQUOTE) > 0)) {
                 if (includeQuotes) {
                     sb.append(c);
                 }
                 expecting = CHAR | ENDQUOTE;
-            } else if (isQuote && ((expecting & ENDQUOTE) > 0)) {    
+            } else if (isQuote && ((expecting & ENDQUOTE) > 0)) {
                 if (includeQuotes) {
                     sb.append(c);
                 }
                 expecting = (CHAR | STARTQUOTE | DELIMITER);
-            } else if ((expecting & CHAR) > 0) {            
+            } else if ((expecting & CHAR) > 0) {
                 sb.append(c);
             } else {
                 throw new IllegalArgumentException("Invalid delimited string: " + value);
             }
         }
 
-        if (sb.length() > 0) {        
+        if (sb.length() > 0) {
             list.add(sb.toString().trim());
         }
 
         return list;
     }
-    
+
     public static class HeaderElement {
-        
+
         private String path;
         private Map<String, String> attributes;
         private Map<String, String> directives;
-        
+
         public HeaderElement(String path) {
             this.path = path;
             this.attributes = new HashMap<String, String>();
             this.directives = new HashMap<String, String>();
         }
-        
+
         public String getName() {
             return this.path;
         }
-        
+
         public Map<String, String> getAttributes() {
             return attributes;
         }
-        
+
         public String getAttribute(String name) {
             return attributes.get(name);
         }
-        
+
         public void addAttribute(String name, String value) {
             attributes.put(name, value);
         }
-        
+
         public Map<String, String> getDirectives() {
             return directives;
         }
-        
+
         public String getDirective(String name) {
             return directives.get(name);
         }
-        
+
         public void addDirective(String name, String value) {
             directives.put(name, value);
         }
@@ -200,6 +206,6 @@ public class HeaderParser  {
             } else if (!path.equals(other.path))
                 return false;
             return true;
-        }                
+        }
     }
 }

Modified: geronimo/xbean/trunk/xbean-bundleutils/src/test/java/org/apache/xbean/osgi/bundle/util/HeaderParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/test/java/org/apache/xbean/osgi/bundle/util/HeaderParserTest.java?rev=1167021&r1=1167020&r2=1167021&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/test/java/org/apache/xbean/osgi/bundle/util/HeaderParserTest.java
(original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/test/java/org/apache/xbean/osgi/bundle/util/HeaderParserTest.java
Fri Sep  9 07:01:22 2011
@@ -39,7 +39,7 @@ public class HeaderParserTest extends Te
 
         assertEquals(paths, HeaderParser.parseHeader(HeaderBuilder.build(paths)));
     }
-    
+
     public void testComplex() throws Exception {
         String header = "OSGI-INF/blueprint/comp1_named.xml;ignored-directive:=true,OSGI-INF/blueprint/comp2_named.xml;some-other-attribute=1";
         List<HeaderElement> paths = HeaderParser.parseHeader(header);
@@ -64,8 +64,8 @@ public class HeaderParserTest extends Te
         assertEquals(1, paths.get(0).getDirectives().size());
         assertEquals("true", paths.get(0).getDirective("ignored-directive"));
         assertEquals("OSGI-INF/blueprint/comp2_named.xml", paths.get(1).getName());
-        assertEquals(0, paths.get(1).getAttributes().size());
-        assertEquals(0, paths.get(1).getDirectives().size());
+        assertEquals(2, paths.get(1).getAttributes().size());
+        assertEquals(2, paths.get(1).getDirectives().size());
         assertEquals("foo.xml", paths.get(2).getName());
         assertEquals(2, paths.get(2).getAttributes().size());
         assertEquals("b", paths.get(2).getAttribute("a"));
@@ -73,40 +73,57 @@ public class HeaderParserTest extends Te
         assertEquals(2, paths.get(2).getDirectives().size());
         assertEquals("d", paths.get(2).getDirective("c"));
         assertEquals("2", paths.get(2).getDirective("1"));
-        System.out.println(HeaderBuilder.build(paths));
         assertEquals(paths, HeaderParser.parseHeader(HeaderBuilder.build(paths)));
     }
-    
+
     public void testExportPackages() throws Exception {
         String header = "org.apache.geronimo.kernel.rmi;uses:=\"javax.rmi.ssl,org.apache.geronimo.gbean,org.slf4j\",org.apache.geronimo.kernel.proxy";
         List<HeaderElement> paths = HeaderParser.parseHeader(header);
         assertEquals(2, paths.size());
-        
+
         assertEquals("org.apache.geronimo.kernel.rmi", paths.get(0).getName());
         assertEquals(0, paths.get(0).getAttributes().size());
         assertEquals(1, paths.get(0).getDirectives().size());
         assertEquals("javax.rmi.ssl,org.apache.geronimo.gbean,org.slf4j", paths.get(0).getDirective("uses"));
-        
+
         assertEquals("org.apache.geronimo.kernel.proxy", paths.get(1).getName());
         assertEquals(0, paths.get(1).getAttributes().size());
         assertEquals(0, paths.get(1).getDirectives().size());
         assertEquals(paths, HeaderParser.parseHeader(HeaderBuilder.build(paths)));
     }
-    
+
     public void testImportPackages() throws Exception {
         String header = "com.thoughtworks.xstream;version=\"1.3\",com.thoughtworks.xstream.converters";
         List<HeaderElement> paths = HeaderParser.parseHeader(header);
         assertEquals(2, paths.size());
-        
+
         assertEquals("com.thoughtworks.xstream", paths.get(0).getName());
         assertEquals(1, paths.get(0).getAttributes().size());
         assertEquals("1.3", paths.get(0).getAttribute("version"));
         assertEquals(0, paths.get(0).getDirectives().size());
-        
+
         assertEquals("com.thoughtworks.xstream.converters", paths.get(1).getName());
         assertEquals(0, paths.get(1).getAttributes().size());
         assertEquals(0, paths.get(1).getDirectives().size());
 
         assertEquals(paths, HeaderParser.parseHeader(HeaderBuilder.build(paths)));
     }
+
+    public void testMultipleImportPackages() throws Exception {
+        String header = "javax.transaction; javax.transaction.xa; version=1.1; partial=true;
mandatory:=partial";
+        List<HeaderElement> paths = HeaderParser.parseHeader(header);
+        assertEquals(2, paths.size());
+
+        assertEquals("javax.transaction", paths.get(0).getName());
+        assertEquals(2, paths.get(0).getAttributes().size());
+        assertEquals("1.1", paths.get(0).getAttribute("version"));
+        assertEquals(1, paths.get(0).getDirectives().size());
+        assertEquals("partial", paths.get(0).getDirectives().get("mandatory"));
+
+        assertEquals("javax.transaction.xa", paths.get(1).getName());
+        assertEquals(2, paths.get(1).getAttributes().size());
+        assertEquals("1.1", paths.get(1).getAttribute("version"));
+        assertEquals(1, paths.get(1).getDirectives().size());
+        assertEquals("partial", paths.get(1).getDirectives().get("mandatory"));
+    }
 }



Mime
View raw message