Cleanup of no longer needed code.

+ Removing Modules.normalizeDependencies()
+ Using Modules.resolveNode() instead
+ Chaning Modules.resolveNode() to not throw Exception
This commit is contained in:
Joakim Erdfelt 2014-11-20 09:53:02 -07:00
parent df9414eab2
commit 69daa8d76d
2 changed files with 13 additions and 68 deletions

View File

@ -22,9 +22,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jetty.start.graph.Graph;
import org.eclipse.jetty.start.graph.GraphException;
@ -113,7 +111,8 @@ public class Modules extends Graph<Module>
if (Props.hasPropertyKey(expandedName))
{
throw new GraphException("Unable to expand property in name: " + name);
StartLog.debug("Not yet able to expand property in: %s",name);
return null;
}
Path file = baseHome.getPath("modules/" + expandedName + ".mod");
@ -137,7 +136,7 @@ public class Modules extends Graph<Module>
@Override
public void onNodeSelected(Module module)
{
StartLog.debug("on node selected: %s [%s]",module.getName(),baseHome.toShortForm(module.getFilesystemRef()));
StartLog.debug("on node selected: [%s] (%s.mod)",module.getName(),module.getFilesystemRef());
args.parseModule(module);
module.expandProperties(args.getProperties());
}
@ -182,61 +181,6 @@ public class Modules extends Graph<Module>
}
}
// load missing post-expanded dependent modules
public void normalizeDependencies() throws IOException
{
Set<String> expandedModules = new HashSet<>();
boolean done = false;
while (!done)
{
done = true;
Set<String> missingParents = new HashSet<>();
for (Module m : getNodes())
{
for (String parent : m.getParentNames())
{
String expanded = args.getProperties().expand(parent);
if (containsNode(expanded) || expandedModules.contains(parent))
{
continue; // found. skip it.
}
done = false;
StartLog.debug("Missing parent module %s == %s for %s",parent,expanded,m);
missingParents.add(parent);
}
}
for (String missingParent : missingParents)
{
String expanded = args.getProperties().expand(missingParent);
Path file = baseHome.getPath("modules/" + expanded + ".mod");
if (FS.canReadFile(file))
{
Module module = registerModule(file);
updateParentReferencesTo(module);
if (!expanded.equals(missingParent))
{
expandedModules.add(missingParent);
}
}
else
{
if (Props.hasPropertyKey(expanded))
{
StartLog.debug("Module property not expandable (yet) [%s]",expanded);
expandedModules.add(missingParent);
}
else
{
StartLog.debug("Missing module definition: %s expanded to %s",missingParent,expanded);
// missingModules.add(missingParent);
}
}
}
}
}
private Module registerModule(Path file)
{
if (!FS.canReadFile(file))

View File

@ -106,15 +106,20 @@ public abstract class Graph<T extends Node<T>> implements Iterable<T>
public void buildGraph() throws FileNotFoundException, IOException
{
normalizeDependencies();
// Connect edges
for (T node : nodes.values())
// Make a copy of nodes.values() as the list could be modified
List<T> nodeList = new ArrayList<>(nodes.values());
for (T node : nodeList)
{
for (String parentName : node.getParentNames())
{
T parent = get(parentName);
if (parent == null)
{
parent = resolveNode(parentName);
}
if (parent == null)
{
if (Props.hasPropertyKey(parentName))
@ -295,15 +300,11 @@ public abstract class Graph<T extends Node<T>> implements Iterable<T>
return nodes.values().iterator();
}
public void normalizeDependencies() throws IOException
{
// override to implement
}
public abstract void onNodeSelected(T node);
public T register(T node)
{
StartLog.debug("Registering Node: [%s] %s", node.getName(), node);
nodes.put(node.getName(),node);
return node;
}
@ -428,7 +429,7 @@ public abstract class Graph<T extends Node<T>> implements Iterable<T>
throw new GraphException("Missing referenced dependency: " + name);
}
count += selectNode(name,selection);
count += selectNode(node.getName(),selection);
}
return count;