Search in sources :

Example 6 with Dependency

use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class AggregateBdioCreator method createAggregateDependency.

private Dependency createAggregateDependency(File sourcePath, final DetectCodeLocation codeLocation) {
    String name = null;
    String version = null;
    try {
        name = codeLocation.getExternalId().name;
        version = codeLocation.getExternalId().version;
    } catch (final Exception e) {
        logger.warn("Failed to get name or version to use in the wrapper for a code location.", e);
    }
    final ExternalId original = codeLocation.getExternalId();
    final String codeLocationSourcePath = codeLocation.getSourcePath();
    final String bomToolType = codeLocation.getCodeLocationType().toString();
    final String relativePath = FileNameUtils.relativize(sourcePath.getAbsolutePath(), codeLocationSourcePath);
    final List<String> externalIdPieces = new ArrayList<>();
    externalIdPieces.addAll(Arrays.asList(original.getExternalIdPieces()));
    externalIdPieces.add(relativePath);
    externalIdPieces.add(bomToolType);
    final String[] pieces = externalIdPieces.toArray(new String[externalIdPieces.size()]);
    return new Dependency(name, version, new ExternalIdFactory().createModuleNamesExternalId(original.forge, pieces));
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)

Example 7 with Dependency

use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class GemlockNodeParserTest method testParsingEqualsGemfileLock.

@Test
public void testParsingEqualsGemfileLock() {
    final String text = testUtils.getResourceAsUTF8String("/rubygems/Gemfile_equals_version.lock");
    final List<String> gemfileLockContents = Arrays.asList(text.split("\n"));
    final GemlockParser gemlockNodeParser = new GemlockParser(new ExternalIdFactory());
    final DependencyGraph dependencyGraph = gemlockNodeParser.parseProjectDependencies(gemfileLockContents);
    Dependency bundler = dependencyGraph.getDependency(new ExternalIdFactory().createNameVersionExternalId(Forge.RUBYGEMS, "bundler", "1.11.2"));
    assertNotNull(bundler);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Test(org.junit.Test)

Example 8 with Dependency

use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class GemlockNodeParserTest method testMissingVersionsGemfileLock.

@Test
public void testMissingVersionsGemfileLock() {
    final String text = testUtils.getResourceAsUTF8String("/rubygems/Gemfile_missing_versions.lock");
    final List<String> gemfileLockContents = Arrays.asList(text.split("\n"));
    final GemlockParser gemlockNodeParser = new GemlockParser(new ExternalIdFactory());
    final DependencyGraph dependencyGraph = gemlockNodeParser.parseProjectDependencies(gemfileLockContents);
    Dependency newrelic_rpm = dependencyGraph.getDependency(new ExternalIdFactory().createNameVersionExternalId(Forge.RUBYGEMS, "newrelic_rpm", ""));
    assertNotNull(newrelic_rpm);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Test(org.junit.Test)

Example 9 with Dependency

use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class GoVendorJsonParser method parseVendorJson.

public DependencyGraph parseVendorJson(final Gson gson, final String vendorJsonContents) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    GoVendorJsonData vendorJsonData = gson.fromJson(vendorJsonContents, GoVendorJsonData.class);
    logger.trace(String.format("vendorJsonData: %s", vendorJsonData));
    for (GoVendorJsonPackageData pkg : vendorJsonData.getPackages()) {
        if (StringUtils.isNotBlank(pkg.getPath()) && StringUtils.isNotBlank(pkg.getRevision())) {
            final ExternalId dependencyExternalId = externalIdFactory.createNameVersionExternalId(Forge.GOLANG, pkg.getPath(), pkg.getRevision());
            final Dependency dependency = new Dependency(pkg.getPath(), pkg.getRevision(), dependencyExternalId);
            logger.trace(String.format("dependency: %s", dependency.externalId.toString()));
            graph.addChildToRoot(dependency);
        } else {
            logger.debug(String.format("Omitting package path:'%s', revision:'%s' (one or both of path, revision is/are missing)", pkg.getPath(), pkg.getRevision()));
        }
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 10 with Dependency

use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class GradleReportLine method createDependencyNode.

public Dependency createDependencyNode(final ExternalIdFactory externalIdFactory) {
    if (!originalLine.contains(COMPONENT_PREFIX)) {
        return null;
    }
    String cleanedOutput = StringUtils.trimToEmpty(originalLine);
    cleanedOutput = cleanedOutput.substring(cleanedOutput.indexOf(COMPONENT_PREFIX) + COMPONENT_PREFIX.length());
    if (cleanedOutput.endsWith(SEEN_ELSEWHERE_SUFFIX)) {
        final int lastSeenElsewhereIndex = cleanedOutput.lastIndexOf(SEEN_ELSEWHERE_SUFFIX);
        cleanedOutput = cleanedOutput.substring(0, lastSeenElsewhereIndex);
    }
    // we might need to modify the returned list, so it needs to be an actual ArrayList
    List<String> gavPieces = new ArrayList<>(Arrays.asList(cleanedOutput.split(":")));
    if (cleanedOutput.contains(WINNING_INDICATOR)) {
        // WINNING_INDICATOR can point to an entire GAV not just a version
        final String winningSection = cleanedOutput.substring(cleanedOutput.indexOf(WINNING_INDICATOR) + WINNING_INDICATOR.length());
        if (winningSection.contains(":")) {
            gavPieces = Arrays.asList(winningSection.split(":"));
        } else {
            // the WINNING_INDICATOR is not always preceded by a : so if isn't, we need to clean up from the original split
            if (gavPieces.get(1).contains(WINNING_INDICATOR)) {
                final String withoutWinningIndicator = gavPieces.get(1).substring(0, gavPieces.get(1).indexOf(WINNING_INDICATOR));
                gavPieces.set(1, withoutWinningIndicator);
                // since there was no : we don't have a gav piece for version yet
                gavPieces.add("");
            }
            gavPieces.set(2, winningSection);
        }
    }
    if (gavPieces.size() != 3) {
        logger.error(String.format("The line can not be reasonably split in to the neccessary parts: %s", originalLine));
        return null;
    }
    final String group = gavPieces.get(0);
    final String artifact = gavPieces.get(1);
    final String version = gavPieces.get(2);
    final Dependency dependency = new Dependency(artifact, version, externalIdFactory.createMavenExternalId(group, artifact, version));
    return dependency;
}
Also used : ArrayList(java.util.ArrayList) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Aggregations

Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)46 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)23 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)12 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)11 Test (org.junit.Test)11 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)10 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)9 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 File (java.io.File)5 DependencyHistory (com.blackducksoftware.integration.hub.detect.util.DependencyHistory)4 ArrayList (java.util.ArrayList)3 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)2 Gson (com.google.gson.Gson)2 Forge (com.synopsys.integration.bdio.model.Forge)2 NpmDependency (com.blackducksoftware.integration.hub.detect.detector.npm.model.NpmDependency)1 PackageLockDependency (com.blackducksoftware.integration.hub.detect.detector.npm.model.PackageLockDependency)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 DetectCodeLocationType (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocationType)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1