private Node createProjectHierarchy(ScannerReport.Component rootComponent) { Preconditions.checkArgument(rootComponent.getType() == ScannerReport.Component.ComponentType.PROJECT, "Expected root component of type 'PROJECT'"); LinkedList<ScannerReport.Component> queue = new LinkedList<>(); rootComponent.getChildRefList() .stream() .map(scannerComponentSupplier) .forEach(queue::addLast); Node root = new Node(); root.reportComponent = rootComponent; while (!queue.isEmpty()) { ScannerReport.Component component = queue.removeFirst(); switch (component.getType()) { case FILE: addFile(root, component); break; case MODULE: case DIRECTORY: issueRelocationToRoot.relocate(rootComponent, component); component.getChildRefList().stream() .map(scannerComponentSupplier) .forEach(queue::addLast); break; default: throw new IllegalArgumentException(format("Unsupported component type '%s'", component.getType())); } } return root; }
/** * This should only be needed if we receive a report of the previous version without the path per module explicitly set * (due to blue/green deployment) * Can be removed in any future version */ private Map<String, String> collectModulesPathFromHierarchy(ScannerReport.Metadata metadata) { ScannerReport.Component root = reader.readComponent(metadata.getRootComponentRef()); Map<String, String> modulesPathByKey = new LinkedHashMap<>(); LinkedList<Integer> queue = new LinkedList<>(); queue.addAll(root.getChildRefList()); while (!queue.isEmpty()) { ScannerReport.Component component = reader.readComponent(queue.removeFirst()); if (component.getType() == ScannerReport.Component.ComponentType.MODULE) { queue.addAll(component.getChildRefList()); modulesPathByKey.put(component.getKey(), component.getProjectRelativePath()); } } return modulesPathByKey; }
private static String getNodeName(Component component) { switch (component.getType()) { case PROJECT: case MODULE: return component.getName(); case DIRECTORY: case FILE: return component.getProjectRelativePath(); default: throw new IllegalArgumentException("Unknow component type: " + component.getType()); } }
private ComponentImpl buildComponent(ScannerReport.Component component, ScannerReport.Component closestModule, @Nullable String scmBasePath) { switch (component.getType()) { case PROJECT: String projectKey = keyGenerator.generateKey(component, null); String key = keyGenerator.generateKey(closestModule, component); String publicKey = publicKeyGenerator.generateKey(closestModule, component); return ComponentImpl.builder(convertDirOrFileType(component.getType())) .setUuid(uuidSupplier.apply(key)) .setKey(key) throw new IllegalArgumentException(format("Unsupported component type '%s'", component.getType()));
@CheckForNull private static FileAttributes createFileAttributes(ScannerReport.Component component) { if (component.getType() != ScannerReport.Component.ComponentType.FILE) { return null; } checkArgument(component.getLines() > 0, "File '%s' has no line", component.getPath()); return new FileAttributes( component.getIsTest(), trimToNull(component.getLanguage()), component.getLines()); }
private static String getNodeName(Component component) { switch (component.getType()) { case PROJECT: case MODULE: return component.getName(); case DIRECTORY: case FILE: return component.getProjectRelativePath(); default: throw new IllegalArgumentException("Unknow component type: " + component.getType()); } }
private static FileAttributes createFileAttributes(ScannerReport.Component component) { checkArgument(component.getType() == ScannerReport.Component.ComponentType.FILE); checkArgument(component.getLines() > 0, "File '%s' has no line", component.getProjectRelativePath()); return new FileAttributes( component.getIsTest(), trimToNull(component.getLanguage()), component.getLines()); }
private Component buildComponent(Node node, String currentPath, String parentPath) { List<Component> childComponents = buildChildren(node, currentPath); ScannerReport.Component component = node.reportComponent(); if (component != null) { if (component.getType() == ScannerReport.Component.ComponentType.FILE) { return buildFile(component); } else if (component.getType() == ScannerReport.Component.ComponentType.PROJECT) { return buildProject(childComponents); } } return buildDirectory(parentPath, currentPath, childComponents); }