felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r898360 - in /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver: Main.java StatefulResolver.java manifestparser/Main.java proto3/Proto3Resolver.java
Date Tue, 12 Jan 2010 15:13:52 GMT
Author: rickhall
Date: Tue Jan 12 15:13:51 2010
New Revision: 898360

URL: http://svn.apache.org/viewvc?rev=898360&view=rev
Log:
Added simple shell interface to ease experimentation and debugging.

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

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java?rev=898360&r1=898359&r2=898360&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java Tue
Jan 12 15:13:51 2010
@@ -18,15 +18,16 @@
  */
 package org.apache.felix.resolver;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.felix.resolver.Resolver.ResolverState;
+import java.util.StringTokenizer;
 import org.apache.felix.resolver.cs.Capability;
+import org.apache.felix.resolver.cs.Requirement;
 import org.apache.felix.resolver.felix.FelixResolver;
 import org.apache.felix.resolver.proto3.Proto3Resolver;
 import org.apache.felix.resolver.prototype.ProtoResolver;
@@ -39,16 +40,21 @@
     {
         if (args.length > 2)
         {
-            System.out.println("[-legacy | -proto] [scenario-number]");
+            System.out.println("[-shell] [-legacy | -proto] [scenario-number]");
             System.exit(0);
         }
 
         String scenario = "1";
+        boolean shell = false;
         boolean legacy = false;
         boolean proto = false;
         for (int i = 0; i < args.length; i++)
         {
-            if (args[i].equals("-legacy"))
+            if (args[i].equals("-shell"))
+            {
+                shell = true;
+            }
+            else if (args[i].equals("-legacy"))
             {
                 legacy = true;
             }
@@ -65,7 +71,7 @@
         List<Module> moduleList = new ArrayList<Module>();
         Module target = setupScenario(moduleList, scenario);
 
-        ResolverState state = new ResolverStateImpl(moduleList);
+        ResolverStateImpl state = new ResolverStateImpl(moduleList);
         Resolver statelessResolver = null;
 
         if (legacy)
@@ -83,13 +89,164 @@
 
         StatefulResolver resolver = new StatefulResolver(statelessResolver, state);
 
-        try
+        if (shell)
+        {
+            System.out.println("Resolver");
+            System.out.println("--------");
+            System.out.println("Suggested target: " + target);
+
+            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+
+            String line = null;
+
+            while (true)
+            {
+                try
+                {
+                    System.out.print("-> ");
+                    line = in.readLine();
+                    performCommand(resolver, line);
+                }
+                catch (IOException ex)
+                {
+                    System.err.println("Error reading from stdin: " + ex);
+                }
+            }
+        }
+        else
+        {
+            try
+            {
+                resolver.resolve(target);
+            }
+            catch (Exception ex)
+            {
+                ex.printStackTrace(System.out);
+            }
+        }
+    }
+
+    private static void performCommand(StatefulResolver resolver, String line)
+    {
+        StringTokenizer st = new StringTokenizer(line);
+        String command = st.nextToken();
+        if (command.equals("q"))
+        {
+            System.exit(0);
+        }
+        else if (command.equals("ps"))
+        {
+            listModules(resolver);
+        }
+        else if (command.equals("dump"))
+        {
+            dumpModule(resolver, st);
+        }
+        else if (command.equals("resolve"))
+        {
+            resolveModule(resolver, st);
+        }
+    }
+
+    private static void listModules(StatefulResolver resolver)
+    {
+        List<Module> modules = resolver.getState().getModules();
+        for (Module module : modules)
         {
-            resolver.resolve(target);
+            System.out.println(module + " (" + module.isResolved() + ")");
         }
-        catch (Exception ex)
+    }
+
+    private static void dumpModule(StatefulResolver resolver, StringTokenizer st)
+    {
+        while (st.hasMoreTokens())
         {
-            ex.printStackTrace(System.out);
+            String name = st.nextToken();
+
+            if (name.equals("*"))
+            {
+                List<Module> modules = resolver.getState().getModules();
+                for (Module module : modules)
+                {
+                    dumpModule(module);
+                }
+            }
+            else
+            {
+                List<Module> modules = resolver.getState().getModules();
+                Module target = null;
+                for (Module module : modules)
+                {
+                    if (module.getName().equals(name))
+                    {
+                        target = module;
+                    }
+                }
+                if (target != null)
+                {
+                    dumpModule(target);
+                }
+                else
+                {
+                    System.err.println("No such module: " + name);
+                }
+            }
+        }
+    }
+
+    private static void dumpModule(Module module)
+    {
+        System.out.println(module + " (" + module.isResolved() + ")");
+        System.out.println("   CAPS:");
+        for (Capability cap : module.getCapabilities())
+        {
+            System.out.println("      " + cap);
+        }
+        System.out.println("   REQS:");
+        for (Requirement req : module.getRequirements())
+        {
+            System.out.println("      " + req);
+        }
+        if (module.isResolved())
+        {
+            System.out.println("   WIRES:");
+            for (Wire wire : module.getWires())
+            {
+                System.out.println("      " + wire);
+            }
+        }
+    }
+
+    private static void resolveModule(StatefulResolver resolver, StringTokenizer st)
+    {
+        while (st.hasMoreTokens())
+        {
+            String name = st.nextToken();
+
+            List<Module> modules = resolver.getState().getModules();
+            Module target = null;
+            for (Module module : modules)
+            {
+                if (module.getName().equals(name))
+                {
+                    target = module;
+                }
+            }
+            if (target != null)
+            {
+                try
+                {
+                    resolver.resolve(target);
+                }
+                catch (Exception ex)
+                {
+                    ex.printStackTrace(System.out);
+                }
+            }
+            else
+            {
+                System.err.println("No such module: " + name);
+            }
         }
     }
 
@@ -916,4 +1073,32 @@
 
         return target;
     }
