You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rule_failure.rb 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #
  2. # Sonar, entreprise quality control tool.
  3. # Copyright (C) 2008-2011 SonarSource
  4. # mailto:contact AT sonarsource DOT com
  5. #
  6. # Sonar is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 3 of the License, or (at your option) any later version.
  10. #
  11. # Sonar is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with {library}; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. #
  20. class RuleFailure < ActiveRecord::Base
  21. belongs_to :rule
  22. belongs_to :snapshot
  23. has_many :reviews, :primary_key => "permanent_id", :foreign_key => "rule_failure_permanent_id", :order => "created_at"
  24. def get_open_review
  25. reviews.each do |review|
  26. if review.status == "open"
  27. return review
  28. end
  29. end
  30. return nil
  31. end
  32. def to_hash_json
  33. json = {}
  34. json['message'] = message
  35. json['line'] = line if line
  36. json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
  37. if created_at
  38. json['createdAt'] = format_datetime(created_at)
  39. end
  40. json['rule'] = {
  41. :key => rule.key,
  42. :name => rule.name
  43. }
  44. json['resource'] = {
  45. :key => snapshot.project.key,
  46. :name => snapshot.project.name,
  47. :scope => snapshot.project.scope,
  48. :qualifier => snapshot.project.qualifier,
  49. :language => snapshot.project.language
  50. }
  51. json
  52. end
  53. def to_xml(xml=Builder::XmlMarkup.new(:indent => 0))
  54. xml.violation do
  55. xml.message(message)
  56. xml.line(line) if line
  57. xml.priority(Sonar::RulePriority.to_s(failure_level))
  58. if created_at
  59. xml.createdAt(format_datetime(created_at))
  60. end
  61. xml.rule do
  62. xml.key(rule.key)
  63. xml.name(rule.name)
  64. end
  65. xml.resource do
  66. xml.key(snapshot.project.key)
  67. xml.name(snapshot.project.name)
  68. xml.scope(snapshot.project.scope)
  69. xml.qualifier(snapshot.project.qualifier)
  70. xml.language(snapshot.project.language)
  71. end
  72. end
  73. end
  74. def format_datetime(datetime)
  75. datetime.strftime("%Y-%m-%dT%H:%M:%S%z")
  76. end
  77. end