<commit_before>/*
 * Copyright 2004-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.
 */

import griffon.util.Environment
import griffon.util.PlatformUtils
import griffon.util.RunMode
import griffon.util.Metadata
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.text.SimpleDateFormat
import static griffon.util.GriffonNameUtils.capitalize
import static griffon.util.GriffonApplicationUtils.is64Bit
import static griffon.util.GriffonApplicationUtils.osArch

/**
 * Gant script that packages a Griffon application (note: does not create WAR)
 *
 * @author <NAME> (Grails 0.4)
 * @author <NAME>
 * @author <NAME>
 */

// No point doing this stuff more than once.
if (getBinding().variables.containsKey("_griffon_package_called")) return
_griffon_package_called = true

includeTargets << griffonScript("_GriffonCompile")
includeTargets << griffonScript("_PackagePlugins")

configTweaks = []

target(createConfig: "Creates the configuration object") {
    depends(compile)
    configTweaks.each {tweak -> tweak() }
}

target(packageApp : "Implementation of package target") {
    depends(createStructure)

    try {
        profile("compile") {
            compile()
        }
    }
    catch(Exception e) {
        logError("Compilation error",e)
        exit(1)
    }
    profile("creating config") {
        createConfig()
    }

    // flag if <application>.jar is up to date
    jardir = ant.antProject.replaceProperties(buildConfig.griffon.jars.destDir)
    ant.uptodate(property:'appJarUpToDate', targetfile:"${jardir}/${buildConfig.griffon.jars.jarName}") {
        srcfiles(dir:"${basedir}/griffon-app/", includes:"**/*")
        srcfiles(dir:"$classesDirPath", includes:"**/*")
    }

    packageResources()

    loadPlugins()
    checkKey()
    _copyLibs()
    jarFiles()

    event("PackagingEnd",[])
}

target(packageResources : "Presp app/plugin resources for packaging") {
    i18nDir = new File("${resourcesDirPath}/griffon-app/i18n")
    ant.mkdir(dir:i18nDir)

    resourcesDir = new File("${resourcesDirPath}/griffon-app/resources")
    ant.mkdir(dir:resourcesDir)

    if(!isPluginProject || isAddonPlugin) collectArtifactMetadata()

    if(buildConfig.griffon.enable.native2ascii) {
        profile("converting native message bundles to ascii") {
            ant.native2ascii(src:"${basedir}/griffon-app/i18n",
                             dest:i18nDir,
                             includes:"*.properties",
                             encoding:"UTF-8")
        }
    }
    else {
        ant.copy(todir:i18nDir) {
            fileset(dir:"${basedir}/griffon-app/i18n", includes:"*.properties")
        }
    }
    ant.copy(todir:resourcesDir) {
        fileset(dir:"${basedir}/griffon-app/resources", includes:"**/*.*")
        fileset(dir:"${basedir}/src/main") {
            include(name:"**/*")
            exclude(name:"**/*.java")
            exclude(name:"**/*.groovy")
        }
    }
    ant.copy(todir:classesDirPath) {
        fileset(dir:"${basedir}", includes:metadataFile.name)
    }

    // GRIFFON-189 add environment info to metadata
    def metaFile = new File(classesDirPath, metadataFile.name)
    updateMetadata(metaFile, (Environment.KEY): Environment.current.name)

    ant.copy(todir:resourcesDirPath, failonerror:false) {
        fileset(dir:"${basedir}/griffon-app/conf", includes:"**", excludes:"*.groovy, log4j*, webstart")
        fileset(dir:"${basedir}/src/main") {
            include(name:"**/**")
            exclude(name:"**/*.java")
            exclude(name:"**/*.groovy")
        }
    }
}

