aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-12-10 17:06:44 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-12-21 09:24:35 +0100
commit8239ac084eb9aaaba9f661a4e2fe5891bda8d452 (patch)
treee8671ff750ad840a57c5c3268bc3b2b028f32f81 /sonar-batch
parent13a6da5b9d25ef38b92b140fef845a46e6325939 (diff)
downloadsonarqube-8239ac084eb9aaaba9f661a4e2fe5891bda8d452.tar.gz
sonarqube-8239ac084eb9aaaba9f661a4e2fe5891bda8d452.zip
SONAR-7121 Project's File Lock not released on error
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java10
2 files changed, 24 insertions, 0 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 7c5e87050f9..427f5c3fb7d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -117,6 +117,20 @@ public class ProjectScanContainer extends ComponentContainer {
}
}
+ @Override
+ public ComponentContainer startComponents() {
+ try {
+ return super.startComponents();
+ } catch (Exception e) {
+ // ensure that lock is released
+ ProjectLock lock = getComponentByType(ProjectLock.class);
+ if (lock != null) {
+ lock.stop();
+ }
+ throw e;
+ }
+ }
+
private void addBatchComponents() {
add(
props,
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java
index bf432556235..41c47d03b9d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java
@@ -76,6 +76,16 @@ public class ProjectLockTest {
lock.tryLock();
lock.tryLock();
}
+
+ @Test
+ /**
+ * If there is an error starting up the scan, we'll still try to unlock even if the lock
+ * was never done
+ */
+ public void stopWithoutStarting() {
+ lock.stop();
+ lock.stop();
+ }
@Test
public void tryLockTwice() {