gradle/gradle — pull request #264 by bashnesnos (2014-04-05 08:36:06+00:00)
Title: ApplicationPlugin configurability

Hello,
Just thought it might be useful to make ApplicationPlugin configuration a bit easier. Basically, it's hard because the root spec in CopySpec is immutable in terms of the child specs manipulation. Say, if I want to have an application plugin structure other than
````
/whatever
|-- /bin
|-- /lib
````
I can't do that without full replacement of installApp, distZip/Tar task and createStartScripts too due to hardcoded default applicationDistribution CopySpec. I've implemented another task which will take care of that re-configuration if it's configure closure is triggered. If the task is not there, then it falls back to the defaults like before the change.

E.g. the script before the proposed change (which is ok as a work around for installApp, but something like that would need to be done to distZip too):
````groovy
installApp {
applicationDistribution.with copySpec {
from(processResources) {
includeEmptyDirs = false
}
from(startScripts) {
fileMode = 0755
}
}

if(project.hasProperty('installDir')) {
destinationDir = new File(installDir)
cleanInstallDir.delete destinationDir.getAbsolutePath()
clean.dependsOn(':cleanInstallDir')
}

doLast {
new File("${destinationDir.getAbsolutePath()}/bin").deleteDir()
}

}

startScripts {
mainClassName = "bla.bla.bla.Main"
classpath += files('/config')

doLast {
def windowsScriptFile = file getWindowsScript()
def unixScriptFile = file getUnixScript()
windowsScriptFile.text = windowsScriptFile.text.replace('%APP_HOME%\\lib\\config', '%APP_HOME%\\config').replace('set APP_HOME=%DIRNAME%..','set APP_HOME=%DIRNAME%')
unixScriptFile.text = unixScriptFile.text.replace('$APP_HOME/lib/config', '$APP_HOME/config').replace('cd "`dirname \\"$PRG\\"`/.." >&-','cd "`dirname \\"$PRG\\"`" >&-')
}
}
````
And after:
````groovy
configureDist {
applicationBinDir = "."
applicationDistribution.with {
from(processResources) {
includeEmptyDirs = false

}
}
}

installApp {
if(project.hasProperty('installDir')) {
destinationDir = new File(installDir)
cleanInstallDir.delete destinationDir.getAbsolutePath()
clean.dependsOn(':cleanInstallDir')
}
}

startScripts {
mainClassName = "bla.bla.bla.Main"
classpath += files('config')
}
````
The last bit with 'config' dir to classpath addition relates to GRADLE-2333