org.sandev.sandbuild
Class SandProject

java.lang.Object
  extended by org.sandev.sandbuild.SandProject

public class SandProject
extends java.lang.Object

A representation of a SAND project used in dependency structures and other build processing.


Field Summary
protected  org.apache.tools.ant.Project antProject
          A reference to the Ant Project object for this SandProject
protected  java.io.File[] envFiles
          A SandProject may require access to zero or more files at runtime.
protected  java.util.Collection genDecls
          The SandGenDecl instances for this project.
protected  java.lang.String name
          A SandProject has a name which is used to identify it within the overall build.
static java.lang.String NODE_DECLS_FILE
          Name of the NodeDecls.txt file
protected  SandDecl[] nodeDecls
          The SandDecl objects for the nodes declared in this project
protected  SandPersistDef persistenceDef
          A SandProject has a single persistence definition.
protected  SandProject[] requiredBy
          A SandProject may be required by zero or more other SandProjects.
protected  SandUIDeployment[] sandUIDeployments
          A SandProject may declare zero or more deployments of a SandUI definition.
static java.lang.String STRUCT_DECLS_FILE
          Name of the StructDecls.txt file
protected  SandDecl[] structDecls
          The SandDecl objects for the structs declared in this project.
 
Constructor Summary
SandProject(java.lang.String name)
          All projects must have a name, so no default ctor.
 
Method Summary
protected  void addDeletedDecls(java.util.Collection curr, java.util.Collection prev)
          Given a collection of current declarations, and a collection of previous declarations, add any deleted declarations to the current collection.
 void addEnvFile(java.io.File file)
          Add a file to the list of required files.
 void addGenDecl(SandGenDecl decl)
          Add a generator declaration to the collection.
 void addRequiredBy(SandProject proj)
          Add a new project to those projects that require this one.
 void addUIDeployment(SandUIDeployment uidep)
          Add a SandUIDeployment to our list of UIs for this project.
 void callTarget(java.lang.String targetName)
          Call the specified target in this project.
protected  boolean changedGeneratorFound(java.lang.String classname)
          Search through all the projects which declare this generator and return true if any of them have changed.
protected  boolean changedGeneratorFoundInProject(SandProject proj, java.lang.String classname)
           
 void checkDefaultDebugFlag()
          Check that the debug flag is set, and default it if nothing was specified.
 void checkDefaultJarPrefix()
          Check that the DeploymentPrefix for jarfiles is set.
 void cleanCompileGenerators()
          Undo the work done by compileGenerators.
 void cleanDocGenerators()
          Undo the work done by docGenerators
 void cleanDocSource()
          Undo work done by docSource
 void cleanJarGenerators()
          Undo the work done by jarGenerators
 void compileGenerators()
          Compile the generators by calling the build.compile.generators target.
 void copyfile(java.lang.String srcfilename, java.lang.String targetdir)
          Copy the specified file to the specified directory.
 void deletefile(java.lang.String filename)
          Delete the specified file.
 void docGenerators(java.util.Collection changed)
          Document the generators.
 void docSource(java.util.Collection dirtyFiles)
          Document the main source.
 java.util.ArrayList findNodeDecls(java.io.File rootDir, java.util.ArrayList coll)
          Walk the directory tree downwards recursively, loading any node declarations.
 SandProject findProject(java.lang.String projname)
          Return the project instance matching the specified name, or null if have no matching instance.
 java.util.ArrayList findStructDecls(java.io.File rootDir, java.util.ArrayList coll)
          If this is a structs directory, load any struct declarations.
 boolean genJarExists()
          Return true if the generator jar file is found, false otherwise.
 org.apache.tools.ant.Project getAntProject()
          accessor for antProject
 java.io.File[] getEnvFiles()
          Return the files this project requires at runtime.
 java.util.Collection getGenDecls()
          initializing accessor for genDecls
protected  java.lang.String getGeneratorSrcDirName()
          Return the name of the generator src directory.
 java.lang.String getName()
          accessor for name
 SandDecl[] getNodeDecls()
          Initializing accessor for nodeDecls
 SandPersistDef getPersistenceDef()
          accessor for persistenceDef
 SandProject[] getRequiredBy()
          Returns an array of the projects that require this one.
 java.lang.String getSandName()
          Return the SAND project name.
 SandUIDeployment[] getSandUIDeployments()
          Return the SandUI deployment definitions for this project.
 SandDecl[] getStructAndNodeDecls()
          Return all the struct and node declarations for this project.
 SandDecl[] getStructDecls()
          Initializing accessor for structDecls
 boolean hasRequiredBy(java.lang.String projname)
          Return true if the specified project name exists in our requiredBy array, false otherwise.
