use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PubDepsExtractor method extract.
public Extraction extract(File directory, @Nullable ExecutableTarget dartExe, @Nullable ExecutableTarget flutterExe, DartPubDepsDetectableOptions dartPubDepsDetectableOptions, File pubSpecYamlFile) {
try {
toolVersionLogger.log(directory, dartExe);
toolVersionLogger.log(directory, flutterExe);
List<String> pubDepsCommand = new ArrayList<>();
pubDepsCommand.add("pub");
pubDepsCommand.add("deps");
if (dartPubDepsDetectableOptions.getDependencyTypeFilter().shouldExclude(DartPubDependencyType.DEV)) {
pubDepsCommand.add("--no-dev");
}
ExecutableOutput pubDepsOutput = null;
if (dartExe != null) {
pubDepsOutput = runPubDepsCommand(directory, dartExe, pubDepsCommand);
}
if (pubDepsOutput == null || pubDepsOutput.getReturnCode() != 0) {
if (flutterExe == null && dartExe != null) {
return new Extraction.Builder().failure(String.format("An error occurred trying to run %s %s", dartExe.toCommand(), String.join(" ", pubDepsCommand))).build();
} else {
// If command does not work with Dart, it could be because at least one of the packages requires Flutter
logger.debug("Running dart pub deps was not successful. Going to try running flutter pub deps.");
pubDepsCommand.add(0, "--no-version-check");
pubDepsOutput = runPubDepsCommand(directory, flutterExe, pubDepsCommand);
}
}
Optional<NameVersion> nameVersion = Optional.empty();
if (pubSpecYamlFile != null) {
List<String> pubSpecYamlLines = Files.readAllLines(pubSpecYamlFile.toPath(), StandardCharsets.UTF_8);
nameVersion = nameVersionParser.parseNameVersion(pubSpecYamlLines);
}
DependencyGraph dependencyGraph = pubDepsParser.parse(pubDepsOutput.getStandardOutputAsList());
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(nameVersion).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class DockerExtractor method findCodeLocations.
private Extraction.Builder findCodeLocations(File directoryToSearch, File directory, @Nullable String dockerInspectorMessage) {
File bdioFile = fileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
if (bdioFile != null) {
SimpleBdioDocument simpleBdioDocument = null;
try (InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
simpleBdioDocument = bdioReader.readSimpleBdioDocument();
} catch (Exception e) {
return new Extraction.Builder().exception(e);
}
if (simpleBdioDocument != null) {
String projectName = simpleBdioDocument.getProject().name;
String projectVersionName = simpleBdioDocument.getProject().version;
// TODO ejk - update this when project external id is not req'd anymore
Forge dockerForge = new Forge(BdioId.BDIO_ID_SEPARATOR, simpleBdioDocument.getProject().bdioExternalIdentifier.forge);
String externalIdPath = simpleBdioDocument.getProject().bdioExternalIdentifier.externalId;
ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
ProjectDependency projectDependency = new ProjectDependency(projectName, projectVersionName, projectExternalId);
DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(projectDependency, simpleBdioDocument.getProject(), simpleBdioDocument.getComponents());
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, projectExternalId);
return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
}
}
logger.error("Docker Inspector returned no BDIO files");
String dockerInspectorMsgSuffix = Optional.ofNullable(dockerInspectorMessage).filter(StringUtils::isNotBlank).map(s -> "; Docker Inspector message: " + s).orElse("");
return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString() + dockerInspectorMsgSuffix);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class GoDepExtractor method extract.
public Extraction extract(InputStream goLockInputStream) {
DependencyGraph graph = goLockParser.parseDepLock(goLockInputStream);
CodeLocation codeLocation = new CodeLocation(graph);
return new Extraction.Builder().success(codeLocation).build();
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class DetectorToolTest method createExtractionBuilder.
private Extraction.Builder createExtractionBuilder() {
File relevantFile = new File("go.mod");
DependencyGraph dependencyGraph = Mockito.mock(DependencyGraph.class);
CodeLocation codeLocation = new CodeLocation(dependencyGraph, relevantFile);
Extraction.Builder builder = new Extraction.Builder();
return builder.relevantFiles(relevantFile).codeLocations(codeLocation).projectName("test-project").projectVersion("1.0").unrecognizedPaths(Collections.emptyList());
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method doesntThrowOnMissingExternalId.
@Test
void doesntThrowOnMissingExternalId() throws MissingExternalIdException {
// Ensure components not defined in the graph doesn't cause an exception to be thrown. See IDETECT-1974.
PackageJson rawPackageJson = new PackageJson();
rawPackageJson.dependencies = new HashMap<>();
rawPackageJson.dependencies.put("foo", "fooFuzzyVersion-1.0");
NullSafePackageJson packageJson = new NullSafePackageJson(rawPackageJson);
List<YarnLockEntryId> validYarnLockEntryIds = Collections.singletonList(new YarnLockEntryId("foo", "fooFuzzyVersion-1.0"));
List<YarnLockDependency> validYarnLockDependencies = Collections.singletonList(new YarnLockDependency("yarn", "^1.22.4", false));
List<YarnLockEntry> yarnLockEntries = Collections.singletonList(new YarnLockEntry(false, validYarnLockEntryIds, "1.0", validYarnLockDependencies));
YarnLock yarnLock = new YarnLock(null, true, yarnLockEntries);
YarnLockResult yarnLockResult = new YarnLockResult(packageJson, YarnWorkspaces.EMPTY, yarnLock);
// This should not throw an exception.
List<CodeLocation> codeLocations = createTransformer().generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
// Sanity check.
assertEquals(1, codeLocations.size());
CodeLocation codeLocation = codeLocations.get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
Assertions.assertNotNull(dependencyGraph, "The dependency graph should not be null.");
assertEquals(1, dependencyGraph.getRootDependencies().size(), "Only 'foo:1.0' should appear in the graph.");
ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
assertTrue(dependencyGraph.hasDependency(fooExternalId), "Missing the only expected dependency.");
}
Aggregations