aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-11-27 13:47:50 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-11-27 15:08:29 +0100
commit2d575bd89ffebc75899267c695a9bb55e974ba35 (patch)
treeecf3bac9a9467da20aae7073f57604bd6d428351
parentf2ceeb253e6a1cbcd98610319aeccfd8b86ed0e0 (diff)
downloadsonarqube-2d575bd89ffebc75899267c695a9bb55e974ba35.tar.gz
sonarqube-2d575bd89ffebc75899267c695a9bb55e974ba35.zip
Fix quality flaws
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java1
4 files changed, 9 insertions, 10 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java
index 9633b348ba8..aeafabbb6b7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java
@@ -19,13 +19,12 @@
*/
package org.sonar.server.db.migrations.v50;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.Database;
-import org.sonar.server.db.migrations.BaseDataChange;
-import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.db.migrations.*;
import org.sonar.server.db.migrations.Select.Row;
import org.sonar.server.db.migrations.Select.RowReader;
-import org.sonar.server.db.migrations.SqlStatement;
import javax.annotation.Nullable;
@@ -52,7 +51,7 @@ public class FeedFileSources extends BaseDataChange {
public boolean handle(Row row, SqlStatement update) throws SQLException {
String projectUuid = row.getString(1);
String fileUuid = row.getString(2);
- String source = row.getString(3);
+ String source = StringUtils.defaultIfBlank(row.getString(3), "");
Date updatedAt = row.getDate(4);
byte[] shortRevisions = row.getBytes(5);
byte[] longRevisions = row.getBytes(6);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
index 466d92cfe53..bf4e16c536c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
@@ -106,7 +106,10 @@ class SourceLineResultSetIterator extends ResultSetIterator<SourceLineResultSetI
protected SourceFile read(ResultSet rs) throws SQLException {
String projectUuid = rs.getString(1);
String fileUuid = rs.getString(2);
- long updatedAt = SqlUtil.getLong(rs, 3);
+ Long updatedAt = SqlUtil.getLong(rs, 3);
+ if (updatedAt == null) {
+ updatedAt = System.currentTimeMillis();
+ }
Date updatedDate = new Date(updatedAt);
SourceFile result = new SourceFile(fileUuid, updatedAt);
@@ -148,7 +151,7 @@ class SourceLineResultSetIterator extends ResultSetIterator<SourceLineResultSetI
line++;
}
} catch (IOException ioError) {
- throw new IllegalStateException("Impossible to open stream for file_sources.data with file_uuid " + fileUuid);
+ throw new IllegalStateException("Impossible to open stream for file_sources.data with file_uuid " + fileUuid, ioError);
} catch (ArrayIndexOutOfBoundsException lineError) {
throw new IllegalStateException(
String.format("Impossible to parse source line data, stuck at line %d", line), lineError);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java
index 7a780ecbad6..deff5e4e2f3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java
@@ -29,7 +29,6 @@ import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.source.db.FileSourceDao;
import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.NotFoundException;
import java.io.OutputStream;
@@ -64,9 +63,6 @@ public class HashAction implements RequestHandler {
try {
String componentKey = request.mandatoryParam("key");
ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
- if (component == null) {
- throw new NotFoundException("Unable to find component with key " + componentKey);
- }
String lineHashes = fileSourceDao.selectLineHashes(component.uuid(), session);
if (lineHashes == null) {
response.noContent();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
index 20be6fbedda..0318b24de3b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
@@ -95,6 +95,7 @@ public class HashActionTest {
@Test
public void fail_to_show_hashes_if_file_does_not_exist() throws Exception {
String componentKey = "project:src/File.xoo";
+ when(componentDao.getByKey(any(DbSession.class), eq(componentKey))).thenThrow(NotFoundException.class);
try {
WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", componentKey);
request.execute();