protected  void initDecls(java.util.Collection currDecls)
          Given a collection of SandDecls, call to initialize the qualifiedName and the status for each one.
 void jarGenerators()
          Jar the generators by calling the build.jar.generators target.
 void loadAntProject(java.lang.String sandDir, SandProject proj)
          Given a sand directory specification (eg "apps/basics"), load the corresponding ant project into our local references.
 void loadNodeDecls()
          Load the node declarations for this project
 java.util.ArrayList loadPrevDecls(int decltype)
          The last time we built, we wrote out the declarations we were dealing with so we could keep track of what happened for an incremental build.
 void loadStructDecls()
          Load the struct declarations for this project
 void removeRequiredBy(java.lang.String projname)
          Removes a project from our requiredBy.
 void setAntProject(org.apache.tools.ant.Project proj)
          mutator for antProject
protected  void setChangedGenSrcProperty(java.util.Collection changed)
          Set the changedGenSrc property for this project, so we can javadoc just these files.
 void setEnvFiles(java.io.File[] files)
          mutator for envFiles
 void setGenDecls(java.util.Collection decls)
          mutator for genDecls
 void setName(java.lang.String val)
          mutator for name
 void setNodeDecls(SandDecl[] decls)
          mutator for nodeDecls
 void setPersistenceDef(SandPersistDef val)
          mutator for persistenceDef
 void setRequiredBy(SandProject[] downstream)
          mutator for requiredBy
 void setSandUIDeployments(SandUIDeployment[] deps)
          Mutator for sandUIDeployments.
 void setStructDecls(SandDecl[] decls)
          mutator for structDecls
 boolean targetExists(java.lang.String targetName)
          Return true if the specified target is defined in this project, false otherwise.
 java.util.Collection updateGenChangeStatus()
          Walk our generator declarations and set the change flags if their corresponding .class files are older or nonexistent.
 void writeCurrDecls(java.util.Collection coll, int decltype)
          Write out our current declarations so we can keep track of deleted declarations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRUCT_DECLS_FILE

public static final java.lang.String STRUCT_DECLS_FILE
Name of the StructDecls.txt file

See Also:
Constant Field Values

NODE_DECLS_FILE

public static final java.lang.String NODE_DECLS_FILE
Name of the NodeDecls.txt file

See Also:
Constant Field Values

name

protected java.lang.String name
A SandProject has a name which is used to identify it within the overall build. This name matches the name in the Ant project, for lookup purposes.


requiredBy

protected SandProject[] requiredBy
A SandProject may be required by zero or more other SandProjects. Obviously this project must be built before any of the projects that require it can be built, so this list of requiring projects is used as input for the order of the overall build.


antProject

protected org.apache.tools.ant.Project antProject
A reference to the Ant Project object for this SandProject


envFiles

protected java.io.File[] envFiles
A SandProject may require access to zero or more files at runtime. These may be third party .jar files, initialization files etc.


sandUIDeployments

protected SandUIDeployment[] sandUIDeployments
A SandProject may declare zero or more deployments of a SandUI definition.


persistenceDef

protected SandPersistDef persistenceDef
A SandProject has a single persistence definition.


genDecls

protected java.util.Collection genDecls
The SandGenDecl instances for this project.


structDecls

protected SandDecl[] structDecls
The SandDecl objects for the structs declared in this project.


nodeDecls

protected SandDecl[] nodeDecls
The SandDecl objects for the nodes declared in this project

Constructor Detail

SandProject

public SandProject(java.lang.String name)
All projects must have a name, so no default ctor. The name given must be the name of the project as specified in build.xml. This is equivalent to the last token in a sandDir project specification, so this ctor will convert as needed. So for example creating a SandProject with "basics" or "apps/basics" is equivalent.

Method Detail

getName

public java.lang.String getName()
accessor for name


setName

public void setName(java.lang.String val)
mutator for name


getRequiredBy

public SandProject[] getRequiredBy()
Returns an array of the projects that require this one. The array may be empty but will not be null.


setRequiredBy

public void setRequiredBy(SandProject[] downstream)
mutator for requiredBy


addRequiredBy

public void addRequiredBy(SandProject proj)
Add a new project to those projects that require this one.


hasRequiredBy

public boolean hasRequiredBy(java.lang.String projname)
Return true if the specified project name exists in our requiredBy array, false otherwise. Not recursive.


removeRequiredBy

public void removeRequiredBy(java.lang.String projname)
Removes a project from our requiredBy. Dies if the project is not found, since we initialize our result array to be one element shorter than what's there. Use hasRequiredBy to test.


