Search in sources :

Example 41 with ExternalIdFactory

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

the class YarnListParserTest method testThatYarnListWithGreatGrandchildrenIsParsedCorrectly.

@Test
public void testThatYarnListWithGreatGrandchildrenIsParsedCorrectly() {
    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("");
    designedYarnLock.add("ms@5.5.2:");
    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");
    testLines.add("│  │  └─ ms@0.7.2");
    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> rootDependencies = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    assertListContainsDependency("yargs-parser", "4.2.1", rootDependencies);
    final List<ExternalId> childDependencies = new ArrayList<>(dependencyGraph.getChildrenExternalIdsForParent(rootDependencies.get(0)));
    assertListContainsDependency("camelcase", "5.5.2", childDependencies);
    final List<ExternalId> grandchildDependencies = new ArrayList<>(dependencyGraph.getChildrenExternalIdsForParent(childDependencies.get(0)));
    assertListContainsDependency("ms", "0.7.2", grandchildDependencies);
}
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 42 with ExternalIdFactory

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

the class YarnListParserTest method parseYarnListWithResolvableVersions.

@Test
public void parseYarnListWithResolvableVersions() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("ajv@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536\"");
    designedYarnLock.add("  dependencies:");
    designedYarnLock.add("    co \"^4.6.0\"");
    designedYarnLock.add("    tr46 \"~0.0.3\"");
    designedYarnLock.add("    cssstyle \">= 0.2.37 < 0.3.0\"");
    designedYarnLock.add("");
    designedYarnLock.add("co@^4.6.0:");
    designedYarnLock.add("  version \"4.6.0\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184\"");
    designedYarnLock.add("  dependencies:");
    designedYarnLock.add("    hoek \"4.x.x\"");
    designedYarnLock.add("");
    designedYarnLock.add("tr46@~0.0.3:");
    designedYarnLock.add("  version \"0.0.3\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a\"");
    designedYarnLock.add("");
    designedYarnLock.add("\"cssstyle@>= 0.2.37 < 0.3.0\":");
    designedYarnLock.add("  version \"0.2.37\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/cssstyle/-/cssstyle-0.2.37.tgz#541097234cb2513c83ceed3acddc27ff27987d54\"");
    designedYarnLock.add("  dependencies:");
    designedYarnLock.add("    cssom \"0.3.x\"");
    designedYarnLock.add("hoek@4.x.x:");
    designedYarnLock.add("  version \"4.2.1\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb\"");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final String yarnListText = testUtil.getResourceAsUTF8String("/yarn/yarn.list.res.txt");
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, Arrays.asList(yarnListText.split(System.lineSeparator())));
    DependencyGraphResourceTestUtil.assertGraph("/yarn/list_expected_graph_2.json", dependencyGraph);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 43 with ExternalIdFactory

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

the class BazelCodeLocationBuilderTest method test.

@Test
public void test() {
    BazelCodeLocationBuilder bdioBuilder = new BazelCodeLocationBuilder(new ExternalIdFactory());
    final List<DetectCodeLocation> codeLocations = bdioBuilder.setWorkspaceDir(new File("src/test/resources/bazel/multiLevel")).addDependency(BazelExternalId.fromBazelArtifactString("testGroup:testArtifact:testVersion", ":")).build();
    assertEquals(1, codeLocations.size());
    assertEquals("src/test/resources/bazel/multiLevel", codeLocations.get(0).getExternalId().path);
    assertEquals(1, codeLocations.get(0).getDependencyGraph().getRootDependencies().size());
    Dependency dep = codeLocations.get(0).getDependencyGraph().getRootDependencies().iterator().next();
    assertEquals("testArtifact", dep.name);
    assertEquals("testVersion", dep.version);
    assertEquals("testGroup", dep.externalId.group);
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File) Test(org.junit.Test)

Example 44 with ExternalIdFactory

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

the class DependencyGraphAssertions method mavenGavToExternalId.

private static ExternalId mavenGavToExternalId(final String gav) {
    final String[] split = gav.split(":");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    return externalIdFactory.createMavenExternalId(split[0], split[1], split[2]);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)

Example 45 with ExternalIdFactory

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

the class DependencyGraphAssertions method assertHasMavenGav.

public static void assertHasMavenGav(final DependencyGraph dependencyGraph, final String org, final String name, final String version) {
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final ExternalId id = externalIdFactory.createMavenExternalId(org, name, version);
    final Dependency dep = dependencyGraph.getDependency(id);
    assertNotNull("Expected dependency '" + org + ":" + name + ":" + version + "' to exist in graph but it was null.", dep);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

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