use of com.synopsys.integration.detectable.ExecutableTarget in project synopsys-detect by blackducksoftware.
the class MavenCliExtractor method extract.
// TODO: Limit 'extractors' to 'execute' and 'read', delegate all other work.
public Extraction extract(File directory, ExecutableTarget mavenExe, MavenCliExtractorOptions mavenCliExtractorOptions) throws ExecutableFailedException {
toolVersionLogger.log(directory, mavenExe);
List<String> commandArguments = commandParser.parseCommandString(mavenCliExtractorOptions.getMavenBuildCommand().orElse("")).stream().filter(arg -> !arg.equals("dependency:tree")).collect(Collectors.toList());
commandArguments.add("dependency:tree");
// Force maven to use a single thread to ensure the tree output is in the correct order.
commandArguments.add("-T1");
ExecutableOutput mvnExecutableResult = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, mavenExe, commandArguments));
List<String> mavenOutput = mvnExecutableResult.getStandardOutputAsList();
List<String> excludedScopes = mavenCliExtractorOptions.getMavenExcludedScopes();
List<String> includedScopes = mavenCliExtractorOptions.getMavenIncludedScopes();
List<String> excludedModules = mavenCliExtractorOptions.getMavenExcludedModules();
List<String> includedModules = mavenCliExtractorOptions.getMavenIncludedModules();
List<MavenParseResult> mavenResults = mavenCodeLocationPackager.extractCodeLocations(directory.toString(), mavenOutput, excludedScopes, includedScopes, excludedModules, includedModules);
List<CodeLocation> codeLocations = Bds.of(mavenResults).map(MavenParseResult::getCodeLocation).toList();
Optional<MavenParseResult> firstWithName = Bds.of(mavenResults).firstFiltered(it -> StringUtils.isNotBlank(it.getProjectName()));
Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
if (firstWithName.isPresent()) {
builder.projectName(firstWithName.get().getProjectName());
builder.projectVersion(firstWithName.get().getProjectVersion());
}
return builder.build();
}
use of com.synopsys.integration.detectable.ExecutableTarget in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method extract.
public Extraction extract(List<File> targets, File outputDirectory, ExecutableTarget inspector, NugetInspectorOptions nugetInspectorOptions) {
try {
List<NugetTargetResult> results = new ArrayList<>();
for (int i = 0; i < targets.size(); i++) {
File targetDirectory = new File(outputDirectory, "inspection-" + i);
results.add(executeTarget(inspector, targets.get(i), targetDirectory, nugetInspectorOptions));
}
List<CodeLocation> codeLocations = results.stream().flatMap(it -> it.codeLocations.stream()).collect(Collectors.toList());
Map<File, CodeLocation> codeLocationsBySource = new HashMap<>();
codeLocations.forEach(codeLocation -> {
File sourcePathFile = codeLocation.getSourcePath().orElse(null);
if (codeLocationsBySource.containsKey(sourcePathFile)) {
logger.debug("Combined code location for: " + sourcePathFile);
CodeLocation destination = codeLocationsBySource.get(sourcePathFile);
// TODO: I don't like this casting, perhaps this doesn't have to happen here in 8.0.0. JM-04/2022
destination.getDependencyGraph().copyGraphToRoot((BasicDependencyGraph) codeLocation.getDependencyGraph());
} else {
codeLocationsBySource.put(sourcePathFile, codeLocation);
}
});
Optional<NameVersion> nameVersion = results.stream().filter(it -> it.nameVersion != null).map(it -> it.nameVersion).findFirst();
List<CodeLocation> uniqueCodeLocations = new ArrayList<>(codeLocationsBySource.values());
return new Extraction.Builder().success(uniqueCodeLocations).nameVersionIfPresent(nameVersion).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.ExecutableTarget in project synopsys-detect by blackducksoftware.
the class BitbakeExtractor method extract.
public Extraction extract(File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile) throws ExecutableFailedException, IOException {
toolVersionLogger.log(() -> bitbakeCommandRunner.runBitbakeVersion(sourceDirectory, bashExecutable, buildEnvironmentFile));
File buildDirectory = determineBuildDirectory(sourceDirectory, bashExecutable, buildEnvironmentFile);
BitbakeEnvironment bitbakeEnvironment = executeBitbakeForEnvironment(sourceDirectory, bashExecutable, buildEnvironmentFile);
ShowRecipesResults showRecipesResults = executeBitbakeForRecipeLayerCatalog(sourceDirectory, bashExecutable, buildEnvironmentFile);
List<CodeLocation> codeLocations = packageNames.stream().map(targetPackage -> generateCodeLocationForTargetPackage(targetPackage, sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, showRecipesResults, bitbakeEnvironment)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (codeLocations.isEmpty()) {
return Extraction.failure("No Code Locations were generated during extraction");
} else {
return Extraction.success(codeLocations);
}
}
use of com.synopsys.integration.detectable.ExecutableTarget in project synopsys-detect by blackducksoftware.
the class LernaPackageDiscovererTest method discoverLernaPackages.
@Test
void discoverLernaPackages() throws ExecutableRunnerException {
File workingDirectory = new File("workingDir");
ExecutableTarget lernaExecutable = ExecutableTarget.forCommand("lerna");
DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
Mockito.when(executableRunner.execute(Mockito.any(Executable.class))).thenReturn(new ExecutableOutput(0, String.join(System.lineSeparator(), "[", " {", " \"name\": \"@lerna/packageA\",", " \"version\": \"1.2.3\",", " \"private\": false,", " \"location\": \"/source/packages/packageA\"", " },", " {", " \"name\": \"@lerna/packageB\",", " \"version\": \"3.2.1\",", " \"private\": true,", " \"location\": \"/source/packages/packageB\"", " },", " {", " \"name\": \"@lerna/packageC\",", " \"version\": \"1.1.1\",", " \"private\": true,", " \"location\": \"/source/packages/packageC\"", " }", "]"), ""));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
LernaPackageDiscoverer lernaPackageDiscoverer = new LernaPackageDiscoverer(executableRunner, gson, Collections.singletonList("@lerna/packageC"), new LinkedList<>());
List<LernaPackage> lernaPackages = lernaPackageDiscoverer.discoverLernaPackages(workingDirectory, lernaExecutable);
Assertions.assertEquals(2, lernaPackages.size(), "Expected to find two Lerna packages.");
LernaPackage lernaPackageA = lernaPackages.get(0);
Assertions.assertEquals("@lerna/packageA", lernaPackageA.getName());
Assertions.assertEquals("1.2.3", lernaPackageA.getVersion());
Assertions.assertFalse(lernaPackageA.isPrivate());
Assertions.assertEquals("/source/packages/packageA", lernaPackageA.getLocation());
LernaPackage lernaPackageB = lernaPackages.get(1);
Assertions.assertEquals("@lerna/packageB", lernaPackageB.getName());
Assertions.assertEquals("3.2.1", lernaPackageB.getVersion());
Assertions.assertTrue(lernaPackageB.isPrivate());
Assertions.assertEquals("/source/packages/packageB", lernaPackageB.getLocation());
}
use of com.synopsys.integration.detectable.ExecutableTarget 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));
}
Aggregations