getAntProject

public org.apache.tools.ant.Project getAntProject()
accessor for antProject


setAntProject

public void setAntProject(org.apache.tools.ant.Project proj)
mutator for antProject


loadAntProject

public void loadAntProject(java.lang.String sandDir,
                           SandProject proj)
                    throws SandBuildException
Given a sand directory specification (eg "apps/basics"), load the corresponding ant project into our local references. To do this, we need to bootstrap off an existing Ant project, so the second parameter gives a reference to use.

Make sure that the project you are loading is available for lookup by the SandBuildDriver before calling this method.

When RequiredProject is processing the declaration, it calls SandBuildDriver to insert or append the required project. That in turn calls through to here, which calls the "standby" target, which fills in the Ant project information. The call to the project ends quickly, but we retain a reference to it so that we can call other targets as needed.

If this processing breaks, then we will have to do more work to keep the project "on call" in suspended animation. This can be forced by not returning from the "standby" target call until we are done using the project, but that's more of a hassle and involves threads. Keeping an active reference to the project avoids a lot of overhead when processing across projects.

Throws:
SandBuildException

getEnvFiles

public java.io.File[] getEnvFiles()
Return the files this project requires at runtime. The returned array may be empty but will not be null.


setEnvFiles

public void setEnvFiles(java.io.File[] files)
mutator for envFiles


addEnvFile

public void addEnvFile(java.io.File file)
Add a file to the list of required files.


getSandUIDeployments

public SandUIDeployment[] getSandUIDeployments()
Return the SandUI deployment definitions for this project. The returned array may be empty but will not be null.


setSandUIDeployments

public void setSandUIDeployments(SandUIDeployment[] deps)
Mutator for sandUIDeployments.


addUIDeployment

public void addUIDeployment(SandUIDeployment uidep)
Add a SandUIDeployment to our list of UIs for this project.


getPersistenceDef

public SandPersistDef getPersistenceDef()
accessor for persistenceDef


setPersistenceDef

public void setPersistenceDef(SandPersistDef val)
mutator for persistenceDef


getGenDecls

public java.util.Collection getGenDecls()
initializing accessor for genDecls


setGenDecls

public void setGenDecls(java.util.Collection decls)
mutator for genDecls


addGenDecl

public void addGenDecl(SandGenDecl decl)
Add a generator declaration to the collection.


getStructDecls

public SandDecl[] getStructDecls()
Initializing accessor for structDecls


setStructDecls

public void setStructDecls(SandDecl[] decls)
mutator for structDecls


loadStructDecls

public void loadStructDecls()
                     throws SandBuildException
Load the struct declarations for this project

Throws:
SandBuildException

loadPrevDecls

public java.util.ArrayList loadPrevDecls(int decltype)
                                  throws SandBuildException
The last time we built, we wrote out the declarations we were dealing with so we could keep track of what happened for an incremental build. These were written out in the order they were loaded (natural file order), which is the same order as we are working with them this time, so we don't need to do any additional sorting here.

This method takes one of the SandDecl.TYPE_* constants to determine what to load.

Throws:
SandBuildException

findStructDecls

public java.util.ArrayList findStructDecls(java.io.File rootDir,
                                           java.util.ArrayList coll)
                                    throws SandBuildException
If this is a structs directory, load any struct declarations. Otherwise recurse downwards to find any struct directories.

Throws:
SandBuildException

writeCurrDecls

public void writeCurrDecls(java.util.Collection coll,
                           int decltype)
                    throws SandBuildException
Write out our current declarations so we can keep track of deleted declarations. We use the natural order we read things in. That will be the same each run, so there is no need for additional sorting.

Throws:
SandBuildException

addDeletedDecls

protected void addDeletedDecls(java.util.Collection curr,
                               java.util.Collection prev)
                        throws SandBuildException
Given a collection of current declarations, and a collection of previous declarations, add any deleted declarations to the current collection. The two collections are in the same order so that we don't do lots of extra traversal work in the merge process.

Throws:
SandBuildException

initDecls

protected void initDecls(java.util.Collection currDecls)
                  throws SandBuildException
Given a collection of SandDecls, call to initialize the qualifiedName and the status for each one.

Throws:
SandBuildException

getNodeDecls

public SandDecl[] getNodeDecls()
Initializing accessor for nodeDecls


setNodeDecls

public void setNodeDecls(SandDecl[] decls)
mutator for nodeDecls


loadNodeDecls

public void loadNodeDecls()
                   throws SandBuildException
Load the node declarations for this project

Throws:
SandBuildException

findNodeDecls

public java.util.ArrayList findNodeDecls(java.io.File rootDir,
                                         java.util.ArrayList coll)
                                  throws SandBuildException
