/** * 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; }
@Test public void publish_project_without_version_and_name() throws IOException { ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); ProjectDefinition rootDef = ProjectDefinition.create() .setKey("foo") .setDescription("Root description") .setBaseDir(temp.newFolder()) .setWorkDir(temp.newFolder()); DefaultInputProject project = new DefaultInputProject(rootDef, 1); InputComponentStore store = new InputComponentStore(branchConfiguration); ComponentsPublisher publisher = new ComponentsPublisher(project, store); publisher.publish(writer); assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); ScannerReportReader reader = new ScannerReportReader(outputDir); Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getName()).isEqualTo(""); assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); assertThat(rootProtobuf.getVersion()).isEqualTo(""); assertThat(rootProtobuf.getLinkCount()).isEqualTo(0); }
@Test public void should_set_modified_name_with_branch() throws IOException { ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); ProjectDefinition rootDef = ProjectDefinition.create() .setKey("foo") .setDescription("Root description") .setBaseDir(temp.newFolder()) .setWorkDir(temp.newFolder()) .setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch"); DefaultInputProject project = new DefaultInputProject(rootDef, 1); InputComponentStore store = new InputComponentStore(branchConfiguration); ComponentsPublisher publisher = new ComponentsPublisher(project, store); publisher.publish(writer); Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getName()).isEqualTo("foo my_branch"); }
private void validateBatchKey(Component rawComponent) { String batchKey = reportReader.readComponent(rawComponent.getReportAttributes().getRef()).getKey(); if (!ComponentKeys.isValidModuleKey(batchKey)) { validationMessages.add(format("\"%s\" is not a valid project or module key. " + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", batchKey)); } }
@Override public String generateKey(Component module, @Nullable Component component) { String mainBranchKey = component == null ? module.getKey() : ComponentKeys.createEffectiveKey(module.getKey(), StringUtils.trimToNull(component.getPath())); return main ? mainBranchKey : mainBranchKey + ComponentDto.BRANCH_KEY_SEPARATOR + branchName; }
@Override public String generateKey(ScannerReport.Component module, @Nullable ScannerReport.Component fileOrDir) { String moduleWithBranch = module.getKey(); if (isLegacyBranch) { moduleWithBranch = ComponentKeys.createKey(module.getKey(), branchName); } if (fileOrDir == null || isEmpty(fileOrDir.getPath())) { return moduleWithBranch; } return ComponentKeys.createEffectiveKey(moduleWithBranch, trimToNull(fileOrDir.getPath())); } }
assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
private ComponentImpl buildFile(ScannerReport.Component component) { String key = keyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); String publicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); return ComponentImpl.builder(Component.Type.FILE) .setUuid(uuidSupplier.apply(key)) .setDbKey(key) .setKey(publicKey) .setName(component.getProjectRelativePath()) .setShortName(FilenameUtils.getName(component.getProjectRelativePath())) .setStatus(convertStatus(component.getStatus())) .setDescription(trimToNull(component.getDescription())) .setReportAttributes(createAttributesBuilder(component.getRef(), component.getProjectRelativePath(), scmBasePath).build()) .setFileAttributes(createFileAttributes(component)) .build(); }
private Component buildProject(List<Component> children) { String projectKey = keyGenerator.generateKey(rootComponent.getKey(), null); String uuid = uuidSupplier.apply(projectKey); String projectPublicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), null); ComponentImpl.Builder builder = ComponentImpl.builder(Component.Type.PROJECT) .setUuid(uuid) .setDbKey(projectKey) .setKey(projectPublicKey) .setStatus(convertStatus(rootComponent.getStatus())) .setProjectAttributes(new ProjectAttributes(createProjectVersion(rootComponent))) .setReportAttributes(createAttributesBuilder(rootComponent.getRef(), rootComponent.getProjectRelativePath(), scmBasePath).build()) .addChildren(children); setNameAndDescription(rootComponent, builder); return builder.build(); }
private ComponentImpl buildDirectory(String parentPath, String path, List<Component> children) { String key = keyGenerator.generateKey(rootComponent.getKey(), path); String publicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), path); return ComponentImpl.builder(Component.Type.DIRECTORY) .setUuid(uuidSupplier.apply(key)) .setDbKey(key) .setKey(publicKey) .setName(path) .setShortName(removeStart(removeStart(path, parentPath), "/")) .setStatus(convertStatus(FileStatus.UNAVAILABLE)) .setReportAttributes(createAttributesBuilder(null, path, scmBasePath).build()) .addChildren(children) .build(); }