Search in sources :

Example 1 with DetectorType

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

the class ShutdownManager method shutdown.

public void shutdown(Optional<RunResult> runResultOptional) {
    if (connectivityManager.getPhoneHomeManager().isPresent()) {
        try {
            logger.debug("Ending phone home.");
            connectivityManager.getPhoneHomeManager().get().endPhoneHome();
        } catch (final Exception e) {
            logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
        }
    }
    try {
        if (diagnosticManager.getDiagnosticSystem().isPresent()) {
            logger.debug("Ending diagnostics.");
            diagnosticManager.getDiagnosticSystem().get().finish();
        }
    } catch (final Exception e) {
        logger.debug(String.format("Error trying to finish diagnostics: %s", e.getMessage()));
    }
    try {
        if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_CLEANUP, PropertyAuthority.None)) {
            logger.info("Detect will cleanup.");
            boolean dryRun = detectConfiguration.getBooleanProperty(DetectProperty.DETECT_BLACKDUCK_SIGNATURE_SCANNER_DRY_RUN, PropertyAuthority.None);
            boolean offline = !connectivityManager.isDetectOnline();
            List<File> cleanupToSkip = new ArrayList<>();
            if (dryRun || offline) {
                logger.debug("Will not cleanup scan folder.");
                cleanupToSkip.add(directoryManager.getScanOutputDirectory());
            }
            if (offline) {
                logger.debug("Will not cleanup bdio folder.");
                cleanupToSkip.add(directoryManager.getBdioOutputDirectory());
            }
            logger.debug("Cleaning up directory: " + directoryManager.getRunHomeDirectory().getAbsolutePath());
            cleanup(directoryManager.getRunHomeDirectory(), cleanupToSkip);
        } else {
            logger.info("Skipping cleanup, it is disabled.");
        }
    } catch (final Exception e) {
        logger.debug(String.format("Error trying cleanup: %s", e.getMessage()));
    }
    Set<DetectorType> detectorTypes = new HashSet<>();
    if (runResultOptional.isPresent()) {
        detectorTypes.addAll(runResultOptional.get().getApplicableDetectors());
    }
    // Check required detector types
    String requiredDetectors = detectConfiguration.getProperty(DetectProperty.DETECT_REQUIRED_DETECTOR_TYPES, PropertyAuthority.None);
    RequiredDetectorChecker requiredDetectorChecker = new RequiredDetectorChecker();
    RequiredDetectorChecker.RequiredDetectorResult requiredDetectorResult = requiredDetectorChecker.checkForMissingDetectors(requiredDetectors, detectorTypes);
    if (requiredDetectorResult.wereDetectorsMissing()) {
        String missingDetectors = requiredDetectorResult.getMissingDetectors().stream().map(it -> it.toString()).collect(Collectors.joining(","));
        logger.error("One or more required detector types were not found: " + missingDetectors);
        exitCodeManager.requestExitCode(ExitCodeType.FAILURE_DETECTOR_REQUIRED);
    }
}
Also used : DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) ConnectivityManager(com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager) File(java.io.File) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiagnosticManager(com.blackducksoftware.integration.hub.detect.workflow.diagnostic.DiagnosticManager) List(java.util.List) ExitCodeType(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType) PropertyAuthority(com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) Optional(java.util.Optional) RunResult(com.blackducksoftware.integration.hub.detect.lifecycle.run.RunResult) DetectStatusManager(com.blackducksoftware.integration.hub.detect.workflow.status.DetectStatusManager) RequiredDetectorChecker(com.blackducksoftware.integration.hub.detect.workflow.detector.RequiredDetectorChecker) ReportManager(com.blackducksoftware.integration.hub.detect.workflow.report.ReportManager) DetectProperty(com.blackducksoftware.integration.hub.detect.configuration.DetectProperty) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) ArrayList(java.util.ArrayList) RequiredDetectorChecker(com.blackducksoftware.integration.hub.detect.workflow.detector.RequiredDetectorChecker) File(java.io.File) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with DetectorType

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

the class ExtractionManager method performExtractions.

public ExtractionResult performExtractions(final List<DetectorEvaluation> results) {
    final List<DetectorEvaluation> extractable = results.stream().filter(result -> result.isExtractable()).collect(Collectors.toList());
    for (int i = 0; i < extractable.size(); i++) {
        final DetectorEvaluation detectorEvaluation = extractable.get(i);
        final String progress = Integer.toString((int) Math.floor((i * 100.0f) / extractable.size()));
        logger.info(String.format("Extracting %d of %d (%s%%)", i + 1, extractable.size(), progress));
        logger.info(ReportConstants.SEPERATOR);
        final ExtractionId extractionId = new ExtractionId(detectorEvaluation.getDetector().getDetectorType(), Integer.toString(i));
        detectorEvaluation.setExtractionId(extractionId);
        extract(extractable.get(i));
    }
    final Set<DetectorType> succesfulBomToolGroups = extractable.stream().filter(it -> it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final Set<DetectorType> failedBomToolGroups = extractable.stream().filter(it -> !it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final List<DetectCodeLocation> codeLocations = extractable.stream().filter(it -> it.wasExtractionSuccessful()).flatMap(it -> it.getExtraction().codeLocations.stream()).collect(Collectors.toList());
    return new ExtractionResult(codeLocations, succesfulBomToolGroups, failedBomToolGroups);
}
Also used : DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) ExtractionResultType(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction.ExtractionResultType) Logger(org.slf4j.Logger) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) InfoLogReportWriter(com.blackducksoftware.integration.hub.detect.workflow.report.writer.InfoLogReportWriter) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ReportConstants(com.blackducksoftware.integration.hub.detect.workflow.report.util.ReportConstants) ObjectPrinter(com.blackducksoftware.integration.hub.detect.workflow.report.util.ObjectPrinter) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId)

