Skip to content

Commit

Permalink
Convert optionsProperty to provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerbertrand committed Jul 30, 2024
1 parent 76e6d60 commit cfd02fa
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ 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.Input
Expand Down Expand Up @@ -108,7 +107,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask<AsciidoctorJvmExe
private final Property<FileCollection> jvmClasspath
private final List<Provider<File>> gemJarProviders = []

private final MapProperty<String, Object> optionsProperty = project.objects.mapProperty(String, Object)
private final Provider<Map<String, Object>> optionsProvider
private final Provider<Map<String, Object>> attributesProvider
private final Provider<List<AsciidoctorAttributeProvider>> attributeProvidersProvider
private final Provider<FileCollection> configurationsFileCollectionProvider
Expand Down Expand Up @@ -263,7 +262,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask<AsciidoctorJvmExe
*/
@Input
Map<String, Object> getOptions() {
resolveAsCacheable(optionsProperty.get(), projectOperations)
resolveAsCacheable(optionsProvider.get(), projectOperations)
}

/** Apply a new set of Asciidoctor options, clearing any options previously set.
Expand All @@ -275,8 +274,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask<AsciidoctorJvmExe
* @param m Map with new options
*/
void setOptions(Map m) {
checkForAttributesInOptions(m)
optionsProperty.set(m)
asciidoctorJExtension.options = m
}

/** Add additional asciidoctor options
Expand All @@ -288,8 +286,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask<AsciidoctorJvmExe
* @param m Map with new options
*/
void options(Map m) {
checkForAttributesInOptions(m)
this.optionsProperty.putAll(m)
asciidoctorJExtension.options(m)
}

/** Returns all of the Asciidoctor options.
Expand Down Expand Up @@ -511,7 +508,7 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask<AsciidoctorJvmExe
this.baseDirConfiguration = new DefaultAsciidoctorBaseDirConfiguration(project, this)

def asciidoctorj = extensions.create(AsciidoctorJExtension.NAME, AsciidoctorJExtension, this)
this.optionsProperty.set(asciidoctorj.options)
this.optionsProvider = project.provider { asciidoctorj.options }
this.safeModeProperty.set(asciidoctorj.safeMode)
this.attributesProvider = project.provider { asciidoctorj.attributes }
this.attributeProvidersProvider = project.provider { asciidoctorj.attributeProviders }
Expand Down Expand Up @@ -685,12 +682,6 @@ class AbstractAsciidoctorTask extends AbstractJvmModelExecTask<AsciidoctorJvmExe
}
}

private void checkForAttributesInOptions(Map m) {
if (m.containsKey('attributes')) {
throw new GradleException('Attributes found in options. Please use \'attributes\' method')
}
}

private List<Object> getSerializableAsciidoctorJExtensions() {
asciidoctorJExtensions.findAll { !(it instanceof Dependency) }.collect {
getSerializableAsciidoctorJExtension(it)
Expand Down

0 comments on commit cfd02fa

Please sign in to comment.