edu.umd.cs.findbugs
Class Project

java.lang.Object
  extended by edu.umd.cs.findbugs.Project
All Implemented Interfaces:
XMLWriteable

public class Project
extends java.lang.Object
implements XMLWriteable

A project in the GUI. This consists of some number of Jar files to analyze for bugs, and optionally

Author:
David Hovemeyer

Nested Class Summary
private static class Project.WorkList
          Worklist for finding implicit classpath entries.
private static class Project.WorkListItem
          Worklist item for finding implicit classpath entries.
 
Field Summary
private static java.lang.String AUX_CLASSPATH_ENTRIES_KEY
           
private static java.lang.String AUX_CLASSPATH_ENTRY_ELEMENT_NAME
           
private  java.util.LinkedList<java.lang.String> auxClasspathEntryList
          The list of auxiliary classpath entries.
private static boolean DEBUG
           
private static boolean FILE_IGNORE_CASE
          Hack for whether files are case insensitive.
private  java.util.LinkedList<java.lang.String> fileList
          The list of project files.
private static java.lang.String FILENAME_ATTRIBUTE_NAME
           
private  boolean isModified
          Flag to indicate that this Project has been modified.
private static java.lang.String JAR_ELEMENT_NAME
           
private static java.lang.String JAR_FILES_KEY
           
private static java.lang.String OPTIONS_KEY
           
private  java.util.Map<java.lang.String,java.lang.Boolean> optionsMap
          Options.
private  java.lang.String projectFileName
          Project filename.
static java.lang.String RELATIVE_PATHS
           
private static java.lang.String SRC_DIR_ELEMENT_NAME
           
private static java.lang.String SRC_DIRS_KEY
           
private  java.util.LinkedList<java.lang.String> srcDirList
          The list of source directories.
static java.lang.String UNNAMED_PROJECT
          Constant used to name anonymous projects.
 
Constructor Summary
Project()
          Create an anonymous project.
 
Method Summary
 boolean addAuxClasspathEntry(java.lang.String auxClasspathEntry)
          Add an auxiliary classpath entry
 boolean addFile(java.lang.String fileName)
          Add a file to the project.
 boolean addSourceDir(java.lang.String dirName)
          Add a source directory to the project.
private  boolean addToListInternal(java.util.List<java.lang.String> list, java.lang.String value)
          Add a value to given list, making the Project modified if the value is not already present in the list.
private  java.lang.String convertToAbsolute(java.lang.String fileName)
          Converts a relative path to an absolute path if possible.
private  java.lang.String convertToRelative(java.lang.String srcFile, java.lang.String base)
          Converts a full path to a relative path if possible
 Project duplicate()
          Return an exact copy of this Project.
 java.lang.String getAuxClasspathEntry(int n)
          Get the n'th auxiliary classpath entry.
 java.util.List<java.lang.String> getAuxClasspathEntryList()
          Return the list of aux classpath entries.
 java.lang.String getFile(int num)
          Get the given file in the list of project files.
 java.lang.String[] getFileArray()
          Get project files as an array of Strings.
 int getFileCount()
          Get the number of files in the project.
 java.util.List<java.lang.String> getFileList()
          Get the list of files, directories, and zip files in the project.
 java.util.List<java.lang.String> getImplicitClasspathEntryList()
          Return the list of implicit classpath entries.
private static java.lang.String getLine(java.io.BufferedReader reader)
          Read a line from a BufferedReader, ignoring blank lines and comments.
 int getNumAuxClasspathEntries()
          Get the number of auxiliary classpath entries.
 int getNumSourceDirs()
          Get the number of source directories in the project.
 boolean getOption(java.lang.String option)
          Retrieve the Options value.
 java.lang.String getProjectFileName()
          Get the project filename.
 java.lang.String getSourceDir(int num)
          Get the given source directory.
 java.lang.String[] getSourceDirArray()
          Get source dirs as an array of Strings.
 java.util.List<java.lang.String> getSourceDirList()
          Get the source dir list.
 boolean isModified()
          Return whether or not this Project has unsaved modifications.
private static java.lang.String makeAbsoluteCWD(java.lang.String fileName)
          Make the given filename absolute relative to the current working directory.
private  void makeListAbsoluteProject(java.util.List<java.lang.String> list)
          Make the given list of pathnames absolute relative to the absolute path of the project file.
private  void parseOption(java.lang.String option)
          Parse one line in the [Options] section.
private  void processComponentJar(java.net.URL jarFileURL, Project.WorkList workList, java.util.List<java.lang.String> implicitClasspath)
          Examine the manifest of a single zip/jar file for implicit classapth entries.
 void read(java.lang.String inputFile)
          Read the project from an input file.
 void removeAuxClasspathEntry(int n)
          Remove the n'th auxiliary classpath entry.
 void removeFile(int num)
          Remove file at the given index in the list of project files
 void removeSourceDir(int num)
          Remove source directory at given index.
 void setModified(boolean isModified)
          Set whether or not this Project has unsaved modifications.
 void setProjectFileName(java.lang.String projectFileName)
          Set the project filename.
 java.lang.String toString()
          Convert to a string in a nice (displayable) format.