Example 3 with DetectorType

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

the class DetectorEvaluationNameVersionDecider method decideSuggestion.

public Optional<NameVersion> decideSuggestion(final List<DetectorEvaluation> detectorEvaluations, String projectDetector) {
    DetectorType preferredDetectorType = null;
    if (StringUtils.isNotBlank(projectDetector)) {
        final String projectDetectorFixed = projectDetector.toUpperCase();
        if (!DetectorType.POSSIBLE_NAMES.contains(projectDetectorFixed)) {
            logger.info("A valid preferred detector type was not provided, deciding project name automatically.");
        } else {
            preferredDetectorType = DetectorType.valueOf(projectDetectorFixed);
        }
    }
    final List<DetectorProjectInfo> detectorProjectInfo = transformIntoProjectInfo(detectorEvaluations);
    return detectorNameVersionDecider.decideProjectNameVersion(detectorProjectInfo, preferredDetectorType);
}
Also used : DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType)

Example 4 with DetectorType

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

the class DetectorNameVersionDecider method decideProjectNameVersionFromDetector.

private NameVersionDecision decideProjectNameVersionFromDetector(final List<DetectorProjectInfo> projectNamePossibilities, final DetectorType preferredBomToolType) {
    final NameVersionDecision decision;
    if (preferredBomToolType != null) {
        final List<DetectorProjectInfo> possiblePreferred = projectNamePossibilities.stream().filter(it -> it.getDetectorType() == preferredBomToolType).collect(Collectors.toList());
        final List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(possiblePreferred);
        if (lowestDepthPossibilities.size() == 0) {
            decision = new PreferredDetectorNotFoundDecision(preferredBomToolType);
        } else if (lowestDepthPossibilities.size() == 1) {
            decision = new PreferredDetectorDecision(lowestDepthPossibilities.get(0));
        } else {
            decision = new TooManyPreferredDetectorTypesFoundDecision(preferredBomToolType);
        }
    } else {
        final List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(projectNamePossibilities);
        final Map<DetectorType, Long> lowestDepthTypeCounts = lowestDepthPossibilities.stream().collect(Collectors.groupingBy(it -> it.getDetectorType(), Collectors.counting()));
        final List<DetectorType> singleInstanceLowestDepthBomTools = lowestDepthTypeCounts.entrySet().stream().filter(it -> it.getValue() == 1).map(it -> it.getKey()).collect(Collectors.toList());
        if (singleInstanceLowestDepthBomTools.size() == 1) {
            final DetectorType type = singleInstanceLowestDepthBomTools.get(0);
            final Optional<DetectorProjectInfo> chosen = lowestDepthPossibilities.stream().filter(it -> it.getDetectorType() == type).findFirst();
            if (chosen.isPresent()) {
                decision = new UniqueDetectorDecision(chosen.get());
            } else {
                decision = new UniqueDetectorNotFoundDecision();
            }
        } else if (singleInstanceLowestDepthBomTools.size() > 1) {
            decision = decideProjectNameVersionArbitrarily(lowestDepthPossibilities, singleInstanceLowestDepthBomTools);
        } else {
            decision = new UniqueDetectorNotFoundDecision();
        }
    }
    return decision;
}
Also used : UniqueDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorNotFoundDecision) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) NameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.NameVersionDecision) LoggerFactory(org.slf4j.LoggerFactory) ArbitraryNameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.ArbitraryNameVersionDecision) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) UniqueDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorDecision) PreferredDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorDecision) PreferredDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorNotFoundDecision) Map(java.util.Map) Optional(java.util.Optional) Comparator(java.util.Comparator) TooManyPreferredDetectorTypesFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.TooManyPreferredDetectorTypesFoundDecision) NameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.NameVersionDecision) ArbitraryNameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.ArbitraryNameVersionDecision) PreferredDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorDecision) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) UniqueDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorDecision) TooManyPreferredDetectorTypesFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.TooManyPreferredDetectorTypesFoundDecision) PreferredDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorNotFoundDecision) UniqueDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorNotFoundDecision)

Example 5 with DetectorType

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

the class PreparationManager method prepareExtractions.

public PreparationResult prepareExtractions(final List<DetectorEvaluation> results) {
    for (final DetectorEvaluation result : results) {
        prepare(result);
    }
    final Set<DetectorType> succesfulBomToolGroups = results.stream().filter(it -> it.isApplicable()).filter(it -> it.isExtractable()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final Set<DetectorType> failedBomToolGroups = results.stream().filter(it -> it.isApplicable()).filter(it -> !it.isExtractable()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    return new PreparationResult(succesfulBomToolGroups, failedBomToolGroups, results);
}
Also used : List(java.util.List) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Event(com.blackducksoftware.integration.hub.detect.workflow.event.Event) Logger(org.slf4j.Logger) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) EventSystem(com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem) ExceptionDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.ExceptionDetectorResult) Collectors(java.util.stream.Collectors) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)

Aggregations

DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)10 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 DetectorEvaluation (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)5 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 HashSet (java.util.HashSet)3 Detector (com.blackducksoftware.integration.hub.detect.detector.Detector)2 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)2 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)2 Event (com.blackducksoftware.integration.hub.detect.workflow.event.Event)2 EventSystem (com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem)2 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)1 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)1 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)1 DetectorException (com.blackducksoftware.integration.hub.detect.detector.DetectorException)1 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1