use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class SbtResolutionCacheExtractor method extract.
public Extraction extract(final File directory) {
try {
final String included = detectConfiguration.getProperty(DetectProperty.DETECT_SBT_INCLUDED_CONFIGURATIONS, PropertyAuthority.None);
final String excluded = detectConfiguration.getProperty(DetectProperty.DETECT_SBT_EXCLUDED_CONFIGURATIONS, PropertyAuthority.None);
final int depth = detectConfiguration.getIntegerProperty(DetectProperty.DETECT_SBT_REPORT_DEPTH, PropertyAuthority.None);
final SbtPackager packager = new SbtPackager(externalIdFactory, detectFileFinder);
final SbtProject project = packager.extractProject(directory.getAbsolutePath(), depth, included, excluded);
final List<DetectCodeLocation> codeLocations = new ArrayList<>();
String projectName = null;
String projectVersion = null;
for (final SbtDependencyModule module : project.modules) {
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.SBT, directory.toString(), project.projectExternalId, module.graph).build();
if (projectName == null) {
projectName = project.projectName;
projectVersion = project.projectVersion;
}
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 (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class YarnLockExtractor method extract.
public Extraction extract(final File directory, final File yarnlock, final String yarnExe) {
try {
final List<String> yarnLockText = Files.readAllLines(yarnlock.toPath(), StandardCharsets.UTF_8);
final List<String> exeArgs = Stream.of("list", "--emoji", "false").collect(Collectors.toCollection(ArrayList::new));
if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_YARN_PROD_ONLY, PropertyAuthority.None)) {
exeArgs.add("--prod");
}
final Executable yarnListExe = new Executable(directory, yarnExe, exeArgs);
final ExecutableOutput executableOutput = executableRunner.execute(yarnListExe);
if (executableOutput.getReturnCode() != 0) {
final Extraction.Builder builder = new Extraction.Builder().failure(String.format("Executing command '%s' returned a non-zero exit code %s", String.join(" ", exeArgs), executableOutput.getReturnCode()));
return builder.build();
}
final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(yarnLockText, executableOutput.getStandardOutputAsList());
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.NPM, directory.getCanonicalPath());
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.YARN, directory.getCanonicalPath(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(detectCodeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class NugetInspectorPackager method createDetectCodeLocation.
public NugetParseResult createDetectCodeLocation(final File dependencyNodeFile) throws IOException {
final String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
final NugetInspection nugetInspection = gson.fromJson(text, NugetInspection.class);
final List<DetectCodeLocation> codeLocations = new ArrayList<>();
String projectName = "";
String projectVersion = "";
for (final NugetContainer it : nugetInspection.containers) {
final Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it);
if (possibleParseResult.isPresent()) {
final NugetParseResult result = possibleParseResult.get();
if (StringUtils.isNotBlank(result.projectName)) {
projectName = result.projectName;
projectVersion = result.projectVersion;
}
codeLocations.addAll(result.codeLocations);
}
}
return new NugetParseResult(projectName, projectVersion, codeLocations);
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class GemlockExtractor method extract.
public Extraction extract(final File directory, final File gemlock) {
try {
final List<String> gemlockText = Files.readAllLines(gemlock.toPath(), StandardCharsets.UTF_8);
logger.debug(gemlockText.stream().collect(Collectors.joining("\n")));
final GemlockParser gemlockParser = new GemlockParser(externalIdFactory);
final DependencyGraph dependencyGraph = gemlockParser.parseProjectDependencies(gemlockText);
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.RUBYGEMS, directory.toString());
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.RUBYGEMS, directory.toString(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(codeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations