<commit_before>/*
 * Copyright 2011-2015 Asakusa Framework Team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.asakusafw.gradle.plugins

import javax.inject.Inject

import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.FileVisitDetails
import org.gradle.api.file.RelativePath
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.internal.file.DefaultSourceDirectorySet
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc

import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.CompilerConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.DmdlConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.JavacConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.ModelgenConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.TestToolsConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.ThunderGateConfiguration
import com.asakusafw.gradle.plugins.internal.PluginUtils
import com.asakusafw.gradle.tasks.AnalyzeYaessLogTask
import com.asakusafw.gradle.tasks.CompileBatchappTask
import com.asakusafw.gradle.tasks.CompileDmdlTask
import com.asakusafw.gradle.tasks.GenerateHiveDdlTask
import com.asakusafw.gradle.tasks.GenerateTestbookTask
import com.asakusafw.gradle.tasks.GenerateThunderGateDataModelTask
import com.asakusafw.gradle.tasks.RunBatchappTask
import com.asakusafw.gradle.tasks.TestToolTask
import com.asakusafw.gradle.tasks.internal.AbstractTestToolTask

/**
 * Gradle plugin for building application component blocks.
 */
class AsakusafwPlugin implements Plugin<Project> {

    public static final String ASAKUSAFW_BUILD_GROUP = 'Asakusa Framework Build'

    private final FileResolver fileResolver

    private Project project

    private File frameworkHome

    @Inject
    public AsakusafwPlugin(FileResolver fileResolver) {
        this.fileResolver = fileResolver
    }

    void apply(Project project) {
        this.project = project
        this.frameworkHome = System.env['ASAKUSA_HOME'] == null ? null : new File(System.env['ASAKUSA_HOME'])

        project.apply plugin: JavaPlugin.class
        project.apply plugin: AsakusafwBasePlugin.class

        configureProject()
        configureJavaPlugin()
        defineAsakusaTasks()
        applySubPlugins()
    }

    private void configureProject() {
        configureExtentionProperties()
        configureConfigurations()
        configureDependencies()
        configureSourceSets()
    }

    private void configureExtentionProperties() {
        AsakusafwPluginConvention convention = project.extensions.create('asakusafw', AsakusafwPluginConvention)
        convention.dmdl = convention.extensions.create('dmdl', DmdlConfiguration)
        convention.modelgen = convention.extensions.create('modelgen', ModelgenConfiguration)
        convention.javac = convention.extensions.create('javac', JavacConfiguration)
        convention.compiler = convention.extensions.create('compiler', CompilerConfiguration)
        convention.testtools = convention.extensions.create('testtools', TestToolsConfiguration)
        convention.thundergate = convention.extensions.create('thundergate', ThunderGateConfiguration)
        convention.conventionMapping.with {
            asakusafwVersion = { throw new InvalidUserDataException('"asakusafw.asakusafwVersion" must be set') }
            maxHeapSize = { '1024m' }
            logbackConf = { (String) "src/${project.sourceSets.test.name}/resources/logback-test.xml" }
            basePackage = {
                if (project.group == null || project.group == '') {
                    throw new InvalidUserDataException('"asakusafw.basePackage" must be specified')
                }
                return project.group
            }
        }
        convention.dmdl.conventionMapping.with {
            dmdlEncoding = { 'UTF-8' }
            dmdlSourceDirectory = { (String) "src/${project.sourceSets.main.name}/dmdl" }
        }
        convention.modelgen.conventionMapping.with {
            modelgenSourcePackage = { (String) "${project.asakusafw.basePackage}.modelgen" }
            modelgenSourceDirectory = { (String) "${project.buildDir}/generated-sources/modelgen" }
        }
        convention.javac.conventionMapping.with {
            annotationSourceDirectory = { (String) "${project.buildDir}/generated-sources/annotations" }
            sourceEncoding = { 'UTF-8' }
            sourceCompatibility = { JavaVersion.VERSION_1_7 }
            targetCompatibility = { JavaVersion.VERSION_1_7 }
        }
        convention.compiler.conventionMapping.with {
            compiledSourcePackage = { (String) "${project.asakusafw.basePackage}.batchapp" }
            compiledSourceDirectory = { (String) "${project.buildDir}/batchc" }
            compilerOptions = {[
                String.format("XjavaVersion=%s", JavaVersion.toVersion(convention.javac.targetCompatibility))
            ]}
            compilerWorkDirectory = { null }
            hadoopWorkDirectory = { 'target/hadoopwork/${execution_id}' }
        }
        convention.testtools.conventionMapping.with {
            testDataSheetFormat = { 'ALL' }
            testDataSheetDirectory = { (String) "${project.buildDir}/excel" }
        }
        convention.thundergate.conventionMapping.with {
            target = { null }
            jdbcFile = { null }
            ddlEncoding = { null }
            ddlSourceDirectory = { (String) "src/${project.sourceSets.main.name}/sql/modelgen" }
            includes = { null }
            excludes = { null }
            dmdlOutputDirectory = { (String) "${project.buildDir}/thundergate/dmdl" }
            ddlOutputDirectory = { (String) "${project.buildDir}/thundergate/sql" }
            sidColumn = { 'SID' }
            timestampColumn = { 'UPDT_DATETIME' }
            deleteColumn = { 'DELETE_FLAG' }
            deleteValue = { '"1"' }
        }
        convention.metaClass.toStringDelegate = { -> "asakusafw { ... }" }
    }

