Search in sources :

Example 21 with ExternalIdFactory

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

the class ClangExtractorTest method testJsonWithArgumentsNotCommand.

@Test
public void testJsonWithArgumentsNotCommand() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final String[] argsHello = { "gcc", "hello_world.cpp" };
    final CompileCommand compileCommandWrapperHelloWorld = createCompileCommand("src/test/resources/clang/source/hello_world.cpp", null, argsHello);
    final String[] argsGoodbye = { "gcc", "goodbye_world.cpp" };
    final CompileCommand compileCommandWrapperGoodbyeWorld = createCompileCommand("src/test/resources/clang/source/goodbye_world.cpp", null, argsGoodbye);
    final Set<String> dependencyFilePathsHelloWorld = createDependencyFilePaths(new File("src/test/resources/clang/source/myinclude.h"), new File("/usr/include/nonexistentfile1.h"), new File("/usr/include/nonexistentfile2.h"));
    final Set<String> dependencyFilePathsGoodbyeWorld = createDependencyFilePaths(new File("/usr/include/nonexistentfile4.h"), new File("/usr/include/nonexistentfile3.h"));
    ;
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    final DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    final DependenciesListFileManager dependenciesListFileManager = Mockito.mock(DependenciesListFileManager.class);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapperHelloWorld, true)).thenReturn(dependencyFilePathsHelloWorld);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapperGoodbyeWorld, true)).thenReturn(dependencyFilePathsGoodbyeWorld);
    Mockito.when(executableRunner.executeFromDirQuietly(Mockito.any(File.class), Mockito.anyString(), Mockito.anyList())).thenReturn(new ExecutableOutput(0, "", ""));
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final CodeLocationAssembler codeLocationAssembler = new CodeLocationAssembler(externalIdFactory);
    final ClangExtractor extractor = new ClangExtractor(null, executableRunner, gson, new DetectFileFinder(), directoryManager, dependenciesListFileManager, codeLocationAssembler);
    final ClangLinuxPackageManager pkgMgr = Mockito.mock(ClangLinuxPackageManager.class);
    final File givenDir = new File("src/test/resources/clang/source/build");
    final int depth = 1;
    final ExtractionId extractionId = new ExtractionId(DetectorType.CLANG, EXTRACTION_ID);
    final File jsonCompilationDatabaseFile = new File("src/test/resources/clang/source/build/compile_commands_usesArguments.json");
    Mockito.when(directoryManager.getExtractionOutputDirectory(Mockito.any(ExtractionId.class))).thenReturn(outputDir);
    final List<PackageDetails> packages = new ArrayList<>();
    packages.add(new PackageDetails("testPackageName1", "testPackageVersion1", "testPackageArch1"));
    packages.add(new PackageDetails("testPackageName2", "testPackageVersion2", "testPackageArch2"));
    Mockito.when(pkgMgr.getDefaultForge()).thenReturn(Forge.CENTOS);
    Mockito.when(pkgMgr.getPackages(Mockito.any(File.class), Mockito.any(ExecutableRunner.class), Mockito.any(Set.class), Mockito.any(DependencyFileDetails.class))).thenReturn(packages);
    Mockito.when(pkgMgr.getForges()).thenReturn(Arrays.asList(Forge.CENTOS, Forge.FEDORA, Forge.REDHAT));
    final Extraction extraction = extractor.extract(pkgMgr, givenDir, depth, extractionId, jsonCompilationDatabaseFile);
    checkGeneratedDependenciesComplex(extraction);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File) Test(org.junit.Test)

Example 22 with ExternalIdFactory

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

the class ClangExtractorTest method testSimple.

