bundles/org.eclipse.packagedrone.utils/src/org/eclipse/packagedrone/utils/Locks.java
public static Locked lock ( final Lock lock )
    {
        lock.lock ();

        return new Locked () {

            @Override
            public void close ()
            {
                lock.unlock ();
            }
        };
    }
public static Locked lock ( final Lock lock )
    {
        lock.lock ();

        return new Locked () {

            @Override
            public void close ()
            {
                lock.unlock ();
            }
        };
    }
Lock and return {@link AutoCloseable} instance for unlocking
Use with a <tt>try-with-resources</tt> construct:

<pre>
{@code}
try ( Locked l = lock ( myLock ) ) {
// locked "myLock"
}
}
</pre>

@param lock
the lock to lock
@return the {@link AutoCloseable} instance which unlocks the lock