diff --git a/base/src/main/groovy/org/asciidoctor/gradle/base/internal/AsciidoctorAttributes.groovy b/base/src/main/groovy/org/asciidoctor/gradle/base/internal/AsciidoctorAttributes.groovy index 3472cbe97..3beb43943 100644 --- a/base/src/main/groovy/org/asciidoctor/gradle/base/internal/AsciidoctorAttributes.groovy +++ b/base/src/main/groovy/org/asciidoctor/gradle/base/internal/AsciidoctorAttributes.groovy @@ -41,7 +41,7 @@ class AsciidoctorAttributes { * * @param attrs Attributes * @param po {@link ProjectOperations} instance - * @return Cacheable map whicvh can contain providers. + * @return Cacheable map which can contain providers. */ static Map resolveAsCacheable(Map attrs, ProjectOperations po) { resolveMapRecursive(attrs, po) diff --git a/gradle.properties b/gradle.properties index 32fb4bd44..9ffe701e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version = 4.0.2 +version = 4.1.0-alpha.1 group = org.asciidoctor copyrightYear = 2013-2024 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..8d567a9fc 100644 --- a/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AbstractAsciidoctorTask.groovy +++ b/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AbstractAsciidoctorTask.groovy @@ -60,6 +60,7 @@ 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 static org.asciidoctor.gradle.base.AsciidoctorUtils.getClassLocation import static org.asciidoctor.gradle.base.internal.AsciidoctorAttributes.evaluateProviders @@ -93,7 +94,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask asciidocConfigurations = [] @@ -103,6 +104,10 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask, Configuration> detachedConfigurationCreator private final Property jvmClasspath private final List> gemJarProviders = [] + private final Provider> asciidoctorJOptionsProvider + private final Provider> asciidoctorJAttributesProvider + private final Provider> fatalWarningsProvider + private final Provider> asciidoctorJRequiresProvider @Delegate private final DefaultAsciidoctorFileOperations asciidoctorTaskFileOperations @@ -219,10 +224,24 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getOptions() { - resolveAsCacheable(asciidoctorj.options, projectOperations) + resolveAsCacheable(asciidoctorj().options, projectOperations) + } + + /** + * AsciidoctorJ options. + * + * @return A provider to AsciidoctorJ options. + * + * @since 4.1 + */ + @Input + Provider> getOptionsProvider() { + this.asciidoctorJOptionsProvider } /** Apply a new set of Asciidoctor options, clearing any options previously set. @@ -232,9 +251,12 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask> getAttributesProvider() { + this.asciidoctorJAttributesProvider + } + + /** Returns all of the Asciidoctor options. + * + * This is equivalent of using {@code asciidoctorj.getAttributes} + * + * @deprecated Use {@link #getAttributesProvider} instead. + */ + @Internal + @Deprecated Map getAttributes() { - resolveAsCacheable(asciidoctorj.attributes, projectOperations) + this.asciidoctorJAttributesProvider.get() +// resolveAsCacheable(asciidoctorj.attributes, projectOperations) } /** Apply a new set of Asciidoctor options, clearing any options previously set. @@ -266,9 +304,12 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getAttributeProviders() { - asciidoctorj.attributeProviders + asciidoctorj().attributeProviders } - /** Returns all of the specified configurations as a collections of files. + /** + * Returns all of the specified configurations as a collections of files. * * If any docExtensions are dependencies then they will be included here too. * @@ -305,7 +353,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask seed + projectOperations.configurations.asConfiguration(it) } @@ -348,7 +396,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getReportableConfigurations() { - ([asciidoctorj.configuration] + projectOperations.configurations.asConfigurations(asciidocConfigurations)) + ([asciidoctorj().configuration] + projectOperations.configurations.asConfigurations(asciidocConfigurations)) .toSet() } @@ -467,7 +515,11 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask aj.requires } + this.fatalWarningsProvider = aj.fatalWarningsProvider this.projectDir = project.projectDir this.rootDir = project.rootDir this.jvmClasspath = project.objects.property(FileCollection) @@ -479,11 +531,11 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask, Configuration> - inputs.files(this.asciidoctorj.configuration) + inputs.files(aj.configuration) inputs.files { gemJarProviders }.withPathSensitivity(RELATIVE) inputs.property 'backends', { -> backends() } - inputs.property 'asciidoctorj-version', { -> asciidoctorj.version } - inputs.property 'jruby-version', { -> asciidoctorj.jrubyVersion ?: '' } + inputs.property 'asciidoctorj-version', aj.versionProvider + inputs.property 'jruby-version', aj.jrubyVersionProvider.orElse('') execSpec = new AsciidoctorJvmExecSpec(projectOperations) entrypoint { mainClass = AsciidoctorJavaExec.canonicalName @@ -492,10 +544,14 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask getAsciidoctorJExtensions() { - asciidoctorj.docExtensions + asciidoctorj().docExtensions } @Nested @@ -703,7 +759,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask deps = asciidoctorj.docExtensions.findAll { + List deps = asciidoctorj().docExtensions.findAll { it instanceof Dependency } as List @@ -753,38 +809,24 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask deps) { Configuration cfg = detachedConfigurationCreator.apply(deps) - asciidoctorj.loadJRubyResolutionStrategy(cfg) + asciidoctorj().loadJRubyResolutionStrategy(cfg) cfg } private Map preparePreserialisedAttributes(final File workingSourceDir, Optional lang) { prepareAttributes( projectOperations.stringTools, - attributes, - (lang.present ? asciidoctorj.getAttributesForLang(lang.get()) : [:]), + asciidoctorj().attributes, + (lang.present ? asciidoctorj().getAttributesForLang(lang.get()) : [:]), getTaskSpecificDefaultAttributes(workingSourceDir) as Map, - attributeProviders, + asciidoctorj().attributeProviders, lang ) } private List findExtensionClosures() { - asciidoctorj.docExtensions.findAll { + asciidoctorj().docExtensions.findAll { it instanceof Closure } as List } - -// @SuppressWarnings('AbstractClassWithoutAbstractMethod') -// abstract static class AsciidoctorJExecuterWorker implements WorkAction { -// static interface Params extends WorkParameters { -// ExecutorConfigurationContainer getExtensionConfigurationContainer() -// -// void setExtensionConfigurationContainer(ExecutorConfigurationContainer container) -// } -// -// @Override -// void execute() { -// new AsciidoctorJExecuter(parameters.extensionConfigurationContainer).run() -// } -// } } diff --git a/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AsciidoctorJExtension.groovy b/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AsciidoctorJExtension.groovy index 0467565b7..f316cfb55 100644 --- a/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AsciidoctorJExtension.groovy +++ b/jvm/src/main/groovy/org/asciidoctor/gradle/jvm/AsciidoctorJExtension.groovy @@ -74,6 +74,44 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension { drd.useVersion(versionResolver.call()) } as BiConsumer> + /** + * Provider to the Asciidoctor version. + * + * @since 4.1 + */ + final Provider versionProvider + + /** + * Provider to the JRuby version. + * Can be empty. + * + * @since 4.1 + */ + final Provider jrubyVersionProvider + + /** + * Provide patterns for Asciidoctor messages that are treated as failures. + * + * @since 4.1 + */ + final Provider> fatalWarningsProvider + + /** + * Provider to AsciidoctorJ options. + * Never empty, but contained map can be empty. + * + * @since 4.1 + */ + final Provider> optionsProvider + + /** + * Provider to AsciidoctorJ attributes. + * Never empty, but contained map can be empty. + * + * @since 4.1 + */ + final Provider> attributesProvider + private final LogLevel defaultLogLevel private final Map options = [:] private final List jrubyRequires = [] @@ -118,6 +156,12 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension { ) } + this.versionProvider = project.provider { -> getVersion() } + this.jrubyVersionProvider = project.provider { -> getJrubyVersion() } + this.optionsProvider = project.provider { -> getOptions() } + this.attributesProvider = project.provider { -> getAttributes() } + this.fatalWarningsProvider = project.provider { -> patternize(owner.warningsAsErrors) } + this.modules.onUpdate { owner.updateConfiguration() } updateConfiguration() } @@ -143,6 +187,22 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension { this.dependencyCreator = createDependencyLoader(task.project.dependencies, this.privateConfiguration) this.projectDependency = createProjectDependencyLoader(task.project.dependencies) + + this.versionProvider = task.project.provider { -> getVersion() } + this.jrubyVersionProvider = task.project.provider { -> getJrubyVersion() } + this.optionsProvider = task.project.provider { -> getOptions() } + this.attributesProvider = task.project.provider { -> getAttributes() } + + this.fatalWarningsProvider = task.project.provider { -> + if (onlyTaskWarnings) { + patternize(this.warningsAsErrors) + } else if (this.warningsAsErrors.empty) { + extFromProject.fatalWarnings + } else { + extFromProject.fatalWarnings + patternize(this.warningsAsErrors) + } + } + this.modules = new DefaultAsciidoctorJModules(projectOperations, this, defaultVersionMap) this.modules.onUpdate { owner.updateConfiguration() } updateConfiguration() @@ -322,13 +382,7 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension { * */ List getFatalWarnings() { - if (!task || onlyTaskWarnings) { - patternize(this.warningsAsErrors) - } else if (this.warningsAsErrors.empty) { - extFromProject.fatalWarnings - } else { - extFromProject.fatalWarnings + patternize(this.warningsAsErrors) - } + this.fatalWarningsProvider.get() } /** Provide patterns for Asciidoctor messages that are treated as failures. diff --git a/jvm/src/test/groovy/org/asciidoctor/gradle/jvm/AsciidoctorTaskSpec.groovy b/jvm/src/test/groovy/org/asciidoctor/gradle/jvm/AsciidoctorTaskSpec.groovy index 741733bc4..06fc6b57b 100755 --- a/jvm/src/test/groovy/org/asciidoctor/gradle/jvm/AsciidoctorTaskSpec.groovy +++ b/jvm/src/test/groovy/org/asciidoctor/gradle/jvm/AsciidoctorTaskSpec.groovy @@ -336,16 +336,16 @@ class AsciidoctorTaskSpec extends Specification { } } final task = createTask { - asciidoctorj { + asciidoctorj() { requires 'slim', 'tilt' } } then: !systemOut.toString().contains('deprecated') - task.asciidoctorj.requires[0] == 'asciidoctor-pdf' - task.asciidoctorj.requires[1] == 'slim' - task.asciidoctorj.requires[2] == 'tilt' + task.asciidoctorj().requires[0] == 'asciidoctor-pdf' + task.asciidoctorj().requires[1] == 'slim' + task.asciidoctorj().requires[2] == 'tilt' } void "Allow setting of requires via assignment"() { @@ -356,16 +356,16 @@ class AsciidoctorTaskSpec extends Specification { } } final task = createTask { - asciidoctorj { + asciidoctorj() { requires = ['slim', 'tilt'] } } then: !systemOut.toString().contains('deprecated') - !task.asciidoctorj.requires.contains('asciidoctor-pdf') - task.asciidoctorj.requires.contains('tilt') - task.asciidoctorj.requires.contains('slim') + !task.asciidoctorj().requires.contains('asciidoctor-pdf') + task.asciidoctorj().requires.contains('tilt') + task.asciidoctorj().requires.contains('slim') } void "Allow setting of sourceDir via method"() { @@ -406,7 +406,7 @@ class AsciidoctorTaskSpec extends Specification { void 'When attribute providers are registered on the task, then global ones will not be used.'() { when: final task = createTask { - asciidoctorj { + asciidoctorj() { attributeProvider { [:] }