]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2293 support CR and CR/LF newlines in source viewers and web service
authorsimonbrandhof <simon.brandhof@gmail.com>
Sun, 17 Apr 2011 19:40:03 +0000 (21:40 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Sun, 17 Apr 2011 19:40:03 +0000 (21:40 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb

index c66a9272183b715667c7e4c2f12aaa1e1a1f4936..da4dbd299fbb5355936665f036c21a8c944eef6f 100644 (file)
@@ -78,7 +78,7 @@ class ResourceController < ApplicationController
     @expanded=(params[:expand]=='true')
 
     if @snapshot.source
-      source_lines=Java::OrgSonarServerUi::JRubyFacade.new.colorizeCode(@snapshot.source.data, @snapshot.project.language).split("\n")
+      source_lines=@snapshot.source.syntax_highlighted_lines()
       init_scm()
 
       @lines=[]
index 023f0ecd2d34efa5640b9b2660f67209b5b4b557..9a0d2b5eaa394a2d59287bedbd5b547d035e6208 100644 (file)
@@ -212,7 +212,7 @@ class Snapshot < ActiveRecord::Base
   def period_datetime(period_index)
     project_snapshot.send "period#{period_index}_date"
   end
-
+  
   private
 
   def measures_hash
index daed9bbb57257f25c5612fb630db7b53a53b5604..b2eff95b0d22b58f53eb85a7badd1097bd67881a 100644 (file)
@@ -26,11 +26,11 @@ class SnapshotSource < ActiveRecord::Base
     from = (options[:from] ? options[:from].to_i - 1 : 0)
     to = (options[:to] ? options[:to].to_i - 2 : -1)
 
-   if (options[:color]=='true')
-      lines=Java::OrgSonarServerUi::JRubyFacade.new.colorizeCode(data, snapshot.project.language).split("\n")
-   else
-     lines=lines(false)
-   end
+    if (options[:color]=='true')
+      lines=syntax_highlighted_lines()
+    else
+      lines=lines(false)
+    end
 
     json = {}
     lines[from..to].each_with_index do |line, id|
@@ -67,7 +67,22 @@ class SnapshotSource < ActiveRecord::Base
   end
 
   def lines(encode)
-    encoded_data(encode).split("\n")
+    SnapshotSource.split_newlines(encoded_data(encode))
+  end
+  
+  def syntax_highlighted_source
+    @syntax_highlighted_source||=
+      begin
+        data ? Java::OrgSonarServerUi::JRubyFacade.getInstance().colorizeCode(data, snapshot.project.language) : ''
+      end
+  end
+  
+  def syntax_highlighted_lines
+    SnapshotSource.split_newlines(syntax_highlighted_source)
   end
 
+  private
+  def self.split_newlines(input)
+    input.split(/\r?\n|\r/)
+  end
 end