felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r811571 - in /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver: Main.java felix/FelixResolver.java
Date Fri, 04 Sep 2009 23:37:23 GMT
Author: rickhall
Date: Fri Sep  4 23:37:22 2009
New Revision: 811571

URL: http://svn.apache.org/viewvc?rev=811571&view=rev
Log:
Made it easier to run different scenarios.

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/felix/FelixResolver.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=811571&r1=811570&r2=811571&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 Fri
Sep  4 23:37:22 2009
@@ -6,9 +6,9 @@
  *  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
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.resolver;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -29,21 +31,33 @@
 public class Main
 {
     public static void main(String[] args)
+        throws NoSuchMethodException, IllegalAccessException,
+            IllegalArgumentException, InvocationTargetException
     {
-        List<Module> moduleList = new ArrayList<Module>();
-
-        Module module = scenario5(moduleList);
-
-        Resolver resolver;
-        if ((args.length == 1) && (args[0].equals("-legacy")))
+        if (args.length > 2)
         {
-            resolver = new FelixResolver(moduleList);
+            System.out.println("[-legacy] [scenario-number]");
+            System.exit(0);
         }
-        else
+
+        List<Module> moduleList = new ArrayList<Module>();
+        String scenario = "1";
+
+        Resolver resolver = new ProtoResolver(moduleList);
+        for (int i = 0; i < args.length; i++)
         {
-            resolver = new ProtoResolver(moduleList);
+            if (args[i].equals("-legacy"))
+            {
+                resolver = new FelixResolver(moduleList);
+            }
+            else
+            {
+                scenario = args[i];
+            }
         }
 
+        Module module = setupScenario(moduleList, scenario);
+
         try
         {
             long starttime = System.currentTimeMillis();
@@ -71,6 +85,17 @@
         }
     }
 
+    private static Module setupScenario(List<Module> moduleList, String scenario)
+        throws NoSuchMethodException, IllegalAccessException,
+            IllegalArgumentException, InvocationTargetException
+    {
+        int i = Integer.parseInt(scenario);
+        String methodName = "scenario" + i;
+        System.out.println(methodName + ":\n");
+        Method method = Main.class.getDeclaredMethod(methodName, new Class<?>[] { List.class
});
+        return (Module) method.invoke(null, moduleList);
+    }
+
     // SOLUTION:
     // A: bar->B, baz->E
     // B: woz->D

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/felix/FelixResolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/felix/FelixResolver.java?rev=811571&r1=811570&r2=811571&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/felix/FelixResolver.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/felix/FelixResolver.java
Fri Sep  4 23:37:22 2009
@@ -33,23 +33,21 @@
 public class FelixResolver implements Resolver
 {
     private final List<Module> m_moduleList;
-    private final Module[] m_modules;
     private final FelixResolverImpl m_resolver = new FelixResolverImpl();
     private final ResolverStateImpl m_state = new ResolverStateImpl();
 
     public FelixResolver(List<Module> moduleList)
     {
         m_moduleList = moduleList;
-        m_modules = (Module[]) moduleList.toArray(new Module[moduleList.size()]);
     }
 
     public Module getModule(String name)
     {
-        for (int i = 0; i < m_modules.length; i++)
+        for (int i = 0; i < m_moduleList.size(); i++)
         {
-            if (m_modules[i].getName().equals(name))
+            if (m_moduleList.get(i).getName().equals(name))
             {
-                return m_modules[i];
+                return m_moduleList.get(i);
             }
         }
         return null;
@@ -74,7 +72,7 @@
     {
         public Module[] getModules()
         {
-            return m_modules;
+            return (Module[]) m_moduleList.toArray(new Module[m_moduleList.size()]);
         }
 
         public PackageSource[] getResolvedCandidates(ImportedPackage req)
@@ -85,14 +83,14 @@
         public PackageSource[] getUnresolvedCandidates(ImportedPackage req)
         {
             List<PackageSource> ps = new ArrayList<PackageSource>();
-            for (int modIdx = 0; modIdx < m_modules.length; modIdx++)
+            for (int modIdx = 0; modIdx < m_moduleList.size(); modIdx++)
             {
-                List<ExportedPackage> exports = m_modules[modIdx].getExports();
+                List<ExportedPackage> exports = m_moduleList.get(modIdx).getExports();
                 for (int expIdx = 0; expIdx < exports.size(); expIdx++)
                 {
                     if (req.isSatistfiedBy(exports.get(expIdx)))
                     {
-                        ps.add(new PackageSource(m_modules[modIdx], exports.get(expIdx)));
+                        ps.add(new PackageSource(m_moduleList.get(modIdx), exports.get(expIdx)));
                     }
                 }
             }



Mime
View raw message