Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

Upgrade json simple & fix big overview comment issue #118

Open
wants to merge 9 commits into
base: coverage_split_sensor
Choose a base branch
from

Conversation

kingoleg
Copy link

@t-8ch
Copy link
Contributor

t-8ch commented Mar 28, 2017

Can you remove the workingdir/projectbasedir changes from this PR?

Copy link
Contributor

@t-8ch t-8ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this is useful, I would like the implementation to change a bit though.
And we should define what maxiumum comment sizes to use.

return extractResponse(response);
} catch (ExecutionException | TimeoutException | InterruptedException e) {
throw new StashClientException(e);
}
}

private static void validateResponse(Response response, int expectedStatusCode, String message) throws StashClientException {
private static void validateResponse(JsonObject body, Response response, int expectedStatusCode, String message) throws StashClientException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this parameter.
If we keep it it should be named requestBody.
OTOH it seems weird to pass the body only for logging.
How about removing the exception from validateResponse(), making it return a bool instead and throwing the exception/logging from performRequest directly

private static final Logger LOGGER = LoggerFactory.getLogger(StashProjectBuilder.class);

private static final int SOFT_SUMMARY_COMMENT_MAX_LENGTH = 30000;
private static final int HARD_SUMMARY_COMMENT_MAX_LENGTH = Short.MAX_VALUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you obtain these values?

@@ -60,6 +67,11 @@ public static String printIssueListBySeverityMarkdown(List<Issue> report, String
for (Map.Entry<String, Issue> rule : rules.entrySet()) {
Issue issue = rule.getValue();
sb.append("| ").append(printIssueMarkdown(issue, sonarQubeURL)).append(" |").append(NEW_LINE);
if (sb.length() > maxLength) {
sb.append("| ").append(MarkdownPrinter.printSeverityMarkdown(issue.severity()));
sb.append("The rest issues are skipped |").append(NEW_LINE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The rest of the issues have been skipped, because of..."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would still allow the message to exceed maxLength

@@ -119,20 +131,30 @@ public static String printReportMarkdown(PullRequestRef pr, String stashURL, Str
sb.append("| Issues list |").append(NEW_LINE);
sb.append("|------------|").append(NEW_LINE);
for (String severity: orderedSeverities) {
sb.append(printIssueListBySeverityMarkdown(generalIssues, sonarQubeURL, severity));
int maxLength = SOFT_SUMMARY_COMMENT_MAX_LENGTH / 2 - sb.length();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why divide by two?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have the truncation/maxlength logic in its own wrapper class around StringBuffer.
With the signature:

class SizeSensitiveStringBuffer() {
    public SizeSensitiveStringBuffer(int maxLength);
    public boolean append(String content, int maxLength, String alternativeContent);
    public void append(String content);
}

}

if (sb.length() > HARD_SUMMARY_COMMENT_MAX_LENGTH) {
LOGGER.debug("Overview comment is too big, trimming");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be WARN

assertEquals(diff1.getSource(), (long) 10);
assertEquals(diff1.getDestination(),(long) 20);
assertEquals(diff1.getSource(), 10);
assertEquals(diff1.getDestination(),20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a space missing before the ,

@transamericamoon
Copy link

transamericamoon commented Jul 21, 2017

This would be a nice fix to have, on large projects we are getting this error:
Please enter a non-empty value less than 32768 characters

[ERROR] Unable to push SonarQube analysis overview to Stash
org.sonar.plugins.stash.exceptions.StashClientException: Unable to post a comment to transamerica-demo #2. Received 400: null: Please enter a non-empty value less than 32768 characters
	at org.sonar.plugins.stash.client.StashClient.validateResponse(StashClient.java:363) ~[sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.client.StashClient.performRequest(StashClient.java:351) ~[sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.client.StashClient.postCreate(StashClient.java:317) ~[sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.client.StashClient.postCommentOnPullRequest(StashClient.java:106) ~[sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.StashRequestFacade.postAnalysisOverview(StashRequestFacade.java:76) ~[sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.StashIssueReportingPostJob.postInfoAndPRsActions(StashIssueReportingPostJob.java:134) [sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.StashIssueReportingPostJob.updateStashWithSonarInfo(StashIssueReportingPostJob.java:98) [sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.plugins.stash.StashIssueReportingPostJob.executeOn(StashIssueReportingPostJob.java:55) [sonar-stash-plugin-1.3.0-SNAPSHOT.jar:na]
	at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:63) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:53) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:82) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:184) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:118) [sonar-scanner-engine-shaded-6.0.jar:na]
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63) [sonar-scanner-api-batch5373357516405033365.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) [sonar-scanner-api-2.9.0.887.jar:na]
	at com.sun.proxy.$Proxy23.execute(Unknown Source) [na:na]
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233) [sonar-scanner-api-2.9.0.887.jar:na]
	at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151) [sonar-scanner-api-2.9.0.887.jar:na]
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:77) [sonar-maven-plugin-3.3.0.603.jar:na]
	at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:139) [sonar-maven-plugin-3.3.0.603.jar:na]
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) [maven-core-3.3.9.jar:3.3.9]
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) [maven-embedder-3.3.9.jar:3.3.9]
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) [maven-embedder-3.3.9.jar:3.3.9]
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) [maven-embedder-3.3.9.jar:3.3.9]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) [plexus-classworlds-2.5.2.jar:na]
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) [plexus-classworlds-2.5.2.jar:na]
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) [plexus-classworlds-2.5.2.jar:na]
	at org.codehaus.plexus.classworlds

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants