]> source.dussan.org Git - sonarqube.git/commitdiff
(SONAR-3893) Improve the highlighter API to not depend on sonar-channel and allow...
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Wed, 10 Apr 2013 16:09:33 +0000 (18:09 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Wed, 10 Apr 2013 16:09:33 +0000 (18:09 +0200)
sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java
sonar-core/src/main/java/org/sonar/core/source/SyntaxHighlighter.java
sonar-core/src/main/java/org/sonar/core/source/SyntaxHighlightingRuleSet.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb

index d99aff3201a18915a55a137214305c83ec220207..62cf3bfdbf6068c838e94d39849269de9f09c956 100644 (file)
@@ -38,9 +38,6 @@ import static org.sonar.core.source.CharactersReader.END_OF_STREAM;
  */
 public class HtmlTextWrapper {
 
-  private static final String OPEN_TABLE_LINE = "<tr><td>";
-  private static final String CLOSE_TABLE_LINE = "</td></tr>";
-
   public static final char CR_END_OF_LINE = '\r';
   public static final char LF_END_OF_LINE = '\n';
 
@@ -61,7 +58,6 @@ public class HtmlTextWrapper {
         if (shouldStartNewLine(charsReader)) {
           decoratedHtmlLines.add(currentHtmlLine.toString());
           currentHtmlLine = new StringBuilder();
-//          currentHtmlLine.append(OPEN_TABLE_LINE);
           if (shouldReopenPendingTags(charsReader)) {
             reopenCurrentSyntaxTags(charsReader, currentHtmlLine);
           }
@@ -72,7 +68,6 @@ public class HtmlTextWrapper {
 
         if (shouldClosePendingTags(charsReader)) {
           closeCurrentSyntaxTags(charsReader, currentHtmlLine);
-//          currentHtmlLine.append(CLOSE_TABLE_LINE);
         }
 
         Collection<String> tagsToOpen = getTagsToOpen(charsReader.getCurrentIndex(), context);
index c33a9fd47655a03681014978326474a8aaad738a..c9beafd8a94c34a90e5279059b6e066fb319bca8 100644 (file)
@@ -44,10 +44,11 @@ public class SyntaxHighlighter {
     String snapshotSource = snapshotSourceDao.selectSnapshotSource(snapshotId);
     String highlightingRules = snapshotDataDao.selectSnapshotData(snapshotId);
 
-    HighlightingContext highlightingContext = HighlightingContext.buildFrom(highlightingRules);
-
-    HtmlTextWrapper textWrapper = new HtmlTextWrapper();
-
-    return textWrapper.wrapTextWithHtml(snapshotSource, highlightingContext);
+    if(snapshotSource != null && highlightingRules != null) {
+      HighlightingContext highlightingContext = HighlightingContext.buildFrom(highlightingRules);
+      HtmlTextWrapper textWrapper = new HtmlTextWrapper();
+      return textWrapper.wrapTextWithHtml(snapshotSource, highlightingContext);
+    }
+    return null;
   }
 }
index bbcc51a0fd691ed0d5e90c8089707aea726490a5..b83c1b1b71196818cd27680d6e6004850b7d0a1b 100644 (file)
@@ -95,7 +95,7 @@ public class SyntaxHighlightingRuleSet {
                   return false;
                 }
               });
-      return conflictingRules.size() > 0;
+      return !conflictingRules.isEmpty();
     }
   }
 
index b74b6398e135ee72a492d7662f24056ffe03277d..fbcb801ae9817715659ec279637e975293c820fe 100644 (file)
@@ -158,7 +158,7 @@ class ResourceController < ApplicationController
     @expanded=(params[:expand]=='true')
     @display_manual_violation_form=(current_user && has_role?(:user, @snapshot))
     if @snapshot.source
-      source_lines=@snapshot.source.syntax_highlighted_lines()
+      source_lines = @snapshot.highlighting_data || @snapshot.source.syntax_highlighted_lines()
       init_scm()
 
       @lines=[]
index 4d618141afc59497ffa0ef9e0898e47094a3ba69..b1b3753f32316ef6510f1003c54cb98b121f9b1b 100644 (file)
@@ -45,7 +45,8 @@ module SourceHelper
     panel.html_lines=[]
     line_range=sanitize_line_range(options[:line_range])
     highlighted_lines=options[:highlighted_lines]||[]
-    snapshot.source.syntax_highlighted_lines().each_with_index do |source, index|
+    source_lines = snapshot.highlighting_data || snapshot.source.syntax_highlighted_lines()
+    source_lines.each_with_index do |source, index|
       if line_range.include?(index+1)
         html_line=HtmlLine.new(source, index+1)
         html_line.revision=revisions_by_line[index+1]
index c03a6949ae4e2364ffc3de55957a9033df644dd8..01c70cb0f3a05532e7cf917cfac2f58eb9c88c1f 100644 (file)
@@ -252,6 +252,10 @@ class Snapshot < ActiveRecord::Base
       end
   end
 
+  def highlighting_data
+    Java::OrgSonarServerUi::JRubyFacade.getInstance().getHighlightedSourceLines(id)
+  end
+
 
   private