public static <T> ClosureBackedAction<T> of(Closure<?> closure) { return new ClosureBackedAction<T>(closure); }
public static <T> void execute(T delegate, Closure<?> closure) { new ClosureBackedAction<T>(closure).execute(delegate); }
public void create(Closure<?> closure) { create(ClosureBackedAction.of(closure)); }
public void json(Closure<?> configureClosure) throws IOException { ClosureBackedAction.execute(this.getJson(), configureClosure); }
@Override public void execute(CachedClassLoader cachedClassLoader) { ClassLoader classLoader = cachedClassLoader.getClassLoader(); Object antBuilder = newInstanceOf("org.gradle.api.internal.project.ant.BasicAntBuilder"); Object antLogger = newInstanceOf("org.gradle.api.internal.project.ant.AntLoggingAdapter"); // This looks ugly, very ugly, but that is apparently what Ant does itself ClassLoader originalLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { configureAntBuilder(antBuilder, antLogger); // Ideally, we'd delegate directly to the AntBuilder, but its Closure class is different to our caller's // Closure class, so the AntBuilder's methodMissing() doesn't work. It just converts our Closures to String // because they are not an instanceof its Closure class. Object delegate = new AntBuilderDelegate(antBuilder, classLoader); ClosureBackedAction.execute(delegate, antClosure); } finally { Thread.currentThread().setContextClassLoader(originalLoader); disposeBuilder(antBuilder, antLogger); } } });
public CopySpec into(Object destPath, Closure configureClosure) { return into(destPath, new ClosureBackedAction<CopySpec>(configureClosure)); }
private static <T> void configureTarget(Closure configureClosure, T target, ConfigureDelegate closureDelegate) { if (!(configureClosure instanceof GeneratedClosure)) { new ClosureBackedAction<T>(configureClosure, Closure.DELEGATE_FIRST, false).execute(target); return; } // Hackery to make closure execution faster, by short-circuiting the expensive property and method lookup on Closure Closure withNewOwner = configureClosure.rehydrate(target, closureDelegate, configureClosure.getThisObject()); new ClosureBackedAction<T>(withNewOwner, Closure.OWNER_ONLY, false).execute(target); } }
public void model(Closure<?> modelRules) { ModelRegistry modelRegistry = getModelRegistry(); if (TransformedModelDslBacking.isTransformedBlock(modelRules)) { ClosureBackedAction.execute(new TransformedModelDslBacking(modelRegistry, this.getRootProject().getFileResolver()), modelRules); } else { new NonTransformedModelDslBacking(modelRegistry).configure(modelRules); } }
public void beforeEach(Closure<?> closure) { beforeEach(ClosureBackedAction.of(closure)); }
public <S extends I> void create(String name, Class<S> type, Closure<? super S> configAction) { create(name, type, new ClosureBackedAction<I>(configAction)); }
public static <T> T evaluate(@SuppressWarnings("rawtypes") Closure closure, Class<T> clazz) { try { T o = clazz.newInstance(); ClosureBackedAction<T> a = new ClosureBackedAction<T>(closure); a.execute(o); return o; } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } }
public void afterEach(Closure<?> closure) { afterEach(ClosureBackedAction.of(closure)); }
public void named(String name, Closure<? super I> configAction) { named(name, new ClosureBackedAction<I>(configAction)); }
public <S> void withType(Class<S> type, Closure<? super S> configAction) { withType(type, new ClosureBackedAction<S>(configAction)); }
public void beforeEach(Closure<? super I> configAction) { beforeEach(new ClosureBackedAction<I>(configAction)); }
public void afterEach(Closure<? super I> configAction) { afterEach(new ClosureBackedAction<I>(configAction)); }
public <S> void afterEach(Class<S> type, Closure<? super S> configAction) { afterEach(type, new ClosureBackedAction<S>(configAction)); }
public CopySpec from(Object sourcePath, final Closure c) { return delegate.from(sourcePath, new ClosureBackedAction<CopySpec>(c)); }
@Override public JGivenReportsContainer reports( Closure closure ) { return reports( new ClosureBackedAction<JGivenReportsContainer>( closure ) ); }
public void create(String name, Closure<? super I> configAction) { create(name, new ClosureBackedAction<I>(configAction)); }