Search in sources :

Example 1 with Status

use of com.blackducksoftware.integration.hub.detect.workflow.status.Status in project hub-detect by blackducksoftware.

the class PolarisTool method runPolaris.

public void runPolaris(final IntLogger logger, File projectDirectory) throws DetectUserFriendlyException {
    logger.info("Checking if Polaris can run.");
    PolarisEnvironmentCheck polarisEnvironmentCheck = new PolarisEnvironmentCheck();
    if (!polarisEnvironmentCheck.canRun(directoryManager.getUserHome())) {
        logger.info("Polaris determined it should not run.");
        logger.debug("Checked the following user directory: " + directoryManager.getUserHome().getAbsolutePath());
        return;
    }
    logger.info("Polaris determined it should attempt to run.");
    IntHttpClient restConnection = connectionManager.createUnauthenticatedRestConnection(PolarisDownloadUtility.DEFAULT_POLARIS_SERVER_URL);
    CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
    File toolsDirectory = directoryManager.getPermanentDirectory();
    PolarisDownloadUtility polarisDownloadUtility = new PolarisDownloadUtility(logger, restConnection, cleanupZipExpander, PolarisDownloadUtility.DEFAULT_POLARIS_SERVER_URL, toolsDirectory);
    Optional<String> swipCliPath = polarisDownloadUtility.retrievePolarisCliExecutablePath();
    if (swipCliPath.isPresent()) {
        Map<String, String> environmentVariables = new HashMap<>();
        environmentVariables.put("COVERITY_UNSUPPORTED", "1");
        environmentVariables.put("SWIP_USER_INPUT_TIMEOUT_MINUTES", "1");
        logger.info("Found polaris cli: " + swipCliPath.get());
        List<String> arguments = new ArrayList<>();
        arguments.add("analyze");
        arguments.add("-w");
        Executable swipExecutable = new Executable(projectDirectory, environmentVariables, swipCliPath.get(), arguments);
        try {
            ExecutableOutput output = executableRunner.execute(swipExecutable);
            if (output.getReturnCode() == 0) {
                eventSystem.publishEvent(Event.StatusSummary, new Status("POLARIS", StatusType.SUCCESS));
            } else {
                logger.error("Polaris returned a non-zero exit code.");
                eventSystem.publishEvent(Event.StatusSummary, new Status("POLARIS", StatusType.FAILURE));
            }
        } catch (ExecutableRunnerException e) {
            eventSystem.publishEvent(Event.StatusSummary, new Status("POLARIS", StatusType.FAILURE));
            logger.error("Couldn't run the executable: " + e.getMessage());
        }
    } else {
        logger.error("Check the logs - the Polaris CLI could not be found.");
    }
}
Also used : Status(com.blackducksoftware.integration.hub.detect.workflow.status.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException) CleanupZipExpander(com.synopsys.integration.util.CleanupZipExpander) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) PolarisDownloadUtility(com.synopsys.integration.polaris.common.PolarisDownloadUtility) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Example 2 with Status

use of com.blackducksoftware.integration.hub.detect.workflow.status.Status in project hub-detect by blackducksoftware.

the class BlackDuckBinaryScannerTool method uploadBinaryScanFile.

public Set<String> uploadBinaryScanFile(final BinaryScannerService binaryService, final File file, final String projectName, final String projectVersionName, final String prefix, final String suffix) throws DetectUserFriendlyException {
    final String codeLocationName = codeLocationNameManager.createBinaryScanCodeLocationName(file.getName(), projectName, projectVersionName, prefix, suffix);
    try {
        logger.info("Preparing to upload binary scan file: " + codeLocationName);
        binaryService.scanBinary(file, projectName, projectVersionName, codeLocationName);
        logger.info("Successfully uploaded binary scan file: " + codeLocationName);
        eventSystem.publishEvent(Event.StatusSummary, new Status("BINARY_SCAN", StatusType.SUCCESS));
        Set<String> names = new HashSet<String>();
        names.add(codeLocationName);
        return names;
    } catch (IOException | IntegrationException | URISyntaxException e) {
        logger.error("Failed to upload binary scan file: " + e.getMessage());
        eventSystem.publishEvent(Event.StatusSummary, new Status("BINARY_SCAN", StatusType.FAILURE));
        throw new DetectUserFriendlyException("Failed to upload binary scan file.", e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
    }
}
Also used : Status(com.blackducksoftware.integration.hub.detect.workflow.status.Status) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) HashSet(java.util.HashSet)

Example 3 with Status

use of com.blackducksoftware.integration.hub.detect.workflow.status.Status in project hub-detect by blackducksoftware.

the class ToolRunner method publishExtractionResults.

private void publishExtractionResults(final EventSystem eventSystem, final RunResult runResult, final Extraction extractionResult) {
    runResult.addToolNameVersionIfPresent(toolDetector.getToolEnum(), Optional.of(new NameVersion(extractionResult.projectName, extractionResult.projectVersion)));
    Optional<Object> dockerTar = extractionResult.getMetaDataValue(DockerExtractor.DOCKER_TAR_META_DATA_KEY);
    if (dockerTar.isPresent()) {
        runResult.addDockerFile(Optional.of((File) dockerTar.get()));
    }
    runResult.addDetectCodeLocations(extractionResult.codeLocations);
    if (extractionResult.result == Extraction.ExtractionResultType.SUCCESS) {
        eventSystem.publishEvent(Event.StatusSummary, new Status(toolDetector.getToolEnum().toString(), StatusType.SUCCESS));
    } else {
        eventSystem.publishEvent(Event.StatusSummary, new Status(toolDetector.getToolEnum().toString(), StatusType.FAILURE));
        eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extractionResult.description));
    }
}
Also used : Status(com.blackducksoftware.integration.hub.detect.workflow.status.Status) NameVersion(com.synopsys.integration.util.NameVersion) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest) File(java.io.File)

Example 4 with Status

use of com.blackducksoftware.integration.hub.detect.workflow.status.Status in project hub-detect by blackducksoftware.

the class ToolRunner method publishNotExtractableResults.

private void publishNotExtractableResults(final EventSystem eventSystem, final DetectorResult extractableResult, final String toolName) {
    logger.error(String.format("%s was not extractable: %s", toolName, extractableResult.toDescription()));
    eventSystem.publishEvent(Event.StatusSummary, new Status(DetectTool.BAZEL.toString(), StatusType.FAILURE));
    eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extractableResult.toDescription()));
}
Also used : Status(com.blackducksoftware.integration.hub.detect.workflow.status.Status) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest)

Aggregations

Status (com.blackducksoftware.integration.hub.detect.workflow.status.Status)4 ExitCodeRequest (com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest)2 File (java.io.File)2 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)1 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)1 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 PolarisDownloadUtility (com.synopsys.integration.polaris.common.PolarisDownloadUtility)1 IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)1 CleanupZipExpander (com.synopsys.integration.util.CleanupZipExpander)1 NameVersion (com.synopsys.integration.util.NameVersion)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1