aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-29 16:34:35 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-29 16:38:45 +0200
commit2f33601f05590ca85f1dad42c78d97d27b17ad5e (patch)
tree66158b3af2469c2b90eec9e68b2fb3379ba1c6bf
parent0b1226871a26f136739f29050de52088b2aa1c3e (diff)
downloadsonarqube-2f33601f05590ca85f1dad42c78d97d27b17ad5e.tar.gz
sonarqube-2f33601f05590ca85f1dad42c78d97d27b17ad5e.zip
Fix Quality flaws
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java10
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java1
3 files changed, 7 insertions, 10 deletions
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
index a1db8436737..2051957bf42 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
@@ -122,9 +122,9 @@ class JavaProcessLauncher {
props.setProperty(PROPERTY_PROCESS_INDEX, Integer.toString(javaCommand.getProcessId().getIpcIndex()));
props.setProperty(PROPERTY_TERMINATION_TIMEOUT, String.valueOf(timeouts.getTerminationTimeout()));
props.setProperty(PROPERTY_SHARED_PATH, tempDir.getAbsolutePath());
- OutputStream out = new FileOutputStream(propertiesFile);
- props.store(out, String.format("Temporary properties file for command [%s]", javaCommand.getProcessId().getKey()));
- out.close();
+ try (OutputStream out = new FileOutputStream(propertiesFile)) {
+ props.store(out, String.format("Temporary properties file for command [%s]", javaCommand.getProcessId().getKey()));
+ }
return propertiesFile;
} catch (Exception e) {
throw new IllegalStateException("Cannot write temporary settings to " + propertiesFile, e);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java
index a65ad3d8d80..368e1f98aa3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java
@@ -44,19 +44,17 @@ public class ActivityIndexer extends BaseIndexer {
BulkIndexer bulk = new BulkIndexer(esClient, ActivityIndexDefinition.INDEX);
bulk.setLarge(lastUpdatedAt == 0L);
- DbSession dbSession = dbClient.openSession(false);
- try {
- ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
+ try (
+ DbSession dbSession = dbClient.openSession(false);
+ ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbSession, lastUpdatedAt)) {
+
bulk.start();
while (it.hasNext()) {
bulk.add(it.next());
}
bulk.stop();
- it.close();
return it.getMaxRowDate();
- } finally {
- dbSession.close();
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
index 2bb86289c32..2140aab032b 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
@@ -23,7 +23,6 @@ import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.scanner.bootstrap.BatchWsClient;
-import org.sonar.scanner.platform.DefaultServer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;