Search in sources :

Example 6 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class YarnListParserTest method testThatYarnListLineAtBeginningIsIgnored.

@Test
public void testThatYarnListLineAtBeginningIsIgnored() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("abab@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("yarn list v1.5.1");
    testLines.add("├─ abab@1.0.4");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    assertNotNull(tempList.get(0));
    assertEquals(1, tempList.size());
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 7 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class YarnListParserTest method testThatYarnListWithGrandchildIsParsedCorrectly.

@Test
public void testThatYarnListWithGrandchildIsParsedCorrectly() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("yargs-parser@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    designedYarnLock.add("camelcase@^3.0.0:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("├─ yargs-parser@4.2.1");
    testLines.add("│  └─ camelcase@^3.0.0");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    List<ExternalId> kidsList = new ArrayList<>();
    for (int i = 0; i < tempList.size(); i++) {
        if ("yargs-parser".equals(tempList.get(i).name)) {
            kidsList = new ArrayList<>(dependencyGraph.getChildrenExternalIdsForParent(tempList.get(i)));
        }
    }
    assertListContainsDependency("yargs-parser", "4.2.1", tempList);
    assertListContainsDependency("camelcase", "5.5.2", kidsList);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 8 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class YarnListParserTest method testDependencyInYarnListAndNotInLock.

@Test
public void testDependencyInYarnListAndNotInLock() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("ajv@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("yarn list v1.5.1");
    testLines.add("├─ abab@1.0.4");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    assertEquals(1, tempList.size());
    assertListContainsDependency("abab", "1.0.4", tempList);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 9 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory in project hub-detect by blackducksoftware.

the class CodeLocationNameGeneratorTest method testBomCodeLocationName.

@Test
public void testBomCodeLocationName() {
    final String expected = "hub-common-rest/child/group/name/version npm/bom";
    // = path/externalId tool/type
    final ExternalIdFactory factory = new ExternalIdFactory();
    final ExternalId externalId = factory.createMavenExternalId("group", "name", "version");
    final DetectFileFinder detectFileFinder = new DetectFileFinder();
    final CodeLocationNameGenerator codeLocationNameGenerator = new CodeLocationNameGenerator(detectFileFinder);
    final String sourcePath = "/Users/ekerwin/Documents/source/integration/hub-common-rest";
    final String codeLocationPath = "/Users/ekerwin/Documents/source/integration/hub-common-rest/child";
    final String prefix = "";
    final String suffix = "";
    final String actual = codeLocationNameGenerator.createBomCodeLocationName(sourcePath, codeLocationPath, externalId, DetectCodeLocationType.NPM, prefix, suffix);
    assertEquals(expected, actual);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Test(org.junit.Test)

Example 10 with ExternalIdFactory

use of com.synopsys.integration.bdio.model.externalid.ExternalIdFactory 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)

Aggregations

ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)46 Test (org.junit.Test)33 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)17 File (java.io.File)13 ArrayList (java.util.ArrayList)12 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)10 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)8 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)5 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)4 TestUtil (com.blackducksoftware.integration.hub.detect.testutils.TestUtil)4 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)4 DependencyGraphResourceTestUtil (com.blackducksoftware.integration.hub.detect.testutils.DependencyGraphResourceTestUtil)3 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3