+
+    private static Module scenario20(List<Module> moduleList)
+    {
+        Module m, target;
+
+        // Bundle A
+        moduleList.add(
+            target = (m = new Module("A"))
+                .requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=foo")));
+        // Bundle B
+        moduleList.add(
+            (m = new Module("B"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=foo"))
+                .requiring(new RequirementImpl(Capability.MODULE_NAMESPACE).with("bundle-symbolic-name=C")));
+        // Bundle C
+        moduleList.add(
+            (m = new Module("C"))
+                .providing(new CapabilityImpl(m, Capability.MODULE_NAMESPACE).with("bundle-symbolic-name=C"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=foo"))
+                .requiring(new RequirementImpl(Capability.MODULE_NAMESPACE).with("bundle-symbolic-name=D")));
+        // Bundle D
+        moduleList.add(
+            (m = new Module("D"))
+                .providing(new CapabilityImpl(m, Capability.MODULE_NAMESPACE).with("bundle-symbolic-name=D"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=foo")));
+
+        return target;
+    }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java?rev=898360&r1=898359&r2=898360&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/StatefulResolver.java
Tue Jan 12 15:13:51 2010
@@ -21,19 +21,23 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import org.apache.felix.resolver.Resolver.ResolverState;
 
 public class StatefulResolver
 {
     private final Resolver m_resolver;
-    private final ResolverState m_state;
+    private final ResolverStateImpl m_state;
 
-    public StatefulResolver(Resolver resolver, ResolverState state)
+    public StatefulResolver(Resolver resolver, ResolverStateImpl state)
     {
         m_resolver = resolver;
         m_state = state;
     }
 
+    public ResolverStateImpl getState()
+    {
+        return m_state;
+    }
+
     public void resolve(Module module)
     {
         System.out.println("Target: " + module + " (" + module.getRequirements().size() +
")");

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=898360&r1=898359&r2=898360&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
Tue Jan 12 15:13:51 2010
@@ -338,7 +338,7 @@
 
         System.out.println("Generated " + moduleList.size() + " modules.");
 
-        ResolverState state = new ResolverStateImpl(moduleList);
+        ResolverStateImpl state = new ResolverStateImpl(moduleList);
         Resolver statelessResolver = null;
 
         if (legacy)

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java?rev=898360&r1=898359&r2=898360&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Tue Jan 12 15:13:51 2010
@@ -336,7 +336,7 @@
         {
             for (int i = 0; i < caps.size(); i++)
             {
-// TODO: PROTO2 RESOLVER - Assume if a module imports the same package it
+// TODO: PROTO3 RESOLVER - Assume if a module imports the same package it
 //       exports that the import will overlap the export.
                 if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE)
                     && !hasOverlappingImport(module, caps.get(i)))
@@ -424,6 +424,8 @@
             m_invokeCounts.put(methodName, count);
         }
 
+// TODO: PROTO3 RESOLVER - Check for merging where module imports from itself,
+//       then it should be listed as an export.
         if (candBlame.m_cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
         {
 System.out.println("+++ MERGING " + candBlame.m_cap + " INTO " + current);
@@ -581,7 +583,7 @@
         cycleMap.put(pkgName, list);
 
 //System.out.println("+++ VERIFYING USES " + current + " FOR " + candBlame);
-        for (Capability candCapSource : getPackageSources(candBlame.m_cap, modulePkgMap))
+        for (Capability candCapSource : getPackageSources(candBlame.m_cap, modulePkgMap,
new ArrayList<Capability>()))
         {
             for (String usedPkgName : candCapSource.getUses())
             {
@@ -592,7 +594,7 @@
 
                 Packages sourcePkgs = modulePkgMap.get(candCapSource.getModule());
 System.out.println("+++ candCapSource " + candCapSource);
-System.out.println("+++ candCapSource.getModule() " + candCapSource.getModule());
+System.out.println("+++ candCapSource.getModule() " + candCapSource.getModule() + " (" +
candCapSource.getModule().isResolved() + ")");
 System.out.println("+++ sourcePkgs " + sourcePkgs);
 System.out.println("+++ sourcePkgs.m_exportedPkgs " + sourcePkgs.m_exportedPkgs);
                 Blame sourceBlame = sourcePkgs.m_exportedPkgs.get(usedPkgName);
@@ -690,8 +692,8 @@
     {
         if ((currentCap != null) && (candCap != null))
         {
-            List<Capability> currentSources = getPackageSources(currentCap, modulePkgMap);
-            List<Capability> candSources = getPackageSources(candCap, modulePkgMap);
+            List<Capability> currentSources = getPackageSources(currentCap, modulePkgMap,
new ArrayList<Capability>());
+            List<Capability> candSources = getPackageSources(candCap, modulePkgMap,
new ArrayList<Capability>());
 //System.out.println("+++ currentSources " + currentSources + " - candSources " + candSources);
             return currentSources.containsAll(candSources) || candSources.containsAll(currentSources);
         }
@@ -699,33 +701,85 @@
     }
 
     private static List<Capability> getPackageSources(
-        Capability cap, Map<Module, Packages> modulePkgMap)
+        Capability cap, Map<Module, Packages> modulePkgMap, List<Capability>
sources)
     {
-        List<Capability> sources = null;
         if (cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
         {
-            sources = new ArrayList<Capability>();
-            if (!cap.getModule().isResolved())
+            Packages pkgs = modulePkgMap.get(cap.getModule());
+            if ((pkgs == null) && cap.getModule().isResolved())
             {
-                Packages pkgs = modulePkgMap.get(cap.getModule());
-                sources.add(cap);
-                String pkgName = cap.getAttribute(Capability.PACKAGE_ATTR).getValue().toString();
-                List<Blame> required = pkgs.m_requiredPkgs.get(pkgName);
-                if (required != null)
+                pkgs = new Packages();
+                calculateResolvedPackages(cap.getModule(), pkgs);
+                modulePkgMap.put(cap.getModule(), pkgs);
+System.out.println("RESOLVED PACKAGES:");
+dumpModulePkgs(cap.getModule(), pkgs);
+            }
+            sources.add(cap);
+            String pkgName = cap.getAttribute(Capability.PACKAGE_ATTR).getValue().toString();
+            List<Blame> required = pkgs.m_requiredPkgs.get(pkgName);
+            if (required != null)
+            {
+                for (Blame blame : required)
                 {
-                    for (Blame blame : required)
-                    {
-                        sources.add(blame.m_cap);
-                    }
+                    getPackageSources(blame.m_cap, modulePkgMap, sources);
                 }
             }
-            else
+        }
+
+        return sources;
+    }
+
+    private static void calculateResolvedPackages(Module module, Packages pkgs)
+    {
+        List<Capability> caps = module.getCapabilities();
+        if (caps.size() > 0)
+        {
+            for (int i = 0; i < caps.size(); i++)
             {
-// TODO: PROTO3 RESOLVER - Need to properly calculate resolved package sources.
-                sources.add(cap);
+// TODO: PROTO3 RESOLVER - Assume if a module imports the same package it
+//       exports that the import will overlap the export.
+                if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE)
+                    && !hasOverlappingImport(module, caps.get(i)))
+                {
+                    pkgs.m_exportedPkgs.put(
+                        (String) caps.get(i).getAttribute(Capability.PACKAGE_ATTR).getValue(),
+                        new Blame(null, caps.get(i)));
+                }
             }
         }
-        return sources;
+
+        for (Wire wire : module.getWires())
+        {
+            if (wire.getCapability().getNamespace().equals(Capability.PACKAGE_NAMESPACE))
+            {
+                pkgs.m_importedPkgs.put(
+                    (String) wire.getCapability().getAttribute(Capability.PACKAGE_ATTR).getValue(),
+                    new Blame(null, wire.getCapability()));
+                calculateResolvedUses(wire.getCapability(), pkgs.m_usedPkgs);
+            }
+            else if (wire.getCapability().getNamespace().equals(Capability.MODULE_NAMESPACE))
+            {
+                for (Capability cap : wire.getCapability().getModule().getCapabilities())
+                {
+                    if (cap.getNamespace().equals(Capability.PACKAGE_ATTR))
+                    {
+                        String pkgName = (String) cap.getAttribute(Capability.PACKAGE_ATTR).getValue();
+                        List<Blame> requiredBlames = pkgs.m_requiredPkgs.get(pkgName);
+                        if (requiredBlames == null)
+                        {
+                            requiredBlames = new ArrayList<Blame>();
+                            pkgs.m_requiredPkgs.put(pkgName, requiredBlames);
+                        }
+                        requiredBlames.add(new Blame(null, cap));
+                        calculateResolvedUses(wire.getCapability(), pkgs.m_usedPkgs);
+                    }
+                }
+            }
+        }
+    }
+
+    private static void calculateResolvedUses(Capability cap, Map<String, List<Blame>>
usedPkgs)
+    {
     }
 
     private static Map<Requirement, Set<Capability>> copyCandidateMap(



Mime
View raw message