Search in sources :

Example 1 with Engine

use of org.owasp.dependencycheck.Engine in project dependency-check-plugin by jenkinsci.

the class DependencyCheckExecutor method call.

/**
 * Performs a DependencyCheck analysis build.
 *
 * @return a boolean value indicating if the build was successful or not. A
 * successful build is not determined by the ability to analyze
 * dependencies, rather, simply to determine if errors were encountered
 * during the execution.
 */
public Boolean call() throws IOException {
    if (getJavaVersion() <= 1.6) {
        log(Messages.Failure_Java_Version());
        return false;
    }
    log(Messages.Executor_Display_Options());
    log(options.toString());
    if (!prepareDirectories()) {
        return false;
    }
    Engine engine = null;
    try {
        engine = executeDependencyCheck();
        if (options.isUpdateOnly()) {
            return true;
        } else {
            return generateExternalReports(engine);
        }
    } catch (DatabaseException ex) {
        log(Messages.Failure_Database_Connect());
        log(ex.getMessage());
    } catch (UpdateException ex) {
        log(Messages.Failure_Database_Update());
    } catch (ExceptionCollection ec) {
        log(Messages.Failure_Collection());
        for (Throwable t : ec.getExceptions()) {
            log("Exception Caught: " + t.getClass().getCanonicalName());
            if (t.getCause() != null && t.getCause().getMessage() != null) {
                log("Cause: " + t.getCause().getMessage());
            }
            log("Message: " + t.getMessage());
            log(ExceptionUtils.getStackTrace(t));
        }
    } finally {
        settings.cleanup(true);
        if (engine != null) {
            engine.close();
        }
    }
    return false;
}
Also used : ExceptionCollection(org.owasp.dependencycheck.exception.ExceptionCollection) UpdateException(org.owasp.dependencycheck.data.update.exception.UpdateException) DatabaseException(org.owasp.dependencycheck.data.nvdcve.DatabaseException) Engine(org.owasp.dependencycheck.Engine)

Example 2 with Engine

use of org.owasp.dependencycheck.Engine in project dependency-check-plugin by jenkinsci.

the class DependencyCheckExecutor method executeDependencyCheck.

/**
 * Executes the Dependency-Check on the dependent libraries.
 *
 * @return the Engine used to scan the dependencies.
 */
private Engine executeDependencyCheck() throws DatabaseException, UpdateException, ExceptionCollection {
    populateSettings();
    Engine engine;
    if (classLoader != null) {
        engine = new Engine(classLoader, settings);
    } else {
        engine = new Engine(settings);
    }
    if (options.isUpdateOnly()) {
        log(Messages.Executor_Update_Only());
        engine.doUpdates();
    } else {
        for (String scanPath : options.getScanPath()) {
            if (new File(scanPath).exists()) {
                log(Messages.Executor_Scanning() + " " + scanPath);
                engine.scan(scanPath);
            } else {
                // Scan path does not exist. Check for Ant style pattern sets.
                final File baseDir = new File(options.getWorkspace());
                // Remove the workspace path from the scan path so FileSet can assume
                // the specified path is a patternset that defines includes.
                final String includes = scanPath.replace(options.getWorkspace() + File.separator, "");
                final FileSet fileSet = Util.createFileSet(baseDir, includes, null);
                final Iterator filePathIter = fileSet.iterator();
                while (filePathIter.hasNext()) {
                    final FilePath foundFilePath = new FilePath(new FilePath(baseDir), filePathIter.next().toString());
                    log(Messages.Executor_Scanning() + " " + foundFilePath.getRemote());
                    engine.scan(foundFilePath.getRemote());
                }
            }
        }
        log(Messages.Executor_Analyzing_Dependencies());
        engine.analyzeDependencies();
    }
    return engine;
}
Also used : FilePath(hudson.FilePath) FileSet(org.apache.tools.ant.types.FileSet) Iterator(java.util.Iterator) File(java.io.File) Engine(org.owasp.dependencycheck.Engine)

Aggregations

Engine (org.owasp.dependencycheck.Engine)2 FilePath (hudson.FilePath)1 File (java.io.File)1 Iterator (java.util.Iterator)1 FileSet (org.apache.tools.ant.types.FileSet)1 DatabaseException (org.owasp.dependencycheck.data.nvdcve.DatabaseException)1 UpdateException (org.owasp.dependencycheck.data.update.exception.UpdateException)1 ExceptionCollection (org.owasp.dependencycheck.exception.ExceptionCollection)1