    private void configureConfigurations() {
        def provided = project.configurations.create('provided')
        provided.description = 'Emulating Maven’s provided scope'

        def embedded = project.configurations.create('embedded')
        embedded.description = 'Project embedded libraries'

        def asakusaThunderGateFiles = project.configurations.create('asakusaThunderGateFiles')
        asakusaThunderGateFiles.description = 'Asakusa ThunderGate system files'
        asakusaThunderGateFiles.transitive = false

        def asakusaYaessLogAnalyzer = project.configurations.create('asakusaYaessLogAnalyzer')
        asakusaYaessLogAnalyzer.description = 'Asakusa YAESS Log Analyzer Libraries'

        def asakusaHiveCli = project.configurations.create('asakusaHiveCli')
        asakusaHiveCli.description = 'Asakusa Hive CLI Libraries'
        asakusaHiveCli.extendsFrom project.configurations.compile
    }<commit_msg>Replace non-ASCII character.<commit_after>/*
 * Copyright 2011-2015 Asakusa Framework Team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.asakusafw.gradle.plugins

import javax.inject.Inject

import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.FileVisitDetails
import org.gradle.api.file.RelativePath
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.internal.file.DefaultSourceDirectorySet
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc

import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.CompilerConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.DmdlConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.JavacConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.ModelgenConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.TestToolsConfiguration
import com.asakusafw.gradle.plugins.AsakusafwPluginConvention.ThunderGateConfiguration
import com.asakusafw.gradle.plugins.internal.PluginUtils
import com.asakusafw.gradle.tasks.AnalyzeYaessLogTask
import com.asakusafw.gradle.tasks.CompileBatchappTask
import com.asakusafw.gradle.tasks.CompileDmdlTask
import com.asakusafw.gradle.tasks.GenerateHiveDdlTask
import com.asakusafw.gradle.tasks.GenerateTestbookTask
import com.asakusafw.gradle.tasks.GenerateThunderGateDataModelTask
import com.asakusafw.gradle.tasks.RunBatchappTask
import com.asakusafw.gradle.tasks.TestToolTask
import com.asakusafw.gradle.tasks.internal.AbstractTestToolTask

/**
 * Gradle plugin for building application component blocks.
 */
class AsakusafwPlugin implements Plugin<Project> {

    public static final String ASAKUSAFW_BUILD_GROUP = 'Asakusa Framework Build'

    private final FileResolver fileResolver

    private Project project

    private File frameworkHome

    @Inject
    public AsakusafwPlugin(FileResolver fileResolver) {
        this.fileResolver = fileResolver
    }

    void apply(Project project) {
        this.project = project
        this.frameworkHome = System.env['ASAKUSA_HOME'] == null ? null : new File(System.env['ASAKUSA_HOME'])

        project.apply plugin: JavaPlugin.class
        project.apply plugin: AsakusafwBasePlugin.class

        configureProject()
        configureJavaPlugin()
        defineAsakusaTasks()
        applySubPlugins()
    }

    private void configureProject() {
        configureExtentionProperties()
        configureConfigurations()
        configureDependencies()
        configureSourceSets()
    }

