org.makumba.devel.relations
Class RelationCrawler

java.lang.Object
  extended by org.makumba.devel.relations.RelationCrawler

public class RelationCrawler
extends Object

This crawler looks for relations between Makumba files and stores them in a database table.
TODO keep a list of things that could not be analyzed (may it be entire files, or query strings etc

Version:
$Id: RelationsCrawler.java,v 1.1 Apr 13, 2008 4:16:16 PM manu Exp $
Author:
Manuel Gay

Nested Class Summary
static class RelationCrawler.MakumbaRelatedFileFilter
          A filenameFilter that accepts .jsp, .mdd and .java files, or directories.
 
Field Summary
protected static boolean subProcess
           
 
Method Summary
protected  void addJavaAnalysisError(String s)
           
protected  void addJSPAnalysisError(String s, Throwable t)
           
protected  void addRelation(String fromFile, String toFile, String type, Dictionary<String,Object> relationData)
          Adds a relation which will later on be written to the database
 void crawl(String path)
          Crawls through a file using the relation miners
 void deleteFileRelations(String relativePath)
          Deletes the dependency relations of this file
static String getDefaultTargetDatabase()
          Gets the default target database, can be set using the org.makumba.devel.relations.databaseName JVM property.
 FileRelations getFileDependencies(String relativePath)
          Gets the dependencies of a file, i.e. the JSP, Java and MDD files this file depends on
 FileRelations getFileDependents(String relativePath)
          Gets the dependents of a file, i.e. the JSP, Java and MDD files that depend on this file
 Vector<String> getJavaAnalysisErrors()
           
 Hashtable<String,Throwable> getJSPAnalysisErrors()
           
 int getJSPCrawlCount()
           
static RelationCrawler getRelationCrawler(String webappRoot, String targetDatabase, boolean forcetarget, String URLprefix, String URLroot, boolean relationTypeDetail)
          Gets a RelationCrawler instance.
 String getTargetDatabaseName()
           
protected  String getWebappRoot()
           
static void main(String[] args)
          Extracts relations from a set of files.
 boolean wasCrawled()
          Checks whether this webapp has already been crawled
static void writeJSPAnalysisError(String fileName, Hashtable<String,Throwable> analysisErrors, int JSPCrawlCount)
           
 void writeRelationsToDb(boolean updateExistingRelations)
          Writes the relations to the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subProcess

protected static boolean subProcess
Method Detail

getRelationCrawler

public static RelationCrawler getRelationCrawler(String webappRoot,
                                                 String targetDatabase,
                                                 boolean forcetarget,
                                                 String URLprefix,
                                                 String URLroot,
                                                 boolean relationTypeDetail)
Gets a RelationCrawler instance.

Parameters:
webappRoot - the path to the root of the webapp that should be crawled
targetDatabase - the makumba name of the database the relations should be written to.
forcetarget - indicates whether the target database should be forced: if set to true, even if relations were previously written to another database, this will force writing them to the indicated database
URLprefix - the prefix of the relation URL, e.g. "file://"
URLroot - the root of the relation, e.g. a webapp name
relationTypeDetail - TODO
Returns:
a RelationCrawler instance

getDefaultTargetDatabase

public static String getDefaultTargetDatabase()
Gets the default target database, can be set using the org.makumba.devel.relations.databaseName JVM property.


getTargetDatabaseName

public String getTargetDatabaseName()

getWebappRoot

protected String getWebappRoot()

getJSPAnalysisErrors

public Hashtable<String,Throwable> getJSPAnalysisErrors()

getJSPCrawlCount

public int getJSPCrawlCount()

getJavaAnalysisErrors

public Vector<String> getJavaAnalysisErrors()

addJSPAnalysisError

protected void addJSPAnalysisError(String s,
                                   Throwable t)

addJavaAnalysisError

protected void addJavaAnalysisError(String s)

writeJSPAnalysisError

public static void writeJSPAnalysisError(String fileName,
                                         Hashtable<String,Throwable> analysisErrors,
                                         int JSPCrawlCount)

main

public static void main(String[] args)
Extracts relations from a set of files.

Parameters:
args - the arguments needed to crawl: webappRoot destinationDb forceDatabase URLprefix URLroot [fileList]
where:
  • webappRoot is the absolute path to the webapp root on the disk
  • destinationDb is the database (e.g. localhost_mysql_karamba) to which the relations table should be written
  • forceDatabase indicates whether relations should be written to the indicated database, even if there's already an existing table for this webapp indicated somewhere. in order to be enabled, the value should be "forceDatabase", any other value disabling it. this should not be used for standalone makumba webapps, but may be used in an environment where all makumba webapps should have their relations saved in the same table of one database.
  • URLprefix is the prefix given to the file URL, e.g. "file://"
  • URLroot is the root of the URL, e.g. the name of the crawled webapp
  • fileList is a list of files to be crawled

crawl

public void crawl(String path)
Crawls through a file using the relation miners

Parameters:
path - the path to the file

addRelation

protected void addRelation(String fromFile,
                           String toFile,
                           String type,
                           Dictionary<String,Object> relationData)
Adds a relation which will later on be written to the database

Parameters:
toFile - the path to the file there is a relation with
type - TODO
relationData - the relation data

writeRelationsToDb

public void writeRelationsToDb(boolean updateExistingRelations)
Writes the relations to the database. This should be called after crawling is done.

Parameters:
updateExistingRelations - if true, recomputes existing relations one by one, if false, flush all the previous relations

wasCrawled

public boolean wasCrawled()
Checks whether this webapp has already been crawled


deleteFileRelations

public void deleteFileRelations(String relativePath)
Deletes the dependency relations of this file

Parameters:
relativePath - the relative path to the file

getFileDependencies

public FileRelations getFileDependencies(String relativePath)
Gets the dependencies of a file, i.e. the JSP, Java and MDD files this file depends on

Parameters:
relativePath - the relative path to the file, within the webapp root
Returns:
a FileRelations object containing all the dependencies, as well as their origin detail

getFileDependents

public FileRelations getFileDependents(String relativePath)
Gets the dependents of a file, i.e. the JSP, Java and MDD files that depend on this file

Parameters:
relativePath - the relative path to the file, within the webapp root
Returns:
a FileRelations object containing all the dependents, as well as their origin detail