Walk the directory tree downwards recursively, loading any node declarations.

Throws:
SandBuildException

getStructAndNodeDecls

public SandDecl[] getStructAndNodeDecls()
Return all the struct and node declarations for this project. This is computed on request on the assumption this is an infrequent call. If this turns out to be noticeable overhead, then we can make a data member to hold this.


findProject

public SandProject findProject(java.lang.String projname)
Return the project instance matching the specified name, or null if have no matching instance.


getSandName

public java.lang.String getSandName()
Return the SAND project name. This is the directory off SAND_HOME (eg "apps" or "deploy"), followed by a forward slash, followed by the name of the project. So for example "apps/basics".


callTarget

public void callTarget(java.lang.String targetName)
                throws SandBuildException
Call the specified target in this project. All calls are considered optional, if the target is not found then this simply returns. Use the targetExists method if you want to make sure that a target is defined.

Throws:
SandBuildException

targetExists

public boolean targetExists(java.lang.String targetName)
                     throws SandBuildException
Return true if the specified target is defined in this project, false otherwise.

Throws:
SandBuildException

updateGenChangeStatus

public java.util.Collection updateGenChangeStatus()
                                           throws SandBuildException
Walk our generator declarations and set the change flags if their corresponding .class files are older or nonexistent. Return a Collection of the changed generators.

Throws:
SandBuildException

changedGeneratorFound

protected boolean changedGeneratorFound(java.lang.String classname)
                                 throws SandBuildException
Search through all the projects which declare this generator and return true if any of them have changed. One of them has the source and hence has the update flag set.

Throws:
SandBuildException

changedGeneratorFoundInProject

protected boolean changedGeneratorFoundInProject(SandProject proj,
                                                 java.lang.String classname)

checkDefaultDebugFlag

public void checkDefaultDebugFlag()
                           throws SandBuildException
Check that the debug flag is set, and default it if nothing was specified. Default is "on".

Throws:
SandBuildException

getGeneratorSrcDirName

protected java.lang.String getGeneratorSrcDirName()
Return the name of the generator src directory.


compileGenerators

public void compileGenerators()
                       throws SandBuildException
Compile the generators by calling the build.compile.generators target. This defaults the debug parameter if not already set.

Throws:
SandBuildException

cleanCompileGenerators

public void cleanCompileGenerators()
                            throws SandBuildException
Undo the work done by compileGenerators.

Throws:
SandBuildException

genJarExists

public boolean genJarExists()
Return true if the generator jar file is found, false otherwise.


jarGenerators

public void jarGenerators()
                   throws SandBuildException
Jar the generators by calling the build.jar.generators target.

Throws:
SandBuildException

cleanJarGenerators

public void cleanJarGenerators()
                        throws SandBuildException
Undo the work done by jarGenerators

Throws:
SandBuildException

docGenerators

public void docGenerators(java.util.Collection changed)
                   throws SandBuildException
Document the generators. The changed SandGenDecls are given so we can do an incremental doc run if needed.

Throws:
SandBuildException

setChangedGenSrcProperty

protected void setChangedGenSrcProperty(java.util.Collection changed)
                                 throws SandBuildException
Set the changedGenSrc property for this project, so we can javadoc just these files.

Throws:
SandBuildException

cleanDocGenerators

public void cleanDocGenerators()
                        throws SandBuildException
Undo the work done by docGenerators

Throws:
SandBuildException

checkDefaultJarPrefix

public void checkDefaultJarPrefix()
                           throws SandBuildException
Check that the DeploymentPrefix for jarfiles is set. This should be defined for each deployment, but defaults to "SAND" otherwise.

Throws:
SandBuildException

copyfile

public void copyfile(java.lang.String srcfilename,
                     java.lang.String targetdir)
              throws SandBuildException
Copy the specified file to the specified directory. This essentially wraps a call to the ant copy task. If this fails, we spit out a message and continue anyway. Throwing an exception is usually not helpful.

Throws:
SandBuildException

deletefile

public void deletefile(java.lang.String filename)
                throws SandBuildException
Delete the specified file. This essentially wraps a call to the ant delete task. If this fails, we spit out a message and continue anyway. Throwing an exception is usually not helpful.

Throws:
SandBuildException

docSource

public void docSource(java.util.Collection dirtyFiles)
               throws SandBuildException
Document the main source. The dirtyFiles are those files known to have been changed, which is used for incremental javadoc.

Throws:
SandBuildException

cleanDocSource

public void cleanDocSource()
                    throws SandBuildException
Undo work done by docSource

Throws:
SandBuildException