From: simonbrandhof Date: Thu, 5 May 2011 13:19:52 +0000 (+0200) Subject: Rename the class MarkdownEngine to Markdown X-Git-Tag: 2.8~39 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=38b3cc5a1332ad9871c4f7f189a23724d774a1ea;p=sonarqube.git Rename the class MarkdownEngine to Markdown --- diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/Markdown.java b/sonar-markdown/src/main/java/org/sonar/markdown/Markdown.java new file mode 100644 index 00000000000..9e7522cd692 --- /dev/null +++ b/sonar-markdown/src/main/java/org/sonar/markdown/Markdown.java @@ -0,0 +1,63 @@ +/* + * Sonar, open source software quality management 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 + */ +package org.sonar.markdown; + +import org.sonar.channel.Channel; +import org.sonar.channel.ChannelDispatcher; +import org.sonar.channel.CodeReader; + +import java.util.Arrays; +import java.util.List; + +/** + * Entry point of the Markdown library + */ +public final class Markdown { + + private ChannelDispatcher dispatcher; + + private Markdown() { + List markdownChannels = Arrays.asList( + new HtmlUrlChannel(), + new HtmlEndOfLineChannel(), + new HtmlEmphasisChannel(), + new HtmlListChannel(), + new HtmlCodeChannel(), + new IdentifierAndNumberChannel(), + new BlackholeChannel()); + dispatcher = new ChannelDispatcher(markdownChannels); + } + + private String convert(String input) { + CodeReader reader = new CodeReader(input); + try { + MarkdownOutput output = new MarkdownOutput(); + dispatcher.consume(reader, output); + return output.toString(); + + } finally { + reader.close(); + } + } + + public static String convertToHtml(String input) { + return new Markdown().convert(input); + } +} diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java b/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java deleted file mode 100644 index 13c80ce39ff..00000000000 --- a/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Sonar, open source software quality management 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 - */ -package org.sonar.markdown; - -import org.sonar.channel.Channel; -import org.sonar.channel.ChannelDispatcher; -import org.sonar.channel.CodeReader; - -import java.util.Arrays; -import java.util.List; - -/** - * Entry point of the Markdown library - */ -public final class MarkdownEngine { - - private ChannelDispatcher dispatcher; - - private MarkdownEngine() { - List markdownChannels = Arrays.asList( - new HtmlUrlChannel(), - new HtmlEndOfLineChannel(), - new HtmlEmphasisChannel(), - new HtmlListChannel(), - new HtmlCodeChannel(), - new IdentifierAndNumberChannel(), - new BlackholeChannel()); - dispatcher = new ChannelDispatcher(markdownChannels); - } - - private String convert(String input) { - CodeReader reader = new CodeReader(input); - try { - MarkdownOutput output = new MarkdownOutput(); - dispatcher.consume(reader, output); - return output.toString(); - - } finally { - reader.close(); - } - } - - public static String convertToHtml(String input) { - return new MarkdownEngine().convert(input); - } -} diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java deleted file mode 100644 index b1979254828..00000000000 --- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Sonar, open source software quality management 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 - */ -package org.sonar.markdown; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class MarkdownEngineTest { - - @Test - public void shouldDecorateUrl() { - assertThat(MarkdownEngine.convertToHtml("http://google.com"), - is("http://google.com")); - } - - @Test - public void shouldDecorateEndOfLine() { - assertThat(MarkdownEngine.convertToHtml("1\r2\r\n3\n"), is("1
2
3
")); - } - - @Test - public void shouldDecorateList() { - assertThat(MarkdownEngine.convertToHtml(" * one\r* two\r\n* three\n * \n *five"), - is("
  • one
  • \r
  • two
  • \r\n
  • three
  • \n
  • \n
*five")); - assertThat(MarkdownEngine.convertToHtml(" * one\r* two"), is("
  • one
  • \r
  • two
")); - } - - @Test - public void shouldDecorateCode() { - assertThat(MarkdownEngine.convertToHtml("This is a ``line of code``"), is("This is a line of code")); - assertThat(MarkdownEngine.convertToHtml("This is not a ``line of code"), is("This is not a ``line of code")); - } - - @Test - public void shouldEmphaseText() { - assertThat(MarkdownEngine.convertToHtml("This is *important*"), is("This is important")); - assertThat(MarkdownEngine.convertToHtml("This should not be * \n emphase"), is("This should not be *
emphase")); - assertThat(MarkdownEngine.convertToHtml("This is *very* very *important*"), is("This is very very important")); - assertThat(MarkdownEngine.convertToHtml("Not * emphase * because of whitespaces"), is("Not * emphase * because of whitespaces")); - assertThat(MarkdownEngine.convertToHtml("Not *emphase * because of whitespace"), is("Not *emphase * because of whitespace")); - assertThat(MarkdownEngine.convertToHtml("Not * emphase* because of whitespace"), is("Not * emphase* because of whitespace")); - assertThat(MarkdownEngine.convertToHtml("emphase*inside*word"), is("emphaseinsideword")); - assertThat(MarkdownEngine.convertToHtml("*Emphase many words*"), is("Emphase many words")); - } - - @Test - public void shouldNotChangeAnythingInTheText() { - assertThat(MarkdownEngine.convertToHtml("My text is $123 ''"), is("My text is $123 ''")); - } - -} diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java new file mode 100644 index 00000000000..095263734db --- /dev/null +++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java @@ -0,0 +1,70 @@ +/* + * Sonar, open source software quality management 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 + */ +package org.sonar.markdown; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class MarkdownTest { + + @Test + public void shouldDecorateUrl() { + assertThat(Markdown.convertToHtml("http://google.com"), + is("http://google.com")); + } + + @Test + public void shouldDecorateEndOfLine() { + assertThat(Markdown.convertToHtml("1\r2\r\n3\n"), is("1
2
3
")); + } + + @Test + public void shouldDecorateList() { + assertThat(Markdown.convertToHtml(" * one\r* two\r\n* three\n * \n *five"), + is("
  • one
  • \r
  • two
  • \r\n
  • three
  • \n
  • \n
*five")); + assertThat(Markdown.convertToHtml(" * one\r* two"), is("
  • one
  • \r
  • two
")); + } + + @Test + public void shouldDecorateCode() { + assertThat(Markdown.convertToHtml("This is a ``line of code``"), is("This is a line of code")); + assertThat(Markdown.convertToHtml("This is not a ``line of code"), is("This is not a ``line of code")); + } + + @Test + public void shouldEmphaseText() { + assertThat(Markdown.convertToHtml("This is *important*"), is("This is important")); + assertThat(Markdown.convertToHtml("This should not be * \n emphase"), is("This should not be *
emphase")); + assertThat(Markdown.convertToHtml("This is *very* very *important*"), is("This is very very important")); + assertThat(Markdown.convertToHtml("Not * emphase * because of whitespaces"), is("Not * emphase * because of whitespaces")); + assertThat(Markdown.convertToHtml("Not *emphase * because of whitespace"), is("Not *emphase * because of whitespace")); + assertThat(Markdown.convertToHtml("Not * emphase* because of whitespace"), is("Not * emphase* because of whitespace")); + assertThat(Markdown.convertToHtml("emphase*inside*word"), is("emphaseinsideword")); + assertThat(Markdown.convertToHtml("*Emphase many words*"), is("Emphase many words")); + } + + @Test + public void shouldNotChangeAnythingInTheText() { + assertThat(Markdown.convertToHtml("My text is $123 ''"), is("My text is $123 ''")); + } + +} 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 7fae7b28124..dbadf5ac349 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 @@ -33,7 +33,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.markdown.Markdown; import org.sonar.server.configuration.Backup; import org.sonar.server.configuration.CoreConfiguration; import org.sonar.server.configuration.ProfilesManager; @@ -123,7 +123,7 @@ public final class JRubyFacade { } public static String markdownToHtml(String input) { - return MarkdownEngine.convertToHtml(input); + return Markdown.convertToHtml(input); }