use of com.synopsys.integration.detectable.detectable.result.FailedDetectableResult in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceDetectable method extract.
@Override
public Extraction extract(ExtractionEnvironment extractionEnvironment) throws IOException, ParserConfigurationException, SAXException {
List<CodeLocation> codeLocations = new LinkedList<>();
if (foundPackageResolvedFile != null) {
PackageResolvedResult localResult = packageResolvedExtractor.extract(foundPackageResolvedFile);
Optional<FailedDetectableResult> failedDetectableResult = localResult.getFailedDetectableResult();
if (failedDetectableResult.isPresent()) {
return Extraction.failure(failedDetectableResult.get());
}
codeLocations.add(new CodeLocation(localResult.getDependencyGraph(), environment.getDirectory()));
}
if (foundWorkspaceDataFile != null) {
XcodeWorkspaceResult xcodeWorkspaceResult = xcodeWorkspaceExtractor.extract(foundWorkspaceDataFile, workspaceDirectory);
if (xcodeWorkspaceResult.isFailure()) {
return Extraction.failure(xcodeWorkspaceResult.getFailedDetectableResults());
}
codeLocations.addAll(xcodeWorkspaceResult.getCodeLocations());
}
return Extraction.success(codeLocations);
}
use of com.synopsys.integration.detectable.detectable.result.FailedDetectableResult in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceExtractor method extract.
public XcodeWorkspaceResult extract(File workspaceDataFile, File workspaceDirectory) throws IOException, ParserConfigurationException, SAXException {
String workspaceFileContents = FileUtils.readFileToString(workspaceDataFile, Charset.defaultCharset());
XcodeWorkspace xcodeWorkspace = xcodeWorkspaceParser.parse(workspaceFileContents);
xcodeWorkspaceFormatChecker.checkForVersionCompatibility(xcodeWorkspace);
List<CodeLocation> codeLocations = new LinkedList<>();
List<FailedDetectableResult> failedDetectableResults = new LinkedList<>();
for (XcodeFileReference fileReference : xcodeWorkspace.getFileReferences()) {
File workspaceReferencedDirectory = workspaceDirectory.getParentFile().toPath().resolve(fileReference.getRelativeLocation()).toFile();
if (!workspaceReferencedDirectory.exists()) {
logger.warn("Failed to find subproject '{}' as defined in the workspace at '{}'", workspaceReferencedDirectory, workspaceDataFile.getParentFile().getAbsolutePath());
continue;
}
switch(fileReference.getFileReferenceType()) {
case DIRECTORY:
PackageResolvedResult swiftProjectResult = extractStandalonePackageResolved(workspaceReferencedDirectory);
swiftProjectResult.getFailedDetectableResult().ifPresent(failedDetectableResults::add);
codeLocations.add(new CodeLocation(swiftProjectResult.getDependencyGraph(), workspaceReferencedDirectory));
break;
case XCODE_PROJECT:
PackageResolvedResult xcodeProjectResult = extractFromXcodeProject(workspaceReferencedDirectory);
xcodeProjectResult.getFailedDetectableResult().ifPresent(failedDetectableResults::add);
codeLocations.add(new CodeLocation(xcodeProjectResult.getDependencyGraph(), workspaceReferencedDirectory));
break;
default:
throw new UnsupportedOperationException(String.format("Unrecognized FileReferenceType: %s", fileReference.getFileReferenceType()));
}
}
if (CollectionUtils.isNotEmpty(failedDetectableResults)) {
return XcodeWorkspaceResult.failure(failedDetectableResults);
}
return XcodeWorkspaceResult.success(codeLocations);
}
use of com.synopsys.integration.detectable.detectable.result.FailedDetectableResult in project synopsys-detect by blackducksoftware.
the class ApplicableEvaluatorTest method createEvaluationMocks.
private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean alreadyApplicable, boolean searchable) {
DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
Mockito.when(detectorEvaluation.isApplicable()).thenReturn(alreadyApplicable);
Mockito.when(detectorEvaluation.isSearchable()).thenReturn(searchable);
Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
Predicate<DetectorRule> rulePredicate = it -> true;
Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
Detectable detectable = Mockito.mock(Detectable.class);
Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
Mockito.when(detectable.applicable()).thenReturn(new FailedDetectableResult());
return detectorEvaluation;
}
Aggregations