collectArtifactMetadata = {
    def artifactPaths = [
        [type: "model",      path: "models",      suffix: "Model"],
        [type: "view",       path: "views",       suffix: "View"],<commit_msg>In i18n, all .groovy files will be copied aswell to support ConfigSlurper-Files In resources, all .properties files will be converted via native2ascii aswell<commit_after>/*
 * Copyright 2004-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.
 */

import griffon.util.Environment
import griffon.util.PlatformUtils
import griffon.util.RunMode
import griffon.util.Metadata
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.text.SimpleDateFormat
import static griffon.util.GriffonNameUtils.capitalize
import static griffon.util.GriffonApplicationUtils.is64Bit
import static griffon.util.GriffonApplicationUtils.osArch

/**
 * Gant script that packages a Griffon application (note: does not create WAR)
 *
 * @author <NAME> (Grails 0.4)
 * @author <NAME>
 * @author <NAME>
 */

// No point doing this stuff more than once.
if (getBinding().variables.containsKey("_griffon_package_called")) return
_griffon_package_called = true

includeTargets << griffonScript("_GriffonCompile")
includeTargets << griffonScript("_PackagePlugins")

configTweaks = []

target(createConfig: "Creates the configuration object") {
    depends(compile)
    configTweaks.each {tweak -> tweak() }
}

target(packageApp : "Implementation of package target") {
    depends(createStructure)

    try {
        profile("compile") {
            compile()
        }
    }
    catch(Exception e) {
        logError("Compilation error",e)
        exit(1)
    }
    profile("creating config") {
        createConfig()
    }

    // flag if <application>.jar is up to date
    jardir = ant.antProject.replaceProperties(buildConfig.griffon.jars.destDir)
    ant.uptodate(property:'appJarUpToDate', targetfile:"${jardir}/${buildConfig.griffon.jars.jarName}") {
        srcfiles(dir:"${basedir}/griffon-app/", includes:"**/*")
        srcfiles(dir:"$classesDirPath", includes:"**/*")
    }

    packageResources()

    loadPlugins()
    checkKey()
    _copyLibs()
    jarFiles()

    event("PackagingEnd",[])
}

target(packageResources : "Presp app/plugin resources for packaging") {
    i18nDir = new File("${resourcesDirPath}/griffon-app/i18n")
    ant.mkdir(dir:i18nDir)

    resourcesDir = new File("${resourcesDirPath}/griffon-app/resources")
    ant.mkdir(dir:resourcesDir)

    if(!isPluginProject || isAddonPlugin) collectArtifactMetadata()

    if(buildConfig.griffon.enable.native2ascii) {
        profile("converting native message bundles to ascii") {
            ant.native2ascii(src:"${basedir}/griffon-app/i18n",
                             dest:i18nDir,
                             includes:"*.properties",
                             encoding:"UTF-8")
            ant.native2ascii(src:"${basedir}/griffon-app/resources",
                             dest:resourcesDir,
                             includes:"*.properties",
                             encoding:"UTF-8")
        }
    }
    else {
        ant.copy(todir:i18nDir) {
            fileset(dir:"${basedir}/griffon-app/i18n", includes:"*.properties")
        }
        ant.copy(todir:resourcesDir) {
            fileset(dir:"${basedir}/griffon-app/resources", includes:"*.properties")
        }
    }
    ant.copy(todir:i18nDir) {
            fileset(dir:"${basedir}/griffon-app/i18n", includes:"*.groovy")
        }
    ant.copy(todir:resourcesDir) {
        fileset(dir:"${basedir}/griffon-app/resources", includes:"**/*.*", excludes:"**/*.properties" )
        fileset(dir:"${basedir}/src/main") {
            include(name:"**/*")
            exclude(name:"**/*.java")
            exclude(name:"**/*.groovy")
        }
    }
    ant.copy(todir:classesDirPath) {
        fileset(dir:"${basedir}", includes:metadataFile.name)
    }

    // GRIFFON-189 add environment info to metadata
    def metaFile = new File(classesDirPath, metadataFile.name)
    updateMetadata(metaFile, (Environment.KEY): Environment.current.name)

    ant.copy(todir:resourcesDirPath, failonerror:false) {
        fileset(dir:"${basedir}/griffon-app/conf", includes:"**", excludes:"*.groovy, log4j*, webstart")
        fileset(dir:"${basedir}/src/main") {
            include(name:"**/**")
            exclude(name:"**/*.java")
            exclude(name:"**/*.groovy")
        }
    }
}

collectArtifactMetadata = {
    def artifactPaths = [
        [type: "model",      path: "models",      suffix: "Model"],
        [type: "view",       path: "views",       suffix: "View"],
{'fraction_non_alphanumeric': 0.13475024274463265, 'fraction_numerical': 0.009170352788866113, 'mean_word_length': 3.011250540891389, 'pattern_counts': {'":': 0, '<': 19, '<?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': '5886613', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2778, 'n_words': 584}