SNARK-71: buildDependencyGraph is implemented
This commit is contained in:
parent
088697da78
commit
c76ecd592f
@ -7,25 +7,44 @@ import java.nio.file.Path
|
||||
private val DEFAULT_DOCUMENT_ROOT = "main.md"
|
||||
|
||||
public suspend fun buildDocument(documentDirectory: Directory) {
|
||||
|
||||
val dependencyGraph = buildDependencyGraph(documentDirectory)
|
||||
|
||||
TODO() /*resolving of dependencies*/
|
||||
}
|
||||
|
||||
public suspend fun buildDependencyGraph(root: Directory) : DependencyGraph {
|
||||
// val rootDcoument = root.get(DEFAULT_DOCUMENT_ROOT)
|
||||
public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
||||
val nodes = HashMap<FileName, DependencyGraphNode>()
|
||||
|
||||
// val filesToParse: Queue<FileReader> = LinkedList<FileReader>(listOf(root))
|
||||
// var documentName = "."
|
||||
// buildNodes(root, nodes)
|
||||
|
||||
// val nodes = HashMap<FileName, DependencyGraphNode>()
|
||||
val rootDcoument = root.get(DEFAULT_DOCUMENT_ROOT)
|
||||
|
||||
// while (!filesToParse.isEmpty())
|
||||
// {
|
||||
// dependencyGraphNode = buildDependencyNode(filesToParse.remove())
|
||||
nodes.put(".", buildDependencyGraphNode(rootDcoument.readAll()))
|
||||
|
||||
// nodes.put()
|
||||
// }
|
||||
val filesToParse = getDependencies(nodes.getValue("."))
|
||||
|
||||
while (!filesToParse.isEmpty())
|
||||
{
|
||||
val currentFile = filesToParse.remove()
|
||||
val currentDocument = Directory(currentFile).get(DEFAULT_DOCUMENT_ROOT)
|
||||
|
||||
nodes.put(currentFile, buildDependencyGraphNode(currentDocument.readAll()))
|
||||
|
||||
val currentDependencies = getDependencies(nodes.getValue(currentFile))
|
||||
|
||||
for (fileName in currentDependencies) {
|
||||
if (!nodes.containsKey(fileName) && !filesToParse.contains(fileName))
|
||||
filesToParse.add(fileName)
|
||||
}
|
||||
}
|
||||
|
||||
return DependencyGraph(nodes)
|
||||
}
|
||||
|
||||
// private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, DependencyGraphNode>) {
|
||||
// assert(!nodes.containsKey(folder.getPath()))
|
||||
// }
|
||||
|
||||
public suspend fun getDependencies(node: DependencyGraphNode): Set<FileName> {
|
||||
TODO()
|
||||
}
|
Loading…
Reference in New Issue
Block a user