private void registerConfigurationAction(final Closure<?> action) { modelRegistry.mutate(new ModelMutator<Object>() { public ModelReference<Object> getSubject() { return ModelReference.untyped(modelPath); } public void mutate(Object object, Inputs inputs) { new ClosureBackedAction<Object>(action).execute(object); } public ModelRuleDescriptor getDescriptor() { return new SimpleModelRuleDescriptor("model." + modelPath); } public List<ModelReference<?>> getInputs() { return Collections.emptyList(); } }); }
private RemoteRepository createRepository(Map properties, Closure closure) { RemoteRepository repository = new MavenRemoteRepository(); ConfigureUtil.configureByMap(properties, repository); // Should be using ConfigureUtil (with DELEGATE_FIRST strategy), however for backwards compatibility need to use OWNER_FIRST new ClosureBackedAction<RemoteRepository>(closure, Closure.OWNER_FIRST).execute(repository); return repository; }
private void registerConfigurationAction(final Closure<?> action) { modelRegistry.configure(ModelActionRole.Mutate, new NoInputsModelAction<Object>( ModelReference.untyped(modelPath), new SimpleModelRuleDescriptor("model." + modelPath), new ClosureBackedAction<Object>(action) )); }
public void configure(Closure<?> action) { executingDsl.set(true); try { ClosureBackedAction.execute(this, action); } finally { executingDsl.set(false); } }
public void execute(final Closure antClosure) { classLoaderCache.withCachedClassLoader(libClasspath, gradleApiGroovyLoader, antAdapterGroovyLoader, new Factory<ClassLoader>() { @Override public ClassLoader create() { return new VisitableURLClassLoader(baseAntLoader, libClasspath); } }, new Action<CachedClassLoader>() { @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 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); } }
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 synchronized AndroidTask<Task> create( TaskFactory taskFactory, String taskName, Closure configAction) { taskFactory.create(taskName, DefaultTask.class, new ClosureBackedAction<Task>(configAction)); final AndroidTask<Task> newTask = new AndroidTask<Task>(taskName, Task.class); tasks.put(taskName, newTask); return newTask; }
public synchronized <T extends Task> AndroidTask<T> create( TaskFactory taskFactory, String taskName, Class<T> taskClass, Closure configAction) { taskFactory.create(taskName, taskClass, new ClosureBackedAction<T>(configAction)); final AndroidTask<T> newTask = new AndroidTask<T>(taskName, taskClass); tasks.put(taskName, newTask); return newTask; }
public void configure(Closure<?> action) { executingDsl.set(true); try { new ClosureBackedAction<Object>(action).execute(this); } finally { executingDsl.set(false); } }
public void mutate(final Object object, Inputs inputs) { RuleInputAccessBacking.runWithContext(inputs, new Runnable() { public void run() { new ClosureBackedAction<Object>(action).execute(object); } }); }
@Nonnull public FileCollection repackage(@Nonnull String name, @Nonnull Closure<?> c) { JarjarTask jarjar = project.getTasks().create( name, JarjarTask.class, new ClosureBackedAction<JarjarTask>(c)); return jarjar.getOutputs().getFiles(); }
/** * Configures the reports to be generated by this task. */ public PmdReports reports(@DelegatesTo(value = PmdReports.class, strategy = Closure.DELEGATE_FIRST) Closure closure) { return reports(new ClosureBackedAction<PmdReports>(closure)); }
/** * Configures the reports to be generated by this task. */ public CodeNarcReports reports(Closure closure) { return reports(new ClosureBackedAction<CodeNarcReports>(closure)); }
public void create(Closure<?> closure) { create(ClosureBackedAction.of(closure)); }
public void afterEach(Closure<?> closure) { afterEach(ClosureBackedAction.of(closure)); }
public void beforeEach(Closure<?> closure) { beforeEach(ClosureBackedAction.of(closure)); }
public void create(String name, Closure<? super I> configAction) { create(name, new ClosureBackedAction<I>(configAction)); }
public <S extends I> void create(String name, Class<S> type, Closure<? super S> configAction) { create(name, type, new ClosureBackedAction<I>(configAction)); }
public void named(String name, Closure<? super I> configAction) { named(name, new ClosureBackedAction<I>(configAction)); }
public void all(Closure<? super I> configAction) { all(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 <S> void beforeEach(Class<S> type, Closure<? super S> configAction) { beforeEach(type, new ClosureBackedAction<S>(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 void beforeExecute(@DelegatesTo(GradleExecuter.class) Closure action) { beforeExecute.add(new ClosureBackedAction<GradleExecuter>(action)); }
public void afterExecute(@DelegatesTo(GradleExecuter.class) Closure action) { afterExecute.add(new ClosureBackedAction<GradleExecuter>(action)); }
private <T> void register(Class<T> type, Closure<?> closure) { register(type, new ClosureBackedAction<T>(closure)); }
public ScalaSourceSet scala(Closure configureClosure) { return scala(ClosureBackedAction.of(configureClosure)); }
@Override public Configuration resolutionStrategy(Closure closure) { return resolutionStrategy(ClosureBackedAction.of(closure)); }
public void render(Closure<?> renderAction) { ClosureBackedAction.execute(markupBuilder, renderAction); }
/** * Configures the reports to be generated by this task. */ @Override public JacocoReportsContainer reports(Closure closure) { return reports(new ClosureBackedAction<JacocoReportsContainer>(closure)); }
@Override public DependencyReportContainer reports(Closure closure) { return reports(new ClosureBackedAction<DependencyReportContainer>(closure)); }
/** * {@inheritDoc} */ public AbstractCopyTask from(Object sourcePath, final Closure c) { getMainSpec().from(sourcePath, new ClosureBackedAction<CopySpec>(c)); return this; }
public DependencyArtifact artifact(Closure configureClosure) { return artifact(ClosureBackedAction.of(configureClosure)); }
public FileTree matching(Closure filterConfigClosure) { return matching(ClosureBackedAction.<PatternFilterable>of(filterConfigClosure)); }
public FileTree visit(Closure visitor) { return visit(ClosureBackedAction.<FileVisitDetails>of(visitor)); }