use of com.synopsys.integration.detect.workflow.DetectRunId in project synopsys-detect by blackducksoftware.
the class Application method run.
@Override
public void run(ApplicationArguments applicationArguments) {
long startTime = System.currentTimeMillis();
// Events, Status and Exit Codes are required even if boot fails.
EventSystem eventSystem = new EventSystem();
DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
ExceptionUtility exceptionUtility = new ExceptionUtility();
ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exceptionUtility);
ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
ReportListener.createDefault(eventSystem);
FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
InstalledToolManager installedToolManager = new InstalledToolManager();
// Before boot even begins, we create a new Spring context for Detect to work within.
logger.debug("Initializing detect.");
DetectRunId detectRunId = DetectRunId.createDefault();
Gson gson = BlackDuckServicesFactory.createDefaultGsonBuilder().setPrettyPrinting().create();
DetectInfo detectInfo = DetectInfoUtility.createDefaultDetectInfo();
FileFinder fileFinder = new SimpleFileFinder();
boolean shouldForceSuccess = false;
Optional<DetectBootResult> detectBootResultOptional = bootApplication(detectRunId, applicationArguments.getSourceArgs(), eventSystem, exitCodeManager, gson, detectInfo, fileFinder, installedToolManager, exceptionUtility);
if (detectBootResultOptional.isPresent()) {
DetectBootResult detectBootResult = detectBootResultOptional.get();
shouldForceSuccess = detectBootResult.shouldForceSuccess();
runApplication(eventSystem, exitCodeManager, detectBootResult, exceptionUtility);
detectBootResult.getProductRunData().filter(ProductRunData::shouldUseBlackDuckProduct).map(ProductRunData::getBlackDuckRunData).flatMap(BlackDuckRunData::getPhoneHomeManager).ifPresent(PhoneHomeManager::phoneHomeOperations);
// Create status output file.
logger.info("");
detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createStatusOutputFile(formattedOutputManager, detectInfo, directoryManager));
// Create installed tool data file.
detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createOrUpdateInstalledToolsFile(installedToolManager, directoryManager.getPermanentDirectory()));
shutdownApplication(detectBootResult, exitCodeManager);
} else {
logger.info("Will not create status file, detect did not boot.");
}
logger.debug("All Detect actions completed.");
exitApplication(exitManager, startTime, shouldForceSuccess);
}
use of com.synopsys.integration.detect.workflow.DetectRunId in project synopsys-detect by blackducksoftware.
the class RapidModeGenerateJsonOperationTest method test.
@Test
void test(@TempDir Path tempPath) throws IOException, DetectUserFriendlyException {
Gson gson = Mockito.mock(Gson.class);
File tempDir = tempPath.toFile();
File scanDir = new File(tempDir, "scan");
DirectoryOptions directoryOptions = new DirectoryOptions(null, null, null, scanDir.toPath(), null, null);
DetectRunId detectRunId = new DetectRunId("testId");
DirectoryManager directoryManager = new DirectoryManager(directoryOptions, detectRunId);
RapidModeGenerateJsonOperation op = new RapidModeGenerateJsonOperation(gson, directoryManager);
NameVersion projectNameVersion = new NameVersion("testName", "testVersion");
List<DeveloperScanComponentResultView> results = new LinkedList<>();
DeveloperScanComponentResultView resultView = Mockito.mock(DeveloperScanComponentResultView.class);
results.add(resultView);
String mockedResultsJsonString = "mocked json string for results";
Mockito.when(gson.toJson(results)).thenReturn(mockedResultsJsonString);
File generatedFile = op.generateJsonFile(projectNameVersion, results);
String expectedFilename = String.format("%s_%s_BlackDuck_DeveloperMode_Result.json", projectNameVersion.getName(), projectNameVersion.getVersion());
String expectedPath = new File(scanDir, expectedFilename).getAbsolutePath();
assertEquals(expectedPath, generatedFile.getAbsolutePath());
String generatedString = FileUtils.readFileToString(generatedFile);
assertEquals(mockedResultsJsonString, generatedString);
}
Aggregations