]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7121 Project's File Lock not released on error 691/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 10 Dec 2015 16:06:44 +0000 (17:06 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 21 Dec 2015 08:24:35 +0000 (09:24 +0100)
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java

index 7c5e87050f999ba3b2c2894b50f228f00974312f..427f5c3fb7d19197b7117c70fab5fd3b6b6e4338 100644 (file)
@@ -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,
index bf432556235285f6ad3950065ef8ea7baec1a221..41c47d03b9d7cf71a15965aa5f0909141cb728bb 100644 (file)
@@ -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() {