Search in sources :

Example 1 with BazelCommandExecutor

use of com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor in project synopsys-detect by blackducksoftware.

the class PipelinesTest method doTest.

private List<Dependency> doTest(WorkspaceRule workspaceRule, List<String> expectedBazelCommandArgs, List<String> userProvidedCqueryAdditionalOptions, String input) throws IntegrationException, ExecutableFailedException {
    BazelCommandExecutor bazelCommandExecutor = Mockito.mock(BazelCommandExecutor.class);
    Mockito.when(bazelCommandExecutor.executeToString(expectedBazelCommandArgs)).thenReturn(Optional.of(input));
    BazelVariableSubstitutor bazelVariableSubstitutor = new BazelVariableSubstitutor("/:testTarget", userProvidedCqueryAdditionalOptions);
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    HaskellCabalLibraryJsonProtoParser haskellCabalLibraryJsonProtoParser = new HaskellCabalLibraryJsonProtoParser(new Gson());
    Pipelines pipelines = new Pipelines(bazelCommandExecutor, bazelVariableSubstitutor, externalIdFactory, haskellCabalLibraryJsonProtoParser);
    Pipeline pipeline = pipelines.get(workspaceRule);
    return pipeline.run();
}
Also used : Pipelines(com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipelines) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Gson(com.google.gson.Gson) HaskellCabalLibraryJsonProtoParser(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.HaskellCabalLibraryJsonProtoParser) BazelCommandExecutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor) Pipeline(com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipeline)

Example 2 with BazelCommandExecutor

use of com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor in project synopsys-detect by blackducksoftware.

the class BazelExtractor method extract.

public Extraction extract(ExecutableTarget bazelExe, File workspaceDir, File workspaceFile) throws ExecutableFailedException, DetectableException {
    toolVersionLogger.log(workspaceDir, bazelExe, "version");
    BazelCommandExecutor bazelCommandExecutor = new BazelCommandExecutor(executableRunner, workspaceDir, bazelExe);
    Pipelines pipelines = new Pipelines(bazelCommandExecutor, bazelVariableSubstitutor, externalIdFactory, haskellCabalLibraryJsonProtoParser);
    Set<WorkspaceRule> workspaceRulesFromFile = parseWorkspaceRulesFromFile(workspaceFile);
    Set<WorkspaceRule> workspaceRulesToQuery = workspaceRuleChooser.choose(workspaceRulesFromFile, workspaceRulesFromProperty);
    CodeLocation codeLocation = generateCodelocation(pipelines, workspaceRulesToQuery);
    return buildResults(codeLocation, bazelProjectNameGenerator.generateFromBazelTarget(bazelTarget));
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Pipelines(com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipelines) BazelCommandExecutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor)

Example 3 with BazelCommandExecutor

use of com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor in project synopsys-detect by blackducksoftware.

the class IntermediateStepExecuteBazelOnEachLineTest method testNoInput.

@Test
public void testNoInput() throws ExecutableRunnerException, IntegrationException, ExecutableFailedException {
    File workspaceDir = new File(".");
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    ExecutableTarget bazelExe = ExecutableTarget.forCommand("/usr/bin/bazel");
    ExecutableOutput bazelCmdExecutableOutput = Mockito.mock(ExecutableOutput.class);
    Mockito.when(bazelCmdExecutableOutput.getReturnCode()).thenReturn(0);
    Mockito.when(bazelCmdExecutableOutput.getStandardOutput()).thenReturn("@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar");
    Mockito.when(executableRunner.executeSuccessfully(Mockito.any(Executable.class))).thenReturn(bazelCmdExecutableOutput);
    BazelCommandExecutor bazelCommandExecutor = new BazelCommandExecutor(executableRunner, workspaceDir, bazelExe);
    BazelVariableSubstitutor bazelVariableSubstitutor = new BazelVariableSubstitutor("//:ProjectRunner", null);
    IntermediateStep executor = new IntermediateStepExecuteBazelOnEachLine(bazelCommandExecutor, bazelVariableSubstitutor, Arrays.asList("cquery", "filter(\\\"@.*:jar\\\", deps(${detect.bazel.target}))"), false);
    List<String> input = new ArrayList<>(0);
    List<String> output = executor.process(input);
    assertEquals(1, output.size());
    assertEquals("@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar", output.get(0));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IntermediateStep(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStep) ArrayList(java.util.ArrayList) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) BazelCommandExecutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor) IntermediateStepExecuteBazelOnEachLine(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStepExecuteBazelOnEachLine) Test(org.junit.jupiter.api.Test)

Aggregations

BazelCommandExecutor (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor)3 Pipelines (com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipelines)2 BazelVariableSubstitutor (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor)2 Gson (com.google.gson.Gson)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)1 Pipeline (com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipeline)1 HaskellCabalLibraryJsonProtoParser (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.HaskellCabalLibraryJsonProtoParser)1 IntermediateStep (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStep)1 IntermediateStepExecuteBazelOnEachLine (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStepExecuteBazelOnEachLine)1 Executable (com.synopsys.integration.executable.Executable)1 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1