diff options
12 files changed, 71 insertions, 15 deletions
@@ -392,6 +392,11 @@ </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-markdown</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-check-api</artifactId> <version>${project.version}</version> </dependency> diff --git a/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java b/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java index d772d81ffd5..dcbd5c56a74 100644 --- a/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java +++ b/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java @@ -46,7 +46,7 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> { @SuppressWarnings("rawtypes") public ChannelDispatcher(List<Channel> channels, boolean failIfNoChannelToConsumeOneCharacter) { - this.channels = channels.toArray(new Channel[0]); // NOSONAR, lack of performance is not an issue here + this.channels = channels.toArray(new Channel[channels.size()]); this.failIfNoChannelToConsumeOneCharacter = failIfNoChannelToConsumeOneCharacter; } diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java index 25ad180b4b3..2358e0bfa44 100644 --- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java +++ b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java @@ -258,9 +258,9 @@ public class CodeBuffer implements CharSequence { public final String toString() { StringBuilder result = new StringBuilder(); result.append("CodeReader("); - result.append("line:" + cursor.line); - result.append("|column:" + cursor.column); - result.append("|cursor value:'" + (char) peek() + "'"); + result.append("line:").append(cursor.line); + result.append("|column:").append(cursor.column); + result.append("|cursor value:'").append((char) peek()).append("'"); result.append(")"); return result.toString(); } diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 5927afa3eae..5b5e2fa614d 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -43,6 +43,10 @@ <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-java-api</artifactId> </dependency> + <dependency> + <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-markdown</artifactId> + </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 5c680ab91bc..972017928b3 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -34,6 +34,7 @@ import org.sonar.api.web.*; import org.sonar.jpa.dao.AsyncMeasuresService; import org.sonar.jpa.dialect.Dialect; import org.sonar.jpa.session.DatabaseConnector; +import org.sonar.markdown.MarkdownEngine; import org.sonar.server.configuration.Backup; import org.sonar.server.configuration.CoreConfiguration; import org.sonar.server.configuration.ProfilesManager; @@ -64,7 +65,7 @@ public final class JRubyFacade { return getContainer().getComponent(FilterExecutor.class).execute(filter); } - /* UPDATE CENTER */ + // UPDATE CENTER ------------------------------------------------------------ public void downloadPlugin(String pluginKey, String pluginVersion) { getContainer().getComponent(PluginDownloader.class).download(pluginKey, Version.create(pluginVersion)); @@ -94,7 +95,7 @@ public final class JRubyFacade { return getContainer().getComponent(UpdateCenterMatrixFactory.class).getMatrix(forceReload); } - /* PLUGINS */ + // PLUGINS ------------------------------------------------------------------ public Property[] getPluginProperties(PluginMetadata metadata) { Plugins plugins = getContainer().getComponent(Plugins.class); @@ -109,6 +110,9 @@ public final class JRubyFacade { return getContainer().getComponent(PluginDeployer.class).getPluginsMetadata(); } + + // SYNTAX HIGHLIGHTING ------------------------------------------------------ + public String colorizeCode(String code, String language) { try { return getContainer().getComponent(CodeColorizers.class).toHtml(code, language); @@ -119,6 +123,14 @@ public final class JRubyFacade { } } + public static String markdownToHtml(String input) { + return MarkdownEngine.convertToHtml(input); + } + + + + + public List<ViewProxy<Widget>> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage) { return getContainer().getComponent(Views.class).getWidgets(resourceScope, resourceQualifier, resourceLanguage); } 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 4c2f796a5dd..4e221556509 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 @@ -20,7 +20,7 @@ class ResourceController < ApplicationController SECTION=Navigation::SECTION_RESOURCE - helper DashboardHelper + helper :dashboard, :markdown def index @resource = Project.by_key(params[:id]) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 55bd4c55896..d7d038e98df 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -24,6 +24,8 @@ class ReviewsController < ApplicationController verify :method => :post, :only => [ :create, :create_comment ], :redirect_to => { :action => :error_not_post } + helper(:reviews, :markdown) + def index init_params search_reviews diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb new file mode 100644 index 00000000000..bd4f6481885 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb @@ -0,0 +1,26 @@ + # + # 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 + # +module MarkdownHelper + + def markdown_to_html(input) + input ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(h(input)) : '' + end + +end
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb index 51e07df0043..c690fd5ff4f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb @@ -23,6 +23,10 @@ class ReviewComment < ActiveRecord::Base validates_presence_of :user => "can't be empty" validate :comment_should_not_be_empty + alias_attribute :text, :review_text + + private + def comment_should_not_be_empty errors.add("Comment", " cannot be empty") if review_text.strip.blank? end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb index 84b476fa9ac..4d52a57dcfe 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb @@ -106,10 +106,10 @@ </h4> <% if review_comment == last_comment %> <div id="lastComment<%= violation.id -%>"> - <%= h(review_comment.review_text) -%> + <%= markdown_to_html(review_comment.text) -%> </div> <% else %> - <%= h(review_comment.review_text) -%> + <%= markdown_to_html(review_comment.text) -%> <% end %> </div> <% @@ -131,4 +131,4 @@ </div> <% end %> -<div>
\ No newline at end of file +</div>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb index 35407e6eb7a..970a328bfee 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb @@ -27,10 +27,10 @@ <%= review.assignee ? h(review.assignee.name) : '-'-%> </td> <td class="key"> - Created: + Created by: </td> <td class="val"> - by <%= h(review.user.name) -%> at <%= l(review.created_at) -%> + <%= h(review.user.name) -%> at <%= l(review.created_at) -%> </td> </tr> <% if review.rule %> @@ -68,8 +68,8 @@ <% review.comments.each do |comment| %> <div class="discussionComment"> <h4><%= image_tag("reviews/comment.png") -%> <b><%= comment.user.name -%></b> (<%= distance_of_time_in_words_to_now(comment.created_at) -%>)</h4> - <%= h(comment.review_text) -%> + <%= markdown_to_html(comment.text) -%> </div> <% end %> </div> -<div>
\ No newline at end of file +</div>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 52d2e3bd5e0..ed955431b87 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -289,11 +289,14 @@ code { .small { font-size: 85%; } -em { +small { color: #AAA; font-size: 85%; font-style: normal; } +em { + font-weight: bold; +} a.external { background: url('../images/links/external.png') no-repeat 100% 0; |