Search in sources :

Example 1 with ExternalIdFactory

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

the class SbtPackager method makeModuleAggregate.

private List<SbtDependencyModule> makeModuleAggregate(final List<File> reportFiles, final String include, final String exclude) throws SAXException, IOException, ParserConfigurationException {
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = factory.newDocumentBuilder();
    final SbtReportParser parser = new SbtReportParser();
    final SbtDependencyResolver resolver = new SbtDependencyResolver(externalIdFactory);
    final ExcludedIncludedFilter filter = new ExcludedIncludedFilter(exclude, include);
    final SbtModuleAggregator aggregator = new SbtModuleAggregator();
    final List<SbtDependencyModule> modules = new ArrayList<>();
    for (final File reportFile : reportFiles) {
        final Document xml = builder.parse(reportFile);
        logger.debug(String.format("Parsing SBT report file: %s", reportFile.getCanonicalPath()));
        final SbtReport report = parser.parseReportFromXml(xml);
        final SbtDependencyModule tree = resolver.resolveReport(report);
        modules.add(tree);
    }
    final List<SbtDependencyModule> includedModules = modules.stream().filter(module -> filter.shouldInclude(module.configuration)).collect(Collectors.toList());
    if (modules.size() <= 0) {
        logger.warn("No sbt configurations were found in report folder.");
        return null;
    } else if (includedModules.size() <= 0) {
        logger.warn(String.format("Although %s configs were found, none were included.", modules.size()));
        return null;
    }
    return aggregator.aggregateModules(includedModules);
}
Also used : Arrays(java.util.Arrays) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) ExcludedIncludedFilter(com.synopsys.integration.util.ExcludedIncludedFilter) Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ArrayList(java.util.ArrayList) ExcludedIncludedFilter(com.synopsys.integration.util.ExcludedIncludedFilter) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File)

Example 2 with ExternalIdFactory

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

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

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

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

the class YarnListParserTest method parseYarnListTest.

@Test
public void parseYarnListTest() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("async@~0.9.0:");
    designedYarnLock.add("  version \"0.9.2\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d\"");
    designedYarnLock.add("  dependencies:");
    designedYarnLock.add("    minimist \"0.0.8\"");
    designedYarnLock.add("");
    designedYarnLock.add("minimist@0.0.8:");
    designedYarnLock.add("  version \"0.0.8\"");
    designedYarnLock.add("  resolved \"http://nexus/nexus3/repository/npm-all/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d\"");
    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.txt");
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, Arrays.asList(yarnListText.split(System.lineSeparator())));
    DependencyGraphResourceTestUtil.assertGraph("/yarn/list_expected_graph.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)

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