Search in sources :

Example 1 with LoggedDetectExtraction

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());
}
Also used : DetectExtractionParser(com.synopsys.detect.doctor.logparser.DetectExtractionParser) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) Test(org.junit.Test)

Example 2 with LoggedDetectExtraction

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.");
    }
}
Also used : DetectRunInfo(com.synopsys.detect.doctor.diagnosticparser.DetectRunInfo) HashMap(java.util.HashMap) SpringPropertySource(com.blackducksoftware.integration.hub.detect.property.SpringPropertySource) DoctorDirectoryManager(com.synopsys.detect.doctor.run.DoctorDirectoryManager) DoctorRun(com.synopsys.detect.doctor.run.DoctorRun) DetectLogParseResult(com.synopsys.detect.doctor.logparser.DetectLogParseResult) DetectPropertyMap(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap) DetectPropertySource(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertySource) DetectLogParser(com.synopsys.detect.doctor.logparser.DetectLogParser) DoctorArgumentState(com.synopsys.detect.doctor.configuration.DoctorArgumentState) HashSet(java.util.HashSet) ExtractionHandler(com.synopsys.detect.doctor.extraction.ExtractionHandler) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) DoctorConfiguration(com.synopsys.detect.doctor.configuration.DoctorConfiguration) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) DoctorProperty(com.synopsys.detect.doctor.configuration.DoctorProperty) PropertyMap(com.blackducksoftware.integration.hub.detect.property.PropertyMap) DetectPropertyMap(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap) DiagnosticParser(com.synopsys.detect.doctor.diagnosticparser.DiagnosticParser) File(java.io.File) DoctorArgumentStateParser(com.synopsys.detect.doctor.configuration.DoctorArgumentStateParser)

Example 3 with LoggedDetectExtraction

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);
    }
}
Also used : NugetInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Gson(com.google.gson.Gson) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) NugetInspectorPackager(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager) NugetInspector(com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File)

Example 4 with LoggedDetectExtraction

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);
}
Also used : GradleInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) GradleReportParser(com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParser) ExternalIdFactory(com.synopsys.integration.hub.bdio.model.externalid.ExternalIdFactory) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) File(java.io.File) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)

Aggregations

LoggedDetectExtraction (com.synopsys.detect.doctor.logparser.LoggedDetectExtraction)4 File (java.io.File)3 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)2 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)2 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)2 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)1 DetectPropertyMap (com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap)1 DetectPropertySource (com.blackducksoftware.integration.hub.detect.configuration.DetectPropertySource)1 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)1 GradleInspectorExtractor (com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor)1 GradleReportParser (com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParser)1 NugetInspectorExtractor (com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor)1 NugetInspectorPackager (com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager)1 NugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector)1 PropertyMap (com.blackducksoftware.integration.hub.detect.property.PropertyMap)1 SpringPropertySource (com.blackducksoftware.integration.hub.detect.property.SpringPropertySource)1 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)1 Gson (com.google.gson.Gson)1 DoctorArgumentState (com.synopsys.detect.doctor.configuration.DoctorArgumentState)1 DoctorArgumentStateParser (com.synopsys.detect.doctor.configuration.DoctorArgumentStateParser)1