Search in sources :

Example 6 with DetectorException

use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.

the class NpmExecutableFinder method findNpm.

public String findNpm(final DetectorEnvironment environment) throws DetectorException {
    try {
        if (!hasLookedForNpm) {
            foundNpm = findNpm();
            hasLookedForNpm = true;
        }
        return foundNpm;
    } catch (final Exception e) {
        throw new DetectorException(e);
    }
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 7 with DetectorException

use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.

the class GradleInspectorManager method getGradleInspector.

public String getGradleInspector() throws DetectorException {
    if (!hasResolvedInspector) {
        hasResolvedInspector = true;
        try {
            final File airGapPath = deriveGradleAirGapDir();
            final File generatedGradleScriptFile = directoryManager.getSharedFile(GRADLE_DIR_NAME, GENERATED_GRADLE_SCRIPT_NAME);
            GradleScriptCreator gradleScriptCreator = new GradleScriptCreator(detectConfiguration, configuration);
            if (airGapPath == null) {
                Optional<String> version = findVersion();
                if (version.isPresent()) {
                    logger.info("Resolved the gradle inspector version: " + version.get());
                    generatedGradleScriptPath = gradleScriptCreator.generateOnlineScript(generatedGradleScriptFile, version.get());
                } else {
                    throw new DetectorException("Unable to find the gradle inspector version from artifactory.");
                }
            } else {
                generatedGradleScriptPath = gradleScriptCreator.generateAirGapScript(generatedGradleScriptFile, airGapPath.getCanonicalPath());
            }
        } catch (final Exception e) {
            throw new DetectorException(e);
        }
        if (generatedGradleScriptPath == null) {
            throw new DetectorException("Unable to initialize the gradle inspector.");
        } else {
            logger.trace("Derived generated gradle script path: " + generatedGradleScriptPath);
        }
    } else {
        logger.debug("Already attempted to resolve the gradle inspector script, will not attempt again.");
    }
    if (StringUtils.isBlank(generatedGradleScriptPath)) {
        throw new DetectorException("Unable to find or create the gradle inspector script.");
    }
    return generatedGradleScriptPath;
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File) IntegrationException(com.synopsys.integration.exception.IntegrationException) IOException(java.io.IOException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException)

Example 8 with DetectorException

use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.

the class ExtractionHandler method processExtraction.

public void processExtraction(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) throws DetectorException, ExecutableRunnerException {
    if (extraction.bomToolDescription.equals("NUGET - Solution")) {
        logger.info("OOOO Snap, I know how to handle this.");
        NugetSolutionExtractionDebugger debugger = new NugetSolutionExtractionDebugger();
        debugger.debug(extraction, detectRunInfo, detectConfiguration);
    } else if (extraction.bomToolDescription.equals("GRADLE - Gradle Inspector")) {
        logger.info("OOOO Snap, I know how to handle this.");
        GradleExtractionDebugger debugger = new GradleExtractionDebugger();
        debugger.debug(extraction, detectRunInfo, detectConfiguration);
    } else {
        throw new DetectorException("Don't know what to do with this extraction, sorry brah.");
    }
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException)

Example 9 with DetectorException

use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.

the class DetectorFinder method findApplicableBomTools.

private List<DetectorEvaluation> findApplicableBomTools(final List<File> directoriesToSearch, final Set<Detector> appliedBefore, final int depth, final DetectorFinderOptions options) throws DetectorException, DetectUserFriendlyException {
    final List<DetectorEvaluation> results = new ArrayList<>();
    if (depth > options.getMaximumDepth()) {
        return results;
    }
    if (null == directoriesToSearch || directoriesToSearch.size() == 0) {
        return results;
    }
    for (final File directory : directoriesToSearch) {
        if (depth > 0 && options.getDetectorSearchFilter().shouldExclude(directory)) {
            // NEVER skip at depth 0.
            logger.info("Skipping excluded directory: " + directory.getPath());
            continue;
        }
        logger.info("Searching directory: " + directory.getPath());
        final Set<DetectorType> applicableTypes = new HashSet<>();
        final Set<Detector> applied = new HashSet<>();
        final List<DetectorEvaluation> evaluations = processDirectory(directory, appliedBefore, depth, options);
        results.addAll(evaluations);
        final List<Detector> appliedBomTools = evaluations.stream().filter(it -> it.isApplicable()).map(it -> it.getDetector()).collect(Collectors.toList());
        applied.addAll(appliedBomTools);
        // TODO: Used to have a remaining detectors and would bail early here, not sure how to go about that?
        final Set<Detector> everApplied = new HashSet<>();
        everApplied.addAll(applied);
        everApplied.addAll(appliedBefore);
        final List<File> subdirectories = getSubDirectories(directory, options.getDetectorSearchFilter());
        final List<DetectorEvaluation> recursiveResults = findApplicableBomTools(subdirectories, everApplied, depth + 1, options);
        results.addAll(recursiveResults);
        logger.debug(directory + ": " + applicableTypes.stream().map(it -> it.toString()).collect(Collectors.joining(", ")));
    }
    return results;
}
Also used : Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) Files(java.nio.file.Files) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DetectorEnvironment(com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment) List(java.util.List) ExitCodeType(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType) Stream(java.util.stream.Stream) DetectorSearchRuleSet(com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) Path(java.nio.file.Path) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) ArrayList(java.util.ArrayList) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) File(java.io.File) HashSet(java.util.HashSet)

Example 10 with DetectorException

use of com.blackducksoftware.integration.hub.detect.detector.DetectorException in project hub-detect by blackducksoftware.

the class DockerInspectorManager method findOrDownloadJar.

private DockerInspectorInfo findOrDownloadJar() throws IntegrationException, DetectUserFriendlyException, IOException {
    logger.info("Determining the location of the Docker inspector.");
    String dockerVersion = detectConfiguration.getProperty(DetectProperty.DETECT_DOCKER_INSPECTOR_VERSION, PropertyAuthority.None);
    Optional<String> location = artifactResolver.resolveArtifactLocation(ArtifactoryConstants.ARTIFACTORY_URL, ArtifactoryConstants.DOCKER_INSPECTOR_REPO, ArtifactoryConstants.DOCKER_INSPECTOR_PROPERTY, dockerVersion, ArtifactoryConstants.DOCKER_INSPECTOR_VERSION_OVERRIDE);
    if (location.isPresent()) {
        logger.info("Finding or downloading the docker inspector.");
        File dockerDirectory = directoryManager.getPermanentDirectory(DOCKER_SHARED_DIRECTORY_NAME);
        logger.debug(String.format("Downloading docker inspector from '%s' to '%s'.", location.get(), dockerDirectory.getAbsolutePath()));
        File jarFile = artifactResolver.downloadOrFindArtifact(dockerDirectory, location.get());
        logger.info("Found online docker inspector: " + jarFile.getAbsolutePath());
        return new DockerInspectorInfo(jarFile);
    } else {
        throw new DetectorException("Unable to find Docker version from artifactory.");
    }
}
Also used : DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File)

Aggregations

DetectorException (com.blackducksoftware.integration.hub.detect.detector.DetectorException)13 File (java.io.File)8 IOException (java.io.IOException)5 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)4 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)2 Detector (com.blackducksoftware.integration.hub.detect.detector.Detector)1 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)1 DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)1 DotNetCoreNugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.DotNetCoreNugetInspector)1 ExeNugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.ExeNugetInspector)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)1 DetectorEvaluation (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)1 DetectorSearchRuleSet (com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1