Search in sources :

Example 1 with CodeLocationName

use of com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName in project hub-detect by blackducksoftware.

the class HubSignatureScanner method createScanConfigBuilder.

private HubScanConfigBuilder createScanConfigBuilder(final DetectProject detectProject, final String canonicalPath) {
    final File scannerDirectory = new File(detectConfiguration.getScanOutputDirectoryPath());
    final File toolsDirectory = detectFileManager.createDirectory("tools", false);
    final HubScanConfigBuilder hubScanConfigBuilder = new HubScanConfigBuilder();
    hubScanConfigBuilder.setScanMemory(detectConfiguration.getHubSignatureScannerMemory());
    hubScanConfigBuilder.setToolsDir(toolsDirectory);
    hubScanConfigBuilder.setWorkingDirectory(scannerDirectory);
    hubScanConfigBuilder.addScanTargetPath(canonicalPath);
    hubScanConfigBuilder.setCleanupLogsOnSuccess(detectConfiguration.getCleanupBomToolFiles());
    hubScanConfigBuilder.setDryRun(detectConfiguration.getHubSignatureScannerDryRun());
    hubScanConfigBuilder.setSnippetModeEnabled(detectConfiguration.getHubSignatureScannerSnippetMode());
    final String projectName = detectProject.getProjectName();
    final String projectVersionName = detectProject.getProjectVersionName();
    final String sourcePath = detectConfiguration.getSourcePath();
    final String prefix = detectConfiguration.getProjectCodeLocationPrefix();
    final String suffix = detectConfiguration.getProjectCodeLocationSuffix();
    final CodeLocationName codeLocationName = codeLocationNameService.createScanName(sourcePath, canonicalPath, projectName, projectVersionName, prefix, suffix);
    final String codeLocationNameString = codeLocationNameService.generateScanCurrent(codeLocationName);
    hubScanConfigBuilder.setCodeLocationAlias(codeLocationNameString);
    if (null != detectConfiguration.getHubSignatureScannerExclusionPatterns() && detectConfiguration.getHubSignatureScannerExclusionPatterns().length > 0) {
        hubScanConfigBuilder.setExcludePatterns(detectConfiguration.getHubSignatureScannerExclusionPatterns());
    } else if (null != registeredPathsToExclude && !registeredPathsToExclude.isEmpty()) {
        hubScanConfigBuilder.setExcludePatterns(registeredPathsToExclude.toArray(new String[registeredPathsToExclude.size()]));
    }
    return hubScanConfigBuilder;
}
Also used : HubScanConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder) File(java.io.File) CodeLocationName(com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName)

Example 2 with CodeLocationName

use of com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName in project hub-detect by blackducksoftware.

the class DetectProject method processDetectCodeLocations.

public void processDetectCodeLocations(final Logger logger, final DetectFileManager detectFileManager, final BdioFileNamer bdioFileNamer, final CodeLocationNameService codeLocationNameService) {
    final List<DetectCodeLocation> detectCodeLocations = getDetectCodeLocations();
    final Map<String, DetectCodeLocation> codeLocationNameMap = new HashMap<>(detectCodeLocations.size());
    for (final DetectCodeLocation detectCodeLocation : getDetectCodeLocations()) {
        if (detectCodeLocation.getDependencyGraph() == null) {
            logger.warn(String.format("Dependency graph is null for code location %s", detectCodeLocation.getSourcePath()));
            continue;
        }
        if (detectCodeLocation.getDependencyGraph().getRootDependencies().size() <= 0) {
            logger.warn(String.format("Could not find any dependencies for code location %s", detectCodeLocation.getSourcePath()));
        }
        final CodeLocationName codeLocationName = detectCodeLocation.createCodeLocationName(codeLocationNameService, projectName, projectVersionName, getCodeLocationNamePrefix(), getCodeLocationNameSuffix());
        final String codeLocationNameString = detectCodeLocation.getCodeLocationNameString(codeLocationNameService, codeLocationName);
        if (codeLocationNameMap.containsKey(codeLocationNameString)) {
            failedBomTools.add(detectCodeLocation.getBomToolType());
            logger.error(String.format("Found duplicate Code Locations with the name: %s", codeLocationNameString));
        } else {
            codeLocationNameMap.put(codeLocationNameString, detectCodeLocation);
        }
    }
    final Set<String> bdioFileNames = new HashSet<>();
    for (final Map.Entry<String, DetectCodeLocation> codeLocationEntry : codeLocationNameMap.entrySet()) {
        final String codeLocationNameString = codeLocationEntry.getKey();
        final DetectCodeLocation detectCodeLocation = codeLocationEntry.getValue();
        final String finalSourcePathPiece = detectFileManager.extractFinalPieceFromPath(detectCodeLocation.getSourcePath());
        final String filename = bdioFileNamer.generateShortenedFilename(detectCodeLocation.getBomToolType(), finalSourcePathPiece, detectCodeLocation.getBomToolProjectExternalId());
        if (!bdioFileNames.add(filename)) {
            failedBomTools.add(detectCodeLocation.getBomToolType());
            logger.error(String.format("Found duplicate Bdio files with the name: %s", filename));
        } else {
            codeLocationNameToBdioName.put(codeLocationNameString, filename);
        }
    }
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) CodeLocationName(com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName) HashSet(java.util.HashSet)

Aggregations

CodeLocationName (com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName)2 HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1