<commit_before>/*
 * Copyright 2011 the original author or authors.
 *
 * 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 org.gradle.api.plugins.gae

import groovy.util.logging.Slf4j
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.execution.TaskExecutionGraph
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.testing.Test
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.api.plugins.*
import org.gradle.api.plugins.gae.task.*
import org.gradle.api.plugins.gae.task.appcfg.*
import org.gradle.api.plugins.gae.task.appcfg.backends.*

/**
 * <p>A {@link Plugin} that provides tasks for uploading, running and managing of Google App Engine projects.</p>
 *
 * @author <NAME>
 */
@Slf4j
class GaePlugin implements Plugin<Project> {
    static final String GAE_SDK_CONFIGURATION_NAME = 'gaeSdk'
    static final String GAE_GROUP = 'Google App Engine'
    static final String GAE_DOWNLOAD_SDK = 'gaeDownloadSdk'
    static final String GAE_RUN = 'gaeRun'
    static final String GAE_STOP = 'gaeStop'
    static final String GAE_ENHANCE = 'gaeEnhance'
    static final String GAE_UPLOAD = 'gaeUpload'
    static final String GAE_ROLLBACK = 'gaeRollback'
    static final String GAE_UPDATE_INDEXES = 'gaeUpdateIndexes'
    static final String GAE_VACUUM_INDEXES = 'gaeVacuumIndexes'
    static final String GAE_UPDATE_TASK_QUEUES = 'gaeUpdateQueues'
    static final String GAE_UPDATE_DOS = 'gaeUpdateDos'
    static final String GAE_UPDATE_CRON = 'gaeUpdateCron'
    static final String GAE_CRON_INFO = 'gaeCronInfo'
    static final String GAE_LOGS = 'gaeLogs'
    static final String GAE_VERSION = 'gaeVersion'
    static final String GAE_DOWNLOAD_APP = 'gaeDownloadApp'
    static final String GAE_EXPLODE_WAR = 'gaeExplodeWar'
    static final String GAE_UPDATE_BACKEND = 'gaeUpdateBackend'
    static final String GAE_UPDATE_ALL_BACKENDS = 'gaeUpdateAllBackends'
    static final String GAE_ROLLBACK_BACKEND = 'gaeRollbackBackend'
    static final String GAE_LIST_BACKENDS = 'gaeListBackends'
    static final String GAE_START_BACKEND = 'gaeStartBackend'
    static final String GAE_STOP_BACKEND = 'gaeStopBackend'
    static final String GAE_DELETE_BACKEND = 'gaeDeleteBackend'
    static final String GAE_CONFIGURE_BACKENDS = 'gaeConfigureBackends'
    static final String GAE_UPLOAD_ALL = 'gaeUploadAll'
    static final String GAE_FUNCTIONAL_TEST = 'gaeFunctionalTest'
    static final String GRADLE_USER_PROP_PASSWORD = '<PASSWORD>'
    static final String STOP_PORT_CONVENTION_PARAM = 'stopPort'
    static final String STOP_KEY_CONVENTION_PARAM = 'stopKey'
    static final String EXPLODED_WAR_DIR_CONVENTION_PARAM = 'explodedWarDirectory'
    static final String EXPLODED_SDK_DIR_CONVENTION_PARAM = 'explodedSdkDirectory'
    static final String BACKEND_PROJECT_PROPERTY = 'backend'
    static final String SETTING_PROJECT_PROPERTY = 'setting'
    static final String FUNCTIONAL_TEST_COMPILE_CONFIGURATION = 'functionalTestCompile'
    static final String FUNCTIONAL_TEST_RUNTIME_CONFIGURATION = 'functionalTestRuntime'
    static final String FUNCTIONAL_TEST_SOURCE_SET = 'functionalTest'

