diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-15 16:43:07 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-15 17:35:25 +0100 |
commit | feaf31f478e1980c66297d7527b3d259112b3683 (patch) | |
tree | 24f16eadf624c893fc91ce1125fb1db57f113ef3 /sonar-batch-protocol/src | |
parent | 5e0d16032af2d4ff85b9e9faad17186305bdb420 (diff) | |
download | sonarqube-feaf31f478e1980c66297d7527b3d259112b3683.tar.gz sonarqube-feaf31f478e1980c66297d7527b3d259112b3683.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-batch-protocol/src')
4 files changed, 67 insertions, 5 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/PreviousIssueHelper.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/PreviousIssueHelper.java index d8b211eacde..576cb9105a3 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/PreviousIssueHelper.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/PreviousIssueHelper.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.Iterator; +import java.util.NoSuchElementException; public class PreviousIssueHelper { @@ -47,7 +48,6 @@ public class PreviousIssueHelper { } public <G> void streamIssues(Writer out, Iterable<G> issues, Function<G, PreviousIssue> converter) { - Gson gson = GsonHelper.create(); try { JsonWriter writer = new JsonWriter(out); writer.setIndent(" "); @@ -101,6 +101,13 @@ public class PreviousIssueHelper { @Override public PreviousIssue next() { + try { + if (!jsonreader.hasNext()) { + throw new NoSuchElementException(); + } + } catch (IOException e) { + throw new IllegalStateException("Unable to iterate over JSON file ", e); + } return gson.fromJson(jsonreader, PreviousIssue.class); } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/package-info.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/package-info.java new file mode 100644 index 00000000000..b2ea9bf0e15 --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.batch.protocol.input.issues; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/ReportHelper.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/ReportHelper.java index f407a4a3f01..3bb134df2a0 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/ReportHelper.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/ReportHelper.java @@ -19,14 +19,14 @@ */ package org.sonar.batch.protocol.output; -import org.sonar.batch.protocol.output.component.ReportComponents; - import com.google.gson.Gson; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; +import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.sonar.batch.protocol.GsonHelper; +import org.sonar.batch.protocol.output.component.ReportComponents; import org.sonar.batch.protocol.output.issue.ReportIssue; import java.io.BufferedInputStream; @@ -39,6 +39,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Iterator; +import java.util.NoSuchElementException; public class ReportHelper { @@ -71,7 +72,6 @@ public class ReportHelper { } public void saveIssues(long componentBatchId, Iterable<ReportIssue> issues) { - Gson gson = GsonHelper.create(); File issuesFile = getIssuesFile(componentBatchId); try (OutputStreamWriter out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(issuesFile)), "UTF-8")) { @@ -127,7 +127,7 @@ public class ReportHelper { public ReportIssueIterator(File issuesFile) { try { - reader = new JsonReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(issuesFile)))); + reader = new JsonReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(issuesFile)), Charsets.UTF_8)); reader.beginArray(); } catch (IOException e) { throw new IllegalStateException("Unable to read " + issuesFile, e); @@ -151,6 +151,13 @@ public class ReportHelper { @Override public ReportIssue next() { + try { + if (!reader.hasNext()) { + throw new NoSuchElementException(); + } + } catch (IOException e) { + throw new IllegalStateException("Unable to iterate over JSON file ", e); + } return gson.fromJson(reader, ReportIssue.class); } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/package-info.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/package-info.java new file mode 100644 index 00000000000..a976368c3a7 --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.batch.protocol.output; + +import javax.annotation.ParametersAreNonnullByDefault; + |