Skip to content

Commit

Permalink
Ungradlefy the Groovy DSL mixin of public types
Browse files Browse the repository at this point in the history
As we are moving away from dynamic instantiation, we need to manually
mixin the Groovy DSL methods inside the public types. It can be
perceived as unecessary or going against idiomatic Gradle but is in fact
much better this way as IDEs will have better auto-complete as well as
eliminating a whole class of errors because of the dynamic
instantiation.
  • Loading branch information
lacasseio committed Sep 14, 2020
1 parent b4ef0c9 commit 303a899
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.nokee.platform.base;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.util.ConfigureUtil;

/**
* The dependency buckets for an application component.
Expand All @@ -28,6 +31,13 @@ public interface ApplicationComponentDependencies extends ComponentDependencies
*/
void implementation(Object notation, Action<? super ModuleDependency> action);

/**
* @see #implementation(Object, Action)
*/
default void implementation(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
implementation(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Returns the implementation bucket of dependencies for this component.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.nokee.platform.base;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.util.ConfigureUtil;

/**
* A component with dependency buckets.
Expand All @@ -24,5 +27,12 @@ public interface DependencyAwareComponent<T extends ComponentDependencies> {
default void dependencies(Action<? super T> action) {
action.execute(getDependencies());
}

/**
* @see #dependencies(Action)
*/
default void dependencies(@DelegatesTo(type = "T", strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
dependencies(ConfigureUtil.configureUsing(closure));
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.nokee.platform.base;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.util.ConfigureUtil;

/**
* The dependency buckets for a library component.
Expand All @@ -26,6 +29,13 @@ public interface LibraryComponentDependencies extends ComponentDependencies {
*/
void api(Object notation, Action<? super ModuleDependency> action);

/**
* @see #api(Object, Action)
*/
default void api(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
api(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an implementation dependency to this component.
* An implementation dependency is not visible to consumers that are compiled against this component.
Expand All @@ -43,6 +53,13 @@ public interface LibraryComponentDependencies extends ComponentDependencies {
*/
void implementation(Object notation, Action<? super ModuleDependency> action);

/**
* @see #implementation(Object, Action)
*/
default void implementation(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
implementation(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Returns the implementation bucket of dependencies for this component.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.nokee.platform.base;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.Transformer;
import org.gradle.api.provider.Provider;
import org.gradle.api.specs.Spec;
import org.gradle.util.ConfigureUtil;

import java.util.List;
import java.util.Set;
Expand All @@ -24,6 +27,13 @@ public interface View<T> {
*/
void configureEach(Action<? super T> action);

/**
* @see #configureEach(Action)
*/
default void configureEach(@DelegatesTo(type = "T", strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
configureEach(ConfigureUtil.configureUsing(closure));
}

/**
* Registers an action to execute to configure each element in the view.
* The action is only executed for those elements that are required.
Expand All @@ -37,6 +47,13 @@ public interface View<T> {
*/
<S extends T> void configureEach(Class<S> type, Action<? super S> action);

/**
* @see #configureEach(Class, Action)
*/
default <S extends T> void configureEach(Class<S> type, @DelegatesTo(type = "S", strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
configureEach(type, ConfigureUtil.configureUsing(closure));
}

/**
* Registers an action to execute to configure each element in the view matching the given specification.
* The action is only executed for those elements that are required.
Expand All @@ -48,6 +65,13 @@ public interface View<T> {
*/
void configureEach(Spec<? super T> spec, Action<? super T> action);

/**
* @see #configureEach(Spec, Action)
*/
default void configureEach(Spec<? super T> spec, @DelegatesTo(type = "S", strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
configureEach(spec, ConfigureUtil.configureUsing(closure));
}

/**
* Returns a view containing the objects in this view of the given type.
* The returned view is live, so that when matching objects are later added to this view, they are also visible in the filtered view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import dev.nokee.platform.base.ComponentDependencies;
import dev.nokee.platform.base.DependencyBucket;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.util.ConfigureUtil;

/**
* Allows the API, JVM implementation and native implementation dependencies of a Java Native Interface (JNI) library to be specified.
Expand All @@ -29,6 +32,13 @@ public interface JavaNativeInterfaceLibraryComponentDependencies extends JavaNat
*/
void api(Object notation, Action<? super ModuleDependency> action);

/**
* @see #api(Object, Action)
*/
default void api(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
api(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an JVM implementation dependency to this library. An implementation dependency is not visible to consumers that are compiled against this component.
*
Expand All @@ -45,6 +55,13 @@ public interface JavaNativeInterfaceLibraryComponentDependencies extends JavaNat
*/
void jvmImplementation(Object notation, Action<? super ModuleDependency> action);

/**
* @see #jvmImplementation(Object, Action)
*/
default void jvmImplementation(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
jvmImplementation(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an JVM runtime only dependency to this library.
* An implementation dependency is only visible to consumers that are running against this component.
Expand All @@ -62,6 +79,13 @@ public interface JavaNativeInterfaceLibraryComponentDependencies extends JavaNat
*/
void jvmRuntimeOnly(Object notation, Action<? super ModuleDependency> action);

/**
* @see #jvmRuntimeOnly(Object, Action)
*/
default void jvmRuntimeOnly(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
jvmRuntimeOnly(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Returns the JVM runtime only bucket of dependencies for this component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import dev.nokee.platform.base.ComponentDependencies;
import dev.nokee.platform.base.DependencyBucket;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.util.ConfigureUtil;

/**
* Allows the native implementation dependencies of a Java Native Interface (JNI) library to be specified.
Expand All @@ -31,6 +34,13 @@ public interface JavaNativeInterfaceNativeComponentDependencies extends Componen
*/
void nativeImplementation(Object notation, Action<? super ModuleDependency> action);

/**
* @see #nativeImplementation(Object, Action)
*/
default void nativeImplementation(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
nativeImplementation(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an native link only dependency to this component.
* An link only dependency is not visible to consumers that are compiled or linked against this component.
Expand All @@ -49,6 +59,13 @@ public interface JavaNativeInterfaceNativeComponentDependencies extends Componen
*/
void nativeLinkOnly(Object notation, Action<? super ModuleDependency> action);

/**
* @see #nativeLinkOnly(Object, Action)
*/
default void nativeLinkOnly(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
nativeLinkOnly(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an native runtime only dependency to this component.
* An runtime only dependency is not visible to consumers that are running against this component.
Expand All @@ -66,6 +83,13 @@ public interface JavaNativeInterfaceNativeComponentDependencies extends Componen
*/
void nativeRuntimeOnly(Object notation, Action<? super ModuleDependency> action);

/**
* @see #nativeRuntimeOnly(Object, Action)
*/
default void nativeRuntimeOnly(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
nativeRuntimeOnly(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Returns the native implementation bucket of dependencies for this component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import dev.nokee.platform.base.Variant;
import dev.nokee.platform.nativebase.SharedLibraryBinary;
import dev.nokee.runtime.nativebase.TargetMachine;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.Property;
import org.gradle.util.ConfigureUtil;

/**
* Configuration for a specific Java Native Interface (JNI) library variant, defining the dependencies that make up the library plus other settings.
Expand Down Expand Up @@ -45,6 +48,13 @@ public interface JniLibrary extends Variant, DependencyAwareComponent<JavaNative
*/
void sharedLibrary(Action<? super SharedLibraryBinary> action);

/**
* @see #sharedLibrary(Action)
*/
default void sharedLibrary(@DelegatesTo(value = SharedLibraryBinary.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
sharedLibrary(ConfigureUtil.configureUsing(closure));
}

/**
* Configure the native runtime files to include inside the JNI JAR at the resource path location.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.nokee.platform.nativebase.TargetMachineAwareComponent;
import dev.nokee.platform.nativebase.TargetMachineFactory;
import dev.nokee.runtime.nativebase.TargetMachine;
import org.gradle.api.Action;
import org.gradle.api.provider.SetProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

import dev.nokee.platform.base.ApplicationComponentDependencies;
import dev.nokee.platform.base.ComponentDependencies;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.util.ConfigureUtil;

/**
* Allows the implementation dependencies of a native application to be specified.
*
* @since 0.5
*/
public interface NativeApplicationComponentDependencies extends ApplicationComponentDependencies, NativeComponentDependencies, ComponentDependencies {
/**
* {@inheritDoc}
*/
@Override
default void implementation(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
implementation(notation, ConfigureUtil.configureUsing(closure));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import dev.nokee.platform.base.ComponentDependencies;
import dev.nokee.platform.base.DependencyBucket;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.util.ConfigureUtil;

/**
* Allows the implementation dependencies of a native component to be specified.
Expand All @@ -30,6 +33,13 @@ public interface NativeComponentDependencies extends ComponentDependencies {
*/
void implementation(Object notation, Action<? super ModuleDependency> action);

/**
* @see #implementation(Object, Action)
*/
default void implementation(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
implementation(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an native compile only dependency to this component.
* An compile only dependency is not visible to consumers that are compiled or linked against this component.
Expand All @@ -47,6 +57,13 @@ public interface NativeComponentDependencies extends ComponentDependencies {
*/
void compileOnly(Object notation, Action<? super ModuleDependency> action);

/**
* @see #compileOnly(Object, Action)
*/
default void compileOnly(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
compileOnly(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an native link only dependency to this component.
* An link only dependency is not visible to consumers that are compiled or linked against this component.
Expand All @@ -64,6 +81,13 @@ public interface NativeComponentDependencies extends ComponentDependencies {
*/
void linkOnly(Object notation, Action<? super ModuleDependency> action);

/**
* @see #linkOnly(Object, Action)
*/
default void linkOnly(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
linkOnly(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Adds an native runtime only dependency to this component.
* An runtime only dependency is not visible to consumers that are running against this component.
Expand All @@ -81,6 +105,13 @@ public interface NativeComponentDependencies extends ComponentDependencies {
*/
void runtimeOnly(Object notation, Action<? super ModuleDependency> action);

/**
* @see #runtimeOnly(Object, Action)
*/
default void runtimeOnly(Object notation, @DelegatesTo(value = ModuleDependency.class, strategy = Closure.DELEGATE_FIRST) Closure<Void> closure) {
runtimeOnly(notation, ConfigureUtil.configureUsing(closure));
}

/**
* Returns the implementation bucket of dependencies for this component.
*
Expand Down
Loading

0 comments on commit 303a899

Please sign in to comment.