    @Override
    void apply(Project project) {
        project.plugins.apply(WarPlugin)
        applyFatJarPlugin(project)

        project.configurations.add(GAE_SDK_CONFIGURATION_NAME).setVisible(false).setTransitive(true)
                .setDescription('The Google App Engine SDK to be downloaded and used for this project.')

        GaePluginConvention gaePluginConvention = new GaePluginConvention()
        project.convention.plugins.gae = gaePluginConvention
        
        File explodedSdkDirectory = getExplodedSdkDirectory(project)
        File explodedWarDirectory = getExplodedWarDirectory(project)
        File downloadedAppDirectory = getDownloadedAppDirectory(project)
        configureDownloadSdk(project, explodedSdkDirectory)
        configureWebAppDir(project)
        configureAppConfig(project, gaePluginConvention)
        configureGaeExplodeWarTask(project, gaePluginConvention, explodedWarDirectory)
        configureGaeRun(project, gaePluginConvention, explodedWarDirectory)
        configureGaeStop(project, gaePluginConvention)
        configureGaeEnhance(project)
        configureGaeUpload(project, explodedWarDirectory)
        configureGaeRollback(project)
        configureGaeUpdateIndexes(project)
        configureGaeVacuumIndexes(project)
        configureGaeUpdateTaskQueues(project)
        configureGaeUpdateDoS(project)
        configureGaeUpdateCron(project)
        configureGaeCronInfo(project)
        configureGaeDownloadLogs(project, gaePluginConvention)
        configureGaeVersion(project)
        configureGaeDownloadApplication(project, gaePluginConvention, downloadedAppDirectory)
        configureGaeSdk(project, gaePluginConvention)
        configureGaeSingleBackendTask(project)
        configureGaeUpdateBackends(project, explodedWarDirectory)
        configureGaeUpdateAllBackends(project, explodedWarDirectory)
        configureGaeRollbackBackends(project)
        configureGaeListBackends(project)
        configureGaeStartBackend(project)
        configureGaeStopBackend(project)
        configureGaeDeleteBackend(project)
        configureGaeConfigureBackends(project)
        configureGaeUploadAll(project)
        configureGaeFunctionalTest(project, gaePluginConvention)
    }

    private void applyFatJarPlugin(Project project) {
        try {
            project.plugins.apply(ThirdPartyPlugin.FATJAR.id)

            project.slimWar.doFirst {
                File webAppDir = project.convention.getPlugin(WarPluginConvention).webAppDir
                project.ant.delete dir: new File(webAppDir, 'WEB-INF/lib')
            }
        }
        catch(UnknownPluginException e) {
            log.info 'FatJar plugin not installed.'
        }
    }

    private File getExplodedSdkDirectory(Project project) {
        getBuildSubDirectory(project, 'exploded-gae-sdk')
    }

    private File getExplodedWarDirectory(Project project) {
        getBuildSubDirectory(project, 'exploded-war')
    }<commit_msg>Issue #11: Storing App Engine SDKs in Gradle home directory so they can be shared among projects.<commit_after>/*
 * Copyright 2011 the original author or authors.
 *
 * 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 org.gradle.api.plugins.gae

import groovy.util.logging.Slf4j
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.execution.TaskExecutionGraph
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.testing.Test
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.api.plugins.*
import org.gradle.api.plugins.gae.task.*
import org.gradle.api.plugins.gae.task.appcfg.*
import org.gradle.api.plugins.gae.task.appcfg.backends.*

/**
 * <p>A {@link Plugin} that provides tasks for uploading, running and managing of Google App Engine projects.</p>
 *
 * @author <NAME>
 */
@Slf4j
class GaePlugin implements Plugin<Project> {
    static final String GAE_SDK_CONFIGURATION_NAME = 'gaeSdk'
    static final String GAE_GROUP = 'Google App Engine'
    static final String GAE_DOWNLOAD_SDK = 'gaeDownloadSdk'
    static final String GAE_RUN = 'gaeRun'
    static final String GAE_STOP = 'gaeStop'
    static final String GAE_ENHANCE = 'gaeEnhance'
    static final String GAE_UPLOAD = 'gaeUpload'
    static final String GAE_ROLLBACK = 'gaeRollback'
    static final String GAE_UPDATE_INDEXES = 'gaeUpdateIndexes'
    static final String GAE_VACUUM_INDEXES = 'gaeVacuumIndexes'
    static final String GAE_UPDATE_TASK_QUEUES = 'gaeUpdateQueues'
    static final String GAE_UPDATE_DOS = 'gaeUpdateDos'
    static final String GAE_UPDATE_CRON = 'gaeUpdateCron'
    static final String GAE_CRON_INFO = 'gaeCronInfo'
    static final String GAE_LOGS = 'gaeLogs'
    static final String GAE_VERSION = 'gaeVersion'
    static final String GAE_DOWNLOAD_APP = 'gaeDownloadApp'
    static final String GAE_EXPLODE_WAR = 'gaeExplodeWar'
    static final String GAE_UPDATE_BACKEND = 'gaeUpdateBackend'
    static final String GAE_UPDATE_ALL_BACKENDS = 'gaeUpdateAllBackends'
    static final String GAE_ROLLBACK_BACKEND = 'gaeRollbackBackend'
    static final String GAE_LIST_BACKENDS = 'gaeListBackends'
    static final String GAE_START_BACKEND = 'gaeStartBackend'
    static final String GAE_STOP_BACKEND = 'gaeStopBackend'
    static final String GAE_DELETE_BACKEND = 'gaeDeleteBackend'
    static final String GAE_CONFIGURE_BACKENDS = 'gaeConfigureBackends'
    static final String GAE_UPLOAD_ALL = 'gaeUploadAll'
    static final String GAE_FUNCTIONAL_TEST = 'gaeFunctionalTest'
    static final String GRADLE_USER_PROP_PASSWORD = '<PASSWORD>'
    static final String STOP_PORT_CONVENTION_PARAM = 'stopPort'
    static final String STOP_KEY_CONVENTION_PARAM = 'stopKey'
    static final String EXPLODED_WAR_DIR_CONVENTION_PARAM = 'explodedWarDirectory'
    static final String EXPLODED_SDK_DIR_CONVENTION_PARAM = 'explodedSdkDirectory'
    static final String BACKEND_PROJECT_PROPERTY = 'backend'
    static final String SETTING_PROJECT_PROPERTY = 'setting'
    static final String FUNCTIONAL_TEST_COMPILE_CONFIGURATION = 'functionalTestCompile'
    static final String FUNCTIONAL_TEST_RUNTIME_CONFIGURATION = 'functionalTestRuntime'
    static final String FUNCTIONAL_TEST_SOURCE_SET = 'functionalTest'

