Search in sources :

Example 21 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class GradleReportParserTest method build.

private DetectCodeLocation build(final String resource) throws IOException {
    final File file = new File(resource);
    final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory());
    final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(file);
    if (result.isPresent()) {
        return result.get();
    } else {
        return null;
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) File(java.io.File)

Example 22 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class GradleReportParserTest method testSpringFrameworkAop.

@Test
public void testSpringFrameworkAop() throws IOException {
    final File file = new File("src/test/resources/gradle/spring-framework/spring_aop_dependencyGraph.txt");
    final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory());
    final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(file);
    assertTrue(result.isPresent());
    System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(result.get()));
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) File(java.io.File) Test(org.junit.Test)

Example 23 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class GradleReportParserTest method createNewCodeLocationTest.

private void createNewCodeLocationTest(final String gradleInspectorOutputFilePath, final String expectedResourcePath, final String rootProjectFilePath, final String rootProjectName, final String rootProjectVersionName) throws IOException {
    final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory());
    final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(new File(gradleInspectorOutputFilePath));
    final Optional<NameVersion> rootProjectNameVersion = gradleReportParser.parseRootProjectNameVersion(new File(rootProjectFilePath));
    assertTrue(result.isPresent());
    assertTrue(rootProjectNameVersion.isPresent());
    assertEquals(rootProjectName, rootProjectNameVersion.get().getName());
    assertEquals(rootProjectVersionName, rootProjectNameVersion.get().getVersion());
    testUtil.testJsonResource(expectedResourcePath, result.get());
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) File(java.io.File)

Example 24 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation 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 25 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class NpmCliParser method convertNpmJsonFileToCodeLocation.

NpmParseResult convertNpmJsonFileToCodeLocation(final String sourcePath, final String npmLsOutput) {
    final JsonObject npmJson = new JsonParser().parse(npmLsOutput).getAsJsonObject();
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
    final JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION);
    String projectName = null;
    String projectVersion = null;
    if (projectNameElement != null) {
        projectName = projectNameElement.getAsString();
    }
    if (projectVersionElement != null) {
        projectVersion = projectVersionElement.getAsString();
    }
    populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true);
    final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, projectName, projectVersion);
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NPM, sourcePath, externalId, graph).build();
    return new NpmParseResult(projectName, projectVersion, codeLocation);
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) JsonElement(com.google.gson.JsonElement) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) JsonObject(com.google.gson.JsonObject) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) JsonParser(com.google.gson.JsonParser)

Aggregations

DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)44 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)22 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)18 File (java.io.File)17 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)15 ArrayList (java.util.ArrayList)10 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)9 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)9 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)8 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)8 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)7 Test (org.junit.Test)7 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)5 List (java.util.List)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4