Search in sources :

Example 1 with PolarisDownloadUtility

use of com.synopsys.integration.polaris.common.PolarisDownloadUtility 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)

Aggregations

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 Status (com.blackducksoftware.integration.hub.detect.workflow.status.Status)1 PolarisDownloadUtility (com.synopsys.integration.polaris.common.PolarisDownloadUtility)1 IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)1 CleanupZipExpander (com.synopsys.integration.util.CleanupZipExpander)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1