From 183b78861f7b48113686e19765b2d13d31b5cd64 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 9 Apr 2015 17:33:57 +0200 Subject: [PATCH] Fix quality flaws --- .../server/computation/source/LineReader.java | 2 +- .../step/PersistSyntaxHighLightingStep.java | 98 ------------ .../PersistSyntaxHighLightingStepTest.java | 142 ------------------ .../sonar/batch/index/SourceDataFactory.java | 2 +- .../sonar/batch/mediumtest/TaskResult.java | 2 +- 5 files changed, 3 insertions(+), 243 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/source/LineReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/source/LineReader.java index ab95c60197a..0ec4d573b2a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/source/LineReader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/source/LineReader.java @@ -24,6 +24,6 @@ import org.sonar.server.source.db.FileSourceDb; public interface LineReader { - void read(FileSourceDb.Line.Builder lineBuilder); + void read(FileSourceDb.Line.Builder lineBuilder); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java deleted file mode 100644 index e3f0e458862..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.server.computation.step; - -import com.google.common.annotations.VisibleForTesting; -import org.sonar.api.resources.Qualifiers; -import org.sonar.server.computation.ComputationContext; - -import java.util.Map; - -/** - * Nothing is persist for the moment. Only Syntax Highlighting are read and not persist for the moment - */ -public class PersistSyntaxHighLightingStep implements ComputationStep { - - private static final String OFFSET_SEPARATOR = ","; - - // Temporary variable in order to be able to test that syntax highlighting are well computed. Will only contains data from last processed - // file - private Map syntaxHighlightingByLineForLastProcessedFile; - - @Override - public String[] supportedProjectQualifiers() { - return new String[] {Qualifiers.PROJECT}; - } - - @Override - public void execute(ComputationContext context) { - int rootComponentRef = context.getReportMetadata().getRootComponentRef(); -// recursivelyProcessComponent(context, rootComponentRef); - } -// -// private void recursivelyProcessComponent(ComputationContext context, int componentRef) { -// BatchReportReader reportReader = context.getReportReader(); -// BatchReport.Component component = reportReader.readComponent(componentRef); -// List highlightingRules = reportReader.readComponentSyntaxHighlighting(componentRef); -// processSyntaxHightlighting(component, highlightingRules); -// -// for (Integer childRef : component.getChildRefList()) { -// recursivelyProcessComponent(context, childRef); -// } -// } -// -// private void processSyntaxHightlighting(BatchReport.Component component, List highlightingRules) { -// syntaxHighlightingByLineForLastProcessedFile = newHashMap(); -// if (!highlightingRules.isEmpty()) { -// for (BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule : highlightingRules) { -// processHighlightingRule(highlightingRule); -// } -// } -// } -// -// private void processHighlightingRule(BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule) { -// BatchReport.Range range = highlightingRule.getRange(); -// int startLine = range.getStartLine(); -// int endLine = range.getEndLine(); -// if (startLine != endLine) { -// // TODO support syntax highlighting on multiple lines when source will be in compute, in order to be able to know the end line in this case -// throw new IllegalStateException("To be implemented : Syntax Highlighting on multiple lines are not supported for the moment"); -// } -// StringBuilder symbolLine = syntaxHighlightingByLineForLastProcessedFile.get(startLine); -// if (symbolLine == null) { -// symbolLine = new StringBuilder(); -// syntaxHighlightingByLineForLastProcessedFile.put(startLine, symbolLine); -// } -// symbolLine.append(range.getStartOffset()).append(OFFSET_SEPARATOR); -// symbolLine.append(range.getEndOffset()).append(OFFSET_SEPARATOR); -// symbolLine.append(highlightingRule.getType().toString()); -// } - - @VisibleForTesting - Map getSyntaxHighlightingByLine() { - return syntaxHighlightingByLineForLastProcessedFile; - } - - @Override - public String getDescription() { - return "Read Syntax Highlighting"; - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java deleted file mode 100644 index e38b5dd75e0..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.computation.step; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import org.sonar.batch.protocol.Constants; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReportWriter; - -import java.io.File; -import java.io.IOException; - -public class PersistSyntaxHighLightingStepTest extends BaseStepTest { - - private static final Integer FILE_REF = 3; - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - File reportDir; - - PersistSyntaxHighLightingStep step; - - @Before - public void setup() throws Exception { - reportDir = temp.newFolder(); - step = new PersistSyntaxHighLightingStep(); - } - - @Override - protected ComputationStep step() throws IOException { - return step; - } - -// @Test -// public void compute_no_symbol() throws Exception { -// initReport(); -// -// step.execute(new ComputationContext(new BatchReportReader(reportDir), -// ComponentTesting.newProjectDto("PROJECT_A"))); -// -// assertThat(step.getSyntaxHighlightingByLine()).isEmpty(); -// } -// -// @Test -// public void compute_syntax_highlighting() throws Exception { -// BatchReportWriter writer = initReport(); -// -// writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList( -// BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() -// .setRange(BatchReport.Range.newBuilder() -// .setStartLine(1) -// .setStartOffset(3) -// .setEndLine(1) -// .setEndOffset(5) -// .build()) -// .setType(Constants.HighlightingType.ANNOTATION) -// .build(), -// BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() -// .setRange(BatchReport.Range.newBuilder() -// .setStartLine(3) -// .setStartOffset(6) -// .setEndLine(3) -// .setEndOffset(7) -// .build()) -// .setType(Constants.HighlightingType.COMMENT) -// .build()) -// ); -// -// step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); -// -// assertThat(step.getSyntaxHighlightingByLine()).hasSize(2); -// assertThat(step.getSyntaxHighlightingByLine().get(1).toString()).isEqualTo("3,5,ANNOTATION"); -// assertThat(step.getSyntaxHighlightingByLine().get(3).toString()).isEqualTo("6,7,COMMENT"); -// } -// -// @Test(expected = IllegalStateException.class) -// public void fail_when_range_is_defined_on_different_line() throws Exception { -// BatchReportWriter writer = initReport(); -// -// writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList( -// BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() -// .setRange(BatchReport.Range.newBuilder() -// .setStartLine(1) -// .setStartOffset(3) -// .setEndLine(2) -// .setEndOffset(2) -// .build()) -// .setType(Constants.HighlightingType.ANNOTATION) -// .build())); -// -// step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); -// } - - private BatchReportWriter initReport() { - BatchReportWriter writer = new BatchReportWriter(reportDir); - writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1) - .setProjectKey("PROJECT_KEY") - .setAnalysisDate(150000000L) - .build()); - - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(1) - .setType(Constants.ComponentType.PROJECT) - .setUuid("PROJECT_A") - .addChildRef(2) - .build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(2) - .setType(Constants.ComponentType.MODULE) - .setUuid("BCDE") - .addChildRef(FILE_REF) - .build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(FILE_REF) - .setType(Constants.ComponentType.FILE) - .setUuid("FILE_A") - .build()); - return writer; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java index 8a1447acdee..978dbdb9643 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java @@ -225,7 +225,7 @@ public class SourceDataFactory implements BatchComponent { } } catch (Exception e) { - throw new IllegalStateException("Can't read syntax highlighting for " + inputFile.absolutePath()); + throw new IllegalStateException("Can't read syntax highlighting for " + inputFile.absolutePath(), e); } finally { IOUtils.closeQuietly(inputStream); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 6dff11809b9..4a523b252e1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -217,7 +217,7 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver { } } catch (Exception e) { - throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath()); + throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e); } finally { IOUtils.closeQuietly(inputStream); } -- 2.39.5