Skip to content
Permalink
Browse files
Merge pull request #1 from aquarellian/master
Fix for JENKINS-31001
  • Loading branch information
aquarellian committed Oct 17, 2015
2 parents 7bf4d68 + 88cf89b commit 2e51279ee51c5f492e9796067479989336157d19
@@ -1,7 +1,10 @@
package org.jenkinsci.plugins.sonargerrit;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.*;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.*;
import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.api.changes.ReviewInput;
@@ -68,7 +71,7 @@
private final String projectPath;
private final String sonarURL;
private final String path;
private final Severity severity;
private final String severity;
private final boolean changedLinesOnly;
private final boolean newIssuesOnly;
private final String noIssuesToPostText;
@@ -78,14 +81,14 @@

@DataBoundConstructor
public SonarToGerritBuilder(String projectPath, String sonarURL, String path,
String severity, boolean changedLinesOnly, boolean isNewIssuesOnly,
String severity, boolean changedLinesOnly, boolean newIssuesOnly,
String noIssuesToPostText, String someIssuesToPostText, String issueComment) {
this.projectPath = MoreObjects.firstNonNull(projectPath, EMPTY_STR);
this.sonarURL = MoreObjects.firstNonNull(sonarURL, DEFAULT_SONAR_URL);
this.path = MoreObjects.firstNonNull(path, DEFAULT_PATH);
this.severity = MoreObjects.firstNonNull(Severity.valueOf(severity), Severity.MAJOR);
this.severity = MoreObjects.firstNonNull(severity, Severity.MAJOR.name());
this.changedLinesOnly = changedLinesOnly;
this.newIssuesOnly = isNewIssuesOnly;
this.newIssuesOnly = newIssuesOnly;
this.noIssuesToPostText = noIssuesToPostText;
this.someIssuesToPostText = someIssuesToPostText;
this.issueComment = issueComment;
@@ -95,7 +98,7 @@ public String getPath() {
return path;
}

public Severity getSeverity() {
public String getSeverity() {
return severity;
}

@@ -220,15 +223,6 @@ private void logError(BuildListener listener, String message, Level l, Object...
LOGGER.log(l, message);
}

private void logResultMap(Multimap<String, Issue> file2issues, String message) {
LOGGER.log(Level.INFO, message, file2issues.keySet().size());
for (String file : file2issues.keySet()) {
Collection<Issue> issues = file2issues.get(file);
String issuesAsString = Joiner.on(System.lineSeparator()).join(issues);
LOGGER.log(Level.INFO, "File {0} contains {1} issues:{2}{3}", new Object[]{file, issues.size(), System.lineSeparator(), issuesAsString});
}
}

private String getReviewMessage(Multimap<String, Issue> finalIssues) {
return new CustomReportFormatter(finalIssues.values(), someIssuesToPostText, noIssuesToPostText).getMessage();
}
@@ -246,6 +240,9 @@ ReviewInput getReviewResult(Multimap<String, Issue> finalIssues) {
@Nullable
@Override
public ReviewInput.CommentInput apply(@Nullable Issue input) {
if (input == null) {
return null;
}
ReviewInput.CommentInput commentInput = new ReviewInput.CommentInput();
commentInput.id = input.getKey();
commentInput.line = input.getLine();
@@ -340,9 +337,10 @@ private String appendDelimiter(String subPath) {
@VisibleForTesting
Iterable<Issue> filterIssuesByPredicates(Report report) {
List<Issue> issues = report.getIssues();
Severity sev = Severity.valueOf(severity);
return Iterables.filter(issues,
Predicates.and(
ByMinSeverityPredicate.apply(getSeverity()),
ByMinSeverityPredicate.apply(sev),
ByNewPredicate.apply(isNewIssuesOnly()))
);
}
@@ -384,6 +382,7 @@ public DescriptorImpl() {
* prevent the form from being saved. It just means that a message
* will be displayed to the user.
*/
@SuppressWarnings(value = "unused")
public FormValidation doCheckPath(@QueryParameter String value)
throws IOException, ServletException {
if (value.length() == 0)
@@ -394,6 +393,17 @@ public FormValidation doCheckPath(@QueryParameter String value)
return FormValidation.ok();
}

/**
* Performs on-the-fly validation of the form field 'sonarURL'.
*
* @param value This parameter receives the value that the user has typed.
* @return Indicates the outcome of the validation. This is sent to the browser.
* <p/>
* Note that returning {@link FormValidation#error(String)} does not
* prevent the form from being saved. It just means that a message
* will be displayed to the user.
*/
@SuppressWarnings(value = "unused")
public FormValidation doCheckSonarURL(@QueryParameter String value)
throws IOException, ServletException {
if (value.length() == 0) {
@@ -407,27 +417,78 @@ public FormValidation doCheckSonarURL(@QueryParameter String value)
return FormValidation.ok();
}

/**
* Performs on-the-fly validation of the form field 'noIssuesToPostText'.
*
* @param value This parameter receives the value that the user has typed.
* @return Indicates the outcome of the validation. This is sent to the browser.
* <p/>
* Note that returning {@link FormValidation#error(String)} does not
* prevent the form from being saved. It just means that a message
* will be displayed to the user.
*/
@SuppressWarnings(value = "unused")
public FormValidation doCheckNoIssuesToPostText(@QueryParameter String value) {
if (value.length() == 0) {
return FormValidation.error(getLocalized("jenkins.plugin.validation.review.title.empty"));
}
return FormValidation.ok();
}

/**
* Performs on-the-fly validation of the form field 'someIssuesToPostText'.
*
* @param value This parameter receives the value that the user has typed.
* @return Indicates the outcome of the validation. This is sent to the browser.
* <p/>
* Note that returning {@link FormValidation#error(String)} does not
* prevent the form from being saved. It just means that a message
* will be displayed to the user.
*/
@SuppressWarnings(value = "unused")
public FormValidation doCheckSomeIssuesToPostText(@QueryParameter String value) {
if (value.length() == 0) {
return FormValidation.error(getLocalized("jenkins.plugin.validation.review.title.empty"));
}
return FormValidation.ok();
}

/**
* Performs on-the-fly validation of the form field 'issueComment'.
*
* @param value This parameter receives the value that the user has typed.
* @return Indicates the outcome of the validation. This is sent to the browser.
* <p/>
* Note that returning {@link FormValidation#error(String)} does not
* prevent the form from being saved. It just means that a message
* will be displayed to the user.
*/
@SuppressWarnings(value = "unused")
public FormValidation doCheckIssueComment(@QueryParameter String value) {
if (value.length() == 0) {
return FormValidation.error(getLocalized("jenkins.plugin.validation.review.body.empty"));
}
return FormValidation.ok();
}

/**
* Performs on-the-fly validation of the form field 'severity'.
*
* @param value This parameter receives the value that the user has typed.
* @return Indicates the outcome of the validation. This is sent to the browser.
* <p/>
* Note that returning {@link FormValidation#error(String)} does not
* prevent the form from being saved. It just means that a message
* will be displayed to the user.
*/
@SuppressWarnings(value = "unused")
public FormValidation doCheckSeverity(@QueryParameter String value) {
if (value == null || Severity.valueOf(value) == null) {
return FormValidation.error(getLocalized("jenkins.plugin.validation.review.severity.unknown"));
}
return FormValidation.ok();
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project types
@@ -9,12 +9,16 @@
*/

public class Component {
@SuppressWarnings(value="unused")
private String key;

@SuppressWarnings(value="unused")
private String path;

@SuppressWarnings(value="unused")
private String moduleKey;

@SuppressWarnings(value="unused")
private String status;

public String getKey() {
@@ -9,14 +9,31 @@
*/
public class Issue {

@SuppressWarnings(value = "unused")
private String key;

@SuppressWarnings(value = "unused")
private String component;

@SuppressWarnings(value = "unused")
private Integer line;

@SuppressWarnings(value = "unused")
private String message;

@SuppressWarnings(value = "unused")
private Severity severity;

@SuppressWarnings(value = "unused")
private String rule;

@SuppressWarnings(value = "unused")
private String status;

@SuppressWarnings(value = "unused")
private Boolean isNew;

@SuppressWarnings(value = "unused")
private Date creationDate;

public String getKey() {
@@ -9,11 +9,19 @@
* Author: Tatiana Didik
*/
public class Report {

@SuppressWarnings(value="unused")
private String version;

@SuppressWarnings(value="unused")
private List<Issue> issues;

@SuppressWarnings(value="unused")
private List<Component> components;

@SuppressWarnings(value="unused")
private List<Rule> rules;

@SuppressWarnings(value="unused")
private List<User> users;

public String getVersion() {
@@ -1,43 +1,24 @@
package org.jenkinsci.plugins.sonargerrit.data.entity;



/**
* Project: Sonar-Gerrit Plugin
* Author: Tatiana Didik
*/

public class Rule {
private String key;
private String rule;
private String repository;
private String name;

public Rule(String key, String rule, String repository, String name) {
this.key = key;
this.rule = rule;
this.repository = repository;
this.name = name;
}

public Rule() {
}

public void setKey(String key) {
this.key = key;
}
@SuppressWarnings(value = "unused")
private String key;

public void setRule(String rule) {
this.rule = rule;
}
@SuppressWarnings(value = "unused")
private String rule;

public void setRepository(String repository) {
this.repository = repository;
}
@SuppressWarnings(value = "unused")
private String repository;

public void setName(String name) {
this.name = name;
}
@SuppressWarnings(value = "unused")
private String name;

public String getKey() {
return key;
@@ -15,4 +15,4 @@ jenkins.plugin.error.gerrit.server.empty=Cannot obtain Gerrit server name. Pleas
jenkins.plugin.error.gerrit.config.empty=Cannot obtain Gerrit configuration. Please check your Gerrit Trigger settings
jenkins.plugin.error.gerrit.user.empty=Gerrit authentication is not configured. Please check Gerrit Trigger settings
jenkins.plugin.error.sonar.report.not.exists=Sonar report '%s' does not exist. Please check plugin settings

jenkins.plugin.validation.review.severity.unknown=Unknown severity
@@ -26,28 +26,24 @@
</f:section>

<f:section title="${%jenkins.plugin.settings.section.filter.name}">
<!--<f:entry title="Choose severity level"-->
<!--field="name">-->
<!--<f:enum>${it.name}</f:enum>-->
<!--</f:entry>-->
<f:entry title="${%jenkins.plugin.settings.filter.severity}" field="severity">
<select name="severity">
<option value="INFO">${%jenkins.plugin.data.severity.info}</option>
<option value="MINOR">${%jenkins.plugin.data.severity.minor}</option>
<option value="MAJOR" selected="true">${%jenkins.plugin.data.severity.major}</option>
<option value="CRITICAL">${%jenkins.plugin.data.severity.critical}</option>
<option value="BLOCKER">${%jenkins.plugin.data.severity.blocker}</option>
<f:entry name="severity" title="${%jenkins.plugin.settings.filter.severity}" field="severity">
<select name="severity" field="severity">
<f:option value="INFO" selected="${instance.severity =='INFO'}">INFO</f:option>
<f:option value="MINOR" selected="${instance.severity =='MINOR'}">MINOR</f:option>
<f:option value="MAJOR" selected="${instance.severity =='MAJOR' || instance.severity == null}">MAJOR</f:option>
<f:option value="CRITICAL" selected="${instance.severity =='CRITICAL'}">CRITICAL</f:option>
<f:option value="BLOCKER" selected="${instance.severity =='BLOCKER'}">BLOCKER</f:option>
</select>
</f:entry>

<f:entry title="${%jenkins.plugin.settings.filter.new}" field="newIssuesOnly"
description="${%jenkins.plugin.settings.filter.new.description}">
<f:checkbox checked="true"/>
<f:checkbox default="true"/>
</f:entry>

<f:entry title="${%jenkins.plugin.settings.filter.lines.changed}" field="changedLinesOnly"
description="${%jenkins.plugin.settings.filter.lines.changed.description}">
<f:checkbox checked="true"/>
<f:checkbox default="true"/>
</f:entry>
</f:section>
<f:section title="${%jenkins.plugin.settings.section.review.format.name}">
@@ -1,6 +1,6 @@
jenkins.plugin.settings.section.sonar.name=Sonar Settings
jenkins.plugin.settings.sonar.url=Sonar URL
jenkins.plugin.settings.sonar.report.path=Sonar Report Path
jenkins.plugin.settings.sonar.report.path=Sonar report path
jenkins.plugin.settings.section.filter.name=Filter Settings
jenkins.plugin.settings.filter.severity=Report issues having severity level higher or equal to:
jenkins.plugin.settings.filter.new=Report new issues only?

0 comments on commit 2e51279

Please sign in to comment.