Allows the usage of addShutdownHook without getting the runtime first.

@param self    the object the method is called on (ignored)
@param closure the shutdown hook action
@since 1.5.0
358555
public static void addShutdownHook(Object self, Closure closure) {
        Runtime.getRuntime().addShutdownHook(new Thread(closure));
    }
119016
@FFDCIgnore(IllegalStateException.class)
    public void addShutdownHook() {
        try {
            if (hookSet.compareAndSet(false, true)) {
                Runtime.getRuntime().addShutdownHook(this);
            }
        } catch (IllegalStateException e) {
            // ok. based on timing, if we start shutting down, we may
            // not be able to remove the hook.
        }
    }
1125434
public static <T> T identity(Object self, Closure<T> closure) {
        return DefaultGroovyMethods.with(self, closure);
    }
357170
public void initialization(Closure<?> closure) {
        if (initialization != null) {
            throw new GradleException("Initialization is already set");
        }
        initialization = (Initialization) project.configure(new Initialization(), closure);
    }
941077
@Cmd
	public void optional(final Closure<Void> closure) {
		log.info("Executing optional block ...");
		try {
			closure.call();
		} catch (final Exception ex) {
			log.error("Exception executing optional block: " + ex.getMessage(), ex);
			errors.add(ex);
		} catch (AssertionError err) {
			log.error("Assertion failed executing optional block: " + err.getMessage(), err);
			errors.add(err);
		}
		log.info("... finished execution of optional block");
	}
408562
function onUnload(handler, thisObject){
    // deprecated in 1.4
    /** @cut */ basis.dev.warn('basis.dom.event.onUnload() is deprecated, use basis.teardown() instead');
    basis.teardown(handler, thisObject);
  }
385134
public static <T> Iterator<T> eachWithIndex(Iterator<T> self, @ClosureParams(value=FromString.class, options="T,Integer") Closure closure) {
        final Object[] args = new Object[2];
        int counter = 0;
        while (self.hasNext()) {
            args[0] = self.next();
            args[1] = counter++;
            closure.call(args);
        }
        return self;
    }
526427
public static void invoke() {
        for (final Runnable instance : instances) {
            try {
                instance.run();
            } catch (final Throwable t) {
                LOGGER.error(SHUTDOWN_HOOK_MARKER, "Caught exception executing shutdown hook {}", instance, t);
            }
        }
    }
746034
@SuppressWarnings("unchecked")
  public static <T> T invokeClosure(Closure<T> closure, Object... args) {
    try {
      return closure.call(args);
    } catch (InvokerInvocationException e) {
      ExceptionUtil.sneakyThrow(e.getCause());
      return null; // never reached
    }
  }
876657
private void createShutdownHook() {
        LOG.trace("Creating Jetty ShutdownHook...");

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            try {
                LOG.debug("Shutting Down...");
                stopServer();
            } catch (Exception e) {
                LOG.error("Shutdown", e);
            }
        }));
    }
792109
private Thread createShutdownHook( final Process process )
    {
        LOG.debug( "Wrapping stream I/O." );

        return new Thread(
            new Runnable()
            {
                public void run()
                {
                    try
                    {
                        process.destroy();
                    }
                    catch( Exception e )
                    {
                        // ignore if already shutting down
                    }
                }
            },
            "DefaultJavaRunner shutdown hook"
        );
    }
890901
public function addMethod($name, Closure $closure)
    {
        if (method_exists($this, $name)) {
            throw new Exception('Overriding core methods not allowed.');
        }

        $this->methods[$name] = $closure;
    }
21565
public static void removeShutdownHook(final Thread shutdownHook, final String serviceName, final Logger logger) {

		// Do not run if this is invoked by the shutdown hook itself
		if (shutdownHook == null || shutdownHook == Thread.currentThread()) {
			return;
		}

		checkNotNull(logger);

		try {
			Runtime.getRuntime().removeShutdownHook(shutdownHook);
		} catch (IllegalStateException e) {
			// race, JVM is in shutdown already, we can safely ignore this
			logger.debug("Unable to remove shutdown hook for {}, shutdown already in progress", serviceName, e);
		} catch (Throwable t) {
			logger.warn("Exception while un-registering {}'s shutdown hook.", serviceName, t);
		}
	}
566223
function callHook(vnode) {
		var original = vnode.state
		try {
			return this.apply(original, arguments)
		} finally {
			checkState(vnode, original)
		}
	}
648669
private void addShutdownHook() {
    if (!running) {
      destroyProcessThread = new ProcessDestroyerImpl();
      Runtime.getRuntime().addShutdownHook(destroyProcessThread);
      added = true;
    }
  }
323082
public function beforeEach(\Closure $closure)
    {
        $key = 'beforeEach';
        $beforeEach = new Hook($key, $closure, $this->current);
        $this->current->setHook($key, $beforeEach);
    }
306941
void commitStatus(Runnable closure) {
        GhprbSimpleStatusContext context = new GhprbSimpleStatusContext();
        ContextExtensionPoint.executeInContext(closure, context);

        extensions.add(new GhprbSimpleStatus(
                context.showMatrixStatus,
                context.context,
                context.statusUrl,
                context.triggeredStatus,
                context.startedStatus,
                context.addTestResults,
                context.completedStatus
        ));
    }