aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-colorizer
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-05-25 21:36:47 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-05-28 09:28:50 +0200
commit1bdb2686d791326ea0694127047323ad3d8695be (patch)
treee0d0bc114a152f1797cbcefe612373c0e52ebf5a /sonar-colorizer
parent7934f95f388e4561fd630f9a834d8bd31432f7be (diff)
downloadsonarqube-1bdb2686d791326ea0694127047323ad3d8695be.tar.gz
sonarqube-1bdb2686d791326ea0694127047323ad3d8695be.zip
SONAR-6370 Remove guava from dependencies of sonar-colorizer
Diffstat (limited to 'sonar-colorizer')
-rw-r--r--sonar-colorizer/pom.xml10
-rw-r--r--sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java8
-rw-r--r--sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java16
-rw-r--r--sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java26
-rw-r--r--sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java9
-rw-r--r--sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java19
-rw-r--r--sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java8
-rw-r--r--sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java10
-rw-r--r--sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java1
9 files changed, 36 insertions, 71 deletions
diff --git a/sonar-colorizer/pom.xml b/sonar-colorizer/pom.xml
index 19ff87b1503..9d590ec2d77 100644
--- a/sonar-colorizer/pom.xml
+++ b/sonar-colorizer/pom.xml
@@ -16,12 +16,14 @@
<dependencies>
<dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-channel</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java
index 91982b62c71..f319d6669c4 100644
--- a/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java
+++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java
@@ -40,10 +40,6 @@ public class CodeColorizer {
this.tokenizers = format.getTokenizers();
}
- public String toHtml(Reader code) {
- return toHtml(code, null);
- }
-
public String toHtml(Reader code, @Nullable HtmlOptions options) {
HtmlOptions opts = options == null ? HtmlOptions.DEFAULT : options;
return new HtmlRenderer(opts).render(code, tokenizers);
@@ -57,10 +53,6 @@ public class CodeColorizer {
return new CodeColorizer(Format.GROOVY).toHtml(code, options);
}
- public static String getCss() {
- return HtmlDecorator.getCss();
- }
-
public enum Format {
JAVA(JavaTokenizers.forHtml()), GROOVY(GroovyTokenizers.forHtml());
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java
index 8728faadd92..e7c34270683 100644
--- a/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java
+++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java
@@ -19,8 +19,8 @@
*/
package org.sonar.colorizer;
-import com.google.common.collect.ImmutableSet;
-
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -28,10 +28,14 @@ import java.util.Set;
*/
@Deprecated
public final class GroovyKeywords {
- private static final Set<String> KEYWORDS = ImmutableSet.of(
- "as", "assert", "break", "case", "catch", "class", "continue", "def",
- "default", "do", "else", "extends", "finally", "for", "if", "in", "implements", "import", "instanceof", "interface", "new", "package",
- "property", "return", "switch", "throw", "throws", "try", "while");
+
+ private static final Set<String> KEYWORDS = new HashSet<>();
+
+ static {
+ KEYWORDS.addAll(Arrays.asList("as", "assert", "break", "case", "catch", "class", "continue", "def",
+ "default", "do", "else", "extends", "finally", "for", "if", "in", "implements", "import", "instanceof", "interface", "new", "package",
+ "property", "return", "switch", "throw", "throws", "try", "while"));
+ }
private GroovyKeywords() {
}
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java
index 48b65acaaf9..ed1ee38eb3c 100644
--- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java
+++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java
@@ -19,22 +19,14 @@
*/
package org.sonar.colorizer;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Closeables;
import org.sonar.channel.CodeReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-
/**
* @deprecated since 4.5.2 replace by highlighting mechanism
*/
@Deprecated
public class HtmlDecorator extends Tokenizer {
- private static final String CSS_PATH = "/sonar-colorizer.css";
-
private HtmlOptions options;
private int lineId;
@@ -50,9 +42,7 @@ public class HtmlDecorator extends Tokenizer {
StringBuilder sb = new StringBuilder();
if (options.isGenerateHtmlHeader()) {
sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
- + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><style type=\"text/css\">");
- sb.append(getCss());
- sb.append("</style></head><body>");
+ + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><body>");
}
sb.append("<table class=\"code\" id=\"");
if (options.getTableId() != null) {
@@ -94,18 +84,4 @@ public class HtmlDecorator extends Tokenizer {
}
return false;
}
-
- public static String getCss() {
- InputStream input = null;
- try {
- input = HtmlRenderer.class.getResourceAsStream(CSS_PATH);
- return new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8);
-
- } catch (IOException e) {
- throw new SynhtaxHighlightingException("SonarQube Colorizer CSS file not found: " + CSS_PATH, e);
-
- } finally {
- Closeables.closeQuietly(input);
- }
- }
}
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java
index 164945ad64c..e927e585f0c 100644
--- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java
+++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java
@@ -19,8 +19,9 @@
*/
package org.sonar.colorizer;
-import com.google.common.collect.ImmutableSet;
-
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -29,14 +30,14 @@ import java.util.Set;
@Deprecated
public final class JavaKeywords {
- private static final Set<String> KEYWORDS = ImmutableSet.of(
+ private static final Set<String> KEYWORDS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char",
"class", "const", "continue", "default",
"do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for",
"goto", "if", "implements", "import", "instanceof",
"int", "interface", "long", "native", "new", "null", "package", "private",
"protected", "public", "return", "short", "static", "strictfp",
- "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
+ "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while")));
private JavaKeywords() {
}
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java
index f040d376594..05390a6cbb8 100644
--- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java
+++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java
@@ -29,17 +29,20 @@ import java.util.List;
@Deprecated
public final class JavaTokenizers {
+ private static final List<Tokenizer> TOKENIZERS = Collections.unmodifiableList(Arrays.asList(
+ new JavaAnnotationTokenizer("<span class=\"a\">", "</span>"),
+ new LiteralTokenizer("<span class=\"s\">", "</span>"),
+ new CDocTokenizer("<span class=\"cd\">", "</span>"),
+ new JavadocTokenizer("<span class=\"j\">", "</span>"),
+ new CppDocTokenizer("<span class=\"cppd\">", "</span>"),
+ new JavaConstantTokenizer("<span class=\"c\">", "</span>"),
+ new KeywordsTokenizer("<span class=\"k\">", "</span>", JavaKeywords.get())));
+
private JavaTokenizers() {
+ // only static stuff
}
public static List<Tokenizer> forHtml() {
- return Collections.unmodifiableList(Arrays.asList(
- new JavaAnnotationTokenizer("<span class=\"a\">", "</span>"),
- new LiteralTokenizer("<span class=\"s\">", "</span>"),
- new CDocTokenizer("<span class=\"cd\">", "</span>"),
- new JavadocTokenizer("<span class=\"j\">", "</span>"),
- new CppDocTokenizer("<span class=\"cppd\">", "</span>"),
- new JavaConstantTokenizer("<span class=\"c\">", "</span>"),
- new KeywordsTokenizer("<span class=\"k\">", "</span>", JavaKeywords.get())));
+ return TOKENIZERS;
}
}
diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java
index d3a5c4cb217..5b53df03f79 100644
--- a/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java
+++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java
@@ -79,12 +79,6 @@ public class CodeColorizerTest {
}
@Test
- public void getCss() {
- assertThat(CodeColorizer.getCss().length()).isGreaterThan(100);
- assertThat(CodeColorizer.getCss()).contains(".code");
- }
-
- @Test
public void mustBeThreadsafe() throws InterruptedException, ExecutionException, IOException {
final int taskCount = 50;
final int threadCount = 5;
@@ -151,7 +145,7 @@ public class CodeColorizerTest {
}
private void assertHtml(String html) {
- assertContains(html, "<style", "<table class=\"code\"", "</html>");
+ assertContains(html, "<table class=\"code\"", "</html>");
}
private void assertContains(String html, String... strings) {
diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java
index ff69b9b1e05..49fc1d6711b 100644
--- a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java
+++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java
@@ -30,7 +30,7 @@ public class HtmlDecoratorTest {
public void beginOfFileTag() {
HtmlDecorator decorator = new HtmlDecorator(HtmlOptions.DEFAULT);
String tag = decorator.getTagBeginOfFile();
- assertContains(tag, "<html", "<style", "<table");
+ assertContains(tag, "<html", "<table");
}
@Test
@@ -50,7 +50,7 @@ public class HtmlDecoratorTest {
String tag = decorator.getTagBeginOfFile();
- assertNotContains(tag, "<html", "<style");
+ assertNotContains(tag, "<html", "<body");
assertContains(tag, "<table");
}
@@ -94,12 +94,6 @@ public class HtmlDecoratorTest {
);
}
- @Test
- public void getCss() {
- assertThat(HtmlDecorator.getCss().length()).isGreaterThan(100);
- assertThat(HtmlDecorator.getCss()).contains(".code");
- }
-
public void assertContains(String html, String... strings) {
for (String string : strings) {
assertThat(html).contains(string);
diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java
index f4a897952c1..90e0c32cfd9 100644
--- a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java
+++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java
@@ -59,7 +59,6 @@ public class HtmlRendererTest {
String html = new HtmlRenderer().render(new FileReader(java), Arrays.asList(javaKeywordTokenizer));
assertThat(html).contains("<html>");
- assertThat(html).contains("<style");
assertThat(html).contains("<table class=\"code\"");
assertThat(html).contains("public");
assertThat(html).contains("class");