use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class CodeLocationAssembler method generateCodeLocation.
public DetectCodeLocation generateCodeLocation(final Forge defaultForge, final File rootDir, final List<Dependency> bdioComponents) {
final MutableDependencyGraph dependencyGraph = populateGraph(bdioComponents);
final ExternalId externalId = externalIdFactory.createPathExternalId(defaultForge, rootDir.toString());
return new DetectCodeLocation.Builder(DetectCodeLocationType.CLANG, rootDir.toString(), externalId, dependencyGraph).build();
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class Rebar3TreeParser method parseRebarTreeOutput.
public RebarParseResult parseRebarTreeOutput(final List<String> dependencyTreeOutput, final String sourcePath) {
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
Dependency project = null;
for (final String line : dependencyTreeOutput) {
if (!line.contains(HORIZONTAL_SEPARATOR_CHARACTER)) {
continue;
}
final Dependency currentDependency = createDependencyFromLine(line);
final int lineLevel = getDependencyLevelFromLine(line);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (history.isEmpty() && isProject(line)) {
project = currentDependency;
} else if (history.getLastDependency().equals(project)) {
graph.addChildToRoot(currentDependency);
} else if (history.isEmpty()) {
graph.addChildToRoot(currentDependency);
} else {
graph.addChildWithParents(currentDependency, history.getLastDependency());
}
history.add(currentDependency);
}
if (project == null) {
final ExternalId projectExternalId = externalIdFactory.createPathExternalId(Forge.HEX, sourcePath);
project = new Dependency("", "", projectExternalId);
}
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.HEX, project.name, project.version);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.HEX, sourcePath, externalId, graph).build();
return new RebarParseResult(project.name, project.version, codeLocation);
}
use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.
the class RebarExtractor method extract.
public Extraction extract(final File directory, final File rebarExe) {
try {
final List<DetectCodeLocation> codeLocations = new ArrayList<>();
final Map<String, String> envVars = new HashMap<>();
envVars.put("REBAR_COLOR", "none");
final List<String> arguments = new ArrayList<>();
arguments.add("tree");
final Executable rebar3TreeExe = new Executable(directory, envVars, rebarExe.toString(), arguments);
final List<String> output = executableRunner.execute(rebar3TreeExe).getStandardOutputAsList();
final RebarParseResult parseResult = rebarTreeParser.parseRebarTreeOutput(output, directory.toString());
codeLocations.add(parseResult.getCodeLocation());
return new Extraction.Builder().success(codeLocations).projectName(parseResult.getProjectName()).projectVersion(parseResult.getProjectVersion()).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 MavenCliExtractor method extract.
public Extraction extract(final File directory, final String mavenExe) {
try {
String mavenCommand = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_BUILD_COMMAND, PropertyAuthority.None);
if (StringUtils.isNotBlank(mavenCommand)) {
mavenCommand = mavenCommand.replace("dependency:tree", "");
if (StringUtils.isNotBlank(mavenCommand)) {
mavenCommand = mavenCommand.trim();
}
}
final List<String> arguments = new ArrayList<>();
if (StringUtils.isNotBlank(mavenCommand)) {
arguments.addAll(Arrays.asList(mavenCommand.split(" ")));
}
arguments.add("dependency:tree");
final Executable mvnExecutable = new Executable(directory, mavenExe, arguments);
final ExecutableOutput mvnOutput = executableRunner.execute(mvnExecutable);
if (mvnOutput.getReturnCode() == 0) {
final String mavenScope = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_SCOPE, PropertyAuthority.None);
final String excludedModules = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_EXCLUDED_MODULES, PropertyAuthority.None);
final String includedModules = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_INCLUDED_MODULES, PropertyAuthority.None);
final List<MavenParseResult> mavenResults = mavenCodeLocationPackager.extractCodeLocations(directory.toString(), mvnOutput.getStandardOutput(), mavenScope, excludedModules, includedModules);
final List<DetectCodeLocation> codeLocations = mavenResults.stream().map(it -> it.codeLocation).collect(Collectors.toList());
final Optional<MavenParseResult> firstWithName = mavenResults.stream().filter(it -> StringUtils.isNoneBlank(it.projectName)).findFirst();
final Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
if (firstWithName.isPresent()) {
builder.projectName(firstWithName.get().projectName);
builder.projectVersion(firstWithName.get().projectVersion);
}
return builder.build();
} else {
final Extraction.Builder builder = new Extraction.Builder().failure(String.format("Executing command '%s' returned a non-zero exit code %s", String.join(" ", arguments), mvnOutput.getReturnCode()));
return builder.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 GoDepExtractor method extract.
public Extraction extract(final File directory, final File goExe, final String goDepInspector) {
try {
DependencyGraph graph = depPackager.makeDependencyGraph(directory.toString(), goDepInspector);
if (graph == null) {
graph = new MutableMapDependencyGraph();
}
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_DEP, directory.toString(), externalId, graph).build();
return new Extraction.Builder().success(detectCodeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations