Search in sources :

Example 1 with BazelVariableSubstitutor

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

the class DetectableFactory method bazelExtractor.

// #endregion
// #region Utility
private BazelExtractor bazelExtractor(BazelDetectableOptions bazelDetectableOptions) {
    WorkspaceRuleChooser workspaceRuleChooser = new WorkspaceRuleChooser();
    BazelWorkspaceFileParser bazelWorkspaceFileParser = new BazelWorkspaceFileParser();
    HaskellCabalLibraryJsonProtoParser haskellCabalLibraryJsonProtoParser = new HaskellCabalLibraryJsonProtoParser(gson);
    BazelVariableSubstitutor bazelVariableSubstitutor = new BazelVariableSubstitutor(bazelDetectableOptions.getTargetName().orElse(null), bazelDetectableOptions.getBazelCqueryAdditionalOptions());
    BazelProjectNameGenerator bazelProjectNameGenerator = new BazelProjectNameGenerator();
    return new BazelExtractor(executableRunner, externalIdFactory, bazelWorkspaceFileParser, workspaceRuleChooser, toolVersionLogger, haskellCabalLibraryJsonProtoParser, bazelDetectableOptions.getTargetName().orElse(null), bazelDetectableOptions.getWorkspaceRulesFromProperty(), bazelVariableSubstitutor, bazelProjectNameGenerator);
}
Also used : BazelExtractor(com.synopsys.integration.detectable.detectables.bazel.BazelExtractor) WorkspaceRuleChooser(com.synopsys.integration.detectable.detectables.bazel.pipeline.WorkspaceRuleChooser) BazelProjectNameGenerator(com.synopsys.integration.detectable.detectables.bazel.BazelProjectNameGenerator) BazelWorkspaceFileParser(com.synopsys.integration.detectable.detectables.bazel.BazelWorkspaceFileParser) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) HaskellCabalLibraryJsonProtoParser(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.HaskellCabalLibraryJsonProtoParser)

Example 2 with BazelVariableSubstitutor

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

the class BazelVariableSubstitutorTest method testTargetOnly.

@Test
public void testTargetOnly() {
    BazelVariableSubstitutor substitutor = new BazelVariableSubstitutor("//foo:foolib", new ArrayList<>(0));
    List<String> origArgs = new ArrayList<>();
    origArgs.add("query");
    origArgs.add("filter(\"@.*:jar\", deps(${detect.bazel.target}))");
    List<String> adjustedArgs = substitutor.substitute(origArgs, null);
    assertEquals(2, adjustedArgs.size());
    assertEquals("query", adjustedArgs.get(0));
    assertEquals("filter(\"@.*:jar\", deps(//foo:foolib))", adjustedArgs.get(1));
}
Also used : ArrayList(java.util.ArrayList) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Test(org.junit.jupiter.api.Test)

Example 3 with BazelVariableSubstitutor

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

the class BazelVariableSubstitutorTest method testInput.

@Test
public void testInput() {
    BazelVariableSubstitutor substitutor = new BazelVariableSubstitutor("//foo:foolib", null);
    List<String> origArgs = new ArrayList<>();
    origArgs.add("query");
    origArgs.add("filter(\"@.*:jar\", deps(${detect.bazel.target}))");
    origArgs.add("kind(maven_jar, ${input.item})");
    List<String> adjustedArgs = substitutor.substitute(origArgs, "//external:org_apache_commons_commons_io");
    assertEquals(3, adjustedArgs.size());
    assertEquals("query", adjustedArgs.get(0));
    assertEquals("filter(\"@.*:jar\", deps(//foo:foolib))", adjustedArgs.get(1));
    assertEquals("kind(maven_jar, //external:org_apache_commons_commons_io)", adjustedArgs.get(2));
}
Also used : ArrayList(java.util.ArrayList) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Test(org.junit.jupiter.api.Test)

Example 4 with BazelVariableSubstitutor

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

the class BazelVariableSubstitutorTest method testListInsertion.

@Test
public void testListInsertion() {
    BazelVariableSubstitutor substitutor = new BazelVariableSubstitutor("//foo:foolib", Arrays.asList("--define=a=b", "--define=c=d"));
    List<String> origArgs = new ArrayList<>();
    origArgs.add("cquery");
    origArgs.add("${detect.bazel.cquery.options}");
    origArgs.add("filter(\"@.*:jar\", deps(${detect.bazel.target}))");
    origArgs.add("kind(maven_jar, ${input.item})");
    List<String> adjustedArgs = substitutor.substitute(origArgs, "//external:org_apache_commons_commons_io");
    assertEquals(5, adjustedArgs.size());
    assertEquals("cquery", adjustedArgs.get(0));
    assertEquals("--define=a=b", adjustedArgs.get(1));
    assertEquals("--define=c=d", adjustedArgs.get(2));
    assertEquals("filter(\"@.*:jar\", deps(//foo:foolib))", adjustedArgs.get(3));
    assertEquals("kind(maven_jar, //external:org_apache_commons_commons_io)", adjustedArgs.get(4));
}
Also used : ArrayList(java.util.ArrayList) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Test(org.junit.jupiter.api.Test)

Example 5 with BazelVariableSubstitutor

use of com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor 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)

Aggregations

BazelVariableSubstitutor (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor)6 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 BazelCommandExecutor (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor)2 HaskellCabalLibraryJsonProtoParser (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.HaskellCabalLibraryJsonProtoParser)2 Gson (com.google.gson.Gson)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)1 BazelExtractor (com.synopsys.integration.detectable.detectables.bazel.BazelExtractor)1 BazelProjectNameGenerator (com.synopsys.integration.detectable.detectables.bazel.BazelProjectNameGenerator)1 BazelWorkspaceFileParser (com.synopsys.integration.detectable.detectables.bazel.BazelWorkspaceFileParser)1 Pipeline (com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipeline)1 Pipelines (com.synopsys.integration.detectable.detectables.bazel.pipeline.Pipelines)1 WorkspaceRuleChooser (com.synopsys.integration.detectable.detectables.bazel.pipeline.WorkspaceRuleChooser)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