felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r835908 - /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
Date Fri, 13 Nov 2009 16:40:13 GMT
Author: rickhall
Date: Fri Nov 13 16:40:12 2009
New Revision: 835908

URL: http://svn.apache.org/viewvc?rev=835908&view=rev
Log:
Implemented method to manually read manifest.

Modified:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java?rev=835908&r1=835907&r2=835908&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
Fri Nov 13 16:40:12 2009
@@ -20,20 +20,23 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import org.apache.felix.resolver.ExportedPackage;
 import org.apache.felix.resolver.ImportedPackage;
 import org.apache.felix.resolver.Module;
 import org.apache.felix.resolver.Resolver;
 import org.apache.felix.resolver.Wire;
-import org.apache.felix.resolver.prototype.ProtoResolver;
 import org.apache.felix.resolver.felix.FelixResolver;
+import org.apache.felix.resolver.prototype.ProtoResolver;
 
 public class Main
 {
@@ -192,6 +195,7 @@
             JarFile jarFile = new JarFile(jarList.get(jarIdx));
             try
             {
+//                Map headerMap = new StringMap(getMainAttributes(jarFile), false);
                 Map headerMap = new StringMap(jarFile.getManifest().getMainAttributes(),
false);
                 if (headerMap.containsKey("Bundle-SymbolicName"))
                 {
@@ -231,8 +235,6 @@
         {
             long starttime = System.currentTimeMillis();
             Map<Module, List<Wire>> wireMap = resolver.resolve(maxImporter);
-//            Map<Module, List<Wire>> wireMap = resolver.resolve(resolver.getModule("com.sun.enterprise.hk2-core"));
-//            Map<Module, List<Wire>> wireMap = resolver.resolve(resolver.getModule("com.sun.pkg.client"));
             long endtime = System.currentTimeMillis();
             System.out.println("Resolve time: " + (endtime - starttime));
             System.out.println("Modules resolved: " + wireMap.size());
@@ -258,6 +260,125 @@
         }
     }
 
+    private static Map getMainAttributes(JarFile jarFile) throws IOException
+    {
+        Map map = new HashMap();
+
+        JarEntry je = jarFile.getJarEntry("META-INF/MANIFEST.MF");
+        InputStream is = jarFile.getInputStream(je);
+        try
+        {
+            byte[] buf = new byte[2048];
+            StringBuffer sb = new StringBuffer();
+            int READING_ATTR_NAME = 1;
+            int READING_ATTR_SPACE = 2;
+            int READING_ATTR_VALUE = 4;
+            int READING_ATTR_LINEFEED = 8;
+            int READING_ATTR_CONT = 16;
+            int READING_ATTR_END = 32;
+            int state = READING_ATTR_NAME;
+            String name = null;
+            for (int len = is.read(buf); len >= 0; len = is.read(buf))
+            {
+                for (int i = 0; i < len; i++)
+                {
+                    if (((state & READING_ATTR_NAME) > 0) && (buf[i] == ':'))
+                    {
+                        name = sb.toString();
+                        sb.delete(0, sb.length());
+                        state = READING_ATTR_SPACE;
+                    }
+                    else if (((state & READING_ATTR_SPACE) > 0) && (buf[i]
== ' '))
+                    {
+                        state = READING_ATTR_VALUE;
+                    }
+                    else if (((state & READING_ATTR_SPACE) > 0) && (buf[i]
!= ' '))
+                    {
+                        throw new RuntimeException("Expecting a space!!");
+                    }
+                    else if (((state & READING_ATTR_VALUE) > 0) && (buf[i]
== '\r'))
+                    {
+                        state = READING_ATTR_LINEFEED;
+                    }
+                    else if (((state & READING_ATTR_LINEFEED) > 0) && (buf[i]
== '\n'))
+                    {
+                        state = READING_ATTR_CONT;
+                    }
+                    else if (((state & READING_ATTR_LINEFEED) > 0) && (buf[i]
!= '\n'))
+                    {
+                        throw new RuntimeException("Expecting a linefeed!!");
+                    }
+                    else if (((state & READING_ATTR_CONT) > 0) && (buf[i]
== ' '))
+                    {
+                        state = READING_ATTR_VALUE;
+                    }
+                    else if (((state & READING_ATTR_CONT) > 0) && (buf[i]
== '\r'))
+                    {
+                        map.put(name, sb.toString());
+                        sb.delete(0, sb.length());
+                        state = READING_ATTR_END;
+                    }
+                    else if (((state & READING_ATTR_END) > 0) && (buf[i] ==
'\n'))
+                    {
+                        return map;
+                    }
+                    else if (((state & READING_ATTR_END) > 0) && (buf[i] !=
'\n'))
+                    {
+                        throw new RuntimeException("Expecting end of group!!");
+                    }
+                    else if (((state & READING_ATTR_CONT) > 0) && (buf[i]
!= ' '))
+                    {
+                        map.put(name, sb.toString());
+                        sb.delete(0, sb.length());
+                        sb.append((char) buf[i]);
+                        state = READING_ATTR_NAME;
+                    }
+                    else
+                    {
+                        sb.append((char) buf[i]);
+                    }
+                }
+            }
+        }
+        finally
+        {
+            is.close();
+        }
+
+        return map;
+    }
+
+    private static void compareMaps(Map source, Map target)
+    {
+        for (Iterator it = source.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+            Object value = target.get(entry.getKey());
+            if ((value != null) && !entry.getValue().equals(value))
+            {
+                System.out.println("Different: " + entry.getKey() + " = " + entry.getValue()
+ " / " + value);
+            }
+            if (value == null)
+            {
+                System.out.println("Target missing: " + entry.getKey());
+            }
+        }
+
+        for (Iterator it = target.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+            Object value = source.get(entry.getKey());
+            if ((value != null) && !entry.getValue().equals(value))
+            {
+                System.out.println("Different: " + entry.getKey());
+            }
+            if (value == null)
+            {
+                System.out.println("Source missing: " + entry.getKey());
+            }
+        }
+    }
+
     private static Module createModule(ManifestParser mp)
     {
         Module module = new Module(mp.getSymbolicName());



Mime
View raw message