diff --git a/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AbstractAsciidoctorTask.groovy b/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AbstractAsciidoctorTask.groovy index 2d7c3c387..d17b84636 100644 --- a/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AbstractAsciidoctorTask.groovy +++ b/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AbstractAsciidoctorTask.groovy @@ -22,6 +22,7 @@ import org.asciidoctor.gradle.base.AsciidoctorTaskFileOperations import org.asciidoctor.gradle.base.AsciidoctorTaskMethods import org.asciidoctor.gradle.base.AsciidoctorTaskOutputOptions import org.asciidoctor.gradle.base.AsciidoctorTaskWorkspacePreparation +import org.asciidoctor.gradle.base.SafeMode import org.asciidoctor.gradle.base.Transform import org.asciidoctor.gradle.base.internal.DefaultAsciidoctorBaseDirConfiguration import org.asciidoctor.gradle.base.internal.DefaultAsciidoctorFileOperations @@ -38,13 +39,16 @@ import org.asciidoctor.gradle.internal.ExecutorUtils import org.asciidoctor.gradle.internal.JavaExecUtils import org.asciidoctor.gradle.remote.AsciidoctorJavaExec import org.gradle.api.Action +import org.gradle.api.GradleException import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.Dependency import org.gradle.api.file.FileCollection +import org.gradle.api.logging.LogLevel +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.provider.Provider -import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Nested @@ -60,6 +64,8 @@ import org.ysb33r.grolifant.api.core.runnable.AbstractJvmModelExecTask import org.ysb33r.grolifant.api.remote.worker.WorkerAppExecutorFactory import java.util.function.Function +import java.util.regex.Pattern +import java.util.stream.Collectors import static org.asciidoctor.gradle.base.AsciidoctorUtils.getClassLocation import static org.asciidoctor.gradle.base.internal.AsciidoctorAttributes.evaluateProviders @@ -93,17 +99,53 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask asciidocConfigurations = [] private final File rootDir private final File projectDir private final File execConfigurationDataFile - private final Function, Configuration> detachedConfigurationCreator private final Property jvmClasspath private final List> gemJarProviders = [] + private final MapProperty optionsProperty = project.objects.mapProperty(String, Object) + private final MapProperty attributesProperty = project.objects.mapProperty(String, Object) + private final ListProperty attributeProviderProperty = project.objects + .listProperty(AsciidoctorAttributeProvider) + private FileCollection configurationsFileCollection + private final ListProperty fatalWarningsProperty = project.objects.listProperty(Pattern) + private final ListProperty requiresProperty = project.objects.listProperty(String) + private final Property logLevelProperty = project.objects.property(LogLevel) + private final Property safeModeProperty = project.objects.property(SafeMode) + private final ListProperty docExtensionsProperty = project.objects.listProperty(Object) + + private final Provider jrubyLessDependenciesProvider = project.provider { + List deps = this.docExtensionsProperty.get().findAll { + it instanceof Dependency + } as List + + def detachedConfigurationCreator = { ConfigurationContainer c, List d -> + final cfg = c.detachedConfiguration(d.toArray() as Dependency[]) + cfg.canBeConsumed = false + cfg.canBeResolved = true + cfg + }.curry(project.configurations) as Function, Configuration> + + Configuration cfg = detachedConfigurationCreator.apply(deps) + asciidoctorJExtension.loadJRubyResolutionStrategy(cfg) + cfg + } as Provider + + private final Provider>> attributesByLangProvider = project.provider { + def attributesByLang = [:] + languagesAsOptionals.each { lang -> + if (lang.present) { + attributesByLang.put(lang.get(), asciidoctorJExtension.getAttributesForLang(lang.get())) + } + } + attributesByLang + } as Provider>> + @Delegate private final DefaultAsciidoctorFileOperations asciidoctorTaskFileOperations @@ -222,7 +264,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getOptions() { - resolveAsCacheable(asciidoctorj.options, projectOperations) + resolveAsCacheable(optionsProperty.get(), projectOperations) } /** Apply a new set of Asciidoctor options, clearing any options previously set. @@ -234,7 +276,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getAttributes() { - resolveAsCacheable(asciidoctorj.attributes, projectOperations) + resolveAsCacheable(attributesProperty.get(), projectOperations) } /** Apply a new set of Asciidoctor options, clearing any options previously set. @@ -268,7 +311,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getAttributeProviders() { - asciidoctorj.attributeProviders + attributeProviderProperty.get().stream().collect(Collectors.toList()) } /** Returns all of the specified configurations as a collections of files. @@ -301,11 +344,10 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask seed + projectOperations.configurations.asConfiguration(it) } @@ -348,8 +390,8 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getReportableConfigurations() { - ([asciidoctorj.configuration] + projectOperations.configurations.asConfigurations(asciidocConfigurations)) - .toSet() + ([asciidoctorJExtension.configuration] + projectOperations.configurations + .asConfigurations(asciidocConfigurations)).toSet() } /** @@ -428,7 +470,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask deps -> - final cfg = c.detachedConfiguration(deps.toArray() as Dependency[]) - cfg.canBeConsumed = false - cfg.canBeResolved = true - cfg - }.curry(project.configurations) as Function, Configuration> - inputs.files(this.asciidoctorj.configuration) inputs.files { gemJarProviders }.withPathSensitivity(RELATIVE) inputs.property 'backends', { -> backends() } inputs.property 'asciidoctorj-version', { -> asciidoctorj.version } @@ -585,13 +631,13 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getAsciidoctorJExtensions() { - asciidoctorj.docExtensions + docExtensionsProperty.get().stream().collect(Collectors.toList()) } @Nested @@ -634,6 +680,17 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getSerializableAsciidoctorJExtensions() { asciidoctorJExtensions.findAll { !(it instanceof Dependency) }.collect { getSerializableAsciidoctorJExtension(it) @@ -703,7 +760,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask deps = asciidoctorj.docExtensions.findAll { + List deps = this.docExtensionsProperty.get().findAll { it instanceof Dependency } as List @@ -719,11 +776,11 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask deps) { - Configuration cfg = detachedConfigurationCreator.apply(deps) - asciidoctorj.loadJRubyResolutionStrategy(cfg) - cfg - } - private Map preparePreserialisedAttributes(final File workingSourceDir, Optional lang) { prepareAttributes( projectOperations.stringTools, attributes, - (lang.present ? asciidoctorj.getAttributesForLang(lang.get()) : [:]), + (lang.present ? attributesByLangProvider.get().getOrDefault(lang.get(), [:]) : [:]), getTaskSpecificDefaultAttributes(workingSourceDir) as Map, attributeProviders, lang @@ -769,7 +819,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask findExtensionClosures() { - asciidoctorj.docExtensions.findAll { + this.docExtensionsProperty.get().findAll { it instanceof Closure } as List }