use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class PearCliExtractor method extract.
public Extraction extract(final File directory, final File pearExe, final ExtractionId extractionId) {
try {
File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
final ExecutableOutput pearListing = executableRunner.execute(workingDirectory, pearExe, "list");
final ExecutableOutput pearDependencies = executableRunner.execute(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME);
// TODO: Why is this done here?
final File packageFile = detectFileFinder.findFile(directory, PACKAGE_XML_FILENAME);
final PearParseResult result = pearParser.parse(packageFile, pearListing, pearDependencies);
final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PEAR, result.name, result.version);
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PEAR, directory.toString(), id, result.dependencyGraph).build();
return new Extraction.Builder().success(detectCodeLocation).projectName(result.name).projectVersion(result.version).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 PipenvGraphParser method parse.
public PipParseResult parse(final String projectName, final String projectVersionName, final List<String> pipFreezeOutput, final List<String> pipenvGraphOutput, final String sourcePath) {
final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph();
final Stack<Dependency> dependencyStack = new Stack<>();
final Map<String, String[]> pipFreezeMap = pipFreezeOutput.stream().map(line -> line.split(TOP_LEVEL_SEPARATOR)).filter(splitLine -> splitLine.length == 2).collect(Collectors.toMap(splitLine -> splitLine[0].trim().toLowerCase(), splitLine -> splitLine));
int lastLevel = -1;
for (final String line : pipenvGraphOutput) {
final int currentLevel = getLevel(line);
final Optional<Dependency> parsedDependency = getDependencyFromLine(pipFreezeMap, line);
if (!parsedDependency.isPresent()) {
continue;
}
final Dependency dependency = parsedDependency.get();
if (currentLevel == lastLevel) {
dependencyStack.pop();
} else {
for (; lastLevel >= currentLevel; lastLevel--) {
dependencyStack.pop();
}
}
if (dependencyStack.size() > 0) {
dependencyGraph.addChildWithParent(dependency, dependencyStack.peek());
} else {
dependencyGraph.addChildrenToRoot(dependency);
}
lastLevel = currentLevel;
dependencyStack.push(dependency);
}
if (!dependencyGraph.getRootDependencyExternalIds().isEmpty()) {
final ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, projectExternalId, dependencyGraph).build();
return new PipParseResult(projectName, projectVersionName, codeLocation);
} else {
return null;
}
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class PipInspectorTreeParser method parse.
public Optional<PipParseResult> parse(final List<String> pipInspectorOutputAsList, final String sourcePath) {
PipParseResult parseResult = null;
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
Dependency project = null;
for (final String line : pipInspectorOutputAsList) {
final String trimmedLine = StringUtils.trimToEmpty(line);
if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR) || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
parseErrorsFromLine(trimmedLine);
continue;
}
final Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
final int lineLevel = getLineLevel(trimmedLine);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (project == null) {
project = currentDependency;
} else if (project.equals(history.getLastDependency())) {
graph.addChildToRoot(currentDependency);
} else if (history.isEmpty()) {
graph.addChildToRoot(currentDependency);
} else {
graph.addChildWithParents(currentDependency, history.getLastDependency());
}
history.add(currentDependency);
}
if (project != null) {
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, project.externalId, graph).build();
parseResult = new PipParseResult(project.name, project.version, codeLocation);
}
return Optional.ofNullable(parseResult);
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class NugetInspectorPackager method createDetectCodeLocationFromNugetContainer.
private Optional<NugetParseResult> createDetectCodeLocationFromNugetContainer(final NugetContainer nugetContainer) {
final NugetParseResult parseResult;
String projectName = "";
String projectVersionName = "";
if (NugetContainerType.SOLUTION == nugetContainer.type) {
projectName = nugetContainer.name;
projectVersionName = nugetContainer.version;
final List<DetectCodeLocation> codeLocations = new ArrayList<>();
for (final NugetContainer container : nugetContainer.children) {
final NugetDependencyNodeBuilder builder = new NugetDependencyNodeBuilder(externalIdFactory);
builder.addPackageSets(container.packages);
final DependencyGraph children = builder.createDependencyGraph(container.dependencies);
final String sourcePath = container.sourcePath;
if (StringUtils.isBlank(projectVersionName)) {
projectVersionName = container.version;
}
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NUGET, sourcePath, externalIdFactory.createNameVersionExternalId(Forge.NUGET, projectName, projectVersionName), children).build();
codeLocations.add(codeLocation);
}
parseResult = new NugetParseResult(projectName, projectVersionName, codeLocations);
} else if (NugetContainerType.PROJECT == nugetContainer.type) {
projectName = nugetContainer.name;
projectVersionName = nugetContainer.version;
final String sourcePath = nugetContainer.sourcePath;
final NugetDependencyNodeBuilder builder = new NugetDependencyNodeBuilder(externalIdFactory);
builder.addPackageSets(nugetContainer.packages);
final DependencyGraph children = builder.createDependencyGraph(nugetContainer.dependencies);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NUGET, sourcePath, externalIdFactory.createNameVersionExternalId(Forge.NUGET, projectName, projectVersionName), children).build();
parseResult = new NugetParseResult(projectName, projectVersionName, codeLocation);
} else {
parseResult = null;
}
return Optional.ofNullable(parseResult);
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class BazelCodeLocationBuilder method build.
public List<DetectCodeLocation> build() {
Forge forge = new Forge("/", "/", "DETECT");
final ExternalId externalId = externalIdFactory.createPathExternalId(forge, workspaceDir.toString());
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.BAZEL, workspaceDir.toString(), externalId, dependencyGraph).build();
List<DetectCodeLocation> codeLocations = new ArrayList<>(1);
codeLocations.add(codeLocation);
return codeLocations;
}
Aggregations