Search in sources :

Example 11 with ExecutableOutput

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

the class NugetSolutionExtractionDebugger method debug.

public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) {
    String id = extraction.extractionIdentifier;
    try {
        NugetInspectorPackager packager = new NugetInspectorPackager(new Gson(), new ExternalIdFactory());
        DetectFileFinder detectFileFinder = new DetectFileFinder();
        File extractionFolder = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
        List<File> extractionFiles = Arrays.asList(extractionFolder.listFiles());
        DetectFileFinder mock = Mockito.mock(DetectFileFinder.class);
        Mockito.when(mock.findFiles(Mockito.any(), Mockito.any())).thenReturn(extractionFiles);
        NugetInspectorExtractor nugetInspectorExtractor = new NugetInspectorExtractor(packager, mock, detectConfiguration);
        NugetInspector inspector = Mockito.mock(NugetInspector.class);
        Mockito.when(inspector.execute(Mockito.any(), Mockito.any())).thenReturn(new ExecutableOutput("", ""));
        File mockTarget = Mockito.mock(File.class);
        Mockito.when(mockTarget.toString()).thenReturn("mock/target");
        File mockOutput = Mockito.mock(File.class);
        Mockito.when(mockOutput.getCanonicalPath()).thenReturn("mock/output");
        Mockito.when(mockOutput.toString()).thenReturn("mock/output");
        Extraction newExtraction = nugetInspectorExtractor.extract(mockTarget, mockOutput, inspector, new ExtractionId(DetectorType.NUGET, id));
        logger.info("We did it: " + newExtraction.result.toString());
    } catch (Exception e) {
        logger.info("We did not do it: " + e.toString());
        throw new RuntimeException(e);
    }
}
Also used : NugetInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Gson(com.google.gson.Gson) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) NugetInspectorPackager(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager) NugetInspector(com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File)

Example 12 with ExecutableOutput

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

the class PearDependencyTest method findDependencyNamesTest.

@Test
public void findDependencyNamesTest() {
    Mockito.when(detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PEAR_ONLY_REQUIRED_DEPS, PropertyAuthority.None)).thenReturn(true);
    final String dependenciesList = testUtil.getResourceAsUTF8String("/pear/dependencies-list.txt");
    final ExecutableOutput exeOutput = new ExecutableOutput(dependenciesList, "");
    final List<String> actual = pearParser.findDependencyNames(exeOutput.getStandardOutputAsList());
    final List<String> expected = Arrays.asList("Archive_Tar", "Structures_Graph", "Console_Getopt", "XML_Util", "PEAR_Frontend_Web", "PEAR_Frontend_Gtk", "xml", "pcre");
    Assert.assertEquals(expected, actual);
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) Test(org.junit.Test)

Example 13 with ExecutableOutput

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

the class PearDependencyTest method createPearDependencyNodeFromListTest.

@Test
public void createPearDependencyNodeFromListTest() {
    final String installedPackages = testUtil.getResourceAsUTF8String("/pear/installed-packages.txt");
    final ExecutableOutput exeOutput = new ExecutableOutput(installedPackages, "");
    final List<String> dependencyNames = Arrays.asList("Archive_Tar", "Console_Getopt", "Structures_Graph");
    final DependencyGraph actual = pearParser.createPearDependencyGraphFromList(exeOutput.getStandardOutputAsList(), dependencyNames);
    DependencyGraphResourceTestUtil.assertGraph("/pear/dependency-node-list_graph.json", actual);
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 14 with ExecutableOutput

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

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

Aggregations

ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)30 File (java.io.File)16 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)14 ArrayList (java.util.ArrayList)12 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)10 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)9 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)8 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)7 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 Test (org.junit.Test)6 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)4 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)4 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)3 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)3 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3