1- Update the DB, migration scripts & co.
2- Update the model, controller & co.
3- Update the WS Client
status="OPEN"
rule_failure_permanent_id="1"
resource_id="555"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
<reviews
id="2"
status="CLOSED"
rule_failure_permanent_id="2"
resource_id="666"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
<reviews
id="3"
status="OPEN"
rule_failure_permanent_id="3"
resource_id="666"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
<reviews
id="4"
status="CLOSED"
rule_failure_permanent_id="2"
resource_id="666"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
</dataset>
\ No newline at end of file
rule_failure_permanent_id="1"
resource_id="555"
project_id="1"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/>
<!-- Following must have been deleted
<reviews
rule_failure_permanent_id="2"
resource_id="666"
project_id="2"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/>
-->
<review_comments
rule_failure_permanent_id="1"
resource_id="555"
project_id="1"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/>
<reviews
id="2"
status="CLOSED"
rule_failure_permanent_id="2"
resource_id="666"
project_id="2"
- created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+ created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/>
<review_comments
id="1"
- complete the Derby DDL file used for unit tests : sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
*/
- public static final int LAST_VERSION = 200;
+ public static final int LAST_VERSION = 201;
public final static String TABLE_NAME = "schema_migrations";
violation.save!
end
- @review.review_type = (false_positive ? Review::TYPE_FALSE_POSITIVE : Review::TYPE_VIOLATION)
+ @review.false_positive = false_positive
@review.assignee = nil
@review.save!
unless params[:comment].blank?
if violation.review.nil?
violation.build_review(:user_id => current_user.id)
end
- violation.review.review_type=(false_positive ? Review::TYPE_FALSE_POSITIVE : Review::TYPE_VIOLATION)
+ violation.review.false_positive=false_positive
violation.review.assignee=nil
violation.review.save!
violation.review.comments.create(:review_text => params[:comment], :user_id => current_user.id)
end
def search_reviews
- options = {'review_type' => 'VIOLATION'}
+ options = { 'false_positives' => 'without' }
unless @statuses == ['']
options['statuses']=@statuses.join(',')
end
belongs_to :rule_failure, :foreign_key => 'rule_failure_permanent_id', :primary_key => 'permanent_id'
validates_presence_of :user, :message => "can't be empty"
- validates_presence_of :review_type, :message => "can't be empty"
validates_presence_of :status, :message => "can't be empty"
before_save :assign_project
- TYPE_VIOLATION = 'VIOLATION'
- TYPE_FALSE_POSITIVE = 'FALSE_POSITIVE'
-
STATUS_OPEN = 'OPEN'
STATUS_CLOSED = 'CLOSED'
def self.search(options={})
conditions=[]
values={}
+
+ # --- 'review_type' is deprecated since 2.9 ---
+ # Following code just for backward compatibility
+ review_type = options['review_type']
+ if review_type
+ conditions << 'false_positive=:false_positive'
+ if review_type == 'FALSE_POSITIVE'
+ values[:false_positive]=true
+ else
+ values[:false_positive]=false
+ end
+ end
+ # --- End of code for backward compatibility code ---
- review_type = options['review_type'].split(',') if options['review_type']
- if review_type && review_type.size>0 && !review_type[0].blank?
- conditions << 'review_type in (:review_type)'
- values[:review_type]=review_type
+ false_positives = options['false_positives']
+ if false_positives == "only"
+ conditions << 'false_positive=:false_positive'
+ values[:false_positive]=true
+ elsif false_positives == "without"
+ conditions << 'false_positive=:false_positive'
+ values[:false_positive]=false
end
ids=options['ids'].split(',') if options['ids']
xml.author(user.login)
xml.assignee(assignee.login) if assignee
xml.title(title)
- xml.type(review_type)
+ xml.falsePositive(false_positive)
xml.status(status)
xml.severity(severity)
xml.resource(resource.kee) if resource
json['author'] = user.login
json['assignee'] = assignee.login if assignee
json['title'] = title if title
- json['type'] = review_type
+ json['falsePositive'] = false_positive
json['status'] = status
json['severity'] = severity
json['resource'] = resource.kee if resource
def build_review(options={})
if review.nil?
self.review=Review.new(
- {:review_type => Review::TYPE_VIOLATION,
- :status => Review::STATUS_OPEN,
+ {:status => Review::STATUS_OPEN,
:severity => Sonar::RulePriority.to_s(failure_level),
:resource_line => line,
:resource => snapshot.resource,
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 2.9
+#
+class ChangeFalsePositiveOnReviews < ActiveRecord::Migration
+
+ def self.up
+ add_column 'reviews', 'false_positive', :boolean, :null => true, :default => false
+ Review.reset_column_information
+
+ Review.find(:all).each do |review|
+ review.false_positive= (review.review_type == 'FALSE_POSITIVE')
+ review.save!
+ end
+
+ remove_column 'reviews', 'review_type'
+ Review.reset_column_information
+ end
+
+end
USER_ID INTEGER,
ASSIGNEE_ID INTEGER,
TITLE VARCHAR(500),
- REVIEW_TYPE VARCHAR(10),
STATUS VARCHAR(10),
SEVERITY VARCHAR(10),
RULE_FAILURE_PERMANENT_ID INTEGER,
PROJECT_ID INTEGER,
RESOURCE_ID INTEGER,
RESOURCE_LINE INTEGER,
+ FALSE_POSITIVE SMALLINT,
primary key (id)
);
private String severity = null;
private String resourceKee = null;
private Integer line = null;
+ private Boolean falsePositive = null;
private List<Review.Comment> comments = new ArrayList<Review.Comment>();
/**
}
/**
+ * @deprecated since 2.9. Use {@link #getFalsePositive()} instead.
* @return the type
*/
public String getType() {
}
/**
+ * @deprecated since 2.9. Use {@link #setFalsePositive(Boolean)} instead.
* @param s
* the type to set
*/
public Review setType(String s) {
this.type = s;
+ // the following code is only here to ensure backward compatibility with 2.8
+ if ("FALSE_POSITIVE".equals(type)) {
+ falsePositive = Boolean.TRUE;
+ } else if ("VIOLATION".equals(type)) {
+ falsePositive = Boolean.FALSE;
+ }
return this;
}
return this;
}
+ /**
+ * @since 2.9
+ * @return the falsePositive
+ */
+ public Boolean getFalsePositive() {
+ return falsePositive;
+ }
+
+ /**
+ * @since 2.9
+ * @param falsePositive
+ * true if false positive
+ */
+ public Review setFalsePositive(Boolean falsePositive) {
+ this.falsePositive = falsePositive;
+ return this;
+ }
+
/**
* @return the comments
*/
public static final String OUTPUT_PLAIN = "PLAIN";
public static final String OUTPUT_HTML = "HTML";
+ @Deprecated
private String reviewType;
private Long id;
private Long[] ids;
private String[] authorLoginsOrIds;
private String[] assigneeLoginsOrIds;
private String output;
+ private String falsePositives;
public ReviewQuery() {
}
/**
- * @return the reviewType
+ * @deprecated since 2.9
+ * @return NULL
*/
public String getReviewType() {
return reviewType;
}
/**
+ * @deprecated since 2.9
* @param reviewType
* the reviewType to set
*/
this.severities = severities;
return this;
}
-
-
+
/**
* @return the projectKeysOrIds
*/
return projectKeysOrIds;
}
-
/**
- * @param projectKeysOrIds the projectKeysOrIds to set
+ * @param projectKeysOrIds
+ * the projectKeysOrIds to set
*/
public ReviewQuery setProjectKeysOrIds(String... projectKeysOrIds) {
this.projectKeysOrIds = projectKeysOrIds;
return this;
}
-
/**
* @return the resourceKeysOrIds
*/
return resourceKeysOrIds;
}
-
/**
- * @param resourceKeysOrIds the resourceKeysOrIds to set
+ * @param resourceKeysOrIds
+ * the resourceKeysOrIds to set
*/
public ReviewQuery setResourceKeysOrIds(String... resourceKeysOrIds) {
this.resourceKeysOrIds = resourceKeysOrIds;
return this;
}
-
/**
* @return the authorLoginsOrIds
*/
return authorLoginsOrIds;
}
-
/**
- * @param authorLoginsOrIds the authorLoginsOrIds to set
+ * @param authorLoginsOrIds
+ * the authorLoginsOrIds to set
*/
public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) {
this.authorLoginsOrIds = authorLoginsOrIds;
return this;
}
-
/**
* @return the assigneeLoginsOrIds
*/
return assigneeLoginsOrIds;
}
-
/**
- * @param assigneeLoginsOrIds the assigneeLoginsOrIds to set
+ * @param assigneeLoginsOrIds
+ * the assigneeLoginsOrIds to set
*/
public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) {
this.assigneeLoginsOrIds = assigneeLoginsOrIds;
return output;
}
+ /**
+ *
+ * @param output
+ * the output
+ */
public ReviewQuery setOutput(String output) {
this.output = output;
return this;
}
+ /**
+ * @since 2.9
+ * @return the false_positives
+ */
+ public String getFalsePositives() {
+ return falsePositives;
+ }
+
+ /**
+ * Sets the 'false_positives' parameter that can be:
+ * <ul>
+ * <li>only</li>
+ * <li>with</li>
+ * <li>without</li>
+ * </ul>
+ * , 'with' being the default one on the server side. <br>
+ * <br>
+ *
+ * @since 2.9
+ * @param falsePositives
+ * the false_positives
+ */
+ public void setFalsePositives(String falsePositives) {
+ this.falsePositives = falsePositives;
+ }
+
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
} else if (ids != null) {
appendUrlParameter(url, "ids", ids);
}
- appendUrlParameter(url, "review_type", reviewType);
appendUrlParameter(url, "statuses", statuses);
appendUrlParameter(url, "severities", severities);
appendUrlParameter(url, "projects", projectKeysOrIds);
appendUrlParameter(url, "authors", authorLoginsOrIds);
appendUrlParameter(url, "assignees", assigneeLoginsOrIds);
appendUrlParameter(url, "output", output);
+ appendUrlParameter(url, "false_positives", falsePositives);
+ if (falsePositives == null && reviewType != null) {
+ // Use of the 2.8 deprecated API: handle backward compatibility
+ appendUrlParameter(url, "review_type", reviewType);
+ }
return url.toString();
}
review.setAuthorLogin(utils.getString(json, "author"));
review.setAssigneeLogin(utils.getString(json, "assignee"));
review.setTitle(utils.getString(json, "title"));
- review.setType(utils.getString(json, "type"));
review.setStatus(utils.getString(json, "status"));
review.setSeverity(utils.getString(json, "severity"));
review.setResourceKee(utils.getString(json, "resource"));
review.setLine(utils.getInteger(json, "line"));
+ review.setFalsePositive(utils.getBoolean(json, "falsePositive"));
+ review.setType(utils.getString(json, "type"));
Object comments = utils.getField(json, "comments");
if (comments != null) {
@Test
public void resourceTreeViolations() {
+ ReviewQuery query = new ReviewQuery();
+ query.setIds(10L, 11L).setStatuses("OPEN").setSeverities("MINOR", "INFO").setProjectKeysOrIds("com.sonar.foo:bar")
+ .setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin").setOutput("html")
+ .setFalsePositives("without");
+ assertThat(
+ query.getUrl(),
+ is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&false_positives=without&"));
+ }
+
+ @Test
+ public void resourceTreeViolationsForSonar2_8() {
ReviewQuery query = new ReviewQuery();
query.setIds(10L, 11L).setReviewType("FALSE_POSITIVE").setStatuses("OPEN").setSeverities("MINOR", "INFO")
.setProjectKeysOrIds("com.sonar.foo:bar").setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin")
.setOutput("html");
assertThat(
query.getUrl(),
- is("/api/reviews?ids=10,11&review_type=FALSE_POSITIVE&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&"));
+ is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&review_type=FALSE_POSITIVE&"));
}
}
public class ReviewUnmarshallerTest extends UnmarshallerTestCase {
@Test
- public void testToModels() {
+ public void testEmptyJSON() {
Review review = new ReviewUnmarshaller().toModel("[]");
assertThat(review, nullValue());
+ }
+
+ @Test
+ public void testToModels() {
+ List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews-2.9.json"));
+ assertThat(reviews.size(), is(2));
+
+ Review review = reviews.get(0);
+ assertThat(review.getId(), is(3L));
+ assertNotNull(review.getCreatedAt());
+ assertNotNull(review.getUpdatedAt());
+ assertThat(review.getAuthorLogin(), is("admin"));
+ assertThat(review.getAssigneeLogin(), is("admin"));
+ assertThat(review.getTitle(), is("'static' modifier out of order with the JLS suggestions."));
+ assertThat(review.getFalsePositive(), is(Boolean.FALSE));
+ assertThat(review.getStatus(), is("OPEN"));
+ assertThat(review.getSeverity(), is("MINOR"));
+ assertThat(review.getResourceKee(), is("org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration"));
+ assertThat(review.getLine(), is(33));
+ List<Comment> comments = review.getComments();
+ assertThat(comments.size(), is(4));
+ Comment comment = comments.get(0);
+ assertNotNull(comment.getUpdatedAt());
+ assertThat(comment.getAuthorLogin(), is("admin"));
+ assertThat(comment.getText(), is("This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"));
- List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews.json"));
+ review = reviews.get(1);
+ assertThat(review.getAssigneeLogin(), nullValue());
+ assertThat(review.getFalsePositive(), is(Boolean.TRUE));
+ }
+
+ /*
+ * Test Unmarshaller with JSON data received from a Sonar 2.8
+ */
+ @Test
+ public void testToModelsForSonar2_8() {
+ List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews-2.8.json"));
assertThat(reviews.size(), is(2));
- review = reviews.get(0);
+ Review review = reviews.get(0);
assertThat(review.getAssigneeLogin(), nullValue());
review = reviews.get(1);
--- /dev/null
+[{"id":9,"createdAt":"2011-04-27T14:37:20+0200","updatedAt":"2011-04-27T14:37:20+0200","author":"admin","title":"New exception is thrown in catch block, original stack trace may be lost","type":"VIOLATION","status":"OPEN","severity":"MAJOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReader","line":84,"comments":[{"author":"admin","updatedAt":"2011-04-27T14:37:20+0200","text":"Wazzaaaa"}]},{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","type":"VIOLATION","status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]}]
\ No newline at end of file
--- /dev/null
+[{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","falsePositive":false,"status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]},{"id":9,"createdAt":"2011-04-27T14:37:20+0200","updatedAt":"2011-04-27T14:37:20+0200","author":"admin","title":"New exception is thrown in catch block, original stack trace may be lost","falsePositive":true,"status":"OPEN","severity":"MAJOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReader","line":84,"comments":[{"author":"admin","updatedAt":"2011-04-27T14:37:20+0200","text":"Wazzaaaa"}]}]
\ No newline at end of file
+++ /dev/null
-[{"id":9,"createdAt":"2011-04-27T14:37:20+0200","updatedAt":"2011-04-27T14:37:20+0200","author":"admin","title":"New exception is thrown in catch block, original stack trace may be lost","type":"VIOLATION","status":"OPEN","severity":"MAJOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReader","line":84,"comments":[{"author":"admin","updatedAt":"2011-04-27T14:37:20+0200","text":"Wazzaaaa"}]},{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","type":"VIOLATION","status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]}]
\ No newline at end of file