|
From: <tr...@us...> - 2003-06-27 03:49:43
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/module
In directory sc8-pr-cvs1:/tmp/cvs-serv9691/src/com/babeldoc/core/module
Modified Files:
BabeldocModuleCommand.java BabeldocModuleList.java
Log Message:
update the runtime module handling to use same algorithm as build module handler. Also placed missing i18n messages for ModuleCommand.
Index: BabeldocModuleCommand.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/module/BabeldocModuleCommand.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** BabeldocModuleCommand.java 27 Jun 2003 02:19:58 -0000 1.14
--- BabeldocModuleCommand.java 27 Jun 2003 03:36:21 -0000 1.15
***************
*** 82,86 ****
* @author bruce
*/
! public class BabeldocModuleCommand extends BabeldocCommand {
/**
* Setup the babeldoc command class
--- 82,87 ----
* @author bruce
*/
! public class BabeldocModuleCommand
! extends BabeldocCommand {
/**
* Setup the babeldoc command class
***************
*** 123,135 ****
*/
public void listModules() {
! BabeldocModule[] modules = BabeldocModuleList.getInstance()
! .getSortedModules();
! for (int i = 0; i < modules.length; ++i) {
! BabeldocModule module = modules[i];
! String deps = getDependantsAsCVS(module.getDependsOn());
! System.out.println(I18n.get("core.module.command.list.output",
! module.getName(), deps));
}
}
--- 124,140 ----
*/
public void listModules() {
! BabeldocModule[] modules = BabeldocModuleList.getInstance().getSortedModules();
! if(modules!=null) {
! for (int i = 0; i < modules.length; ++i) {
! BabeldocModule module = modules[i];
! String deps = getDependantsAsCVS(module.getDependsOn());
! System.out.println(I18n.get("core.module.command.list.output",
! module.getName(), deps));
! }
! } else {
! System.out.println("No modules found!!!");
}
+
}
***************
*** 160,177 ****
*/
private String getDependantsAsCVS(Set depSet) {
! String[] depsArray = new String[depSet.size()];
! depSet.toArray(depsArray);
! StringBuffer deps = new StringBuffer();
! for (int j = 0; j < depsArray.length; ++j) {
! if (j != 0) {
! deps.append(", ").append(depsArray[j]);
! } else {
! deps.append(depsArray[j]);
}
- }
! return deps.toString();
}
}
--- 165,186 ----
*/
private String getDependantsAsCVS(Set depSet) {
! if(depSet!=null) {
! String[] depsArray = new String[depSet.size()];
! depSet.toArray(depsArray);
! StringBuffer deps = new StringBuffer();
! for (int j = 0; j < depsArray.length; ++j) {
! if (j != 0) {
! deps.append(", ").append(depsArray[j]);
! } else {
! deps.append(depsArray[j]);
! }
}
! return deps.toString();
! } else {
! return "";
! }
}
}
Index: BabeldocModuleList.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/module/BabeldocModuleList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BabeldocModuleList.java 27 Jun 2003 02:19:58 -0000 1.3
--- BabeldocModuleList.java 27 Jun 2003 03:36:21 -0000 1.4
***************
*** 68,75 ****
import org.apache.commons.discovery.tools.Service;
! import java.util.Enumeration;
! import java.util.HashMap;
! import java.util.Iterator;
! import java.util.Map;
--- 68,72 ----
import org.apache.commons.discovery.tools.Service;
! import java.util.*;
***************
*** 80,84 ****
* is a tie-in with the build process in that the name of the module must
* match the name returned by the getName method. This is important.
! *
* <p>
* This is a singleton class. There is an static instance.
--- 77,81 ----
* is a tie-in with the build process in that the name of the module must
* match the name returned by the getName method. This is important.
! *
* <p>
* This is a singleton class. There is an static instance.
***************
*** 86,92 ****
*/
public class BabeldocModuleList {
/** Instance variable */
private static BabeldocModuleList instance = null;
! BabeldocModule[] modules = null;
private Map map = new HashMap();
--- 83,93 ----
*/
public class BabeldocModuleList {
+ private static final String CORE = "core";
+ private static final String VISITING = "VISITING";
+ private static final String VISITED = "VISITED";
+
/** Instance variable */
private static BabeldocModuleList instance = null;
! private BabeldocModule[] modules = null;
private Map map = new HashMap();
***************
*** 98,114 ****
}
- /*
- private String printOutArrayList(IBabeldocModule [] list) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("[ ");
- for(int i = 0; i < list.length; ++i) {
- buffer.append((list[i].getName()+" "));
- }
- buffer.append("]");
-
- return buffer.toString();
- }
- */
-
/**
* Get the instance variable. Instantiate the object if necessary.
--- 99,102 ----
***************
*** 135,139 ****
}
! /**
* Get the sorted list from the least dependant to the most dependant.
*
--- 123,140 ----
}
! private static RuntimeException makeCircularException(String end, Stack stk) {
! StringBuffer sb = new StringBuffer("Circular dependency: ");
! sb.append(end);
! String c;
! do {
! c = (String) stk.pop();
! sb.append(" <- ");
! sb.append(c);
! } while (!c.equals(end));
!
! return new RuntimeException(new String(sb));
! }
!
! /**
* Get the sorted list from the least dependant to the most dependant.
*
***************
*** 142,205 ****
public BabeldocModule[] getSortedModules() {
if (modules == null) {
! modules = new BabeldocModule[map.size()];
! map.values().toArray(modules);
! for (int i = 0; i < modules.length; ++i) {
! for (int j = 0; j < modules.length; ++j) {
! if (i == j) {
! continue;
! }
! BabeldocModule mod1 = modules[i];
! BabeldocModule mod2 = modules[j];
! if (dependsOn(mod1, mod2)) {
! BabeldocModule tmp = modules[i];
! modules[i] = modules[j];
! modules[j] = tmp;
! }
! }
}
}
! return modules;
}
/**
! * Add the module to the list of modules
*
! * @param module
*/
! public void addModule(BabeldocModule module) {
! module.initialize();
! map.put(module.getName(), module);
! modules = null; // Set the cached list of modules to null.
! }
! /**
! * Returns true if mod1 depends on mod2. This is a fairly expensive
! * operation.
! *
! * @param mod1
! * @param mod2
! *
! * @return
! */
! private boolean dependsOn(BabeldocModule mod1, BabeldocModule mod2) {
! if (mod1.getDependsOn() != null) {
! for (Iterator iter = mod1.getDependsOn().iterator(); iter.hasNext();) {
! String depName = (String) iter.next();
! if (depName.equals(mod2.getName())) {
! return true;
! } else {
! BabeldocModule depMod = getModule(depName);
! return dependsOn(depMod, mod2);
}
}
}
! return false;
}
--- 143,248 ----
public BabeldocModule[] getSortedModules() {
if (modules == null) {
! modules = getPrivSortedModules();
! }
! return modules;
! }
! /**
! * Get an array of sorted modules. The first element in the array should be be
! * the least dependant modules (ie core, etc)
! * @return array of modules, sorted from least dependant to most.
! */
! private BabeldocModule[] getPrivSortedModules() {
! Collection ret = new ArrayList();
! Map state = new HashMap();
! Stack visiting = new Stack();
! /** Handle the core module - always first in list */
! state.put(CORE, VISITED);
! ret.add(map.get(CORE));
! /** Now iterate over each of the modules, sorting as we go */
! for (Iterator en = map.keySet().iterator(); en.hasNext();) {
! String currModuleName = (String)en.next();
! String currModuleState = (String) state.get(currModuleName);
!
! if (currModuleState == null) {
! treeSort(currModuleName, state, visiting, ret);
! } else if (currModuleState == VISITING) {
! throw new RuntimeException("Unexpected node in visiting state: " + currModuleName);
}
}
! return (BabeldocModule[])ret.toArray(new BabeldocModule[0]);
}
/**
! * Sort the nodes from the root node. This is a topographical sort
*
! * @param root
! * @param state
! * @param visiting
! * @param ret
*/
! private final void treeSort(String root, Map state, Stack visiting,
! Collection ret) {
! state.put(root, VISITING);
! visiting.push(root);
! BabeldocModule module = (BabeldocModule) map.get(root);
! // Make sure we exist
! if (module == null) {
! StringBuffer sb = new StringBuffer("Module `");
! sb.append(root);
! sb.append("' does not exist. ");
!
! visiting.pop();
! if (!visiting.empty()) {
! String parent = (String) visiting.peek();
!
! sb.append("It is used from module `");
! sb.append(parent);
! sb.append("'.");
! }
!
! throw new RuntimeException(new String(sb));
! }
!
! if(module.getDependsOn()!=null) {
! for (Iterator iterator = module.getDependsOn().iterator(); iterator.hasNext();) {
! String currModuleName = (String) iterator.next();
! String currModuleState = (String) state.get(currModuleName);
!
! if (currModuleState == null) {
! // Not been visited
! treeSort(currModuleName, state, visiting, ret);
! } else if (currModuleState == VISITING) {
! // Currently visiting this node, so have a cycle
! throw makeCircularException(currModuleName, visiting);
}
}
}
! String p = (String) visiting.pop();
!
! if (root != p) {
! throw new RuntimeException("Unexpected internal error: expected to " + "pop " + root + " but got " + p);
! }
!
! state.put(root, VISITED);
! ret.add(module);
! }
!
! /**
! * Add the module to the list of modules
! *
! * @param module
! */
! public void addModule(BabeldocModule module) {
! module.initialize();
! map.put(module.getName(), module);
! modules = null; // Set the cached list of modules to null.
}
***************
*** 217,228 ****
}
}
-
- /*
- public static String performDynamicSort() {
- BabeldocModuleList modlist = new BabeldocModuleList();
- modlist.loadDynamicModules();
- IBabeldocModule [] modules = modlist.getSortedModulesLeastToMost();
- return modlist.printOutArrayList(modules);
- }
- */
}
--- 260,262 ----
|