    @Override
    void apply(Project project) {
        project.plugins.apply(WarPlugin)
        applyFatJarPlugin(project)

        project.configurations.add(GAE_SDK_CONFIGURATION_NAME).setVisible(false).setTransitive(true)
                .setDescription('The Google App Engine SDK to be downloaded and used for this project.')

        GaePluginConvention gaePluginConvention = new GaePluginConvention()
        project.convention.plugins.gae = gaePluginConvention
        
        File explodedSdkDirectory = getExplodedSdkDirectory(project)
        File explodedWarDirectory = getExplodedWarDirectory(project)
        File downloadedAppDirectory = getDownloadedAppDirectory(project)
        configureDownloadSdk(project, explodedSdkDirectory)
        configureWebAppDir(project)
        configureAppConfig(project, gaePluginConvention)
        configureGaeExplodeWarTask(project, gaePluginConvention, explodedWarDirectory)
        configureGaeRun(project, gaePluginConvention, explodedWarDirectory)
        configureGaeStop(project, gaePluginConvention)
        configureGaeEnhance(project)
        configureGaeUpload(project, explodedWarDirectory)
        configureGaeRollback(project)
        configureGaeUpdateIndexes(project)
        configureGaeVacuumIndexes(project)
        configureGaeUpdateTaskQueues(project)
        configureGaeUpdateDoS(project)
        configureGaeUpdateCron(project)
        configureGaeCronInfo(project)
        configureGaeDownloadLogs(project, gaePluginConvention)
        configureGaeVersion(project)
        configureGaeDownloadApplication(project, gaePluginConvention, downloadedAppDirectory)
        configureGaeSdk(project, gaePluginConvention)
        configureGaeSingleBackendTask(project)
        configureGaeUpdateBackends(project, explodedWarDirectory)
        configureGaeUpdateAllBackends(project, explodedWarDirectory)
        configureGaeRollbackBackends(project)
        configureGaeListBackends(project)
        configureGaeStartBackend(project)
        configureGaeStopBackend(project)
        configureGaeDeleteBackend(project)
        configureGaeConfigureBackends(project)
        configureGaeUploadAll(project)
        configureGaeFunctionalTest(project, gaePluginConvention)
    }

    private void applyFatJarPlugin(Project project) {
        try {
            project.plugins.apply(ThirdPartyPlugin.FATJAR.id)

            project.slimWar.doFirst {
                File webAppDir = project.convention.getPlugin(WarPluginConvention).webAppDir
                project.ant.delete dir: new File(webAppDir, 'WEB-INF/lib')
            }
        }
        catch(UnknownPluginException e) {
            log.info 'FatJar plugin not installed.'
        }
    }

    private File getExplodedSdkDirectory(Project project) {
        new File(project.gradle.gradleUserHomeDir, 'gae-sdk')
    }

    private File getExplodedWarDirectory(Project project) {
        getBuildSubDirectory(project, 'exploded-war')
    }
{'fraction_non_alphanumeric': 0.0643470665307905, 'fraction_numerical': 0.001601397583345465, 'mean_word_length': 4.165037593984962, 'pattern_counts': {'":': 0, '<': 13, '<?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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2558602', 'n_tokens_mistral': 4045, 'n_tokens_neox': 3870, 'n_words': 911}