use of com.synopsys.detect.doctor.diagnosticparser.DiagnosticParser in project hub-detect by blackducksoftware.
the class DoctorApplication method run.
@Override
public void run(final ApplicationArguments applicationArguments) throws Exception {
PropertyMap<DoctorProperty> doctorPropertyPropertyMap = new PropertyMap<>();
SpringPropertySource springPropertySource = new SpringPropertySource(configurableEnvironment);
DoctorConfiguration doctorConfiguration = new DoctorConfiguration(springPropertySource, doctorPropertyPropertyMap);
DoctorArgumentStateParser argumentStateParser = new DoctorArgumentStateParser();
DoctorArgumentState state = argumentStateParser.parseArgs(applicationArguments.getSourceArgs());
doctorConfiguration.init();
DoctorRun doctorRun = DoctorRun.createDefault();
logger.info("Doctor begin: " + doctorRun.getRunId());
DoctorDirectoryManager doctorDirectoryManager = new DoctorDirectoryManager(doctorRun);
logger.info("Doctor ready.");
Optional<DetectRunInfo> detectRunInfo = Optional.empty();
File diagnosticZip = new File(doctorConfiguration.getProperty(DoctorProperty.DETECT_DIAGNOSTIC_FILE));
if (diagnosticZip.exists()) {
logger.info("A diagnostic zip was found: " + diagnosticZip.getAbsolutePath());
DiagnosticParser diagnosticParser = new DiagnosticParser();
detectRunInfo = Optional.of(diagnosticParser.processDiagnosticZip(doctorDirectoryManager, diagnosticZip));
} else {
logger.info("No diagnostic zip provided, looking for the pieces.");
File log = new File(doctorConfiguration.getProperty(DoctorProperty.DETECT_LOG_FILE));
logger.info("Looking for log file at: " + log.getAbsolutePath());
if (log.exists()) {
logger.info("Found log file.");
// detectRunInfo = Optional.of(new DetectRunInfo(log));
} else {
logger.info("No log file found.");
}
}
if (detectRunInfo.isPresent()) {
DetectLogParser logParser = new DetectLogParser();
logger.info("Doctor can proceed, necessary pieces located.");
File log = detectRunInfo.get().getLogFile();
DetectLogParseResult result = logParser.parse(log);
logger.info("Detect log parsed.");
String extractionId = doctorConfiguration.getProperty(DoctorProperty.DETECT_EXTRACTION_ID);
Set<String> extractions = new HashSet<>();
LoggedDetectExtraction extraction = null;
for (LoggedDetectExtraction possibleExtraction : result.loggedConfiguration.extractions) {
extractions.add(possibleExtraction.extractionIdentifier);
if (possibleExtraction.extractionIdentifier.equals(extractionId)) {
extraction = possibleExtraction;
}
}
if (StringUtils.isBlank(extractionId)) {
quit("Doctor needs an extraction to work with, options are: " + extractions.stream().collect(Collectors.joining(",")));
}
if (extraction == null) {
quit("No extraction found for given id: " + extractionId);
}
logger.info("Found extraction with id: " + extractionId);
logger.info("Doctor will attempt to diagnose!");
logger.info("We begin by rebuilding the configuration.");
Map<String, String> propertyMap = new HashMap<>();
result.loggedConfiguration.loggedPropertyList.stream().forEach(it -> propertyMap.put(it.key, it.value));
RehydratedPropertySource rehydratedPropertySource = new RehydratedPropertySource(propertyMap);
DetectConfiguration detectConfiguration = new DetectConfiguration(new DetectPropertySource(rehydratedPropertySource), new DetectPropertyMap());
ExtractionHandler extractionHandler = new ExtractionHandler();
extractionHandler.processExtraction(extraction, detectRunInfo.get(), detectConfiguration);
} else {
quit("Neccessary pieces not found for doctor to proceed.");
}
}
Aggregations