aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-05-13 15:40:24 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-05-13 15:49:00 +0200
commita0b334f10eedb58bb5bbcf1fbf05054e93927988 (patch)
treee4c86a715575108352abac63b6fef06ba5e9e9d9
parent01b50ea9c1e4528e6fb998d3478dc4fd569f6e70 (diff)
downloadsonarqube-a0b334f10eedb58bb5bbcf1fbf05054e93927988.tar.gz
sonarqube-a0b334f10eedb58bb5bbcf1fbf05054e93927988.zip
Fix quality flaws
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/package-info.java25
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java (renamed from server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java)3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java (renamed from server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentLinksStepTest.java)2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/add_links_on_project_and_module-result.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/add_links_on_project_and_module-result.xml)0
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/delete_link.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/delete_link.xml)0
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/empty.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/empty.xml)0
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/not_delete_custom_link.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/not_delete_custom_link.xml)0
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/nothing_to_do_when_link_already_exists.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/nothing_to_do_when_link_already_exists.xml)0
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/update_link-result.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/update_link-result.xml)0
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/update_link.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/update_link.xml)0
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/ProtobufUtil.java34
11 files changed, 56 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/package-info.java
new file mode 100644
index 00000000000..f4d64e0dd85
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * 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.server.plugins;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
index aa88b178334..e93deaf797a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
@@ -50,8 +50,7 @@ import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
@Category(DbTests.class)
-public class
- PersistDuplicationMeasuresStepTest extends BaseStepTest {
+public class PersistDuplicationsStepTest extends BaseStepTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentLinksStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
index 6677e55b24a..d12038ba96a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentLinksStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
@@ -49,7 +49,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Category(DbTests.class)
-public class PersistComponentLinksStepTest extends BaseStepTest {
+public class PersistProjectLinksStepTest extends BaseStepTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/add_links_on_project_and_module-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/add_links_on_project_and_module-result.xml
index 008f804103e..008f804103e 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/add_links_on_project_and_module-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/add_links_on_project_and_module-result.xml
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/delete_link.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/delete_link.xml
index 8b89e7223ec..8b89e7223ec 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/delete_link.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/delete_link.xml
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/empty.xml
index 871dedcb5e9..871dedcb5e9 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/empty.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/empty.xml
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/not_delete_custom_link.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/not_delete_custom_link.xml
index 78c6c1dd41a..78c6c1dd41a 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/not_delete_custom_link.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/not_delete_custom_link.xml
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/nothing_to_do_when_link_already_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/nothing_to_do_when_link_already_exists.xml
index 8b89e7223ec..8b89e7223ec 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/nothing_to_do_when_link_already_exists.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/nothing_to_do_when_link_already_exists.xml
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/update_link-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/update_link-result.xml
index 8b89e7223ec..8b89e7223ec 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/update_link-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/update_link-result.xml
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/update_link.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/update_link.xml
index d40281088f3..d40281088f3 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistComponentLinksStepTest/update_link.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistProjectLinksStepTest/update_link.xml
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/ProtobufUtil.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/ProtobufUtil.java
index 3b85d604365..3962cfd4ed1 100644
--- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/ProtobufUtil.java
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/ProtobufUtil.java
@@ -21,8 +21,16 @@ package org.sonar.batch.protocol;
import com.google.protobuf.Message;
import com.google.protobuf.Parser;
+import org.apache.commons.io.IOUtils;
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
public class ProtobufUtil {
private ProtobufUtil() {
@@ -30,36 +38,52 @@ public class ProtobufUtil {
}
public static <T extends Message> T readFile(File file, Parser<T> parser) {
- try (InputStream input = new BufferedInputStream(new FileInputStream(file))) {
+ InputStream input = null;
+ try {
+ input = new BufferedInputStream(new FileInputStream(file));
return parser.parseFrom(input);
} catch (IOException e) {
throw new IllegalStateException("Failed to read file: " + file, e);
+ } finally {
+ IOUtils.closeQuietly(input);
}
}
public static void writeToFile(Message message, File toFile) {
- try (OutputStream out = new BufferedOutputStream(new FileOutputStream(toFile, false))) {
+ OutputStream out = null;
+ try {
+ out = new BufferedOutputStream(new FileOutputStream(toFile, false));
message.writeTo(out);
} catch (IOException e) {
throw new IllegalStateException("Unable to write protocol buffer data to file " + toFile, e);
+ } finally {
+ IOUtils.closeQuietly(out);
}
}
public static void appendToFile(Message message, File toFile) {
- try (OutputStream out = new BufferedOutputStream(new FileOutputStream(toFile, true))) {
+ OutputStream out = null;
+ try {
+ out = new BufferedOutputStream(new FileOutputStream(toFile, true));
message.writeDelimitedTo(out);
} catch (IOException e) {
throw new IllegalStateException("Unable to append protocol buffer data to file " + toFile, e);
+ } finally {
+ IOUtils.closeQuietly(out);
}
}
public static <MESSAGE extends Message> void writeMessagesToFile(Iterable<MESSAGE> messages, File file) {
- try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file, true))) {
+ OutputStream out = null;
+ try {
+ out = new BufferedOutputStream(new FileOutputStream(file, true));
for (MESSAGE message : messages) {
message.writeDelimitedTo(out);
}
} catch (IOException e) {
throw new IllegalStateException("Failed to read file: " + file, e);
+ } finally {
+ IOUtils.closeQuietly(out);
}
}