use of com.synopsys.detect.doctor.logparser.LoggedDetectExtraction in project hub-detect by blackducksoftware.
the class ExtractionParserTest method testHeaderParsing.
@Test
public void testHeaderParsing() {
List<String> lines = Arrays.asList("2018-08-21 10:51:48 INFO [main] --- Starting extraction: GRADLE - Gradle Inspector", "2018-08-21 10:51:48 INFO [main] --- Identifier: 1", "2018-08-21 10:51:48 INFO [main] --- gradleExe : D:\\BlackDuck\\ScanTarget\\Pilot_AVMSmartPhoneApplication\\gradlew.bat");
DetectExtractionParser parser = new DetectExtractionParser();
LoggedDetectExtraction extraction = new LoggedDetectExtraction();
for (String line : lines) {
parser.parseExtractionHeader(extraction, line);
}
Assert.assertEquals("GRADLE - Gradle Inspector", extraction.bomToolDescription);
Assert.assertEquals("Gradle Inspector", extraction.bomToolName);
Assert.assertEquals("GRADLE", extraction.bomToolGroup);
Assert.assertEquals("1", extraction.extractionIdentifier);
Assert.assertEquals(1, extraction.parameters.size());
Assert.assertEquals("D:\\BlackDuck\\ScanTarget\\Pilot_AVMSmartPhoneApplication\\gradlew.bat", extraction.parameters.get("gradleExe"));
Assert.assertEquals(3, extraction.rawHeader.size());
}
use of com.synopsys.detect.doctor.logparser.LoggedDetectExtraction 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.");
}
}
use of com.synopsys.detect.doctor.logparser.LoggedDetectExtraction in project hub-detect by blackducksoftware.
the class NugetSolutionExtractionDebugger method debug.
public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) {
String id = extraction.extractionIdentifier;
try {
NugetInspectorPackager packager = new NugetInspectorPackager(new Gson(), new ExternalIdFactory());
DetectFileFinder detectFileFinder = new DetectFileFinder();
File extractionFolder = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
List<File> extractionFiles = Arrays.asList(extractionFolder.listFiles());
DetectFileFinder mock = Mockito.mock(DetectFileFinder.class);
Mockito.when(mock.findFiles(Mockito.any(), Mockito.any())).thenReturn(extractionFiles);
NugetInspectorExtractor nugetInspectorExtractor = new NugetInspectorExtractor(packager, mock, detectConfiguration);
NugetInspector inspector = Mockito.mock(NugetInspector.class);
Mockito.when(inspector.execute(Mockito.any(), Mockito.any())).thenReturn(new ExecutableOutput("", ""));
File mockTarget = Mockito.mock(File.class);
Mockito.when(mockTarget.toString()).thenReturn("mock/target");
File mockOutput = Mockito.mock(File.class);
Mockito.when(mockOutput.getCanonicalPath()).thenReturn("mock/output");
Mockito.when(mockOutput.toString()).thenReturn("mock/output");
Extraction newExtraction = nugetInspectorExtractor.extract(mockTarget, mockOutput, inspector, new ExtractionId(DetectorType.NUGET, id));
logger.info("We did it: " + newExtraction.result.toString());
} catch (Exception e) {
logger.info("We did not do it: " + e.toString());
throw new RuntimeException(e);
}
}
use of com.synopsys.detect.doctor.logparser.LoggedDetectExtraction in project hub-detect by blackducksoftware.
the class GradleExtractionDebugger method debug.
public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) throws ExecutableRunnerException {
String id = extraction.extractionIdentifier;
ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
Mockito.when(executableRunner.execute(Mockito.any())).thenReturn(new ExecutableOutput("", ""));
DetectFileFinder detectFileFinder = new DetectFileFinder();
File mockSourceFile = Mockito.mock(File.class);
File outputDirectory = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
GradleInspectorExtractor gradleInspectorExtractor = new GradleInspectorExtractor(executableRunner, detectFileFinder, new GradleReportParser(new ExternalIdFactory()), detectConfiguration);
Extraction extractionResult = gradleInspectorExtractor.extract(mockSourceFile, "", "", outputDirectory);
}
Aggregations