@Test
public void testSimple() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final CompileCommand compileCommandWrapper = createCompileCommand("src/test/resources/clang/source/hello_world.cpp", "gcc hello_world.cpp", null);
    final Set<String> dependencyFilePaths = createDependencyFilePaths(new File("/usr/include/nonexistentfile1.h"), new File("src/test/resources/clang/source/myinclude.h"));
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    final DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    final DependenciesListFileManager dependenciesListFileManager = Mockito.mock(DependenciesListFileManager.class);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapper, true)).thenReturn(dependencyFilePaths);
    Mockito.when(executableRunner.executeFromDirQuietly(Mockito.any(File.class), Mockito.anyString(), Mockito.anyList())).thenReturn(new ExecutableOutput(0, "", ""));
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final CodeLocationAssembler codeLocationAssembler = new CodeLocationAssembler(externalIdFactory);
    final ClangExtractor extractor = new ClangExtractor(null, executableRunner, gson, new DetectFileFinder(), directoryManager, dependenciesListFileManager, codeLocationAssembler);
    final ClangLinuxPackageManager pkgMgr = Mockito.mock(ClangLinuxPackageManager.class);
    final File givenDir = new File("src/test/resources/clang/source/build");
    final int depth = 1;
    final ExtractionId extractionId = new ExtractionId(DetectorType.CLANG, EXTRACTION_ID);
    final File jsonCompilationDatabaseFile = new File("src/test/resources/clang/source/build/compile_commands.json");
    Mockito.when(directoryManager.getExtractionOutputDirectory(Mockito.any(ExtractionId.class))).thenReturn(outputDir);
    final List<PackageDetails> packages = new ArrayList<>();
    packages.add(new PackageDetails("testPackageName", "testPackageVersion", "testPackageArch"));
    Mockito.when(pkgMgr.getDefaultForge()).thenReturn(Forge.UBUNTU);
    Mockito.when(pkgMgr.getPackages(Mockito.any(File.class), Mockito.any(ExecutableRunner.class), Mockito.any(Set.class), Mockito.any(DependencyFileDetails.class))).thenReturn(packages);
    Mockito.when(pkgMgr.getForges()).thenReturn(Arrays.asList(Forge.UBUNTU, Forge.DEBIAN));
    final Extraction extraction = extractor.extract(pkgMgr, givenDir, depth, extractionId, jsonCompilationDatabaseFile);
    checkGeneratedDependenciesSimple(extraction);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File) Test(org.junit.Test)

Example 23 with ExternalIdFactory

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

the class GopkgLockParserTest method gopkgParserTest.

@Test
public void gopkgParserTest() throws IOException {
    final GopkgLockParser gopkgLockParser = new GopkgLockParser(new ExternalIdFactory());
    final String gopkgLockContents = IOUtils.toString(getClass().getResourceAsStream("/go/Gopkg.lock"), StandardCharsets.UTF_8);
    final DependencyGraph dependencyGraph = gopkgLockParser.parseDepLock(gopkgLockContents);
    Assert.assertNotNull(dependencyGraph);
    DependencyGraphResourceTestUtil.assertGraph("/go/Go_GopkgExpected_graph.json", dependencyGraph);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 24 with ExternalIdFactory

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

the class GradleReportLineTest method assertDependency.

private void assertDependency(final String line, final String[] expectedResults) {
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final GradleReportLine gradleReportLine = new GradleReportLine(line);
    final Dependency dependency = gradleReportLine.createDependencyNode(externalIdFactory);
    Assert.assertEquals(expectedResults[0], dependency.name);
    Assert.assertEquals(expectedResults[1], dependency.version);
    Assert.assertEquals(expectedResults[2], dependency.externalId.createExternalId());
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 25 with ExternalIdFactory

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

the class RebarParserTest method setup.

@BeforeClass
public static void setup() {
    externalIdFactory = new ExternalIdFactory();
    rebar3TreeParser = new Rebar3TreeParser(externalIdFactory);
    testUtil = new TestUtil();
}
Also used : TestUtil(com.blackducksoftware.integration.hub.detect.testutils.TestUtil) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) BeforeClass(org.junit.BeforeClass)

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