package com.github.eerohele

import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.file.FileCollection

class DitaOtPlugin implements Plugin<Project> {
    static final String DITA = 'dita'
    static final String DITA_OT = 'ditaOt'

    FileCollection getClasspath(Project project) {
        project.fileTree(dir: project.ditaOt.home).matching {
            include(
                'lib/**/*.jar',
                'resources/messages.xml',
                'plugins/org.dita.pdf2/lib/fo.jar',
                'plugins/org.dita.pdf2/build/libs/fo.jar'
            )
        }
    }

    @Override
    void apply(Project project) {
        project.apply plugin: 'base'

        project.extensions.create(DITA_OT, DitaOtExtension, project)

        def task = project.task(
            DITA,
            type: DitaOtTask,
            group: 'Documentation',
            description: 'Publishes DITA documentation with DITA Open Toolkit.'
        )

        project.afterEvaluate {
            task.conventionMapping.with {
                ditaOtClasspath = { getClasspath(project) }
            }
        }
    }

}

package com.github.eerohele

import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.file.FileCollection

class DitaOtPlugin implements Plugin<Project> {
    static final String DITA = 'dita'
    static final String DITA_OT = 'ditaOt'

    Double getCurrentJavaVersion() {
        System.getProperty('java.specification.version').toDouble()
    }

    FileCollection getClasspath(Project project) {
        project.fileTree(dir: project.ditaOt.home).matching {
            include(
                'lib/**/*.jar',
                'resources/messages.xml',
                'plugins/org.dita.pdf2/lib/fo.jar',
                'plugins/org.dita.pdf2/build/libs/fo.jar'
            )
        }
    }

    @Override
    void apply(Project project) {
        project.apply plugin: 'base'

        project.extensions.create(DITA_OT, DitaOtExtension, project)

        def task = project.task(
            DITA,
            type: DitaOtTask,
            group: 'Documentation',
            description: 'Publishes DITA documentation with DITA Open Toolkit.'
        )

        if (getCurrentJavaVersion() < 1.8) {
            project.logger.warn(MESSAGES.javaVersionWarning)
        }

        project.afterEvaluate {
            task.conventionMapping.with {
                ditaOtClasspath = { getClasspath(project) }
            }
        }
    }

}

Print warning if using Java < 8
Print warning if using Java < 8
