Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 249 lines (218 sloc) 11.102 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
import org.apache.tools.ant.filters.ReplaceTokens

apply plugin: org.grails.gradle.GrailsBuildPlugin

def libsConfigurations = []
subprojects { subproject ->
    configurations {
        libsConfigurations << libs {
            extendsFrom compile, runtime
            ["jsp21", "uaa"].collect { configurations.findByName(it) }.findAll { it != null }.each { extendsFrom it }
        }
    }
}

task checkDuplicateDependencies(description: 'Checks the dependency graph for multiple versions of the same dependency',
                                dependsOn: libsConfigurations) << {
    def moduleToVersionsMap = [:]
    libsConfigurations.each { configuration ->
        configuration.resolvedConfiguration.resolvedArtifacts.each { artifact ->
            def dependency = artifact.resolvedDependency

            def key = "${dependency.moduleGroup}/${dependency.moduleName}".toString()
            def value = dependency.moduleVersion

            def versions = moduleToVersionsMap[key]
            if (!versions) {
                versions = [] as Set
                moduleToVersionsMap[key] = versions
            }
            versions << value
        }
    }
    def dups = moduleToVersionsMap.findAll { k, v ->
        v.size() > 1
    }
    if (dups) {
        def msg = 'Multiple versions of some dependencies have been identified in the dependency graph'
        println msg
        dups.each { k, v ->
            println "Dependency: ${k}, Versions: $v"
        }
        throw new GradleException(msg)
    }
}

task configurePopulateDependencies << {
    def projectNames = rootProject.subprojects*.name

    ext {
        baseCachesDir = "$gradle.gradleUserHomeDir/caches"
        cacheDir = "$baseCachesDir/modules-2"
        metadata = "$cacheDir/metadata-2.1/descriptors"
    }

    def seen = []
    libsConfigurations.each { configuration ->
        def sourceArtifacts = sourcesFor(configuration).resolvedConfiguration.lenientConfiguration.getArtifacts(Specs.satisfyAll()).groupBy { it.moduleVersion.id }
        def javadocArtifacts = javadocFor(configuration).resolvedConfiguration.lenientConfiguration.getArtifacts(Specs.satisfyAll()).groupBy { it.moduleVersion.id }
        for (artifact in configuration.resolvedConfiguration.resolvedArtifacts) {
            if (artifact in seen) continue
            seen << artifact
            def dependency = artifact.moduleVersion.id
            if (!projectNames.contains(dependency.name)) {
                populateDependencies.into("$dependency.group/$dependency.name/jars") {
                    from artifact.file // this will trigger the actual download if necessary
                    def sourceJar = sourceArtifacts[dependency]
                    if (sourceJar) {
                        from sourceJar.file
                    }
                    def javadocJar = javadocArtifacts[dependency]
                    if (javadocJar) {
                        from javadocJar.file
                    }
                }

                populateDependencies.from ("${metadata}/${dependency.group}/${dependency.name}/${dependency.version}") {
                    include "**/*ivy.xml"
                    eachFile { it.path = "$dependency.group/$dependency.name/ivy-${dependency.version}.xml" }
                }
            }
        }
    }
}

task populateDependencies(type: Sync, dependsOn: configurePopulateDependencies) {
    into homeLibDir
    includeEmptyDirs = false
}

// Can't use sync task here because this directory contains other things as well.
task sourcesJars(type: Sync) {
    into homeSrcDir
    from subprojects.findAll { !it.name.startsWith('grails-test-suite') }.sourcesJar*.outputs*.files

    // sourcesFor comes from GrailsBuildPlugin
    from { sourcesFor(libsConfigurations*.copyRecursive { it.name.startsWith('grails-datastore') }.collect { it.transitive = false; it }) }
}

task pluginsFromRepo {
    ext.plugins = [
        cache: "1.1.1",
        'database-migration': "1.3.8",
        hibernate4: "4.3.4.2",
        jquery: "1.11.0.2",
        'asset-pipeline': "1.7.6",
        scaffolding: "2.1.0-SNAPSHOT",
        tomcat: "7.0.52.1",
        webxml: "1.4.1"
    ]

    ext.dir = file("$buildDir/pluginsFromRepo")
    outputs.files { dir.listFiles().findAll { it.name.endsWith(".zip") || it.name.endsWith(".pom") } }
    doFirst {
        ant {
            mkdir(dir: dir)
            plugins.each { name, version ->
                def versionTag = version.replaceAll(/\./, '_').toUpperCase()
                get(src: "http://grails.org/plugins/grails-${name}/tags/RELEASE_${versionTag}/grails-${name}-${version}.zip",
                    dest: dir, verbose: true, usetimestamp: true)
                get(src: "http://grails.org/plugins/grails-${name}/tags/RELEASE_${versionTag}/grails-${name}-${version}.pom",
                    dest: dir, verbose: true, usetimestamp: true)
            }
        }
    }
}

