Class Engine
java.lang.Object
org.owasp.dependencycheck.Engine
- All Implemented Interfaces:
FileFilter, AutoCloseable
Scans files, directories, etc. for Dependencies. Analyzers are loaded and
used to process the files found by the scan, if a file is encountered and an
Analyzer is associated with the file type then the file is turned into a
dependency.
- Author:
- Jeremy Long
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionEngine(@NonNull ClassLoader serviceClassLoader, @NonNull Engine.Mode mode, @NonNull Settings settings) Creates a new Engine.Engine(@NonNull ClassLoader serviceClassLoader, @NonNull Settings settings) Creates a newEngine.Mode.STANDALONEEngine.Engine(@NonNull Engine.Mode mode, @NonNull Settings settings) Creates a new Engine.Creates a newEngine.Mode.STANDALONEEngine. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks all analyzers to see if an extension is supported.voidaddDependency(Dependency dependency) Adds a dependency.protected voidaddFileTypeAnalyzer(@NonNull FileTypeAnalyzer fta) Adds a file type analyzer.voidRuns the analyzers against all of the dependencies.voidclose()Properly cleans up resources allocated during analysis.protected voidcloseAnalyzer(@NonNull Analyzer analyzer) Closes the given analyzer.booleanCycles through the cached web data sources and calls update on all of them.booleandoUpdates(boolean remainOpen) Cycles through the cached web data sources and calls update on all of them.protected voidexecuteAnalysisTasks(@NonNull Analyzer analyzer, List<Throwable> exceptions) Executes executes the analyzer using multiple threads.protected List<AnalysisTask> getAnalysisTasks(Analyzer analyzer, List<Throwable> exceptions) Returns the analysis tasks for the dependencies.Returns a full list of all of the analyzers.getAnalyzers(AnalysisPhase phase) Get the List of the analyzers for a specific phase of analysis.Returns a reference to the database.Returns a copy of the dependencies as an array.protected ExecutorServicegetExecutorService(Analyzer analyzer) Returns the executor service for a given analyzer.Returns the set of file type analyzers.getMode()Returns the mode of the engine.Retrieve an object from the objects collection.Returns the configured settings.booleanVerifies if the object exists in the object store.protected voidinitializeAnalyzer(@NonNull Analyzer analyzer) Initializes the given analyzer.protected final voidCreates a new Engine using the specified classloader to dynamically load Analyzer and Update services.voidThis method is only public for unit/integration testing.voidopenDatabase(boolean readOnly, boolean lockRequired) This method is only public for unit/integration testing.booleanpurge()Purges the cached web data sources.voidPut an object in the object collection.voidremoveDependency(@NonNull Dependency dependency) Removes the dependency.voidremoveObject(String key) Removes an object from the object store.@Nullable List<Dependency> Scans a given file or directory.Scans a given file or directory.Scans an array of files or directories.Scans an array of files or directories.Scans a given file or directory.Scans an array of files or directories.Scans an array of files or directories.Scans a given file or directory.scan(Collection<File> files) Scans a collection of files or directories.scan(Collection<File> files, String projectReference) Scans a collection of files or directories.protected List<Dependency> scanDirectory(@NonNull File dir, @Nullable String projectReference) Recursively scans files and directories.protected List<Dependency> scanDirectory(File dir) Recursively scans files and directories.protected DependencyScans a specified file.protected DependencyScans a specified file.voidsetDependencies(@NonNull List<Dependency> dependencies) Sets the dependencies.voidSorts the dependency list.voidwriteReports(String applicationName, File outputDir, String format) Deprecated.voidwriteReports(String applicationName, File outputDir, String format, ExceptionCollection exceptions) Writes the report to the given output directory.voidwriteReports(String applicationName, @Nullable String groupId, @Nullable String artifactId, @Nullable String version, @NonNull File outputDir, String format) voidwriteReports(String applicationName, @Nullable String groupId, @Nullable String artifactId, @Nullable String version, @NonNull File outputDir, String format, ExceptionCollection exceptions) Writes the report to the given output directory.
-
Constructor Details
-
Engine
Creates a newEngine.Mode.STANDALONEEngine.- Parameters:
settings- reference to the configured settings
-
Engine
Creates a new Engine.- Parameters:
mode- the mode of operationsettings- reference to the configured settings
-
Engine
Creates a newEngine.Mode.STANDALONEEngine.- Parameters:
serviceClassLoader- a reference the class loader being usedsettings- reference to the configured settings
-
Engine
public Engine(@NonNull ClassLoader serviceClassLoader, @NonNull Engine.Mode mode, @NonNull Settings settings) Creates a new Engine.- Parameters:
serviceClassLoader- a reference the class loader being usedmode- the mode of the enginesettings- reference to the configured settings
-
-
Method Details
-
initializeEngine
protected final void initializeEngine()Creates a new Engine using the specified classloader to dynamically load Analyzer and Update services.- Throws:
DatabaseException- thrown if there is an error connecting to the database
-
close
public void close()Properly cleans up resources allocated during analysis.- Specified by:
closein interfaceAutoCloseable
-
getAnalyzers
Get the List of the analyzers for a specific phase of analysis.- Parameters:
phase- the phase to get the configured analyzers.- Returns:
- the analyzers loaded
-
addDependency
Adds a dependency. In some cases, when adding a virtual dependency, the method will identify if the virtual dependency was previously added and update the existing dependency rather then adding a duplicate.- Parameters:
dependency- the dependency to add
-
sortDependencies
public void sortDependencies()Sorts the dependency list. -
removeDependency
Removes the dependency.- Parameters:
dependency- the dependency to remove.
-
getDependencies
Returns a copy of the dependencies as an array.- Returns:
- the dependencies identified
-
setDependencies
Sets the dependencies.- Parameters:
dependencies- the dependencies
-
scan
Scans an array of files or directories. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
paths- an array of paths to files or directories to be analyzed- Returns:
- the list of dependencies scanned
- Since:
- v0.3.2.5
-
scan
Scans an array of files or directories. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
paths- an array of paths to files or directories to be analyzedprojectReference- the name of the project or scope in which the dependency was identified- Returns:
- the list of dependencies scanned
- Since:
- v1.4.4
-
scan
Scans a given file or directory. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
path- the path to a file or directory to be analyzed- Returns:
- the list of dependencies scanned
-
scan
Scans a given file or directory. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
path- the path to a file or directory to be analyzedprojectReference- the name of the project or scope in which the dependency was identified- Returns:
- the list of dependencies scanned
- Since:
- v1.4.4
-
scan
Scans an array of files or directories. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
files- an array of paths to files or directories to be analyzed.- Returns:
- the list of dependencies
- Since:
- v0.3.2.5
-
scan
Scans an array of files or directories. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
files- an array of paths to files or directories to be analyzed.projectReference- the name of the project or scope in which the dependency was identified- Returns:
- the list of dependencies
- Since:
- v1.4.4
-
scan
Scans a collection of files or directories. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
files- a set of paths to files or directories to be analyzed- Returns:
- the list of dependencies scanned
- Since:
- v0.3.2.5
-
scan
Scans a collection of files or directories. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
files- a set of paths to files or directories to be analyzedprojectReference- the name of the project or scope in which the dependency was identified- Returns:
- the list of dependencies scanned
- Since:
- v1.4.4
-
scan
Scans a given file or directory. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
file- the path to a file or directory to be analyzed- Returns:
- the list of dependencies scanned
- Since:
- v0.3.2.4
-
scan
Scans a given file or directory. If a directory is specified, it will be scanned recursively. Any dependencies identified are added to the dependency collection.- Parameters:
file- the path to a file or directory to be analyzedprojectReference- the name of the project or scope in which the dependency was identified- Returns:
- the list of dependencies scanned
- Since:
- v1.4.4
-
scanDirectory
Recursively scans files and directories. Any dependencies identified are added to the dependency collection.- Parameters:
dir- the directory to scan- Returns:
- the list of Dependency objects scanned
-
scanDirectory
Recursively scans files and directories. Any dependencies identified are added to the dependency collection.- Parameters:
dir- the directory to scanprojectReference- the name of the project or scope in which the dependency was identified- Returns:
- the list of Dependency objects scanned
- Since:
- v1.4.4
-
scanFile
Scans a specified file. If a dependency is identified it is added to the dependency collection.- Parameters:
file- The file to scan- Returns:
- the scanned dependency
-
scanFile
Scans a specified file. If a dependency is identified it is added to the dependency collection.- Parameters:
file- The file to scanprojectReference- the name of the project or scope in which the dependency was identified- Returns:
- the scanned dependency
- Since:
- v1.4.4
-
analyzeDependencies
Runs the analyzers against all of the dependencies. Since the mutable dependencies list is exposed viagetDependencies(), this method iterates over a copy of the dependencies list. Thus, the potential forConcurrentModificationExceptions is avoided, and analyzers may safely add or remove entries from the dependencies list.Every effort is made to complete analysis on the dependencies. In some cases an exception will occur with part of the analysis being performed which may not affect the entire analysis. If an exception occurs it will be included in the thrown exception collection.
- Throws:
ExceptionCollection- a collections of any exceptions that occurred during analysis
-
executeAnalysisTasks
protected void executeAnalysisTasks(@NonNull Analyzer analyzer, List<Throwable> exceptions) throws ExceptionCollection Executes executes the analyzer using multiple threads.- Parameters:
analyzer- the analyzer to executeexceptions- a collection of exceptions that occurred during analysis- Throws:
ExceptionCollection- thrown if exceptions occurred during analysis
-
getAnalysisTasks
Returns the analysis tasks for the dependencies.- Parameters:
analyzer- the analyzer to create tasks forexceptions- the collection of exceptions to collect- Returns:
- a collection of analysis tasks
-
getExecutorService
Returns the executor service for a given analyzer.- Parameters:
analyzer- the analyzer to obtain an executor- Returns:
- the executor service
-
initializeAnalyzer
Initializes the given analyzer.- Parameters:
analyzer- the analyzer to prepare- Throws:
InitializationException- thrown when there is a problem initializing the analyzer
-
closeAnalyzer
Closes the given analyzer.- Parameters:
analyzer- the analyzer to close
-
doUpdates
Cycles through the cached web data sources and calls update on all of them.- Returns:
- Whether any updates actually happened
- Throws:
UpdateException- thrown if the operation failsDatabaseException- if the operation fails due to a local database failure
-
doUpdates
Cycles through the cached web data sources and calls update on all of them.- Parameters:
remainOpen- whether or not the database connection should remain open- Returns:
- Whether any updates actually happened
- Throws:
UpdateException- thrown if the operation failsDatabaseException- if the operation fails due to a local database failure
-
purge
public boolean purge()Purges the cached web data sources.- Returns:
trueif the purge was successful; otherwisefalse
-
openDatabase
This method is only public for unit/integration testing. This method should not be called by any integration that uses dependency-check-core.
Opens the database connection.
- Throws:
DatabaseException- if the database connection could not be created
-
openDatabase
This method is only public for unit/integration testing. This method should not be called by any integration that uses dependency-check-core.
Opens the database connection; if readOnly is true a copy of the database will be made.
- Parameters:
readOnly- whether or not the database connection should be readonlylockRequired- whether or not a lock needs to be acquired when opening the database- Throws:
DatabaseException- if the database connection could not be created
-
getDatabase
Returns a reference to the database.- Returns:
- a reference to the database
-
getAnalyzers
-
accept
Checks all analyzers to see if an extension is supported.- Specified by:
acceptin interfaceFileFilter- Parameters:
file- a file extension- Returns:
- true or false depending on whether or not the file extension is supported
-
getFileTypeAnalyzers
Returns the set of file type analyzers.- Returns:
- the set of file type analyzers
-
getSettings
-
getObject
-
putObject
-
hasObject
Verifies if the object exists in the object store.- Parameters:
key- the key to retrieve the object- Returns:
trueif the object exists; otherwisefalse
-
removeObject
Removes an object from the object store.- Parameters:
key- the key to the object
-
getMode
-
addFileTypeAnalyzer
Adds a file type analyzer. This has been added solely to assist in unit testing the Engine.- Parameters:
fta- the file type analyzer to add
-
writeReports
@Deprecated public void writeReports(String applicationName, File outputDir, String format) throws ReportException Deprecated.Writes the report to the given output directory.- Parameters:
applicationName- the name of the application/projectoutputDir- the path to the output directory (can include the full file name if the format is not ALL)format- the report format (seeReportGenerator.Format)- Throws:
ReportException- thrown if there is an error generating the report
-
writeReports
public void writeReports(String applicationName, File outputDir, String format, ExceptionCollection exceptions) throws ReportException Writes the report to the given output directory.- Parameters:
applicationName- the name of the application/projectoutputDir- the path to the output directory (can include the full file name if the format is not ALL)format- the report format (seeReportGenerator.Format)exceptions- a collection of exceptions that may have occurred during the analysis- Throws:
ReportException- thrown if there is an error generating the report
-
writeReports
@Deprecated public void writeReports(String applicationName, @Nullable String groupId, @Nullable String artifactId, @Nullable String version, @NonNull File outputDir, String format) throws ReportException Writes the report to the given output directory.- Parameters:
applicationName- the name of the application/projectgroupId- the Maven groupIdartifactId- the Maven artifactIdversion- the Maven versionoutputDir- the path to the output directory (can include the full file name if the format is not ALL)format- the report format (seeReportGenerator.Format)- Throws:
ReportException- thrown if there is an error generating the report
-
writeReports
public void writeReports(String applicationName, @Nullable String groupId, @Nullable String artifactId, @Nullable String version, @NonNull File outputDir, String format, ExceptionCollection exceptions) throws ReportException Writes the report to the given output directory.- Parameters:
applicationName- the name of the application/projectgroupId- the Maven groupIdartifactId- the Maven artifactIdversion- the Maven versionoutputDir- the path to the output directory (can include the full file name if the format is not ALL)format- the report format (seeReportGenerator.Format)exceptions- a collection of exceptions that may have occurred during the analysis- Throws:
ReportException- thrown if there is an error generating the report
-
writeReports(java.lang.String, java.io.File, java.lang.String, org.owasp.dependencycheck.exception.ExceptionCollection)