From a2d5e82501f3ed8d96239845842770515f5087e6 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 1 Dec 2014 15:36:12 +0100 Subject: [PATCH] SONAR-5864 API cleanup * add a proper way to create perspective on InputFile * add a proper way to convert InputFile to resource * deprecate colorizer --- .../org/sonar/batch/DefaultSensorContext.java | 20 ++++++++-- .../org/sonar/colorizer/CDocTokenizer.java | 4 ++ .../CaseInsensitiveKeywordsTokenizer.java | 4 ++ .../org/sonar/colorizer/CodeColorizer.java | 4 ++ .../org/sonar/colorizer/CppDocTokenizer.java | 4 ++ .../org/sonar/colorizer/GroovyKeywords.java | 10 +++-- .../org/sonar/colorizer/GroovyTokenizers.java | 10 +++-- .../org/sonar/colorizer/HtmlCodeBuilder.java | 4 ++ .../org/sonar/colorizer/HtmlDecorator.java | 4 ++ .../java/org/sonar/colorizer/HtmlOptions.java | 4 ++ .../org/sonar/colorizer/HtmlRenderer.java | 10 +++-- .../sonar/colorizer/InlineDocTokenizer.java | 4 ++ .../colorizer/JavaAnnotationTokenizer.java | 4 ++ .../colorizer/JavaConstantTokenizer.java | 5 ++- .../org/sonar/colorizer/JavaKeywords.java | 18 +++++---- .../org/sonar/colorizer/JavaTokenizers.java | 18 +++++---- .../org/sonar/colorizer/JavadocTokenizer.java | 4 ++ .../sonar/colorizer/KeywordsTokenizer.java | 5 ++- .../org/sonar/colorizer/LiteralTokenizer.java | 6 ++- .../colorizer/MultilinesDocTokenizer.java | 10 +++-- .../colorizer/NotThreadSafeTokenizer.java | 3 +- .../org/sonar/colorizer/RegexpTokenizer.java | 10 +++-- .../java/org/sonar/colorizer/Renderer.java | 8 +++- .../org/sonar/colorizer/StringTokenizer.java | 4 ++ .../SynhtaxHighlightingException.java | 4 ++ .../java/org/sonar/colorizer/Tokenizer.java | 2 + .../core/component/ScanPerspectives.java | 19 ++++++++++ .../java/org/sonar/api/batch/Decorator.java | 3 ++ .../java/org/sonar/api/batch/PostJob.java | 3 ++ .../org/sonar/api/batch/SensorContext.java | 14 ++++--- .../java/org/sonar/api/batch/SonarIndex.java | 4 ++ .../api/component/ResourcePerspectives.java | 37 +++++++++++++++++++ .../org/sonar/api/measures/CoreMetrics.java | 4 +- .../org/sonar/api/source/Highlightable.java | 3 ++ .../org/sonar/api/source/Symbolizable.java | 3 ++ .../sonar/api/web/CodeColorizerFormat.java | 9 +++-- 36 files changed, 231 insertions(+), 51 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java index 089b2a3c58f..56c33623f39 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java @@ -25,11 +25,14 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.Event; import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.SonarIndex; +import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; import org.sonar.api.design.Dependency; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Directory; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectLink; @@ -245,15 +248,24 @@ public class DefaultSensorContext implements SensorContext { @Override public Measure saveMeasure(InputFile inputFile, Metric metric, Double value) { - return saveMeasure(fromInputFile(inputFile), metric, value); + return saveMeasure(getResource(inputFile), metric, value); } @Override public Measure saveMeasure(InputFile inputFile, Measure measure) { - return saveMeasure(fromInputFile(inputFile), measure); + return saveMeasure(getResource(inputFile), measure); } - private Resource fromInputFile(InputFile inputFile) { - return File.create(inputFile.relativePath()); + @Override + public Resource getResource(InputPath inputPath) { + Resource r; + if (inputPath instanceof InputDir) { + r = Directory.create(((InputDir) inputPath).relativePath()); + } else if (inputPath instanceof InputFile) { + r = File.create(((InputFile) inputPath).relativePath()); + } else { + throw new IllegalArgumentException("Unknow input path type: " + inputPath); + } + return getResource(r); } } diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/CDocTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/CDocTokenizer.java index 51d47a13532..3b43e59aefa 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/CDocTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/CDocTokenizer.java @@ -19,6 +19,10 @@ */ package org.sonar.colorizer; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class CDocTokenizer extends InlineDocTokenizer { public CDocTokenizer(String tagBefore, String tagAfter) { diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizer.java index 1fe9930e2e3..02d4e69f35c 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizer.java @@ -21,6 +21,10 @@ package org.sonar.colorizer; import java.util.Set; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class CaseInsensitiveKeywordsTokenizer extends KeywordsTokenizer { public CaseInsensitiveKeywordsTokenizer(String tagBefore, String tagAfter, Set keywords) { 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 bf1fe61df74..f4a0523b7f1 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java @@ -22,6 +22,10 @@ package org.sonar.colorizer; import java.io.Reader; import java.util.List; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class CodeColorizer { private List tokenizers = null; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/CppDocTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/CppDocTokenizer.java index 282e54cd2f6..55a57e24c9d 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/CppDocTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/CppDocTokenizer.java @@ -19,6 +19,10 @@ */ package org.sonar.colorizer; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class CppDocTokenizer extends MultilinesDocTokenizer { public CppDocTokenizer(String tagBefore, String tagAfter) { 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 2b4e0354794..8728faadd92 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java @@ -23,11 +23,15 @@ import com.google.common.collect.ImmutableSet; import java.util.Set; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public final class GroovyKeywords { private static final Set 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"); + "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/GroovyTokenizers.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyTokenizers.java index d66c91b705c..5c18a9f7da7 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyTokenizers.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyTokenizers.java @@ -23,6 +23,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public final class GroovyTokenizers { private static final String SPAN_END = ""; @@ -32,8 +36,8 @@ public final class GroovyTokenizers { public static List forHtml() { return Collections.unmodifiableList(Arrays.asList(new JavaAnnotationTokenizer("", SPAN_END), new LiteralTokenizer( - "", SPAN_END), new CDocTokenizer("", SPAN_END), new CppDocTokenizer("", - SPAN_END), new JavadocTokenizer("", SPAN_END), new JavaConstantTokenizer("", SPAN_END), - new KeywordsTokenizer("", SPAN_END, GroovyKeywords.get()))); + "", SPAN_END), new CDocTokenizer("", SPAN_END), new CppDocTokenizer("", + SPAN_END), new JavadocTokenizer("", SPAN_END), new JavaConstantTokenizer("", SPAN_END), + new KeywordsTokenizer("", SPAN_END, GroovyKeywords.get()))); } } diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java index e6755e7b7e7..8d7057103db 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java @@ -22,6 +22,10 @@ package org.sonar.colorizer; import java.util.HashMap; import java.util.Map; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class HtmlCodeBuilder implements Appendable { private StringBuilder colorizedCode = new StringBuilder(); 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 fdbd02a8180..e55dc91718e 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java @@ -26,6 +26,10 @@ import org.sonar.channel.CodeReader; import java.io.IOException; import java.io.InputStream; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class HtmlDecorator extends Tokenizer { private static final String CSS_PATH = "/sonar-colorizer.css"; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlOptions.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlOptions.java index d91d89bf5e7..38c6b180f07 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlOptions.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlOptions.java @@ -19,6 +19,10 @@ */ package org.sonar.colorizer; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class HtmlOptions { public static final HtmlOptions DEFAULT = new HtmlOptions(true, null, true); public static final OnlySyntaxHtmlOptions ONLY_SYNTAX = new OnlySyntaxHtmlOptions(); diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlRenderer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlRenderer.java index c90cdcff973..a95a4348991 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlRenderer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlRenderer.java @@ -19,13 +19,17 @@ */ package org.sonar.colorizer; +import org.sonar.channel.Channel; +import org.sonar.channel.CodeReader; + import java.io.Reader; import java.util.ArrayList; import java.util.List; -import org.sonar.channel.Channel; -import org.sonar.channel.CodeReader; - +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class HtmlRenderer extends Renderer { private HtmlOptions options = null; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/InlineDocTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/InlineDocTokenizer.java index 7c5b0c851aa..9383296e4a7 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/InlineDocTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/InlineDocTokenizer.java @@ -24,6 +24,10 @@ import org.sonar.channel.EndMatcher; import java.util.Arrays; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public abstract class InlineDocTokenizer extends Tokenizer { private final String tagBefore; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaAnnotationTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaAnnotationTokenizer.java index fc7cdf6b6d2..cf98d21a386 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaAnnotationTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaAnnotationTokenizer.java @@ -22,6 +22,10 @@ package org.sonar.colorizer; import org.sonar.channel.CodeReader; import org.sonar.channel.EndMatcher; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class JavaAnnotationTokenizer extends Tokenizer { private final String tagBefore; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java index 3216b720ef6..12937ac49da 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java @@ -23,8 +23,9 @@ import org.sonar.channel.CodeReader; import org.sonar.channel.EndMatcher; /** - * Detect Java constant + * @deprecated since 4.5.2 replace by highlighting mechanism */ +@Deprecated public class JavaConstantTokenizer extends Tokenizer { private final String tagBefore; @@ -39,7 +40,7 @@ public class JavaConstantTokenizer extends Tokenizer { private boolean hasNextToken(CodeReader code) { int lastChar = code.lastChar(); if (isJavaConstantStart(code.peek()) && !Character.isJavaIdentifierPart(lastChar) && !Character.isJavaIdentifierStart(lastChar) - && lastChar != DOT) { + && lastChar != DOT) { String constant = code.peekTo(endTokenMatcher); int nextCharAfterConstant = code.peek(constant.length() + 1)[constant.length()]; if (nextCharAfterConstant != 0 && Character.isJavaIdentifierPart(nextCharAfterConstant)) { 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 18bed2eda7d..164945ad64c 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java @@ -23,16 +23,20 @@ import com.google.common.collect.ImmutableSet; import java.util.Set; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public final class JavaKeywords { private static final Set KEYWORDS = ImmutableSet.of( - "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"); + "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"); 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 1b30e1a7b30..f040d376594 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaTokenizers.java @@ -23,6 +23,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public final class JavaTokenizers { private JavaTokenizers() { @@ -30,12 +34,12 @@ public final class JavaTokenizers { public static List forHtml() { return Collections.unmodifiableList(Arrays.asList( - new JavaAnnotationTokenizer("", ""), - new LiteralTokenizer("", ""), - new CDocTokenizer("", ""), - new JavadocTokenizer("", ""), - new CppDocTokenizer("", ""), - new JavaConstantTokenizer("", ""), - new KeywordsTokenizer("", "", JavaKeywords.get()))); + new JavaAnnotationTokenizer("", ""), + new LiteralTokenizer("", ""), + new CDocTokenizer("", ""), + new JavadocTokenizer("", ""), + new CppDocTokenizer("", ""), + new JavaConstantTokenizer("", ""), + new KeywordsTokenizer("", "", JavaKeywords.get()))); } } diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavadocTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavadocTokenizer.java index fee02f14bca..404a94a4f12 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavadocTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavadocTokenizer.java @@ -19,6 +19,10 @@ */ package org.sonar.colorizer; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class JavadocTokenizer extends MultilinesDocTokenizer { public JavadocTokenizer(String tagBefore, String tagAfter) { diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java index 3a1395fc5de..06025a33d37 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java @@ -28,8 +28,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Detect case-sensitive keywords + * @deprecated since 4.5.2 replace by highlighting mechanism */ +@Deprecated public class KeywordsTokenizer extends NotThreadSafeTokenizer { private final String tagBefore; @@ -76,7 +77,7 @@ public class KeywordsTokenizer extends NotThreadSafeTokenizer { } private boolean isKeyword(String word) { - if ( !caseInsensitive && keywords.contains(word)) { + if (!caseInsensitive && keywords.contains(word)) { return true; } else if (caseInsensitive && keywords.contains(word.toUpperCase())) { return true; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java index 42161a86d3a..054a74efe57 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java @@ -22,6 +22,10 @@ package org.sonar.colorizer; import org.sonar.channel.CodeReader; import org.sonar.channel.EndMatcher; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class LiteralTokenizer extends Tokenizer { private final String tagBefore; @@ -63,7 +67,7 @@ public class LiteralTokenizer extends Tokenizer { public boolean match(int endFlag) { literalValue.append((char) endFlag); - return code.lastChar()==firstChar && evenNumberOfBackSlashBeforeDelimiter() && literalValue.length()>1; + return code.lastChar() == firstChar && evenNumberOfBackSlashBeforeDelimiter() && literalValue.length() > 1; } private boolean evenNumberOfBackSlashBeforeDelimiter() { diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java index 005d52a3263..120615063e2 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java @@ -24,6 +24,10 @@ import org.sonar.channel.EndMatcher; import java.util.Arrays; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class MultilinesDocTokenizer extends Tokenizer { private static final String COMMENT_STARTED_ON_PREVIOUS_LINE = "COMMENT_STARTED_ON_PREVIOUS_LINE"; @@ -50,9 +54,9 @@ public class MultilinesDocTokenizer extends Tokenizer { public boolean hasNextToken(CodeReader code, HtmlCodeBuilder codeBuilder) { return code.peek() != '\n' - && code.peek() != '\r' - && (isCommentStartedOnPreviousLine(codeBuilder) || (code.peek() == startToken[0] && Arrays.equals(code.peek(startToken.length), - startToken))); + && code.peek() != '\r' + && (isCommentStartedOnPreviousLine(codeBuilder) || (code.peek() == startToken[0] && Arrays.equals(code.peek(startToken.length), + startToken))); } @Override diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/NotThreadSafeTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/NotThreadSafeTokenizer.java index ea46b37f77f..1efa7e67168 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/NotThreadSafeTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/NotThreadSafeTokenizer.java @@ -22,8 +22,9 @@ package org.sonar.colorizer; /** * A thread safe Tokenizer. Before each use by the CodeColorizer, the method clone() is automatically * called to clone the current instance. - * + * @deprecated since 4.5.2 replace by highlighting mechanism */ +@Deprecated public abstract class NotThreadSafeTokenizer extends Tokenizer implements Cloneable { @Override diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/RegexpTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/RegexpTokenizer.java index fe21a8cd79b..11b1c2fe71a 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/RegexpTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/RegexpTokenizer.java @@ -19,12 +19,16 @@ */ package org.sonar.colorizer; +import org.sonar.channel.CodeReader; + import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.sonar.channel.CodeReader; - -public class RegexpTokenizer extends NotThreadSafeTokenizer{ +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated +public class RegexpTokenizer extends NotThreadSafeTokenizer { private final String tagBefore; private final String tagAfter; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/Renderer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/Renderer.java index b6a9c80607b..d9cb84c5f91 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/Renderer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/Renderer.java @@ -19,11 +19,15 @@ */ package org.sonar.colorizer; +import org.sonar.channel.Channel; + import java.io.Reader; import java.util.List; -import org.sonar.channel.Channel; - +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public abstract class Renderer { public abstract String render(Reader code, List> tokenizers); diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/StringTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/StringTokenizer.java index eec4ddd0914..248f12f442f 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/StringTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/StringTokenizer.java @@ -21,6 +21,10 @@ package org.sonar.colorizer; import org.sonar.channel.CodeReader; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class StringTokenizer extends Tokenizer { private final LiteralTokenizer tokenizer; diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/SynhtaxHighlightingException.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/SynhtaxHighlightingException.java index ed7b5bc2a6f..8c008b031da 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/SynhtaxHighlightingException.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/SynhtaxHighlightingException.java @@ -19,6 +19,10 @@ */ package org.sonar.colorizer; +/** + * @deprecated since 4.5.2 replace by highlighting mechanism + */ +@Deprecated public class SynhtaxHighlightingException extends RuntimeException { public SynhtaxHighlightingException(String arg0, Throwable arg1) { diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/Tokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/Tokenizer.java index 4e1d0f7ecd9..3933e521532 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/Tokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/Tokenizer.java @@ -26,6 +26,8 @@ import org.sonar.channel.Channel; * and to add the highlighted token to an HtmlCodeBuilder. * * IMPORTANT: a Tokenizer must be THREAD-SAFE otherwise use {@link NotThreadSafeTokenizer} + * @deprecated since 4.5.2 replace by highlighting mechanism */ +@Deprecated public abstract class Tokenizer extends Channel { } diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java b/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java index 142f52a4f7c..a3cfb20cdc5 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java @@ -22,12 +22,18 @@ package org.sonar.core.component; import com.google.common.collect.Maps; import org.sonar.api.BatchComponent; import org.sonar.api.batch.SonarIndex; +import org.sonar.api.batch.fs.InputDir; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; import org.sonar.api.component.ResourcePerspectives; +import org.sonar.api.resources.Directory; +import org.sonar.api.resources.File; import org.sonar.api.resources.Resource; import javax.annotation.CheckForNull; + import java.util.Map; public class ScanPerspectives implements ResourcePerspectives, BatchComponent { @@ -64,6 +70,19 @@ public class ScanPerspectives implements ResourcePerspectives, BatchComponent { return null; } + @Override + public

P as(Class

perspectiveClass, InputPath inputPath) { + Resource r; + if (inputPath instanceof InputDir) { + r = Directory.create(((InputDir) inputPath).relativePath()); + } else if (inputPath instanceof InputFile) { + r = File.create(((InputFile) inputPath).relativePath()); + } else { + throw new IllegalArgumentException("Unknow input path type: " + inputPath); + } + return as(perspectiveClass, r); + } + private PerspectiveBuilder builderFor(Class clazz) { PerspectiveBuilder builder = (PerspectiveBuilder) builders.get(clazz); if (builder == null) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Decorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Decorator.java index b3f2792b507..d6337af5bc2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Decorator.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Decorator.java @@ -24,7 +24,10 @@ import org.sonar.api.resources.Resource; /** * @since 1.10 + * @deprecated since 4.5.2. Starting from SQ 5.x aggregation/computation of data will be mostly done on server side. + * As a result Decoration on batch side will be dropped at some point. */ +@Deprecated public interface Decorator extends BatchExtension, CheckProject { /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/PostJob.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/PostJob.java index 52eff7acc68..5de94ebd007 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/PostJob.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/PostJob.java @@ -30,7 +30,10 @@ import org.sonar.api.resources.Project; *

* * @since 1.10 + * @deprecated since 4.5.2. Starting from SQ 5.0 a big part of project analysis will be processed asynchnonously on server side. As + * a result batch analysis will ends very quickly and probably before analysis results are persisted in SQ server referentials. */ +@Deprecated public interface PostJob extends BatchExtension { void executeOn(Project project, SensorContext context); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index c76eaf47138..a21d421e6ac 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -19,8 +19,8 @@ */ package org.sonar.api.batch; -import com.google.common.annotations.Beta; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; import org.sonar.api.design.Dependency; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; @@ -252,16 +252,20 @@ public interface SensorContext { void deleteEvent(Event event); /** - * Experimental - do not use + * Save measure on {@link InputFile} * @since 4.2 */ - @Beta Measure saveMeasure(InputFile inputFile, Metric metric, Double value); /** - * Experimental - do not use + * Save measure on {@link InputFile} * @since 4.2 */ - @Beta Measure saveMeasure(InputFile inputFile, Measure measure); + + /** + * Allow to get {@link Resource} corresponding to provided {@link InputPath}. + * @since 4.5.2 + */ + Resource getResource(InputPath inputPath); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java index cbe29014b2f..39124edb2ab 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java @@ -36,6 +36,10 @@ import java.util.Date; import java.util.List; import java.util.Set; +/** + * @deprecated since 4.5.2 should not be used by plugins. + */ +@Deprecated public abstract class SonarIndex implements DirectedGraphAccessor { /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java index d992b571001..18bce8f9e36 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java @@ -19,17 +19,54 @@ */ package org.sonar.api.component; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; +import org.sonar.api.issue.Issuable; import org.sonar.api.resources.Resource; +import org.sonar.api.source.Highlightable; +import org.sonar.api.source.Symbolizable; +import org.sonar.api.test.TestPlan; +import org.sonar.api.test.Testable; import javax.annotation.CheckForNull; /** + * Use this component to create perspective from resources or {@link InputPath} * Only on batch-side. + * + *
+ * public class MySensor implements Sensor {
+ *   private final ResourcePerspectives perspectives;
  *
+ *   public MySensor(ResourcePerspectives perspectives) {
+ *     this.perspectives = perspectives;
+ *   }
+ *   
+ *   public void analyse(Project module, SensorContext context) {
+ *      // Get some Resource or InputFile/InputPath
+ *      Highlightable highlightable = perspectives.as(Highlightable.class, inputPath);
+ *      if (highlightable != null) {
+ *        ...
+ *      }
+ *   }
+ * }
+ * 
+ * @see Issuable + * @see Highlightable + * @see Symbolizable + * @see Testable + * @see TestPlan * @since 3.5 */ public interface ResourcePerspectives extends Perspectives { @CheckForNull

P as(Class

perspectiveClass, Resource resource); + + /** + * Allow to create perspective from {@link InputPath}. In particular from {@link InputFile}. + * @since 4.5.2 + */ + @CheckForNull +

P as(Class

perspectiveClass, InputPath inputPath); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index 3269bd99336..a2a677d7151 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -1319,7 +1319,7 @@ public final class CoreMetrics { .create(); /** - * @deprecated since 4.5. Internal storage of duplication is not an API. No more available on batch side. + * @deprecated since 4.5. Internal storage of duplication is not an API. */ @Deprecated public static final String DUPLICATIONS_DATA_KEY = "duplications_data"; @@ -1340,7 +1340,7 @@ public final class CoreMetrics { * * *

- * @deprecated since 4.5. Internal storage of duplication is not an API. No more available on batch side. + * @deprecated since 4.5. Internal storage of duplication is not an API. */ @Deprecated public static final Metric DUPLICATIONS_DATA = new Metric.Builder(DUPLICATIONS_DATA_KEY, "Duplications details", Metric.ValueType.DATA) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java b/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java index 0ab229be03c..6c843b4ba26 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java @@ -20,8 +20,11 @@ package org.sonar.api.source; import org.sonar.api.component.Perspective; +import org.sonar.api.component.ResourcePerspectives; /** + * Use this perspective to save syntax highlighting on files. + * See {@link ResourcePerspectives}. * @since 3.6 */ public interface Highlightable extends Perspective { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java b/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java index 3a49ada34df..1cc82162047 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java @@ -20,10 +20,13 @@ package org.sonar.api.source; import org.sonar.api.component.Perspective; +import org.sonar.api.component.ResourcePerspectives; import java.util.List; /** + * Use this perspective to save symbol references on files. + * See {@link ResourcePerspectives}. * @since 3.6 */ public interface Symbolizable extends Perspective { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/CodeColorizerFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/CodeColorizerFormat.java index 26544ad5c50..4c6c32a278a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/CodeColorizerFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/CodeColorizerFormat.java @@ -19,17 +19,20 @@ */ package org.sonar.api.web; -import java.util.List; - import com.google.common.base.Objects; import org.sonar.api.ServerExtension; +import org.sonar.api.source.Highlightable; import org.sonar.colorizer.Tokenizer; +import java.util.List; + /** * Extend the library sonar-colorizer to support new languages. By default only Java sources are colorized in Sonar. * * @since 1.12 + * @deprecated since 4.5.2 use {@link Highlightable} */ +@Deprecated public abstract class CodeColorizerFormat implements ServerExtension { private String languageKey; @@ -57,7 +60,7 @@ public abstract class CodeColorizerFormat implements ServerExtension { if (this == o) { return true; } - if ( !(o instanceof CodeColorizerFormat)) { + if (!(o instanceof CodeColorizerFormat)) { return false; } -- 2.39.5