buildscript classes now use Closure<?> instead of Closure<Void>.
This commit is contained in:
parent
44d4baeb62
commit
306b4bb8d3
@ -1,6 +1,5 @@
|
|||||||
package com.jessebrault.ssg.buildscript
|
package com.jessebrault.ssg.buildscript
|
||||||
|
|
||||||
|
|
||||||
import com.jessebrault.ssg.buildscript.Build.AllBuilds
|
import com.jessebrault.ssg.buildscript.Build.AllBuilds
|
||||||
import com.jessebrault.ssg.buildscript.dsl.AllBuildsDelegate
|
import com.jessebrault.ssg.buildscript.dsl.AllBuildsDelegate
|
||||||
import com.jessebrault.ssg.buildscript.dsl.BuildDelegate
|
import com.jessebrault.ssg.buildscript.dsl.BuildDelegate
|
||||||
@ -16,7 +15,7 @@ abstract class BuildScriptBase extends Script {
|
|||||||
|
|
||||||
void build(
|
void build(
|
||||||
@DelegatesTo(value = BuildDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = BuildDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
Closure<Void> buildClosure
|
Closure<?> buildClosure
|
||||||
) {
|
) {
|
||||||
this.build('build' + this.currentBuildNumber, buildClosure)
|
this.build('build' + this.currentBuildNumber, buildClosure)
|
||||||
}
|
}
|
||||||
@ -24,7 +23,7 @@ abstract class BuildScriptBase extends Script {
|
|||||||
void build(
|
void build(
|
||||||
String name,
|
String name,
|
||||||
@DelegatesTo(value = BuildDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = BuildDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
Closure<Void> buildClosure
|
Closure<?> buildClosure
|
||||||
) {
|
) {
|
||||||
def d = new BuildDelegate().tap {
|
def d = new BuildDelegate().tap {
|
||||||
it.name = name
|
it.name = name
|
||||||
@ -38,7 +37,7 @@ abstract class BuildScriptBase extends Script {
|
|||||||
|
|
||||||
void allBuilds(
|
void allBuilds(
|
||||||
@DelegatesTo(value = AllBuildsDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = AllBuildsDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
Closure<Void> allBuildsClosure
|
Closure<?> allBuildsClosure
|
||||||
) {
|
) {
|
||||||
def d = new AllBuildsDelegate()
|
def d = new AllBuildsDelegate()
|
||||||
allBuildsClosure.setDelegate(d)
|
allBuildsClosure.setDelegate(d)
|
||||||
|
@ -27,9 +27,6 @@ final class DefaultBuildScriptConfiguratorFactory implements BuildScriptConfigur
|
|||||||
pageTypes << PageTypes.GSP
|
pageTypes << PageTypes.GSP
|
||||||
templateTypes << TemplateTypes.GSP
|
templateTypes << TemplateTypes.GSP
|
||||||
partTypes << PartTypes.GSP
|
partTypes << PartTypes.GSP
|
||||||
|
|
||||||
//noinspection GroovyUnnecessaryReturn
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
providers { types ->
|
providers { types ->
|
||||||
@ -59,27 +56,18 @@ final class DefaultBuildScriptConfiguratorFactory implements BuildScriptConfigur
|
|||||||
}
|
}
|
||||||
it.allTextsProvider += sourceProviders.textsProvider
|
it.allTextsProvider += sourceProviders.textsProvider
|
||||||
it.allPartsProvider += sourceProviders.partsProvider
|
it.allPartsProvider += sourceProviders.partsProvider
|
||||||
|
|
||||||
//noinspection GroovyUnnecessaryReturn
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register('pageToHtml', PageToHtmlTaskFactory::new) {
|
register('pageToHtml', PageToHtmlTaskFactory::new) {
|
||||||
it.pagesProvider += sourceProviders.pagesProvider
|
it.pagesProvider += sourceProviders.pagesProvider
|
||||||
it.allTextsProvider += sourceProviders.textsProvider
|
it.allTextsProvider += sourceProviders.textsProvider
|
||||||
it.allPartsProvider += sourceProviders.partsProvider
|
it.allPartsProvider += sourceProviders.partsProvider
|
||||||
|
|
||||||
//noinspection GroovyUnnecessaryReturn
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
it.build('default') {
|
it.build('default') {
|
||||||
outputDir = new File('build')
|
outputDir = new File('build')
|
||||||
|
|
||||||
//noinspection GroovyUnnecessaryReturn
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package com.jessebrault.ssg.buildscript
|
package com.jessebrault.ssg.buildscript
|
||||||
|
|
||||||
import groovy.transform.stc.ClosureParams
|
|
||||||
import groovy.transform.stc.SimpleType
|
|
||||||
import org.jetbrains.annotations.Nullable
|
import org.jetbrains.annotations.Nullable
|
||||||
|
|
||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
|
|
||||||
final class OutputDirFunctions {
|
final class OutputDirFunctions {
|
||||||
|
|
||||||
static final Function<Build, OutputDir> DEFAULT = of { new OutputDir(it.name) }
|
static final Function<Build, OutputDir> DEFAULT = { Build build -> new OutputDir(build.name) }
|
||||||
|
|
||||||
static Function<Build, OutputDir> concat(
|
static Function<Build, OutputDir> concat(
|
||||||
Function<Build, OutputDir> f0,
|
Function<Build, OutputDir> f0,
|
||||||
@ -17,19 +15,12 @@ final class OutputDirFunctions {
|
|||||||
f1 == OutputDirFunctions.DEFAULT ? f0 : f1
|
f1 == OutputDirFunctions.DEFAULT ? f0 : f1
|
||||||
}
|
}
|
||||||
|
|
||||||
static Function<Build, OutputDir> of(
|
|
||||||
@ClosureParams(value = SimpleType, options = 'com.jessebrault.ssg.buildscript.Build')
|
|
||||||
Closure<OutputDir> closure
|
|
||||||
) {
|
|
||||||
closure as Function<Build, OutputDir>
|
|
||||||
}
|
|
||||||
|
|
||||||
static Function<Build, OutputDir> of(File dir) {
|
static Function<Build, OutputDir> of(File dir) {
|
||||||
of { new OutputDir(dir) }
|
return { new OutputDir(dir) }
|
||||||
}
|
}
|
||||||
|
|
||||||
static Function<Build, OutputDir> of(@Nullable String path) {
|
static Function<Build, OutputDir> of(@Nullable String path) {
|
||||||
of { new OutputDir(path) }
|
return { new OutputDir(path) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private OutputDirFunctions() {}
|
private OutputDirFunctions() {}
|
||||||
|
@ -9,11 +9,11 @@ import groovy.transform.stc.SimpleType
|
|||||||
|
|
||||||
abstract class AbstractBuildDelegate<T> {
|
abstract class AbstractBuildDelegate<T> {
|
||||||
|
|
||||||
private final Collection<Closure<Void>> siteSpecClosures = []
|
private final Collection<Closure<?>> siteSpecClosures = []
|
||||||
private final Collection<Closure<Void>> globalsClosures = []
|
private final Collection<Closure<?>> globalsClosures = []
|
||||||
private final Collection<Closure<Void>> typesClosures = []
|
private final Collection<Closure<?>> typesClosures = []
|
||||||
private final Collection<Closure<Void>> sourcesClosures = []
|
private final Collection<Closure<?>> sourcesClosures = []
|
||||||
private final Collection<Closure<Void>> taskFactoriesClosures = []
|
private final Collection<Closure<?>> taskFactoriesClosures = []
|
||||||
|
|
||||||
abstract T getResult()
|
abstract T getResult()
|
||||||
|
|
||||||
@ -73,21 +73,21 @@ abstract class AbstractBuildDelegate<T> {
|
|||||||
|
|
||||||
void siteSpec(
|
void siteSpec(
|
||||||
@DelegatesTo(value = SiteSpecDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = SiteSpecDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
Closure<Void> siteSpecClosure
|
Closure<?> siteSpecClosure
|
||||||
) {
|
) {
|
||||||
this.siteSpecClosures << siteSpecClosure
|
this.siteSpecClosures << siteSpecClosure
|
||||||
}
|
}
|
||||||
|
|
||||||
void globals(
|
void globals(
|
||||||
@DelegatesTo(value = GlobalsDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = GlobalsDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
Closure<Void> globalsClosure
|
Closure<?> globalsClosure
|
||||||
) {
|
) {
|
||||||
this.globalsClosures << globalsClosure
|
this.globalsClosures << globalsClosure
|
||||||
}
|
}
|
||||||
|
|
||||||
void types(
|
void types(
|
||||||
@DelegatesTo(value = TypesDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = TypesDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
Closure<Void> typesClosure
|
Closure<?> typesClosure
|
||||||
) {
|
) {
|
||||||
this.typesClosures << typesClosure
|
this.typesClosures << typesClosure
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ abstract class AbstractBuildDelegate<T> {
|
|||||||
void providers(
|
void providers(
|
||||||
@DelegatesTo(value = SourceProvidersDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = SourceProvidersDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
@ClosureParams(value = SimpleType, options = 'com.jessebrault.ssg.buildscript.TypesContainer')
|
@ClosureParams(value = SimpleType, options = 'com.jessebrault.ssg.buildscript.TypesContainer')
|
||||||
Closure<Void> providersClosure
|
Closure<?> providersClosure
|
||||||
) {
|
) {
|
||||||
this.sourcesClosures << providersClosure
|
this.sourcesClosures << providersClosure
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ abstract class AbstractBuildDelegate<T> {
|
|||||||
void taskFactories(
|
void taskFactories(
|
||||||
@DelegatesTo(value = TaskFactoriesDelegate, strategy = Closure.DELEGATE_FIRST)
|
@DelegatesTo(value = TaskFactoriesDelegate, strategy = Closure.DELEGATE_FIRST)
|
||||||
@ClosureParams(value = SimpleType, options = 'com.jessebrault.ssg.buildscript.SourceProviders')
|
@ClosureParams(value = SimpleType, options = 'com.jessebrault.ssg.buildscript.SourceProviders')
|
||||||
Closure<Void> taskFactoriesClosure
|
Closure<?> taskFactoriesClosure
|
||||||
) {
|
) {
|
||||||
this.taskFactoriesClosures << taskFactoriesClosure
|
this.taskFactoriesClosures << taskFactoriesClosure
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ package com.jessebrault.ssg.buildscript.dsl
|
|||||||
|
|
||||||
import com.jessebrault.ssg.task.TaskFactory
|
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.SecondParam
|
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
import java.util.function.Supplier
|
import java.util.function.Supplier
|
||||||
|
|
||||||
final class TaskFactoriesDelegate {
|
final class TaskFactoriesDelegate {
|
||||||
@ -25,18 +24,17 @@ final class TaskFactoriesDelegate {
|
|||||||
def <T extends TaskFactory> void register(
|
def <T extends TaskFactory> void register(
|
||||||
String name,
|
String name,
|
||||||
Supplier<T> factorySupplier,
|
Supplier<T> factorySupplier,
|
||||||
@ClosureParams(value = SecondParam.FirstGenericType)
|
Consumer<T> factoryConfigurator
|
||||||
Closure<Void> factoryConfigureClosure
|
|
||||||
) {
|
) {
|
||||||
this.checkNotRegistered(name)
|
this.checkNotRegistered(name)
|
||||||
this.specs[name] = new TaskFactorySpec(factorySupplier, [factoryConfigureClosure])
|
this.specs[name] = new TaskFactorySpec(factorySupplier, [factoryConfigurator as Closure<?>])
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure(String name, Closure<Void> factoryConfigureClosure) {
|
void configure(String name, Consumer<? extends TaskFactory> 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
|
this.specs[name].configureClosures << (factoryConfigureClosure as Closure<Void>)
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, TaskFactorySpec> getResult() {
|
Map<String, TaskFactorySpec> getResult() {
|
||||||
|
Loading…
Reference in New Issue
Block a user