TaskFactorySpec is now generic and using Consumer<TaskFactory> instead of Closure<Void>.
This commit is contained in:
parent
958d3ca0ff
commit
cca5b0c1d4
@ -21,7 +21,7 @@ final class SimpleBuildTasksConverter implements BuildTasksConverter {
|
|||||||
|
|
||||||
buildScriptResult.taskFactorySpecs.each {
|
buildScriptResult.taskFactorySpecs.each {
|
||||||
def factory = it.supplier.get()
|
def factory = it.supplier.get()
|
||||||
it.configureClosures.each { it(factory) }
|
it.configurators.each { it.accept(factory) }
|
||||||
def result = factory.getTasks(taskSpec)
|
def result = factory.getTasks(taskSpec)
|
||||||
diagnostics.addAll(result.diagnostics)
|
diagnostics.addAll(result.diagnostics)
|
||||||
tasks.addAll(result.get())
|
tasks.addAll(result.get())
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.jessebrault.ssg.buildscript
|
package com.jessebrault.ssg.buildscript
|
||||||
|
|
||||||
import com.jessebrault.ssg.SiteSpec
|
import com.jessebrault.ssg.SiteSpec
|
||||||
|
import com.jessebrault.ssg.task.TaskFactory
|
||||||
import com.jessebrault.ssg.task.TaskFactorySpec
|
import com.jessebrault.ssg.task.TaskFactorySpec
|
||||||
import groovy.transform.EqualsAndHashCode
|
import groovy.transform.EqualsAndHashCode
|
||||||
import groovy.transform.NullCheck
|
import groovy.transform.NullCheck
|
||||||
@ -32,7 +33,7 @@ final class Build {
|
|||||||
|
|
||||||
final SiteSpec siteSpec
|
final SiteSpec siteSpec
|
||||||
final Map<String, Object> globals
|
final Map<String, Object> globals
|
||||||
final Collection<TaskFactorySpec> taskFactorySpecs
|
final Collection<TaskFactorySpec<TaskFactory>> taskFactorySpecs
|
||||||
|
|
||||||
AllBuilds plus(AllBuilds other) {
|
AllBuilds plus(AllBuilds other) {
|
||||||
concat(this, other)
|
concat(this, other)
|
||||||
@ -56,7 +57,7 @@ final class Build {
|
|||||||
args.outputDirFunction as Function<Build, OutputDir> ?: OutputDirFunctions.DEFAULT,
|
args.outputDirFunction as Function<Build, OutputDir> ?: OutputDirFunctions.DEFAULT,
|
||||||
args.siteSpec as SiteSpec ?: SiteSpec.getBlank(),
|
args.siteSpec as SiteSpec ?: SiteSpec.getBlank(),
|
||||||
args.globals as Map<String, Object> ?: [:],
|
args.globals as Map<String, Object> ?: [:],
|
||||||
args.taskFactorySpecs as Collection<TaskFactorySpec> ?: []
|
args.taskFactorySpecs as Collection<TaskFactorySpec<TaskFactory>> ?: []
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ final class Build {
|
|||||||
final Function<Build, OutputDir> outputDirFunction
|
final Function<Build, OutputDir> outputDirFunction
|
||||||
final SiteSpec siteSpec
|
final SiteSpec siteSpec
|
||||||
final Map<String, Object> globals
|
final Map<String, Object> globals
|
||||||
final Collection<TaskFactorySpec> taskFactorySpecs
|
final Collection<TaskFactorySpec<TaskFactory>> taskFactorySpecs
|
||||||
|
|
||||||
Build plus(Build other) {
|
Build plus(Build other) {
|
||||||
concat(this, other)
|
concat(this, other)
|
||||||
|
@ -3,6 +3,7 @@ package com.jessebrault.ssg.buildscript.dsl
|
|||||||
import com.jessebrault.ssg.SiteSpec
|
import com.jessebrault.ssg.SiteSpec
|
||||||
import com.jessebrault.ssg.buildscript.SourceProviders
|
import com.jessebrault.ssg.buildscript.SourceProviders
|
||||||
import com.jessebrault.ssg.buildscript.TypesContainer
|
import com.jessebrault.ssg.buildscript.TypesContainer
|
||||||
|
import com.jessebrault.ssg.task.TaskFactory
|
||||||
import com.jessebrault.ssg.task.TaskFactorySpec
|
import com.jessebrault.ssg.task.TaskFactorySpec
|
||||||
import groovy.transform.stc.ClosureParams
|
import groovy.transform.stc.ClosureParams
|
||||||
import groovy.transform.stc.SimpleType
|
import groovy.transform.stc.SimpleType
|
||||||
@ -57,7 +58,7 @@ abstract class AbstractBuildDelegate<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Collection<TaskFactorySpec> getTaskFactoriesResult(SourceProviders sourceProviders) {
|
protected final Collection<TaskFactorySpec<TaskFactory>> getTaskFactoriesResult(SourceProviders sourceProviders) {
|
||||||
this.taskFactoriesClosures.inject([:] as Map<String, TaskFactorySpec>) { acc, closure ->
|
this.taskFactoriesClosures.inject([:] as Map<String, TaskFactorySpec>) { acc, closure ->
|
||||||
def d = new TaskFactoriesDelegate()
|
def d = new TaskFactoriesDelegate()
|
||||||
closure.delegate = d
|
closure.delegate = d
|
||||||
|
@ -8,7 +8,7 @@ import java.util.function.Supplier
|
|||||||
|
|
||||||
final class TaskFactoriesDelegate {
|
final class TaskFactoriesDelegate {
|
||||||
|
|
||||||
private final Map<String, TaskFactorySpec> specs = [:]
|
private final Map<String, TaskFactorySpec<TaskFactory>> specs = [:]
|
||||||
|
|
||||||
private void checkNotRegistered(String name) {
|
private void checkNotRegistered(String name) {
|
||||||
if (this.specs.containsKey(name)) {
|
if (this.specs.containsKey(name)) {
|
||||||
@ -18,7 +18,7 @@ final class TaskFactoriesDelegate {
|
|||||||
|
|
||||||
void register(String name, Supplier<? extends TaskFactory> factorySupplier) {
|
void register(String name, Supplier<? extends TaskFactory> factorySupplier) {
|
||||||
this.checkNotRegistered(name)
|
this.checkNotRegistered(name)
|
||||||
this.specs[name] = new TaskFactorySpec(factorySupplier, [])
|
this.specs[name] = new TaskFactorySpec<>(factorySupplier, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
def <T extends TaskFactory> void register(
|
def <T extends TaskFactory> void register(
|
||||||
@ -27,14 +27,15 @@ final class TaskFactoriesDelegate {
|
|||||||
Consumer<T> factoryConfigurator
|
Consumer<T> factoryConfigurator
|
||||||
) {
|
) {
|
||||||
this.checkNotRegistered(name)
|
this.checkNotRegistered(name)
|
||||||
this.specs[name] = new TaskFactorySpec(factorySupplier, [factoryConfigurator as Closure<?>])
|
this.specs[name] = new TaskFactorySpec<>(factorySupplier, [factoryConfigurator])
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure(String name, Consumer<? extends TaskFactory> factoryConfigureClosure) {
|
def <T extends TaskFactory> void configure(String name, Class<T> factoryClass, Consumer<T> factoryConfigureClosure) {
|
||||||
if (!this.specs.containsKey(name)) {
|
if (!this.specs.containsKey(name)) {
|
||||||
throw new IllegalArgumentException("there is no TaskFactory registered by name ${ name }")
|
throw new IllegalArgumentException("there is no TaskFactory registered by name ${ name }")
|
||||||
}
|
}
|
||||||
this.specs[name].configureClosures << (factoryConfigureClosure as Closure<Void>)
|
// Potentially dangerous, but the configurators Collection *should* only contain the correct types.
|
||||||
|
this.specs[name].configurators << (factoryConfigureClosure as Consumer<TaskFactory>)
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, TaskFactorySpec> getResult() {
|
Map<String, TaskFactorySpec> getResult() {
|
||||||
|
@ -4,22 +4,23 @@ import groovy.transform.EqualsAndHashCode
|
|||||||
import groovy.transform.NullCheck
|
import groovy.transform.NullCheck
|
||||||
import groovy.transform.TupleConstructor
|
import groovy.transform.TupleConstructor
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
import java.util.function.Supplier
|
import java.util.function.Supplier
|
||||||
|
|
||||||
@TupleConstructor(defaults = false)
|
@TupleConstructor(defaults = false)
|
||||||
@NullCheck(includeGenerated = true)
|
@NullCheck(includeGenerated = true)
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
final class TaskFactorySpec {
|
final class TaskFactorySpec<T extends TaskFactory> {
|
||||||
|
|
||||||
static TaskFactorySpec concat(TaskFactorySpec spec0, TaskFactorySpec spec1) {
|
static <T extends TaskFactory> TaskFactorySpec<T> concat(TaskFactorySpec<T> spec0, TaskFactorySpec<T> spec1) {
|
||||||
if (spec0.supplier != spec1.supplier) {
|
if (spec0.supplier != spec1.supplier) {
|
||||||
throw new IllegalArgumentException("suppliers must be equal!")
|
throw new IllegalArgumentException("suppliers must be equal!")
|
||||||
}
|
}
|
||||||
new TaskFactorySpec(spec0.supplier, spec0.configureClosures + spec1.configureClosures)
|
new TaskFactorySpec(spec0.supplier, spec0.configurators + spec1.configurators)
|
||||||
}
|
}
|
||||||
|
|
||||||
final Supplier<TaskFactory> supplier
|
final Supplier<T> supplier
|
||||||
final Collection<Closure<Void>> configureClosures
|
final Collection<Consumer<T>> configurators
|
||||||
|
|
||||||
TaskFactorySpec plus(TaskFactorySpec other) {
|
TaskFactorySpec plus(TaskFactorySpec other) {
|
||||||
concat(this, other)
|
concat(this, other)
|
||||||
|
Loading…
Reference in New Issue
Block a user