    private void configureExtentionProperties() {
        AsakusafwPluginConvention convention = project.extensions.create('asakusafw', AsakusafwPluginConvention)
        convention.dmdl = convention.extensions.create('dmdl', DmdlConfiguration)
        convention.modelgen = convention.extensions.create('modelgen', ModelgenConfiguration)
        convention.javac = convention.extensions.create('javac', JavacConfiguration)
        convention.compiler = convention.extensions.create('compiler', CompilerConfiguration)
        convention.testtools = convention.extensions.create('testtools', TestToolsConfiguration)
        convention.thundergate = convention.extensions.create('thundergate', ThunderGateConfiguration)
        convention.conventionMapping.with {
            asakusafwVersion = { throw new InvalidUserDataException('"asakusafw.asakusafwVersion" must be set') }
            maxHeapSize = { '1024m' }
            logbackConf = { (String) "src/${project.sourceSets.test.name}/resources/logback-test.xml" }
            basePackage = {
                if (project.group == null || project.group == '') {
                    throw new InvalidUserDataException('"asakusafw.basePackage" must be specified')
                }
                return project.group
            }
        }
        convention.dmdl.conventionMapping.with {
            dmdlEncoding = { 'UTF-8' }
            dmdlSourceDirectory = { (String) "src/${project.sourceSets.main.name}/dmdl" }
        }
        convention.modelgen.conventionMapping.with {
            modelgenSourcePackage = { (String) "${project.asakusafw.basePackage}.modelgen" }
            modelgenSourceDirectory = { (String) "${project.buildDir}/generated-sources/modelgen" }
        }
        convention.javac.conventionMapping.with {
            annotationSourceDirectory = { (String) "${project.buildDir}/generated-sources/annotations" }
            sourceEncoding = { 'UTF-8' }
            sourceCompatibility = { JavaVersion.VERSION_1_7 }
            targetCompatibility = { JavaVersion.VERSION_1_7 }
        }
        convention.compiler.conventionMapping.with {
            compiledSourcePackage = { (String) "${project.asakusafw.basePackage}.batchapp" }
            compiledSourceDirectory = { (String) "${project.buildDir}/batchc" }
            compilerOptions = {[
                String.format("XjavaVersion=%s", JavaVersion.toVersion(convention.javac.targetCompatibility))
            ]}
            compilerWorkDirectory = { null }
            hadoopWorkDirectory = { 'target/hadoopwork/${execution_id}' }
        }
        convention.testtools.conventionMapping.with {
            testDataSheetFormat = { 'ALL' }
            testDataSheetDirectory = { (String) "${project.buildDir}/excel" }
        }
        convention.thundergate.conventionMapping.with {
            target = { null }
            jdbcFile = { null }
            ddlEncoding = { null }
            ddlSourceDirectory = { (String) "src/${project.sourceSets.main.name}/sql/modelgen" }
            includes = { null }
            excludes = { null }
            dmdlOutputDirectory = { (String) "${project.buildDir}/thundergate/dmdl" }
            ddlOutputDirectory = { (String) "${project.buildDir}/thundergate/sql" }
            sidColumn = { 'SID' }
            timestampColumn = { 'UPDT_DATETIME' }
            deleteColumn = { 'DELETE_FLAG' }
            deleteValue = { '"1"' }
        }
        convention.metaClass.toStringDelegate = { -> "asakusafw { ... }" }
    }

    private void configureConfigurations() {
        def provided = project.configurations.create('provided')
        provided.description = '''Emulating Maven's provided scope'''

        def embedded = project.configurations.create('embedded')
        embedded.description = 'Project embedded libraries'

        def asakusaThunderGateFiles = project.configurations.create('asakusaThunderGateFiles')
        asakusaThunderGateFiles.description = 'Asakusa ThunderGate system files'
        asakusaThunderGateFiles.transitive = false

        def asakusaYaessLogAnalyzer = project.configurations.create('asakusaYaessLogAnalyzer')
        asakusaYaessLogAnalyzer.description = 'Asakusa YAESS Log Analyzer Libraries'

        def asakusaHiveCli = project.configurations.create('asakusaHiveCli')
        asakusaHiveCli.description = 'Asakusa Hive CLI Libraries'
        asakusaHiveCli.extendsFrom project.configurations.compile
    }
{'fraction_non_alphanumeric': 0.09205126586274386, 'fraction_numerical': 0.0029042237514994634, 'mean_word_length': 3.367245657568238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5049636', 'n_tokens_mistral': 4476, 'n_tokens_neox': 4325, 'n_words': 778}