view src/main/groovy/org/ssdt_ohio/gradle/plugins/UserDocPlugin.groovy @ 13:a628135958e7

USASR-1307: inititial userdoc plugin/task to produce customizable groovy doc
author Dave Smith <smith@nwoca.org>
date Tue, 10 Dec 2013 22:53:57 +0000
parents
children e3c55e83c9a4
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 for the main source code.");
        userDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);

        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))

    }

}