Search in sources :

Example 1 with ExecutableRunner

use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner in project hub-detect by blackducksoftware.

the class BazelExternalIdGeneratorTest method test.

@Test
public void test() throws ExecutableRunnerException {
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    final String bazelExe = "notUsed";
    final XPathParser xPathParser = new XPathParser();
    final BazelQueryXmlOutputParser parser = new BazelQueryXmlOutputParser(xPathParser);
    final File workspaceDir = new File("notUsed");
    final String bazelTarget = "//testproject:ProjectRunner";
    BazelExternalIdGenerator generator = new BazelExternalIdGenerator(executableRunner, bazelExe, parser, workspaceDir, bazelTarget);
    BazelExternalIdExtractionSimpleRule simpleRule = new BazelExternalIdExtractionSimpleRule("@.*:jar", "maven_jar", "artifact", ":");
    BazelExternalIdExtractionFullRule xPathRule = RuleConverter.simpleToFull(simpleRule);
    // executableRunner.executeQuietly(workspaceDir, bazelExe, targetOnlyVariableSubstitutor.substitute(xPathRule.getTargetDependenciesQueryBazelCmdArguments()));
    final BazelVariableSubstitutor targetOnlyVariableSubstitutor = new BazelVariableSubstitutor(bazelTarget);
    ExecutableOutput executableOutputQueryForDependencies = new ExecutableOutput(0, "@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar", "");
    Mockito.when(executableRunner.executeQuietly(workspaceDir, bazelExe, targetOnlyVariableSubstitutor.substitute(xPathRule.getTargetDependenciesQueryBazelCmdArguments()))).thenReturn(executableOutputQueryForDependencies);
    // executableRunner.executeQuietly(workspaceDir, bazelExe, dependencyVariableSubstitutor.substitute(xPathRule.getDependencyDetailsXmlQueryBazelCmdArguments()));
    final BazelVariableSubstitutor dependencyVariableSubstitutorCommonsIo = new BazelVariableSubstitutor(bazelTarget, "//external:org_apache_commons_commons_io");
    final BazelVariableSubstitutor dependencyVariableSubstitutorGuava = new BazelVariableSubstitutor(bazelTarget, "//external:com_google_guava_guava");
    ExecutableOutput executableOutputQueryCommonsIo = new ExecutableOutput(0, commonsIoXml, "");
    ExecutableOutput executableOutputQueryGuava = new ExecutableOutput(0, guavaXml, "");
    Mockito.when(executableRunner.executeQuietly(workspaceDir, bazelExe, dependencyVariableSubstitutorCommonsIo.substitute(xPathRule.getDependencyDetailsXmlQueryBazelCmdArguments()))).thenReturn(executableOutputQueryCommonsIo);
    Mockito.when(executableRunner.executeQuietly(workspaceDir, bazelExe, dependencyVariableSubstitutorGuava.substitute(xPathRule.getDependencyDetailsXmlQueryBazelCmdArguments()))).thenReturn(executableOutputQueryGuava);
    List<BazelExternalId> bazelExternalIds = generator.generate(xPathRule);
    assertEquals(2, bazelExternalIds.size());
    assertEquals("org.apache.commons", bazelExternalIds.get(0).getGroup());
    assertEquals("commons-io", bazelExternalIds.get(0).getArtifact());
    assertEquals("1.3.2", bazelExternalIds.get(0).getVersion());
    assertEquals("com.google.guava", bazelExternalIds.get(1).getGroup());
    assertEquals("guava", bazelExternalIds.get(1).getArtifact());
    assertEquals("18.0", bazelExternalIds.get(1).getVersion());
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) File(java.io.File) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) Test(org.junit.jupiter.api.Test)

Example 2 with ExecutableRunner

use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner in project hub-detect by blackducksoftware.

the class ApkPackageManagerTest method test.

@Test
public void test() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final StringBuilder sb = new StringBuilder();
    sb.append("garbage\n");
    sb.append("nonsense\n");
    sb.append("this line has the is owned by substring\n");
    sb.append(" is owned by \n");
    // This is the one valid line; rest should be discarded
    sb.append("/usr/include/stdlib.h is owned by musl-dev-1.1.18-r3\n");
    sb.append("/usr/include/stdlib.h is owned by .musl-dev-1.1.18-r99\n");
    final String pkgMgrOwnedByOutput = sb.toString();
    File depFile = new File("/usr/include/stdlib.h");
    final ApkPackageManager pkgMgr = new ApkPackageManager();
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    Mockito.when(executableRunner.executeQuietly(null, "apk", "info", "--print-arch")).thenReturn(new ExecutableOutput(0, "x86_64\n", ""));
    Mockito.when(executableRunner.executeQuietly(null, "apk", Arrays.asList("info", "--who-owns", depFile.getAbsolutePath()))).thenReturn(new ExecutableOutput(0, pkgMgrOwnedByOutput, ""));
    final DependencyFileDetails dependencyFile = new DependencyFileDetails(false, depFile);
    final List<PackageDetails> pkgs = pkgMgr.getPackages(null, executableRunner, new HashSet<>(), dependencyFile);
    assertEquals(1, pkgs.size());
    assertEquals("musl-dev", pkgs.get(0).getPackageName());
    assertEquals("1.1.18-r3", pkgs.get(0).getPackageVersion());
    assertEquals("x86_64", pkgs.get(0).getPackageArch());
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) File(java.io.File) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) Test(org.junit.Test)

Example 3 with ExecutableRunner

use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner in project hub-detect by blackducksoftware.

the class ClangExtractorTest method testMultipleCommandsDependenciesPackages.

@Test
public void testMultipleCommandsDependenciesPackages() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final CompileCommand compileCommandWrapperHelloWorld = createCompileCommand("src/test/resources/clang/source/hello_world.cpp", "gcc hello_world.cpp", null);
    final CompileCommand compileCommandWrapperGoodbyeWorld = createCompileCommand("src/test/resources/clang/source/goodbye_world.cpp", "gcc goodbye_world.cpp", null);
    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.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 4 with ExecutableRunner

use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner 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 5 with ExecutableRunner

use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner 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)

Aggregations

ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)7 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)6 File (java.io.File)5 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)4 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)4 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)4 Test (org.junit.Test)4 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 DetectInfo (com.blackducksoftware.integration.hub.detect.DetectInfo)1 ConnectionManager (com.blackducksoftware.integration.hub.detect.configuration.ConnectionManager)1 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)1 DetectConfigurationFactory (com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory)1 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)1 DetectorFactory (com.blackducksoftware.integration.hub.detect.detector.DetectorFactory)1 GradleInspectorExtractor (com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor)1 GradleReportParser (com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParser)1