view src/main/groovy/org/ssdt_ohio/gradle/plugins/UserDocPlugin.groovy @ 31:bd084c7d01df version-0.4.6

Created version-0.4.6 branch
author Kyle Miller <kyle.miller@mcoecn.org>
date Fri, 05 Aug 2022 16:41:42 +0100
parents e3c55e83c9a4
children 927f02ccc596
line wrap: on
line source
package org.ssdt_ohio.gradle.plugins

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.GroovyRuntime
import org.gradle.api.tasks.GroovySourceSet
import org.gradle.api.tasks.SourceSet
import org.ssdt_ohio.gradle.tasks.UserDoc


class UserDocPlugin implements Plugin<Project> {


    private static final String USERDOC_TASK_NAME = 'userdoc'

    @Override
    void apply(Project project) {

        project.getPlugins().apply(GroovyPlugin.class)
        configureUserdoc(project)

    }

    private void configureUserdoc(final Project project) {
        UserDoc userDoc = project.getTasks().create(USERDOC_TASK_NAME, UserDoc.class);
        userDoc.setDescription("Generates UserDoc API documentation");
        userDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
        userDoc.windowTitle = project.name
        userDoc.docTitle = project.name

        JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
        SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        userDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath()))


        GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
        println "srcdirs: " + groovySourceSet.getGroovy().getSrcDirs()
        userDoc.setSource(groovySourceSet.getGroovy());

        userDoc.setDestinationDir(new File(project.buildDir, "docs/userdoc"))

        userDoc.setGroovyClasspath(new GroovyRuntime(project).inferGroovyClasspath(project.configurations.compile))

    }

}