use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ArtifactoryGradleInspectorResolver method resolveGradleInspector.
@Override
public File resolveGradleInspector() throws DetectableException {
if (!hasResolvedInspector) {
hasResolvedInspector = true;
try {
Optional<File> airGapPath = airGapInspectorPaths.getGradleInspectorAirGapFile();
File generatedGradleScriptFile = directoryManager.getSharedFile(GRADLE_DIR_NAME, GENERATED_GRADLE_SCRIPT_NAME);
GradleInspectorScriptCreator gradleInspectorScriptCreator = new GradleInspectorScriptCreator(configuration);
if (airGapPath.isPresent()) {
generatedGradleScriptPath = gradleInspectorScriptCreator.createOfflineGradleInspector(generatedGradleScriptFile, gradleInspectorScriptOptions, airGapPath.get().getCanonicalPath());
} else {
generatedGradleScriptPath = gradleInspectorScriptCreator.createOnlineGradleInspector(generatedGradleScriptFile, gradleInspectorScriptOptions);
}
} catch (Exception e) {
throw new DetectableException(e);
}
if (generatedGradleScriptPath == null) {
throw new DetectableException("Unable to initialize the gradle inspector.");
} else {
logger.trace(String.format("Derived generated gradle script path: %s", generatedGradleScriptPath));
}
} else {
logger.debug("Already attempted to resolve the gradle inspector script, will not attempt again.");
}
if (generatedGradleScriptPath == null) {
throw new DetectableException("Unable to find or create the gradle inspector script.");
}
return generatedGradleScriptPath;
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class DetectableTool method extract.
public DetectableToolResult extract() {
// TODO: Move docker/bazel out of detectable and drop this notion of a detctable tool. Will simplify this logic and make this unneccessary.
DetectableResult extractable;
try {
extractable = detectable.extractable();
} catch (DetectableException e) {
extractable = new ExceptionDetectableResult(e);
}
if (!extractable.getPassed()) {
logger.error(String.format("Was not extractable: %s", extractable.toDescription()));
statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", Arrays.asList(extractable.toDescription())));
statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_GENERAL_ERROR, extractable.toDescription());
return DetectableToolResult.failed(extractable);
}
logger.debug("Extractable passed.");
ExtractionEnvironment extractionEnvironment = extractionEnvironmentProvider.createExtractionEnvironment(name);
Extraction extraction;
try {
extraction = detectable.extract(extractionEnvironment);
} catch (ExecutableFailedException | ExecutableRunnerException | JsonSyntaxException | IOException | CycleDetectedException | DetectableException | MissingExternalIdException | ParserConfigurationException | SAXException e) {
extraction = new Extraction.Builder().exception(e).build();
}
if (!extraction.isSuccess()) {
logger.error("Extraction was not success.");
List<String> errorMessages = collectErrorMessages(extraction);
statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", errorMessages));
statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extraction.getDescription()));
return DetectableToolResult.failed();
} else {
logger.debug("Extraction success.");
statusEventPublisher.publishStatusSummary(new Status(name, StatusType.SUCCESS));
}
Map<CodeLocation, DetectCodeLocation> detectCodeLocationMap = codeLocationConverter.toDetectCodeLocation(sourcePath, extraction, sourcePath, name);
List<DetectCodeLocation> detectCodeLocations = new ArrayList<>(detectCodeLocationMap.values());
DockerTargetData dockerTargetData = DockerTargetData.fromExtraction(extraction);
DetectToolProjectInfo projectInfo = null;
if (StringUtils.isNotBlank(extraction.getProjectName()) || StringUtils.isNotBlank(extraction.getProjectVersion())) {
NameVersion nameVersion = new NameVersion(extraction.getProjectName(), extraction.getProjectVersion());
projectInfo = new DetectToolProjectInfo(detectTool, nameVersion);
}
logger.debug("Tool finished.");
return DetectableToolResult.success(detectCodeLocations, projectInfo, dockerTargetData);
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class NugetInspectorExecutableLocator method findExecutable.
@Nullable
public File findExecutable(File extractedZip, String executableName) throws DetectableException {
logger.debug("Looking for '" + executableName + "' in " + extractedZip.toString());
File executable = new File(extractedZip, executableName);
if (executable.exists()) {
logger.debug("Found it: " + executable);
if (!executable.canExecute() && !executable.setExecutable(true)) {
throw new DetectableException("Unable to set project inspector to executable: " + executable);
}
return executable;
} else {
logger.debug("Could not find executable: " + executable);
return null;
}
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ConanCodeLocationGenerator method generateCodeLocationFromNodeMap.
@NotNull
public ConanDetectableResult generateCodeLocationFromNodeMap(ExternalIdFactory externalIdFactory, Map<String, ConanNode<String>> nodes) throws DetectableException {
logger.debug("Generating code location from {} dependencies", nodes.keySet().size());
Optional<ConanNode<String>> rootNode = getRoot(nodes.values());
if (!rootNode.isPresent()) {
throw new DetectableException("No root node found");
}
ConanGraphNode rootGraphNode = new ConanGraphNode(rootNode.get());
populateGraphUnderNode(rootGraphNode, nodes);
DependencyGraph dependencyGraph = new BasicDependencyGraph();
CodeLocation codeLocation = generateCodeLocationFromConanGraph(externalIdFactory, dependencyGraph, rootGraphNode);
return new ConanDetectableResult(rootGraphNode.getConanNode().getName().orElse(null), rootGraphNode.getConanNode().getVersion().orElse(null), codeLocation);
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class SbtDotExtractor method extract.
public Extraction extract(File directory, ExecutableTarget sbt, String sbtCommandAdditionalArguments) {
try {
List<String> sbtArgs = sbtCommandArgumentGenerator.generateSbtCmdArgs(sbtCommandAdditionalArguments, "dependencyDot");
Executable dotExecutable = ExecutableUtils.createFromTarget(directory, sbt, sbtArgs);
ExecutableOutput dotOutput = executableRunner.executeSuccessfully(dotExecutable);
List<File> dotGraphs = sbtDotOutputParser.parseGeneratedGraphFiles(dotOutput.getStandardOutputAsList());
Extraction.Builder extraction = new Extraction.Builder();
for (File dotGraph : dotGraphs) {
GraphParser graphParser = new GraphParser(FileUtils.openInputStream(dotGraph));
Set<String> rootIDs = sbtRootNodeFinder.determineRootIDs(graphParser);
// typically found in project-folder/target/<>.dot so .parent.parent == project folder
File projectFolder = dotGraph.getParentFile().getParentFile();
if (rootIDs.size() == 1) {
String projectId = rootIDs.stream().findFirst().get();
DependencyGraph graph = sbtGraphParserTransformer.transformDotToGraph(graphParser, projectId);
Dependency projectDependency = graphNodeParser.nodeToDependency(projectId);
extraction.codeLocations(new CodeLocation(graph, projectDependency.getExternalId(), projectFolder));
if (projectFolder.equals(directory)) {
extraction.projectName(projectDependency.getName());
extraction.projectVersion(projectDependency.getVersion());
}
} else {
logger.warn("Unable to determine which node was the project in an SBT graph: " + dotGraph.toString());
logger.warn("This may mean you have extraneous dependencies and should consider removing them. The dependencies are: " + String.join(",", rootIDs));
DependencyGraph graph = sbtGraphParserTransformer.transformDotToGraph(graphParser, rootIDs);
extraction.codeLocations(new CodeLocation(graph, projectFolder));
}
}
return extraction.success().build();
} catch (IOException | DetectableException | ExecutableFailedException e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations