From 27713b78f858beeca50a49d90d2caf0c6e989cfb Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sat, 18 Feb 2023 09:10:08 +0100 Subject: [PATCH] gradle: make DSL groovy-friendly --- samples/build.gradle.kts | 2 +- .../org/teavm/gradle/TeaVMExtensionImpl.java | 26 +++++++++++++++++++ .../org/teavm/gradle/api/TeaVMExtension.java | 12 +++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts index da236c2c5..f8aef401d 100644 --- a/samples/build.gradle.kts +++ b/samples/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { - id("org.teavm") version "0.7.0-SNAPSHOT" apply false + id("org.teavm") version "0.8.0-SNAPSHOT" apply false id("org.wisepersist.gwt") version "1.1.19" apply false } diff --git a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java index f2eacb3e7..7cd019a5e 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java @@ -15,6 +15,7 @@ */ package org.teavm.gradle; +import groovy.lang.Closure; import java.io.File; import org.gradle.api.Action; import org.gradle.api.Project; @@ -117,6 +118,11 @@ class TeaVMExtensionImpl extends TeaVMBaseExtensionImpl implements TeaVMExtensio action.execute(getJs()); } + @Override + public void js(Closure action) { + action.rehydrate(getJs(), action.getOwner(), action.getThisObject()).call(); + } + @Override public TeaVMWasmConfiguration getWasm() { return wasm; @@ -127,6 +133,11 @@ class TeaVMExtensionImpl extends TeaVMBaseExtensionImpl implements TeaVMExtensio action.execute(getWasm()); } + @Override + public void wasm(Closure action) { + action.rehydrate(getWasm(), action.getOwner(), action.getThisObject()).call(); + } + @Override public TeaVMWasiConfiguration getWasi() { return wasi; @@ -137,6 +148,11 @@ class TeaVMExtensionImpl extends TeaVMBaseExtensionImpl implements TeaVMExtensio action.execute(wasi); } + @Override + public void wasi(Closure action) { + action.rehydrate(getWasi(), action.getOwner(), action.getThisObject()).call(); + } + @Override public TeaVMCConfiguration getC() { return c; @@ -147,6 +163,11 @@ class TeaVMExtensionImpl extends TeaVMBaseExtensionImpl implements TeaVMExtensio action.execute(c); } + @Override + public void c(Closure action) { + action.rehydrate(getC(), action.getOwner(), action.getThisObject()).call(); + } + @Override public TeaVMCommonConfiguration getAll() { return all; @@ -157,6 +178,11 @@ class TeaVMExtensionImpl extends TeaVMBaseExtensionImpl implements TeaVMExtensio action.execute(getAll()); } + @Override + public void all(Closure action) { + action.rehydrate(getAll(), action.getOwner(), action.getThisObject()).call(); + } + private void inherit(TeaVMCommonConfiguration target, TeaVMCommonConfiguration source) { target.getMainClass().convention(source.getMainClass()); target.getOutputDir().convention(source.getOutputDir()); diff --git a/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMExtension.java b/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMExtension.java index ca6732c50..4a50ddf21 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMExtension.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMExtension.java @@ -15,6 +15,8 @@ */ package org.teavm.gradle.api; +import groovy.lang.Closure; +import groovy.lang.DelegatesTo; import org.gradle.api.Action; public interface TeaVMExtension extends TeaVMBaseExtension { @@ -22,19 +24,29 @@ public interface TeaVMExtension extends TeaVMBaseExtension { void js(Action action); + void js(@DelegatesTo(TeaVMJSConfiguration.class) Closure action); + TeaVMWasmConfiguration getWasm(); void wasm(Action action); + void wasm(@DelegatesTo(TeaVMWasmConfiguration.class) Closure action); + TeaVMWasiConfiguration getWasi(); void wasi(Action action); + void wasi(@DelegatesTo(TeaVMWasiConfiguration.class) Closure action); + TeaVMCConfiguration getC(); void c(Action action); + void c(@DelegatesTo(TeaVMCConfiguration.class) Closure action); + TeaVMCommonConfiguration getAll(); void all(Action action); + + void all(@DelegatesTo(TeaVMCommonConfiguration.class) Closure action); }