You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2012/12/17 00:24:18 UTC

svn commit: r1422714 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java

Author: hibou
Date: Sun Dec 16 23:24:17 2012
New Revision: 1422714

URL: http://svn.apache.org/viewvc?rev=1422714&view=rev
Log:
IVY-1388
- add a shutdownhook to delete any lock which might not have been released

Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java   (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1422714&r1=1422713&r2=1422714&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Sun Dec 16 23:24:17 2012
@@ -33,6 +33,7 @@ for detailed view of each issue, please 
 	Mirko Bulovic
 	Ed Burcher
 	Jamie Burns
+	Wei Chen
 	Chris Chilvers
 	Kristian Cibulskis
 	Andrea Bernardo Ciddio
@@ -132,6 +133,8 @@ for detailed view of each issue, please 
 	
    trunk
 =====================================
+- FIX: *.lck files created by "artifact-lock" lock strategy are not cleaned up if ivy quits abruptly (IVY-1388) (thanks to Wei Chen)
+
 - NEW: IvyDependencyTree task : display a dependency tree on the console
 - NEW: Support Conditional Setting of a Property (IVY-1367)
 - NEW: Exposing some parent metadata (organisation, module, revision, branch) as properties (IVY-1288)

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java?rev=1422714&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java Sun Dec 16 23:24:17 2012
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.lock;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+
+class DeleteOnExitHook {
+
+    static {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                runHook();
+            }
+        });
+    }
+
+    private static LinkedHashSet files = new LinkedHashSet();
+
+    private DeleteOnExitHook() {
+    }
+
+    static synchronized void add(File file) {
+        files.add(file);
+    }
+
+    static synchronized void remove(File file) {
+        files.remove(file);
+    }
+
+    static synchronized void runHook() {
+        Iterator itr = files.iterator();
+        while (itr.hasNext()) {
+            ((File) itr.next()).delete();
+            itr.remove();
+        }
+    }
+}
\ No newline at end of file

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/DeleteOnExitHook.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java?rev=1422714&r1=1422713&r2=1422714&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java Sun Dec 16 23:24:17 2012
@@ -150,6 +150,7 @@ public abstract class FileBasedLockStrat
             try {
                 if (file.getParentFile().exists() || file.getParentFile().mkdirs()) {
                     if (file.createNewFile()) {
+                        DeleteOnExitHook.add(file);
                         return true;
                     } else {
                         if (debugLocking) {
@@ -167,6 +168,7 @@ public abstract class FileBasedLockStrat
 
         public void unlock(File file) {
             file.delete();
+            DeleteOnExitHook.remove(file);
         }
     }
     /**