aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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() {