Package com.ilib.tools.jsa
Class AssemblyFile
- java.lang.Object
-
- com.ilib.tools.jsa.AssemblyFile
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<AssemblyFile>
dependencies
protected java.io.File
file
protected java.util.ArrayList<AssemblyFile>
parents
protected java.io.File
root
-
Constructor Summary
Constructors Modifier Constructor Description protected
AssemblyFile(java.io.File root, java.io.File file)
Construct a new assembly file instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addParent(AssemblyFile parent)
Add a parent to the list of parents for this node.java.io.File
getFile()
Return the path to the current node's file in the file system.java.io.File
getRoot()
If this file was created from a relative path, this function returns the root directory that the relative path was relative to.boolean
isProcessed()
Return whether or not this file has been processed already for dependencies.boolean
isWritten()
Return whether or not this file has been written to the output yet.abstract void
process(java.util.ArrayList<java.io.File> includePath, java.util.ArrayList<IlibLocale> locales, java.util.HashMap<java.lang.String,AssemblyFile> allFiles)
Process the file to find all the dependencies on other files and on data.protected java.lang.StringBuffer
readFile()
Read a file into memory in the form of a StringBuffer and then return it.protected void
setProcessed(boolean pro)
Set the processed flag, which indicates that the file has been processed for dependencies already and does not need to be processed again.protected void
setWritten(boolean wr)
Set the written flag to true, which indicates that this file has been written to the output already and does not need to be written again.abstract void
writeDependencies(java.io.Writer out, java.util.ArrayList<java.lang.String> visited, java.util.ArrayList<IlibLocale> locales)
Write out the files that this file is dependent upon to the out writer, and recorded that the files have already been visited in the visited array.abstract void
writeParents(java.io.Writer out, java.util.ArrayList<java.lang.String> visited, java.util.ArrayList<IlibLocale> locales)
Write the dependencies for the farthest ancestors above the current node.
-
-
-
Field Detail
-
root
protected java.io.File root
-
file
protected java.io.File file
-
dependencies
protected java.util.ArrayList<AssemblyFile> dependencies
-
parents
protected java.util.ArrayList<AssemblyFile> parents
-
-
Method Detail
-
getFile
public java.io.File getFile()
Return the path to the current node's file in the file system.- Returns:
- the path to the current node's file in the file system
-
getRoot
public java.io.File getRoot()
If this file was created from a relative path, this function returns the root directory that the relative path was relative to.- Returns:
- the root path that this file is relative to
-
addParent
public void addParent(AssemblyFile parent)
Add a parent to the list of parents for this node.- Parameters:
parent
- node to add
-
setWritten
protected void setWritten(boolean wr)
Set the written flag to true, which indicates that this file has been written to the output already and does not need to be written again.- Parameters:
wr
- the value to set the written flag to
-
isWritten
public boolean isWritten()
Return whether or not this file has been written to the output yet. If so, it should not be written again.- Returns:
- whether or not this file has been written to the output already
-
setProcessed
protected void setProcessed(boolean pro)
Set the processed flag, which indicates that the file has been processed for dependencies already and does not need to be processed again.- Parameters:
pro
- the value to set the processed flag to
-
isProcessed
public boolean isProcessed()
Return whether or not this file has been processed already for dependencies.- Returns:
- whether or not this file has been processed already for dependencies.
-
readFile
protected java.lang.StringBuffer readFile() throws java.io.IOException, java.io.FileNotFoundException
Read a file into memory in the form of a StringBuffer and then return it.- Returns:
- a StringBuffer containing the contents of the file.
- Throws:
java.io.IOException
- if the file could not be readjava.io.FileNotFoundException
- if the file could not be opened
-
process
public abstract void process(java.util.ArrayList<java.io.File> includePath, java.util.ArrayList<IlibLocale> locales, java.util.HashMap<java.lang.String,AssemblyFile> allFiles) throws java.lang.Exception
Process the file to find all the dependencies on other files and on data. This method reads the file contents and searches for comments of the form "// @depends" or "/* @depends *\/". The contents of the comment with that form is a list of files that the current file depends upon. The includePath is a list of directories in which to search for the depended files. The path of a file that is depended upon should be listed as relative to one of the directories in the include path. This method adds all the files found to the allFile hash, mapping the file name to the assembly file instance. In the case where the file already exists in the allFiles hash because some other assembly file already depended upon it, then the dependency is stored, but the mapping is not added again to allFiles.- Parameters:
includePath
- a path to search for depended upon filesallFiles
- a hash where all the depended upon files are stored- Throws:
java.lang.Exception
-
writeParents
public abstract void writeParents(java.io.Writer out, java.util.ArrayList<java.lang.String> visited, java.util.ArrayList<IlibLocale> locales) throws java.lang.Exception
Write the dependencies for the farthest ancestors above the current node. To get all the dependencies right, we start with any arbitrary node in the graph. From there, we traverse the parent links until we find a source node. That is, a node with no parents. From there, we do a depth-first search of the dependencies of that source until we get to a sink node. (A node with no dependencies.) Then, we write out that sink node and recurse back up. Each level writes out all its dependencies first, then itself and then returns to the previous level. We keep track of all the nodes we have already done so that if a subsequent depth first search hits a node that was already done, we can avoid doing that subtree more than once. Once all the dependencies of the source have been satisfied, we recurse back again to find other sources. Once all the parents for a node have been done, we attempt to do the dependencies for the current node if there are any left. This method is the one that traces the ancestry to the source node and then calls the writeDependencies call to actually write out the entire dependency tree from there.- Parameters:
out
- a writer to write the files tovisited
- an array of paths to nodes that have already been visitedlocales
- set of locales to generate data for- Throws:
CircularDependencyException
- if there are any circular dependencies in the codejava.lang.Exception
-
writeDependencies
public abstract void writeDependencies(java.io.Writer out, java.util.ArrayList<java.lang.String> visited, java.util.ArrayList<IlibLocale> locales) throws java.lang.Exception
Write out the files that this file is dependent upon to the out writer, and recorded that the files have already been visited in the visited array.- Parameters:
out
-visited
-locales
- set of locales to generate data for- Throws:
java.lang.Exception
-
-