use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class SbtResolutionCacheExtractor method extract.
public Extraction extract(File directory, SbtResolutionCacheOptions sbtResolutionCacheOptions) {
// TODO: Extractor should not use DetectableOptions
try {
// TODO: Handle null better.
List<String> included = sbtResolutionCacheOptions.getIncludedConfigurations();
List<String> excluded = sbtResolutionCacheOptions.getExcludedConfigurations();
int depth = sbtResolutionCacheOptions.getReportDepth();
SbtProject project = extractProject(directory, sbtResolutionCacheOptions.isFollowSymLinks(), depth, included, excluded);
List<CodeLocation> codeLocations = new ArrayList<>();
String projectName = null;
String projectVersion = null;
for (SbtDependencyModule module : project.getModules()) {
CodeLocation codeLocation;
if (project.getProjectExternalId() != null) {
codeLocation = new CodeLocation(module.getGraph(), project.getProjectExternalId());
} else {
codeLocation = new CodeLocation(module.getGraph());
}
if (projectName == null) {
projectName = project.getProjectName();
projectVersion = project.getProjectVersion();
}
codeLocations.add(codeLocation);
}
if (codeLocations.size() > 0) {
return new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
} else {
logger.error("Unable to find any dependency information.");
return new Extraction.Builder().failure("Unable to find any dependency information.").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 GemspecParseExtractor method extract.
public Extraction extract(File gemspec) {
try (InputStream inputStream = new FileInputStream(gemspec)) {
DependencyGraph dependencyGraph = gemspecParser.parse(inputStream);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
} catch (IOException 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 PipInspectorExtractor method extract.
public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipExe, File pipInspector, File setupFile, List<Path> requirementFilePaths, String providedProjectName) {
toolVersionLogger.log(directory, pythonExe);
toolVersionLogger.log(directory, pipExe);
Extraction extractionResult;
try {
String projectName = getProjectName(directory, pythonExe, setupFile, providedProjectName);
List<CodeLocation> codeLocations = new ArrayList<>();
String projectVersion = null;
List<Path> requirementsPaths = new ArrayList<>();
if (requirementFilePaths.isEmpty()) {
requirementsPaths.add(null);
} else {
requirementsPaths.addAll(requirementFilePaths);
}
for (Path requirementFilePath : requirementsPaths) {
List<String> inspectorOutput = runInspector(directory, pythonExe, pipInspector, projectName, requirementFilePath);
Optional<NameVersionCodeLocation> result = pipInspectorTreeParser.parse(inspectorOutput, directory.toString());
if (result.isPresent()) {
codeLocations.add(result.get().getCodeLocation());
String potentialProjectVersion = result.get().getProjectVersion();
if (projectVersion == null && StringUtils.isNotBlank(potentialProjectVersion)) {
projectVersion = potentialProjectVersion;
}
}
}
if (codeLocations.isEmpty()) {
extractionResult = new Extraction.Builder().failure("The Pip Inspector tree parse failed to produce output.").build();
} else {
extractionResult = new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
}
} catch (Exception e) {
extractionResult = new Extraction.Builder().exception(e).build();
}
return extractionResult;
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PipfileLockExtractor method extract.
public Extraction extract(File pipfileLockFile) throws IOException {
String pipfileLockText = FileUtils.readFileToString(pipfileLockFile, StandardCharsets.UTF_8);
PipfileLock pipfileLock = gson.fromJson(pipfileLockText, PipfileLock.class);
List<PipfileLockDependency> dependencies = pipfileLockTransformer.transform(pipfileLock);
DependencyGraph dependencyGraph = pipfileLockDependencyTransformer.transform(dependencies);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
// No project info - hoping git can help with that.
return Extraction.success(codeLocation);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PackageJsonExtractorFunctionalTest method extractWithDevDependencies.
@Test
void extractWithDevDependencies() {
Extraction extraction = createExtractor(NpmDependencyType.PEER).extract(packageJsonInputStream);
assertEquals(1, extraction.getCodeLocations().size());
CodeLocation codeLocation = extraction.getCodeLocations().get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
graphAssert.hasRootDependency(testDep1);
graphAssert.hasRootDependency(testDep2);
graphAssert.hasRootDependency(testDevDep1);
graphAssert.hasRootDependency(testDevDep2);
graphAssert.hasNoDependency(testPeerDep1);
graphAssert.hasNoDependency(testPeerDep2);
graphAssert.hasRootSize(4);
}
Aggregations