static java.lang.String transformFilename(java.lang.String fileName)
          Transform a user-entered filename into a proper filename, by adding the ".fb" file extension if it isn't already present.
 void write(java.lang.String outputFile, boolean useRelativePaths, java.lang.String relativeBase)
          Save the project to an output file.
 void writeXML(XMLOutput xmlOutput)
          Write this object to given XMLOutput.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

projectFileName

private java.lang.String projectFileName
Project filename.


optionsMap

private java.util.Map<java.lang.String,java.lang.Boolean> optionsMap
Options.


fileList

private java.util.LinkedList<java.lang.String> fileList
The list of project files.


srcDirList

private java.util.LinkedList<java.lang.String> srcDirList
The list of source directories.


auxClasspathEntryList

private java.util.LinkedList<java.lang.String> auxClasspathEntryList
The list of auxiliary classpath entries.


isModified

private boolean isModified
Flag to indicate that this Project has been modified.


UNNAMED_PROJECT

public static final java.lang.String UNNAMED_PROJECT
Constant used to name anonymous projects.

See Also:
Constant Field Values

OPTIONS_KEY

private static final java.lang.String OPTIONS_KEY
See Also:
Constant Field Values

JAR_FILES_KEY

private static final java.lang.String JAR_FILES_KEY
See Also:
Constant Field Values

SRC_DIRS_KEY

private static final java.lang.String SRC_DIRS_KEY
See Also:
Constant Field Values

AUX_CLASSPATH_ENTRIES_KEY

private static final java.lang.String AUX_CLASSPATH_ENTRIES_KEY
See Also:
Constant Field Values

RELATIVE_PATHS

public static final java.lang.String RELATIVE_PATHS
See Also:
Constant Field Values

JAR_ELEMENT_NAME

private static final java.lang.String JAR_ELEMENT_NAME
See Also:
Constant Field Values

AUX_CLASSPATH_ENTRY_ELEMENT_NAME

private static final java.lang.String AUX_CLASSPATH_ENTRY_ELEMENT_NAME
See Also:
Constant Field Values

SRC_DIR_ELEMENT_NAME

private static final java.lang.String SRC_DIR_ELEMENT_NAME
See Also:
Constant Field Values

FILENAME_ATTRIBUTE_NAME

private static final java.lang.String FILENAME_ATTRIBUTE_NAME
See Also:
Constant Field Values

FILE_IGNORE_CASE

private static final boolean FILE_IGNORE_CASE
Hack for whether files are case insensitive. For now, we'll assume that Windows is the only case insensitive OS. (OpenVMS users, feel free to submit a patch :-)

Constructor Detail

Project

public Project()
Create an anonymous project.

Method Detail

duplicate

public Project duplicate()
Return an exact copy of this Project.


isModified

public boolean isModified()
Return whether or not this Project has unsaved modifications.


setModified

public void setModified(boolean isModified)
Set whether or not this Project has unsaved modifications.


getProjectFileName

public java.lang.String getProjectFileName()
Get the project filename.


setProjectFileName

public void setProjectFileName(java.lang.String projectFileName)
Set the project filename.

Parameters:
projectFileName - the new filename

addFile

public boolean addFile(java.lang.String fileName)
Add a file to the project.

Parameters:
fileName - the file to add
Returns:
true if the file was added, or false if the file was already present

addSourceDir

public boolean addSourceDir(java.lang.String dirName)
Add a source directory to the project.

Parameters:
dirName - the directory to add
Returns:
true if the source directory was added, or false if the source directory was already present

getOption

public boolean getOption(java.lang.String option)
Retrieve the Options value.

Parameters:
option - the name of option to get
Returns:
the value of the option

getFileCount

public int getFileCount()
Get the number of files in the project.

Returns:
the number of files in the project

getFile

public java.lang.String getFile(int num)
Get the given file in the list of project files.

Parameters:
num - the number of the file in the list of project files
Returns:
the name of the file

removeFile

public void removeFile(int num)
Remove file at the given index in the list of project files

Parameters:
num - index of the file to remove in the list of project files

getFileList

public java.util.List<java.lang.String> getFileList()
Get the list of files, directories, and zip files in the project.


getNumSourceDirs

public int getNumSourceDirs()
Get the number of source directories in the project.

Returns:
the number of source directories in the project

getSourceDir

public java.lang.String getSourceDir(int num)
Get the given source directory.

Parameters:
num - the number of the source directory
Returns:
the source directory

removeSourceDir

public void removeSourceDir(int num)
Remove source directory at given index.

