use of com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspace 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.detectables.xcode.model.XcodeWorkspace in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceFormatCheckerTest method compatibilityTest.
@ParameterizedTest
@MethodSource("knownFileFormats")
void compatibilityTest(String knownVersion) {
XcodeWorkspaceFormatChecker formatChecker = new XcodeWorkspaceFormatChecker();
XcodeWorkspace xcodeWorkspace = new XcodeWorkspace(knownVersion, Collections.emptyList());
assertTrue(formatChecker.checkForVersionCompatibility(xcodeWorkspace));
}
use of com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspace in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceFormatCheckerTest method incompatibilityTest.
@Test
void incompatibilityTest() {
XcodeWorkspaceFormatChecker formatChecker = new XcodeWorkspaceFormatChecker();
String unknownVersion = "some unknown version";
XcodeWorkspace xcodeWorkspace = new XcodeWorkspace(unknownVersion, Collections.emptyList());
assertFalse(formatChecker.checkForVersionCompatibility(xcodeWorkspace));
}
use of com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspace in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceParser method parse.
public XcodeWorkspace parse(String workspaceDataXmlContents) throws IOException, SAXException, ParserConfigurationException, DOMException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource workspaceInputSource = new InputSource(new StringReader(workspaceDataXmlContents.trim()));
Document workspaceDocument = builder.parse(workspaceInputSource);
Node workspaceNode = XmlUtil.getNode("Workspace", workspaceDocument);
Optional<String> formatVersion = XmlUtil.getAttributeSafetly("version", workspaceNode, logger);
List<Node> fileRefs = XmlUtil.getNodeList("FileRef", workspaceNode);
List<XcodeFileReference> xcodeFileReferences = fileRefs.stream().map(fileRefsNode -> XmlUtil.getAttributeSafetly("location", fileRefsNode, logger)).filter(Optional::isPresent).map(Optional::get).map(this::parseReference).collect(Collectors.toList());
return new XcodeWorkspace(formatVersion.orElse("UNKNOWN"), xcodeFileReferences);
}
use of com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspace in project synopsys-detect by blackducksoftware.
the class XcodeWorkspaceParserTest method parse.
@Test
void parse() throws IOException, ParserConfigurationException, SAXException {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
String workspaceContents = StringUtils.joinWith(System.lineSeparator(), " <?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<Workspace", " version = \"1.0\">", " <FileRef", " location = \"group:ENA/ENASecurity\">", " </FileRef>", " <FileRef", " location = \"group:ENA/HealthCertificateToolkit\">", " </FileRef>", " <FileRef", " location = \"group:ENA/ENA.xcodeproj\">", " </FileRef>", "</Workspace>");
XcodeWorkspaceParser parser = new XcodeWorkspaceParser();
XcodeWorkspace xcodeWorkspace = parser.parse(workspaceContents);
XcodeFileReference enaSecurity = assertReferenceExists(xcodeWorkspace, "ENA/ENASecurity");
assertEquals(FileReferenceType.DIRECTORY, enaSecurity.getFileReferenceType());
XcodeFileReference healthToolkit = assertReferenceExists(xcodeWorkspace, "ENA/HealthCertificateToolkit");
assertEquals(FileReferenceType.DIRECTORY, healthToolkit.getFileReferenceType());
XcodeFileReference xcodeProject = assertReferenceExists(xcodeWorkspace, "ENA/ENA.xcodeproj");
assertEquals(FileReferenceType.XCODE_PROJECT, xcodeProject.getFileReferenceType());
assertEquals(3, xcodeWorkspace.getFileReferences().size(), "There are more file references than are being asserted against");
}
Aggregations