aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-17 21:40:03 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-17 21:40:03 +0200
commitf33f28795a4ce4f414f3c22ee48016d282bc90c1 (patch)
tree7a4877097ab438f9b7e2ecdcb8e433321deb9fb1 /sonar-server
parent58bf36ece8a066417d3ea0f887670cb373807ce2 (diff)
downloadsonarqube-f33f28795a4ce4f414f3c22ee48016d282bc90c1.tar.gz
sonarqube-f33f28795a4ce4f414f3c22ee48016d282bc90c1.zip
SONAR-2293 support CR and CR/LF newlines in source viewers and web service
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb27
3 files changed, 23 insertions, 8 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
index c66a9272183..da4dbd299fb 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
@@ -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=[]
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
index 023f0ecd2d3..9a0d2b5eaa3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb
index daed9bbb572..b2eff95b0d2 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot_source.rb
@@ -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