Parameters:
num - index of the source directory to remove

getFileArray

public java.lang.String[] getFileArray()
Get project files as an array of Strings.


getSourceDirArray

public java.lang.String[] getSourceDirArray()
Get source dirs as an array of Strings.


getSourceDirList

public java.util.List<java.lang.String> getSourceDirList()
Get the source dir list.


addAuxClasspathEntry

public boolean addAuxClasspathEntry(java.lang.String auxClasspathEntry)
Add an auxiliary classpath entry

Parameters:
auxClasspathEntry - the entry
Returns:
true if the entry was added successfully, or false if the given entry is already in the list

getNumAuxClasspathEntries

public int getNumAuxClasspathEntries()
Get the number of auxiliary classpath entries.


getAuxClasspathEntry

public java.lang.String getAuxClasspathEntry(int n)
Get the n'th auxiliary classpath entry.


removeAuxClasspathEntry

public void removeAuxClasspathEntry(int n)
Remove the n'th auxiliary classpath entry.


getAuxClasspathEntryList

public java.util.List<java.lang.String> getAuxClasspathEntryList()
Return the list of aux classpath entries.


getImplicitClasspathEntryList

public java.util.List<java.lang.String> getImplicitClasspathEntryList()
Return the list of implicit classpath entries. The implicit classpath is computed from the closure of the set of jar files that are referenced by the "Class-Path" attribute of the manifest of the any jar file that is part of this project or by the "Class-Path" attribute of any directly or indirectly referenced jar. The referenced jar files that exist are the list of implicit classpath entries.


processComponentJar

private void processComponentJar(java.net.URL jarFileURL,
                                 Project.WorkList workList,
                                 java.util.List<java.lang.String> implicitClasspath)
Examine the manifest of a single zip/jar file for implicit classapth entries.

Parameters:
jarFileURL - URL of the zip/jar file
workList - worklist of zip/jar files to examine
implicitClasspath - list of implicit classpath entries found

write

public void write(java.lang.String outputFile,
                  boolean useRelativePaths,
                  java.lang.String relativeBase)
           throws java.io.IOException
Save the project to an output file.

Parameters:
outputFile - name of output file
useRelativePaths - true if the project should be written using only relative paths
relativeBase - if useRelativePaths is true, this file is taken as the base directory in terms of which all files should be made relative
Throws:
java.io.IOException - if an error occurs while writing

read

public void read(java.lang.String inputFile)
          throws java.io.IOException
Read the project from an input file. This method should only be used on an empty Project (created with the default constructor).

Parameters:
inputFile - name of the input file to read the project from
Throws:
java.io.IOException - if an error occurs while reading

getLine

private static java.lang.String getLine(java.io.BufferedReader reader)
                                 throws java.io.IOException
Read a line from a BufferedReader, ignoring blank lines and comments.

Throws:
java.io.IOException

toString

public java.lang.String toString()
Convert to a string in a nice (displayable) format.

Overrides:
toString in class java.lang.Object

transformFilename

public static java.lang.String transformFilename(java.lang.String fileName)
Transform a user-entered filename into a proper filename, by adding the ".fb" file extension if it isn't already present.


writeXML

public void writeXML(XMLOutput xmlOutput)
              throws java.io.IOException
Description copied from interface: XMLWriteable
Write this object to given XMLOutput.

Specified by:
writeXML in interface XMLWriteable
Parameters:
xmlOutput - the XMLOutput for the document
Throws:
java.io.IOException

parseOption

private void parseOption(java.lang.String option)
                  throws java.io.IOException
Parse one line in the [Options] section.

Parameters:
option - one line in the [Options] section
Throws:
java.io.IOException

convertToRelative

private java.lang.String convertToRelative(java.lang.String srcFile,
                                           java.lang.String base)
Converts a full path to a relative path if possible

Parameters:
srcFile - path to convert
Returns:
the converted filename

convertToAbsolute

private java.lang.String convertToAbsolute(java.lang.String fileName)
                                    throws java.io.IOException
Converts a relative path to an absolute path if possible.

Parameters:
fileName - path to convert
Returns:
the converted filename
Throws:
java.io.IOException

makeAbsoluteCWD

private static java.lang.String makeAbsoluteCWD(java.lang.String fileName)
Make the given filename absolute relative to the current working directory.


addToListInternal

private boolean addToListInternal(java.util.List<java.lang.String> list,
                                  java.lang.String value)
Add a value to given list, making the Project modified if the value is not already present in the list.

Parameters:
list - the list
value - the value to be added
Returns:
true if the value was not already present in the list, false otherwise

makeListAbsoluteProject

private void makeListAbsoluteProject(java.util.List<java.lang.String> list)
                              throws java.io.IOException
Make the given list of pathnames absolute relative to the absolute path of the project file.

Throws:
java.io.IOException