private static String projectKeyFromReport(ScannerReport.Metadata reportMetadata) { String deprecatedBranch = reportMetadata.getDeprecatedBranch(); if (StringUtils.isNotEmpty(deprecatedBranch)) { return ComponentKeys.createKey(reportMetadata.getProjectKey(), deprecatedBranch); } return reportMetadata.getProjectKey(); }
@Test public void scanMultiModuleWithBranch() throws IOException { Path srcDir = baseDir.toPath().resolve("moduleA").resolve("src"); Files.createDirectories(srcDir); File xooFile = new File(srcDir.toFile(), "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "branch") .put("sonar.modules", "moduleA") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("moduleA/src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA/src/sample.xoo"); // no branch in the report DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("moduleA/src/sample.xoo"); assertThat(result.getReportReader().readComponent(inputfile.scannerId()).getProjectRelativePath()).isEqualTo("moduleA/src/sample.xoo"); assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch"); result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "") .put("sonar.modules", "moduleA") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("moduleA/src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA/src/sample.xoo"); }
@Test public void write_project_branch() throws Exception { when(cpdSettings.isCrossProjectDuplicationEnabled()).thenReturn(false); ProjectDefinition projectDef = ProjectDefinition.create() .setKey("foo") .setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "myBranch"); createPublisher(projectDef); File outputDir = temp.newFolder(); ScannerReportWriter writer = new ScannerReportWriter(outputDir); underTest.publish(writer); ScannerReportReader reader = new ScannerReportReader(outputDir); ScannerReport.Metadata metadata = reader.readMetadata(); assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L); assertThat(metadata.getProjectKey()).isEqualTo("root"); assertThat(metadata.getDeprecatedBranch()).isEqualTo("myBranch"); assertThat(metadata.getCrossProjectDuplicationActivated()).isFalse(); }
public void load(ScannerReport.Metadata metadata) { String deprecatedBranch = trimToNull(metadata.getDeprecatedBranch()); String branchName = trimToNull(metadata.getBranchName()); if (deprecatedBranch != null && branchName != null) { throw MessageException.of("Properties sonar.branch and sonar.branch.name can't be set together"); } if (delegate != null && deprecatedBranch == null) { delegate.load(metadata); } else { metadataHolder.setBranch(new DefaultBranchImpl(deprecatedBranch)); } } }
private static String projectKeyFromReport(ScannerReport.Metadata reportMetadata) { String deprecatedBranch = reportMetadata.getDeprecatedBranch(); if (StringUtils.isNotEmpty(deprecatedBranch)) { return ComponentKeys.createKey(reportMetadata.getProjectKey(), deprecatedBranch); } return reportMetadata.getProjectKey(); }
@Test public void scanProjectWithBranch() throws IOException { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "branch") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo"); DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("src/sample.xoo"); assertThat(result.getReportReader().readComponent(inputfile.scannerId()).getProjectRelativePath()).isEqualTo("src/sample.xoo"); assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch"); result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo"); }
public void load(ScannerReport.Metadata metadata) { String deprecatedBranch = trimToNull(metadata.getDeprecatedBranch()); String branchName = trimToNull(metadata.getBranchName()); if (deprecatedBranch != null && branchName != null) { throw MessageException.of("Properties sonar.branch and sonar.branch.name can't be set together"); } if (delegate == null && hasBranchProperties(metadata)) { throw MessageException.of("Current edition does not support branch feature"); } if (delegate != null && deprecatedBranch == null) { delegate.load(metadata); } else { metadataHolder.setBranch(new DefaultBranchImpl(deprecatedBranch)); } }