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.");
}
}
Aggregations