Commits

Anonymous committed 9dbe2ff

don't let externally-provided variables interfere with dependency sorting

Comments (0)

Files changed (1)

src/main/java/org/nrg/dcm/edit/ScriptApplicator.java

 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedSet;
                 graph.put(v, dependencies);
             }
         }
+        
+        // Don't let externally- but not internally-defined variables get
+        // in the way of our dependency resolution.
+        for (final Collection<Variable> dependencies : graph.values()) {
+            for (final Iterator<Variable> i = dependencies.iterator(); i.hasNext(); ) {
+                if (!graph.containsKey(i.next())) {
+                    i.remove();
+                }
+            }
+        }
+        
+        logger.trace("sorting variable dependencies: {}", graph);
         return GraphUtils.topologicalSort(graph);
     }