GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / scripts / ReleasePlugin.groovy
blobbbd7cc5d11fe2eb25d44711445134ca2f43a3549
1 import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
2 import org.tmatesoft.svn.core.io.SVNRepositoryFactory
3 import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory
4 import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
5 import org.tmatesoft.svn.core.io.*
6 import org.tmatesoft.svn.core.*
7 import org.tmatesoft.svn.core.auth.*
8 import org.tmatesoft.svn.core.wc.*
9 import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
11 grailsHome = Ant.project.properties."environment.GRAILS_HOME"
13 includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" )
14 includeTargets << new File ( "${grailsHome}/scripts/PackagePlugin.groovy" )
16 pluginSVN = "https://svn.codehaus.org/grails-plugins"
17 //pluginSVN = "file:///Developer/localsvn"
18 authManager = null
19 message = null
20 trunk = null
21 latestRelease = null
22 versionedRelease = null
24 target ('default': "A target for plug-in developers that uploads and commits the current plug-in as the latest revision. The command will prompt for your SVN login details.") {
25 releasePlugin()
28 target(processAuth:"Prompts user for login details to create authentication manager") {
29 if(!authManager) {
30 Ant.input(message:"Please enter your SVN username:", addproperty:"user.svn.username")
31 Ant.input(message:"Please enter your SVN password:", addproperty:"user.svn.password")
33 def username = Ant.antProject.properties."user.svn.username"
34 def password = Ant.antProject.properties."user.svn.password"
36 authManager = SVNWCUtil.createDefaultAuthenticationManager( username , password )
39 target(releasePlugin: "The implementation target") {
40 //depends(packagePlugin)
41 depends(packagePlugin, processAuth)
43 remoteLocation = "${pluginSVN}/grails-${pluginName}"
44 trunk = SVNURL.parseURIDecoded("${remoteLocation}/trunk")
45 latestRelease = "${remoteLocation}/tags/LATEST_RELEASE"
46 versionedRelease = "${remoteLocation}/tags/RELEASE_${plugin.version.toString().replaceAll('\\.','_')}"
49 FSRepositoryFactory.setup();
50 DAVRepositoryFactory.setup()
52 try {
53 def statusClient = new SVNStatusClient((ISVNAuthenticationManager)authManager,null)
55 boolean imported = false
56 try {
57 // get status of base directory, if this fails exception will be thrown
58 def status = statusClient.doStatus(baseFile, true)
60 catch(SVNException ex) {
62 // error with status, not in repo, attempt import..
63 importToSVN()
64 imported = true
66 if(!imported) {
67 updateAndCommitLatest()
68 tagPluginRelease()
69 event('StatusFinal', ["Plug-in release successfully published"])
72 catch(Exception e) {
73 event('StatusFinal', ["Error occurred with release-plugin: ${e.message}"])
74 e.printStackTrace()
78 target(checkInPluginZip:"Checks in the plug-in zip if it has not been checked in already") {
79 def statusClient = new SVNStatusClient((ISVNAuthenticationManager)authManager,null)
80 def wcClient = new SVNWCClient((ISVNAuthenticationManager)authManager,null)
81 def pluginFile = new File(pluginZip)
82 def addPluginFile = false
83 try {
84 def status = statusClient.doStatus(pluginFile, true)
85 if(status.kind == SVNNodeKind.NONE || status.kind == SVNNodeKind.UNKNOWN) addPluginFile = true
87 catch(SVNException) {
88 // not checked in add and commit
89 addPluginFile = true
91 if(addPluginFile) wcClient.doAdd(pluginFile,true,false,false,false)
92 def pluginXml = new File("${basedir}/plugin.xml")
93 addPluginFile = false
94 try {
95 def status = statusClient.doStatus(pluginXml, true)
96 if(status.kind == SVNNodeKind.NONE || status.kind == SVNNodeKind.UNKNOWN) addPluginFile = true
98 catch(SVNException e) {
99 addPluginFile = true
101 if(addPluginFile) wcClient.doAdd(pluginXml, true, false,false,false)
103 target(updateAndCommitLatest:"Commits the latest revision of the Plug-in") {
104 def result = confirmInput("""
105 This command will perform the following steps to release your plug-in into Grails' SVN repository:
106 * Update your sources to the HEAD revision
107 * Commit any changes you've made to SVN
108 * Tag the release
110 NOTE: This command will not add new resources for you, if you have additional sources to add please run 'svn add' before running this command.
111 NOTE: Make sure you have updated the version number if you *GrailsPlugin.groovy descriptor.
113 Are you sure you wish to proceed?
114 """)
115 if(result == 'n') exit(0)
117 checkInPluginZip()
119 updateClient = new SVNUpdateClient((ISVNAuthenticationManager)authManager, null)
121 println "Updating from SVN '${remoteLocation}'"
122 long r = updateClient.doUpdate(baseFile, SVNRevision.HEAD, true)
123 println "Updated to revision ${r}. Committing local, please wait..."
125 commitClient = new SVNCommitClient((ISVNAuthenticationManager)authManager, null)
127 if(!message) askForMessage()
129 println "Committing code. Please wait..."
131 def commit = commitClient.doCommit([baseFile] as File[],false,message,true,true)
133 println "Committed revision ${commit.newRevision}."
136 target(importToSVN:"Imports a plug-in project to Grails' remote SVN repository") {
137 checkOutDir = new File("${baseFile.parentFile.absolutePath}/checkout/${baseFile.name}")
139 def result = confirmInput("""
140 This plug-in project is not currently in the repository, this command will now:
141 * Perform an SVN import into the repository
142 * Tag the plug-in project as the LATEST_RELEASE
143 * Checkout the imported version of the project from SVN to '${checkOutDir}'
144 Are you sure you wish to proceed?
145 """)
146 if(result == 'n') exit(0)
148 Ant.unzip(src:pluginZip, dest:"${basedir}/unzipped")
149 Ant.copy(file:pluginZip, todir:"${basedir}/unzipped")
152 importClient = new SVNCommitClient((ISVNAuthenticationManager)authManager, null)
153 askForMessage()
155 println "Importing project to ${remoteLocation}. Please wait..."
157 def svnURL = SVNURL.parseURIDecoded("${remoteLocation}/trunk")
158 importClient.doImport(new File("${basedir}/unzipped"),svnURL,message,true)
159 println "Plug-in project imported to SVN at location '${remoteLocation}/trunk'"
161 tagPluginRelease()
163 Ant.delete(dir:"${basedir}/unzipped")
166 checkOutDir.parentFile.mkdirs()
168 updateClient = new SVNUpdateClient((ISVNAuthenticationManager)authManager, null)
169 println "Checking out locally to '${checkOutDir}'."
170 updateClient.doCheckout(svnURL, checkOutDir, SVNRevision.HEAD,SVNRevision.HEAD, true)
172 event('StatusFinal', ["""
173 Completed SVN project import. If you are in terminal navigate to imported project with:
174 cd ${checkOutDir}
176 Future changes should be made to the SVN controlled sources!"""])
179 target(tagPluginRelease:"Tags a plugin-in with the LATEST_RELEASE tag and version tag within the /tags area of SVN") {
182 copyClient = new SVNCopyClient((ISVNAuthenticationManager)authManager, null)
183 commitClient = new SVNCommitClient((ISVNAuthenticationManager)authManager, null)
185 if(!message) askForMessage()
187 println "Tagging release. Please wait..."
189 tags = SVNURL.parseURIDecoded("${remoteLocation}/tags")
190 latest = SVNURL.parseURIDecoded(latestRelease)
191 release = SVNURL.parseURIDecoded(versionedRelease)
193 try { commitClient.doMkDir([tags] as SVNURL[], message)}
194 catch(SVNException e) {
195 // ok - already exists
197 try { commitClient.doDelete([latest] as SVNURL[], message) }
198 catch(SVNException e) {
199 // ok - already exists
201 try { commitClient.doDelete([release] as SVNURL[], message) }
202 catch(SVNException e) {
203 // ok - already exists
205 try { commitClient.doMkDir([latest] as SVNURL[], message) }
206 catch(SVNException e) {
207 // ok - already exists
209 try { commitClient.doMkDir([release] as SVNURL[], message) }
210 catch(SVNException e) {
211 // ok - already exists
215 repository = SVNRepositoryFactory.create( trunk )
216 //repository.setAuthenticationManager( authManager )
218 // we need to get a list of SVNURL entries to copy into the tags/LATEST_RELEASE directory
219 def entries = []
220 def root = repository.getDir("",-1,false , entries)
221 def urls = entries.collect { it.URL }
223 def commit
224 println "Tagging latest release, please wait..."
225 urls.each { url -> commit = copyClient.doCopy(url,SVNRevision.HEAD,latest, false, false, message ) }
226 println "Copied trunk to ${latestRelease} with revision ${commit.newRevision} on ${commit.date}"
228 println "Tagging version release, please wait..."
229 urls.each { url -> commit = copyClient.doCopy(url,SVNRevision.HEAD,release, false, false, message ) }
230 println "Copied trunk to ${versionedRelease} with revision ${commit.newRevision} on ${commit.date}"
233 target(askForMessage:"Asks for the users commit message") {
234 Ant.input(message:"Enter a SVN commit message:", addproperty:"commit.message")
235 message = Ant.antProject.properties."commit.message"