public ScmPublisher(ScmConfiguration configuration, ProjectRepositories projectRepositories, InputComponentStore componentStore, FileSystem fs, ReportPublisher reportPublisher, BranchConfiguration branchConfiguration) { this.configuration = configuration; this.projectRepositories = projectRepositories; this.componentStore = componentStore; this.fs = fs; this.branchConfiguration = branchConfiguration; this.writer = reportPublisher.getWriter(); }
public static String toCssClass(HighlightingType type) { return toBatchType(type).cssClass(); } }
@Test public void skip_if_scm_provider_returns_null() { publisher.publish(writer); assertNotPublished(); }
public void execute() { String taskId = null; File report = generateReportFile(); if (properties.shouldKeepReport()) { LOG.info("Analysis report generated in " + reportDir); } if (!analysisMode.isMediumTest()) { taskId = upload(report); } logSuccess(taskId); }
@Test public void publish_settings_prefixed_with_sonar_analysis_for_webhooks() { props.put("foo", "should not be exported"); props.put("sonar.analysis.revision", "ab45b3"); props.put("sonar.analysis.build.number", "B123"); underTest.publish(writer); List<ScannerReport.ContextProperty> expected = Arrays.asList( newContextProperty("sonar.analysis.revision", "ab45b3"), newContextProperty("sonar.analysis.build.number", "B123")); expectWritten(expected); }
@Test public void write_changed_files() { DefaultInputFile fileWithChangedLines = createInputFile("path1"); DefaultInputFile fileWithoutChangedLines = createInputFile("path2"); Set<Path> paths = new HashSet<>(Arrays.asList(BASE_DIR.resolve("path1"), BASE_DIR.resolve("path2"))); Set<Integer> lines = new HashSet<>(Arrays.asList(1, 10)); when(provider.branchChangedLines(TARGET_BRANCH, BASE_DIR, paths)).thenReturn(Collections.singletonMap(BASE_DIR.resolve("path1"), lines)); when(inputComponentStore.allChangedFilesToPublish()).thenReturn(Arrays.asList(fileWithChangedLines, fileWithoutChangedLines)); publisher.publish(writer); assertPublished(fileWithChangedLines, lines); assertPublished(fileWithoutChangedLines, Collections.emptySet()); }
private static void writeLinks(DefaultInputProject project, ScannerReport.Component.Builder builder) { ComponentLink.Builder linkBuilder = ComponentLink.newBuilder(); writeProjectLink(builder, project.properties(), linkBuilder, CoreProperties.LINKS_HOME_PAGE, ComponentLinkType.HOME); writeProjectLink(builder, project.properties(), linkBuilder, CoreProperties.LINKS_CI, ComponentLinkType.CI); writeProjectLink(builder, project.properties(), linkBuilder, CoreProperties.LINKS_ISSUE_TRACKER, ComponentLinkType.ISSUE); writeProjectLink(builder, project.properties(), linkBuilder, CoreProperties.LINKS_SOURCES, ComponentLinkType.SCM); }
private void writeGlobalSettings(BufferedWriter fileWriter) throws IOException { fileWriter.append("Global server settings:\n"); Map<String, String> props = globalServerSettings.properties(); for (String prop : new TreeSet<>(props.keySet())) { dumpPropIfNotSensitive(fileWriter, prop, props.get(prop)); } }
@Test public void publish_writes_no_properties_to_report() { underTest.publish(writer); expectWritten(emptyList()); }
private static void dumpPropIfNotSensitive(BufferedWriter fileWriter, String prop, String value) throws IOException { fileWriter.append(String.format(KEY_VALUE_FORMAT, prop, isSensitiveProperty(prop) ? "******" : StringUtils.abbreviate(value, MAX_WIDTH))).append('\n'); }
private void addBranchInformation(ScannerReport.Metadata.Builder builder) { builder.setBranchName(branchConfiguration.branchName()); BranchType branchType = toProtobufBranchType(branchConfiguration.branchType()); builder.setBranchType(branchType); String referenceBranch = branchConfiguration.longLivingSonarReferenceBranch(); if (referenceBranch != null) { builder.setMergeBranchName(referenceBranch); } if (branchType == BranchType.PULL_REQUEST) { builder.setPullRequestKey(branchConfiguration.pullRequestKey()); } }
public AnalysisWarningsPublisherTest() { DefaultAnalysisWarnings defaultAnalysisWarnings = new DefaultAnalysisWarnings(mock(System2.class)); this.analysisWarnings = defaultAnalysisWarnings; this.underTest = new AnalysisWarningsPublisher(defaultAnalysisWarnings); }
@Test public void fail_if_public_url_malformed() { when(server.getPublicRootUrl()).thenReturn("invalid"); exception.expect(MessageException.class); exception.expectMessage("Failed to parse public URL set in SonarQube server: invalid"); underTest.start(); }
public void write(int batchId, ScannerReport.ExternalIssue rawIssue) { reportPublisher.getWriter().appendComponentExternalIssue(batchId, rawIssue); } }
@Test public void skip_if_scm_is_disabled() { when(scmConfiguration.isDisabled()).thenReturn(true); publisher.publish(writer); verifyZeroInteractions(inputComponentStore, inputModuleHierarchy, provider); assertNotPublished(); }
@Test public void publish_writes_properties_to_report() { cache.put("foo1", "bar1"); cache.put("foo2", "bar2"); underTest.publish(writer); List<ScannerReport.ContextProperty> expected = Arrays.asList( newContextProperty("foo1", "bar1"), newContextProperty("foo2", "bar2")); expectWritten(expected); }
public void write(int batchId, ScannerReport.Issue rawIssue) { reportPublisher.getWriter().appendComponentIssue(batchId, rawIssue); }
@Test public void skip_if_not_pr_or_slb() { when(branchConfiguration.isShortOrPullRequest()).thenReturn(false); publisher.publish(writer); verifyZeroInteractions(inputComponentStore, inputModuleHierarchy, provider); assertNotPublished(); }
@Test public void skip_if_no_scm_provider() { when(scmConfiguration.provider()).thenReturn(null); publisher.publish(writer); verifyZeroInteractions(inputComponentStore, inputModuleHierarchy, provider); assertNotPublished(); }
@Test public void skip_if_target_branch_is_null() { when(branchConfiguration.targetScmBranch()).thenReturn(null); publisher.publish(writer); verifyZeroInteractions(inputComponentStore, inputModuleHierarchy, provider); assertNotPublished(); }