diff options
12 files changed, 87 insertions, 22 deletions
diff --git a/server/sonar-web/src/main/coffee/component-viewer/main.coffee b/server/sonar-web/src/main/coffee/component-viewer/main.coffee index a35083017ff..ab9241fcbed 100644 --- a/server/sonar-web/src/main/coffee/component-viewer/main.coffee +++ b/server/sonar-web/src/main/coffee/component-viewer/main.coffee @@ -133,6 +133,8 @@ define [ width = @elementToFit.width() height = @elementToFit.height() + return if width == 0 || height == 0 + availableWidth = width - workspace.outerWidth(true) - 20 availableHeight = height - @$(@headerRegion.$el).outerHeight(true) diff --git a/server/sonar-web/src/main/less/components/issues.less b/server/sonar-web/src/main/less/components/issues.less index 04c1f43ac0d..f6c27e10994 100644 --- a/server/sonar-web/src/main/less/components/issues.less +++ b/server/sonar-web/src/main/less/components/issues.less @@ -40,7 +40,7 @@ .issue-message { padding-left: @leftPadding; - padding-right: 40px + @rightPadding; + padding-right: 90px + @rightPadding; line-height: 1.5; font-size: @baseFontSize; font-weight: 500; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java index 5f10cbabf58..252d988be85 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java @@ -58,7 +58,9 @@ import javax.annotation.Nullable; import java.io.IOException; import java.io.StringWriter; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -330,7 +332,15 @@ public class SourcePersister implements ScanPersister { StringBuilder[] symbolRefsPerLine = new StringBuilder[file.lines()]; long[] originalLineOffsets = file.originalLineOffsets(); int symbolId = 1; - for (Symbol symbol : symbolRefs.referencesBySymbol().keySet()) { + List<Symbol> symbols = new ArrayList<Symbol>(symbolRefs.referencesBySymbol().keySet()); + // Sort symbols to avoid false variation that would lead to an unnecessary update + Collections.sort(symbols, new Comparator<Symbol>() { + @Override + public int compare(Symbol o1, Symbol o2) { + return o1.getDeclarationStartOffset() - o2.getDeclarationStartOffset(); + } + }); + for (Symbol symbol : symbols) { int declarationStartOffset = symbol.getDeclarationStartOffset(); int declarationEndOffset = symbol.getDeclarationEndOffset(); int length = declarationEndOffset - declarationStartOffset; diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java index 8499776bfb7..2886cfbc28c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -80,6 +80,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; /** * Main utility class for writing batch medium tests. @@ -406,7 +407,7 @@ public class BatchMediumTester { * @param symbolEndOffset 0-based end offset for the symbol in file */ @CheckForNull - public List<Integer> symbolReferencesFor(InputFile file, int symbolStartOffset, int symbolEndOffset) { + public Set<Integer> symbolReferencesFor(InputFile file, int symbolStartOffset, int symbolEndOffset) { SymbolData data = symbolTablePerFile.get(file); if (data == null) { return null; diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java index e3c5e8387a8..d4df1fafd61 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.BatchComponent; import org.sonar.api.web.CodeColorizerFormat; import org.sonar.batch.highlighting.SyntaxHighlightingData; +import org.sonar.colorizer.CodeColorizer; import org.sonar.colorizer.Tokenizer; import javax.annotation.CheckForNull; @@ -71,7 +72,13 @@ public class CodeColorizers implements BatchComponent { CodeColorizerFormat format = byLang.get(language); List<Tokenizer> tokenizers; if (format == null) { - return null; + // Workaround for Java test code since Java plugin only provides highlighting for main source and no colorizer + // TODO can be dropped when Java plugin embed its own CodeColorizerFormat of (better) provides highlighting for tests + if ("java".equals(language)) { + tokenizers = CodeColorizer.Format.JAVA.getTokenizers(); + } else { + return null; + } } else { tokenizers = format.getTokenizers(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java index 8aafb847386..b4ce0c15878 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java @@ -28,16 +28,18 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; public class DefaultSymbolTable implements Symbolizable.SymbolTable { - private Map<Symbol, List<Integer>> referencesBySymbol; + private Map<Symbol, Set<Integer>> referencesBySymbol; - private DefaultSymbolTable(Map<Symbol, List<Integer>> referencesBySymbol) { + private DefaultSymbolTable(Map<Symbol, Set<Integer>> referencesBySymbol) { this.referencesBySymbol = referencesBySymbol; } - public Map<Symbol, List<Integer>> getReferencesBySymbol() { + public Map<Symbol, Set<Integer>> getReferencesBySymbol() { return referencesBySymbol; } @@ -57,7 +59,7 @@ public class DefaultSymbolTable implements Symbolizable.SymbolTable { public static class Builder implements Symbolizable.SymbolTableBuilder { - private final Map<Symbol, List<Integer>> referencesBySymbol = new LinkedHashMap<Symbol, List<Integer>>(); + private final Map<Symbol, Set<Integer>> referencesBySymbol = new LinkedHashMap<Symbol, Set<Integer>>(); private final String componentKey; public Builder(String componentKey) { @@ -67,7 +69,7 @@ public class DefaultSymbolTable implements Symbolizable.SymbolTable { @Override public Symbol newSymbol(int fromOffset, int toOffset) { Symbol symbol = new DefaultSymbol(fromOffset, toOffset); - referencesBySymbol.put(symbol, new ArrayList<Integer>()); + referencesBySymbol.put(symbol, new TreeSet<Integer>()); return symbol; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java index a6e8c8c0aaf..72d4c050eb4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java @@ -27,17 +27,17 @@ import org.sonar.batch.index.ComponentDataCache; import org.sonar.core.source.SnapshotDataTypes; import java.io.Serializable; -import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; public class DefaultSymbolTableBuilder implements SymbolTableBuilder { private final String componentKey; private final ComponentDataCache cache; - private final Map<org.sonar.api.source.Symbol, List<Integer>> referencesBySymbol = new LinkedHashMap<org.sonar.api.source.Symbol, List<Integer>>(); + private final Map<org.sonar.api.source.Symbol, Set<Integer>> referencesBySymbol = new LinkedHashMap<org.sonar.api.source.Symbol, Set<Integer>>(); public DefaultSymbolTableBuilder(String componentKey, ComponentDataCache cache) { this.componentKey = componentKey; @@ -47,7 +47,7 @@ public class DefaultSymbolTableBuilder implements SymbolTableBuilder { @Override public Symbol newSymbol(int fromOffset, int toOffset) { org.sonar.api.source.Symbol symbol = new DefaultSymbol(fromOffset, toOffset); - referencesBySymbol.put(symbol, new ArrayList<Integer>()); + referencesBySymbol.put(symbol, new TreeSet<Integer>()); return symbol; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java b/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java index 0f55e194e8b..baf897c6d1b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java +++ b/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java @@ -24,21 +24,21 @@ import org.sonar.api.batch.sensor.symbol.Symbol; import org.sonar.batch.index.Data; import java.util.Collection; -import java.util.List; import java.util.Map; +import java.util.Set; public class SymbolData implements Data { public static final String FIELD_SEPARATOR = ","; public static final String SYMBOL_SEPARATOR = ";"; - private final Map<org.sonar.api.source.Symbol, List<Integer>> referencesBySymbol; + private final Map<org.sonar.api.source.Symbol, Set<Integer>> referencesBySymbol; - public SymbolData(Map<org.sonar.api.source.Symbol, List<Integer>> referencesBySymbol) { + public SymbolData(Map<org.sonar.api.source.Symbol, Set<Integer>> referencesBySymbol) { this.referencesBySymbol = referencesBySymbol; } - public Map<org.sonar.api.source.Symbol, List<Integer>> referencesBySymbol() { + public Map<org.sonar.api.source.Symbol, Set<Integer>> referencesBySymbol() { return referencesBySymbol; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java index 7c69ffb6061..40d6d14ce34 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java @@ -362,6 +362,25 @@ public class SourcePersisterTest extends AbstractDaoTestCase { assertThat(symbolsPerLine).containsOnly("1,2,1;0,2,2", "0,1,1;0,2,2", "4,5,1;0,2,2"); } + @Test + public void verifyDeclarationOrderOfSymbolHasNoImpact() { + DefaultInputFile file = new DefaultInputFile(PROJECT_KEY, "src/foo.java") + .setLines(3) + .setOriginalLineOffsets(new long[] {0, 4, 7}); + + DefaultSymbolTableBuilder symbolBuilder = new DefaultSymbolTableBuilder(PROJECT_KEY + ":" + "src/foo.java", null); + org.sonar.api.batch.sensor.symbol.Symbol s2 = symbolBuilder.newSymbol(4, 6); + symbolBuilder.newReference(s2, 7); + symbolBuilder.newReference(s2, 0); + org.sonar.api.batch.sensor.symbol.Symbol s1 = symbolBuilder.newSymbol(1, 2); + symbolBuilder.newReference(s1, 11); + symbolBuilder.newReference(s1, 4); + + String[] symbolsPerLine = sourcePersister.computeSymbolReferencesPerLine(file, symbolBuilder.build()); + + assertThat(symbolsPerLine).containsOnly("1,2,1;0,2,2", "0,1,1;0,2,2", "4,5,1;0,2,2"); + } + private void mockResourceCache(String relativePathEmpty, String projectKey, String uuid) { File sonarFile = File.create(relativePathEmpty); sonarFile.setUuid(uuid); diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java index 3932cdbb630..4fa2716b081 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java @@ -41,7 +41,8 @@ import static org.fest.assertions.Assertions.assertThat; public class CodeColorizersTest { - private static final String HIGHLIGHTING = "0,4,cppd;5,11,cppd;12,15,cppd;16,19,k;29,37,k;65,69,k;85,93,cd;98,102,k;112,114,s;120,124,k"; + private static final String HIGHLIGHTING_JS = "0,4,cppd;5,11,cppd;12,15,cppd;16,19,k;29,37,k;65,69,k;85,93,cd;98,102,k;112,114,s;120,124,k"; + private static final String HIGHLIGHTING_JAVA = "0,4,j;5,11,j;12,15,j;16,22,k;23,28,k;43,50,k;51,54,k;67,78,a;81,87,k;88,92,k;97,100,k;142,146,k;162,170,cd"; @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -53,7 +54,7 @@ public class CodeColorizersTest { SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(jsFile, "UTF-8", "js"); - assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING); + assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JS); } @@ -68,7 +69,18 @@ public class CodeColorizersTest { SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(fileWithBom, "UTF-8", "js"); - assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING); + assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JS); + } + + @Test + public void shouldSupportJavaIfNotProvidedByJavaPluginForBackwardCompatibility() throws Exception { + CodeColorizers codeColorizers = new CodeColorizers(Arrays.<CodeColorizerFormat>asList()); + + File javaFile = new File(this.getClass().getResource("CodeColorizersTest/Person.java").toURI()); + + SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(javaFile, "UTF-8", "java"); + + assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JAVA); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java index aa8c67edc56..c68156c0a2d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java @@ -30,8 +30,8 @@ import org.sonar.batch.index.ComponentDataCache; import org.sonar.core.source.SnapshotDataTypes; import java.util.ArrayList; -import java.util.List; import java.util.Map; +import java.util.Set; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.eq; @@ -58,7 +58,7 @@ public class DefaultSymbolTableBuilderTest { ArgumentCaptor<SymbolData> argCaptor = ArgumentCaptor.forClass(SymbolData.class); verify(componentDataCache).setData(eq("foo"), eq(SnapshotDataTypes.SYMBOL_HIGHLIGHTING), argCaptor.capture()); - Map<org.sonar.api.source.Symbol, List<Integer>> referencesBySymbol = argCaptor.getValue().referencesBySymbol(); + Map<org.sonar.api.source.Symbol, Set<Integer>> referencesBySymbol = argCaptor.getValue().referencesBySymbol(); assertThat(new ArrayList<Symbol>(referencesBySymbol.keySet())).containsExactly(firstSymbol, secondSymbol, thirdSymbol); assertThat(new ArrayList<Integer>(referencesBySymbol.get(firstSymbol))).containsExactly(32); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/source/CodeColorizersTest/Person.java b/sonar-batch/src/test/resources/org/sonar/batch/source/CodeColorizersTest/Person.java new file mode 100644 index 00000000000..c5cc9793730 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/source/CodeColorizersTest/Person.java @@ -0,0 +1,12 @@ +/** + * Doc + */ +public class Person { + + private int first; + + @Deprecated + public void foo(int first, String last, Double middle) { + this.first = first; // First + } +} |