task installResources(type: Copy) {
    into "$buildDir/home-dir" // not actually used, but has to be set to something

    into(homeLibDir.name) {
        from('grails-resources/src/grails/home/tests')
        filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
    }

    into(homeBinDir.name) {
        from("grails-resources/src/grails/home/bash")
        filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
        filter(ReplaceTokens, tokens: ['starter.main.class': 'org.codehaus.groovy.grails.cli.support.GrailsStarter'])
        filter(ReplaceTokens, tokens: ['windows.starter.classpath': "%GRAILS_HOME%\\lib\\org.codehaus.groovy\\groovy-all\\jars\\groovy-all-${groovyVersion}.jar;%GRAILS_HOME%\\dist\\grails-bootstrap-${grailsVersion}.jar".toString()])
        filter(ReplaceTokens, tokens: ['starter.classpath': "\$GRAILS_HOME/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-${groovyVersion}.jar:\$GRAILS_HOME/dist/grails-bootstrap-${grailsVersion}.jar".toString()])
        filter(ReplaceTokens, tokens: ['agent.string': "-javaagent:\$AGENT_GRAILS_HOME/lib/org.springframework/springloaded/jars/springloaded-${springLoadedVersion}.jar ${springLoadedCommonOptions} -Dspringloaded=\$SPRINGLOADED_PARAMS".toString()])
        filter(ReplaceTokens, tokens: ['windows.agent.string': "-javaagent:%GRAILS_HOME:\\=/%/lib/org.springframework/springloaded/jars/springloaded-${springLoadedVersion}.jar ${springLoadedCommonOptions} -Dspringloaded=\\\"%SPRINGLOADED_PARAMS%\\\"".toString()])
        filter(ReplaceTokens, tokens: ['startup.command': ''])
        fileMode = 0755
    }

    // the fileMode property above should take care of the chmod work, but
    // it doesn't per http://jira.codehaus.org/browse/GRADLE-971
    doLast {
        ant.copy(todir:projectDir) {
            fileset(dir:"$buildDir/home-dir")
        }

        ant.chmod(dir: homeBinDir, perm: '755', includes: '*')
    }

    into(homeConfDir.name) {
        from("grails-resources/src/grails/home/conf")

        filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
        filter(ReplaceTokens, tokens: ['groovy.version': groovyVersion])
        filter(ReplaceTokens, tokens: ['jline.version': jlineVersion])
        filter(ReplaceTokens, tokens: ['jansi.version': jansiVersion])
        filter(ReplaceTokens, tokens: ['jna.version': jnaVersion])
        filter(ReplaceTokens, tokens: ['commons.cli.version': commonsCliVersion])
        filter(ReplaceTokens, tokens: ['ant.version': antVersion])
        filter(ReplaceTokens, tokens: ['gant.version': gantVersion])
        filter(ReplaceTokens, tokens: ['ivy.version': ivyVersion])
    }

    into(homeDslSupportDir.name) {
        from 'grails-resources/src/grails/home/dsl-support'
    }

    into ("$homeSrcDir.name/war/WEB-INF") {
        from "grails-resources/src/war/WEB-INF"
    }
}

task install(dependsOn: [populateDependencies, installResources] + subprojects.findAll { !it.name.startsWith('grails-test-suite') }*.install)

task zipDist(type: Zip, dependsOn: [sourcesJars, install]) {
    destinationDir = "${buildDir}/distributions" as File
    baseName = 'grails'
    appendix = grailsVersion

    exclude "**/CVS/**"

    into("grails-$grailsVersion") {
        from(projectDir) {
            include 'lib/', 'media/', 'samples/', 'scripts/', 'LICENSE', 'INSTALL', "src/", 'build.properties'
            exclude 'ant/bin', 'src/grails', 'src/war'
        }
        from("grails-resources") {
            include 'src/grails/**', 'src/war/**'
            // this file is accounted for later with special handling to do some token replacement
            exclude 'src/grails/grails-macros.xml'
        }
        from(docs.destinationDir) {
            into "doc"
        }
        from(pluginsFromRepo.outputs.files) {
            into "plugins"
            rename { it - "grails-" }
        }
        from('grails-resources/src/grails/home/docs/README') {
            filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
        }
        from('grails-resources/src/grails/home/tests') {
            into "src/resources/tests"
            filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
        }
        from("grails-resources/src/grails/home/bash") {
            into "bin"
            filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
            filter(ReplaceTokens, tokens: ['starter.main.class': 'org.codehaus.groovy.grails.cli.support.GrailsStarter'])
            filter(ReplaceTokens, tokens: ['windows.starter.classpath': "%GRAILS_HOME%\\lib\\org.codehaus.groovy\\groovy-all\\jars\\groovy-all-${groovyVersion}.jar;%GRAILS_HOME%\\dist\\grails-bootstrap-${grailsVersion}.jar".toString()])
            filter(ReplaceTokens, tokens: ['starter.classpath': "\$GRAILS_HOME/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-${groovyVersion}.jar:\$GRAILS_HOME/dist/grails-bootstrap-${grailsVersion}.jar".toString()])
            filter(ReplaceTokens, tokens: ['agent.string': "-javaagent:\$AGENT_GRAILS_HOME/lib/org.springframework/springloaded/jars/springloaded-${springLoadedVersion}.jar -noverify -Dspringloaded=\$SPRINGLOADED_PARAMS".toString()])
            filter(ReplaceTokens, tokens: ['windows.agent.string': "-javaagent:\"%GRAILS_HOME:\\=/%/lib/org.springframework/springloaded/jars/springloaded-${springLoadedVersion}.jar\" -noverify -Dspringloaded=\\\"%SPRINGLOADED_PARAMS%\\\"".toString()])
            filter(ReplaceTokens, tokens: ['startup.command': ''])
            fileMode = 0755
        }
        from("conf") {
            into "conf"
        }
        from(homeDistDir) {
            into "dist"
            exclude "*.zip"
        }
        from("grails-resources/src/grails/grails-macros.xml") {
            into "src/grails"
            filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
            filter(ReplaceTokens, tokens: ['groovy.version': groovyVersion])
        }
        from('grails-resources/src/grails/home/dsl-support') {
            into "dsl-support"
        }
    }
}

/*task zipDoc(type: Zip) {
appendix = 'docs'
from docs.destinationDir
}*/


task assemble(dependsOn: zipDist)
Something went wrong with that request. Please try again.