<commit_before>/*
 * Copyright (C) 2005-2017 Qihoo 360 Inc.
 *
 * 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.qihoo360.replugin.gradle.host

import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import com.qihoo360.replugin.gradle.host.creator.FileCreators
import com.qihoo360.replugin.gradle.host.creator.IFileCreator
import com.qihoo360.replugin.gradle.host.creator.impl.json.PluginBuiltinJsonCreator
import com.qihoo360.replugin.gradle.host.handlemanifest.ComponentsGenerator
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel

/**
 * @author RePlugin Team
 */
public class Replugin implements Plugin<Project> {

    def static TAG = AppConstant.TAG
    def project
    def config
    def newManifest

    @Override
    public void apply(Project project) {
        println "${TAG} Welcome to replugin world ! "

        this.project = project

        /* Extensions */
        project.extensions.create(AppConstant.USER_CONFIG, RepluginConfig)

        if (project.plugins.hasPlugin(AppPlugin)) {

            def android = project.extensions.getByType(AppExtension)
            android.applicationVariants.all { variant ->

                addShowPluginTask(variant)

                variant.outputs.each { output ->

                    if (config == null) {
                        config = project.extensions.getByName(AppConstant.USER_CONFIG)
                        def appID = variant.generateBuildConfig.appPackageName
                        checkUserConfig(config, appID)
                        newManifest = ComponentsGenerator.generateComponent(appID, config)
                    }

                    output.processResources.doFirst {
                        new FileCreators().init(project, variant, config).create()
                    }

                    output.processManifest.doLast {
                        def manifestPath = output.processManifest.outputFile.absolutePath
                        def updatedContent = new File(manifestPath).getText("UTF-8").replaceAll("</application>", newManifest + "</application>")
                        new File(manifestPath).write(updatedContent, 'UTF-8')
                    }
                }
            }<commit_msg>* fix mergeAssets task is execute after processResources Task in gradle plugin 2.3.2<commit_after>/*
 * Copyright (C) 2005-2017 Qihoo 360 Inc.
 *
 * 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.qihoo360.replugin.gradle.host

import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import com.qihoo360.replugin.gradle.host.creator.FileCreators
import com.qihoo360.replugin.gradle.host.creator.IFileCreator
import com.qihoo360.replugin.gradle.host.creator.impl.json.PluginBuiltinJsonCreator
import com.qihoo360.replugin.gradle.host.handlemanifest.ComponentsGenerator
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel

/**
 * @author RePlugin Team
 */
public class Replugin implements Plugin<Project> {

    def static TAG = AppConstant.TAG
    def project
    def config
    def newManifest

    @Override
    public void apply(Project project) {
        println "${TAG} Welcome to replugin world ! "

        this.project = project

        /* Extensions */
        project.extensions.create(AppConstant.USER_CONFIG, RepluginConfig)

        if (project.plugins.hasPlugin(AppPlugin)) {

            def android = project.extensions.getByType(AppExtension)
            android.applicationVariants.all { variant ->

                addShowPluginTask(variant)

                if (config == null) {
                    config = project.extensions.getByName(AppConstant.USER_CONFIG)
                    def appID = variant.generateBuildConfig.appPackageName
                    checkUserConfig(config, appID)
                    newManifest = ComponentsGenerator.generateComponent(appID, config)
                }


                def variantData = variant.variantData
                def scope = variantData.scope

                def generateJsonAndHostConfigTaskName = scope.getTaskName("rpGenerate", "JsonAndHostConfig")
                def generateJsonAndHostConfigTask = project.task(generateJsonAndHostConfigTaskName)

                generateJsonAndHostConfigTask.doLast {
                    new FileCreators().init(project, variant, config).create()
                }
                generateJsonAndHostConfigTask.group = AppConstant.TASKS_GROUP

                String generateBuildConfigTaskName = variant.getVariantData().getScope().getGenerateBuildConfigTask().name
                def generateBuildConfigTask = project.tasks.getByName(generateBuildConfigTaskName)
                if (generateBuildConfigTaskName) {
                    generateJsonAndHostConfigTask.dependsOn generateBuildConfigTask
                }

                String mergeAssetsTaskName = variant.getVariantData().getScope().getMergeAssetsTask().name
                def mergeAssetsTask = project.tasks.getByName(mergeAssetsTaskName)
                if (mergeAssetsTask) {
                    generateJsonAndHostConfigTask.dependsOn mergeAssetsTask
                    mergeAssetsTask.finalizedBy generateJsonAndHostConfigTask
                }

                variant.outputs.each { output ->
                    output.processManifest.doLast {
                        def manifestPath = output.processManifest.outputFile.absolutePath
                        def updatedContent = new File(manifestPath).getText("UTF-8").replaceAll("</application>", newManifest + "</application>")
                        new File(manifestPath).write(updatedContent, 'UTF-8')
                    }
                }
            }
{'fraction_non_alphanumeric': 0.0785093533657387, 'fraction_numerical': 0.009868905582560024, 'mean_word_length': 2.4625191228964813, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '4744556', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1640, 'n_words': 409}