use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class NpmCliParser method convertNpmJsonFileToCodeLocation.
public NpmPackagerResult convertNpmJsonFileToCodeLocation(String npmLsOutput, PackageJson packageJson) {
JsonObject npmJson = JsonParser.parseString(npmLsOutput).getAsJsonObject();
DependencyGraph graph = new BasicDependencyGraph();
JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION);
String projectName = null;
String projectVersion = null;
if (projectNameElement != null) {
projectName = projectNameElement.getAsString();
}
if (projectVersionElement != null) {
projectVersion = projectVersionElement.getAsString();
}
populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true, packageJson);
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, projectName, projectVersion);
CodeLocation codeLocation = new CodeLocation(graph, externalId);
return new NpmPackagerResult(projectName, projectVersion, codeLocation);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceDetectable method extract.
@Override
public Extraction extract(ExtractionEnvironment extractionEnvironment) throws IOException, ParserConfigurationException, SAXException {
List<CodeLocation> codeLocations = new LinkedList<>();
if (foundPackageResolvedFile != null) {
PackageResolvedResult localResult = packageResolvedExtractor.extract(foundPackageResolvedFile);
Optional<FailedDetectableResult> failedDetectableResult = localResult.getFailedDetectableResult();
if (failedDetectableResult.isPresent()) {
return Extraction.failure(failedDetectableResult.get());
}
codeLocations.add(new CodeLocation(localResult.getDependencyGraph(), environment.getDirectory()));
}
if (foundWorkspaceDataFile != null) {
XcodeWorkspaceResult xcodeWorkspaceResult = xcodeWorkspaceExtractor.extract(foundWorkspaceDataFile, workspaceDirectory);
if (xcodeWorkspaceResult.isFailure()) {
return Extraction.failure(xcodeWorkspaceResult.getFailedDetectableResults());
}
codeLocations.addAll(xcodeWorkspaceResult.getCodeLocations());
}
return Extraction.success(codeLocations);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceExtractor method extract.
public XcodeWorkspaceResult extract(File workspaceDataFile, File workspaceDirectory) throws IOException, ParserConfigurationException, SAXException {
String workspaceFileContents = FileUtils.readFileToString(workspaceDataFile, Charset.defaultCharset());
XcodeWorkspace xcodeWorkspace = xcodeWorkspaceParser.parse(workspaceFileContents);
xcodeWorkspaceFormatChecker.checkForVersionCompatibility(xcodeWorkspace);
List<CodeLocation> codeLocations = new LinkedList<>();
List<FailedDetectableResult> failedDetectableResults = new LinkedList<>();
for (XcodeFileReference fileReference : xcodeWorkspace.getFileReferences()) {
File workspaceReferencedDirectory = workspaceDirectory.getParentFile().toPath().resolve(fileReference.getRelativeLocation()).toFile();
if (!workspaceReferencedDirectory.exists()) {
logger.warn("Failed to find subproject '{}' as defined in the workspace at '{}'", workspaceReferencedDirectory, workspaceDataFile.getParentFile().getAbsolutePath());
continue;
}
switch(fileReference.getFileReferenceType()) {
case DIRECTORY:
PackageResolvedResult swiftProjectResult = extractStandalonePackageResolved(workspaceReferencedDirectory);
swiftProjectResult.getFailedDetectableResult().ifPresent(failedDetectableResults::add);
codeLocations.add(new CodeLocation(swiftProjectResult.getDependencyGraph(), workspaceReferencedDirectory));
break;
case XCODE_PROJECT:
PackageResolvedResult xcodeProjectResult = extractFromXcodeProject(workspaceReferencedDirectory);
xcodeProjectResult.getFailedDetectableResult().ifPresent(failedDetectableResults::add);
codeLocations.add(new CodeLocation(xcodeProjectResult.getDependencyGraph(), workspaceReferencedDirectory));
break;
default:
throw new UnsupportedOperationException(String.format("Unrecognized FileReferenceType: %s", fileReference.getFileReferenceType()));
}
}
if (CollectionUtils.isNotEmpty(failedDetectableResults)) {
return XcodeWorkspaceResult.failure(failedDetectableResults);
}
return XcodeWorkspaceResult.success(codeLocations);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method testExcludeDevDependencies.
// Not yet covered by these tests: yarn 1 workspaces' dev dependencies specified in workspace package.json
@Test
void testExcludeDevDependencies() throws MissingExternalIdException {
YarnLockResult yarnLockResult = buildTestYarnLockResult(noWorkspaces, noWorkspaces, false);
List<CodeLocation> codeLocations = createTransformer(YarnDependencyType.NON_PRODUCTION).generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
assertEquals(1, codeLocations.size());
CodeLocation codeLocation = codeLocations.get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
assertEquals(1, dependencyGraph.getRootDependencies().size());
Set<Dependency> rootDeps = dependencyGraph.getRootDependencies();
assertEquals("foo", rootDeps.iterator().next().getName());
ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
assertTrue(dependencyGraph.hasDependency(fooExternalId));
ExternalId yarnExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "yarn", "1.22.5");
assertTrue(dependencyGraph.hasDependency(yarnExternalId));
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method testIncludeDevDependencies.
@Test
void testIncludeDevDependencies() throws MissingExternalIdException {
YarnLockResult yarnLockResult = buildTestYarnLockResult(noWorkspaces, noWorkspaces, false);
List<CodeLocation> codeLocations = createTransformer().generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
assertEquals(1, codeLocations.size());
CodeLocation codeLocation = codeLocations.get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
assertEquals(2, dependencyGraph.getRootDependencies().size());
ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
assertTrue(dependencyGraph.hasDependency(fooExternalId));
assertTrue(dependencyGraph.getRootDependencies().stream().map(Dependency::getExternalId).anyMatch(fooExternalId::equals));
ExternalId barExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "bar", "1.0");
assertTrue(dependencyGraph.hasDependency(barExternalId));
assertTrue(dependencyGraph.getRootDependencies().stream().map(Dependency::getExternalId).anyMatch(barExternalId::equals));
ExternalId yarnExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "yarn", "1.22.5");
assertTrue(dependencyGraph.hasDependency(yarnExternalId));
}
Aggregations