felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r898407 - in /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver: Main.java Shell.java manifestparser/Main.java
Date Tue, 12 Jan 2010 16:37:10 GMT
Author: rickhall
Date: Tue Jan 12 16:37:09 2010
New Revision: 898407

URL: http://svn.apache.org/viewvc?rev=898407&view=rev
Log:
Factored out resolver shell and added to other example.

Added:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Shell.java
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/manifestparser/Main.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=898407&r1=898406&r2=898407&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 16:37:09 2010
@@ -91,27 +91,7 @@
 
         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);
-                }
-            }
+            Shell.shell(resolver);
         }
         else
         {
@@ -126,130 +106,6 @@
         }
     }
 
-    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)
-        {
-            System.out.println(module + " (" + module.isResolved() + ")");
-        }
-    }
-
-    private static void dumpModule(StatefulResolver resolver, StringTokenizer st)
-    {
-        while (st.hasMoreTokens())
-        {
-            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);
-            }
-        }
-    }
-
     private static Module setupScenario(List<Module> moduleList, String scenario)
         throws NoSuchMethodException, IllegalAccessException,
             IllegalArgumentException, InvocationTargetException
@@ -1101,4 +957,35 @@
 
         return target;
     }
+
+    private static Module scenario21(List<Module> moduleList)
+    {
+        Module m, target;
+
+        // Bundle A
+        moduleList.add(
+            target = (m = new Module("A"))
+                .requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=foo").with("version=[1.0.0,2.0.0)")));
+        // Bundle B
+        moduleList.add(
+            (m = new Module("B"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=foo").using("bar").with("version=1.0.0"))
+                .requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=bar")));
+        // Bundle C
+        moduleList.add(
+            (m = new Module("C"))
+                .requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=foo"))
+                .requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=bar")));
+        // Bundle D
+        moduleList.add(
+            (m = new Module("D"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=foo").with("version=2.0.0"))
+                .requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=bar")));
+        // Bundle E
+        moduleList.add(
+            (m = new Module("E"))
+                .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=bar").with("version=1.0.0")));
+
+        return target;
+    }
 }
\ No newline at end of file

Added: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Shell.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Shell.java?rev=898407&view=auto
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Shell.java (added)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Shell.java Tue
Jan 12 16:37:09 2010
@@ -0,0 +1,178 @@
+/*
+ *  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.
+ */
+package org.apache.felix.resolver;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+import java.util.StringTokenizer;
+import org.apache.felix.resolver.cs.Capability;
+import org.apache.felix.resolver.cs.Requirement;
+
+public class Shell
+{
+    public static void shell(StatefulResolver resolver)
+    {
+        System.out.println("Resolver");
+        System.out.println("--------");
+
+        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);
+            }
+        }
+    }
+
+    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)
+        {
+            System.out.println(module + " (" + module.isResolved() + ")");
+        }
+    }
+
+    private static void dumpModule(StatefulResolver resolver, StringTokenizer st)
+    {
+        while (st.hasMoreTokens())
+        {
+            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);
+            }
+        }
+    }
+}
\ No newline at end of file

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=898407&r1=898406&r2=898407&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 16:37:09 2010
@@ -27,19 +27,17 @@
 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.CapabilityImpl;
 import org.apache.felix.resolver.RequirementImpl;
 import org.apache.felix.resolver.Module;
 import org.apache.felix.resolver.Resolver;
-import org.apache.felix.resolver.Resolver.ResolverState;
 import org.apache.felix.resolver.ResolverStateImpl;
+import org.apache.felix.resolver.Shell;
 import org.apache.felix.resolver.StatefulResolver;
 import org.apache.felix.resolver.Wire;
 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;
@@ -50,17 +48,22 @@
     {
         if (args.length < 1)
         {
-            System.err.println("usage: [-Dinvoke.count=true] [-legacy | -proto] [-nodupes]
<bundle-dir>");
+            System.err.println("usage: [-Dinvoke.count=true] [-shell] [-legacy | -proto]
[-nodupes] <bundle-dir>");
             System.exit(0);
         }
 
+        boolean shell = false;
         boolean legacy = false;
         boolean proto = false;
         boolean duplicates = true;
         String dir = args[args.length - 1];
         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;
             }
@@ -356,40 +359,30 @@
 
         StatefulResolver resolver = new StatefulResolver(statelessResolver, state);
 
-        try
+        if (shell)
+        {
+            Shell.shell(resolver);
+        }
+        else
         {
-            for (Module target = getTarget(moduleList);
-                target != null;
-                target = getTarget(moduleList))
+            try
             {
-                resolver.resolve(target);
-
-                if (target.getName().equals("jersey-bundle"))
+                for (Module target = getTarget(moduleList);
+                    target != null;
+                    target = getTarget(moduleList))
                 {
-                    System.exit(0);
+                    resolver.resolve(target);
+
+                    if (target.getName().equals("jersey-bundle"))
+                    {
+                        System.exit(0);
+                    }
                 }
             }
-        }
-        catch (Exception ex)
-        {
-            ex.printStackTrace(System.out);
-        }
-    }
-
-    private static void dumpModule(Module module)
-    {
-        System.out.println("MODULE " + module.getName());
-        System.out.println("   CAPS");
-        List<Capability> caps = module.getCapabilities();
-        for (int i = 0; (caps != null) && (i < caps.size()); i++)
-        {
-            System.out.println("      " + caps.get(i));
-        }
-        System.out.println("   REQS");
-        List<Requirement> reqs = module.getRequirements();
-        for (int i = 0; (reqs != null) && (i < reqs.size()); i++)
-        {
-            System.out.println("      " + reqs.get(i));
+            catch (Exception ex)
+            {
+                ex.printStackTrace(System.out);
+            }
         }
     }
 



Mime
View raw message