/* * Copyright 2004-2007 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. */ /** * Gant script that handles the import of a project into an existing SVN repository * * @author Marc Palmer * * @since 0.5 */ Ant.property(environment:"env") grailsHome = Ant.antProject.properties."env.GRAILS_HOME" includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" ) includeTargets << new File ( "${grailsHome}/scripts/Upgrade.groovy" ) webappDirFile = new File( basedir, 'web-app') pluginsDirFile = new File( basedir, 'plugins') generatedContentDirs = [ new File(webappDirFile, 'WEB-INF'), new File(webappDirFile, 'plugins'), new File(pluginsDirFile, 'core') ] svnIgnoresMap = [:] // Map of dir -> list of dirs to ignore, generated svnRepoURL = null svnRepoUser = null task ( "default" : "Import current project into an existing SVN repository") { //depends( checkVersion) 0.5 only svnImport() } task( svnImport: "The implementation task") { depends( init ) println """ This script will import your existing Grails project into an SVN repository. You will need to commit the project once this process is complete. NOTE: The "in place import" mechanism will be used. For this to work you must have an existing SVN repository reflecting the structure you want, with an empty directory where you want the Grails project to go. It is the URL to this empty folder that you must specify. Example: Your repository is at https://somewhere.com/svn/MyProject/ and you want ./trunk/MyProject to be where your Grails project is checked in. To achieve this you must make sure that: https://somewhere.com/svn/MyProject/trunk/MyProject/ ...already exists in the SVN repository and is empty. """ def argList = args.trim().tokenize() if (argList.size() >= 1) { svnRepoURL = argList[0] } if (argList.size() >= 2) { svnRepoUser = argList[1] } if (!svnRepoURL) { Ant.input(message:"Subversion Repository URL not specified. Please enter URL of an existing EMPTY repository ready for checkout:", addProperty:"grails.svn.repo") svnRepoURL = Ant.antProject.properties."grails.svn.repo"?.trim() } if (!svnRepoURL.endsWith(File.separator)) { svnRepoURL += File.separator } Ant.input(addProperty:"svn.checkout.confirm", message:"About to checkout SVN repository ${svnRepoURL} to this directory. Continue? [y/n]") if(Ant.antProject.properties."svn.checkout.confirm" == "y") { println "Checking out from SVN" svnCheckout(svnRepoURL, basedir) println "Adding project files to SVN" svnAdd(basedir + File.separator + '*') println "Setting properties to exclude generated files from SVN" generatedContentDirs.each() { svnIgnore( it) } // Now actually do the propsets svnIgnoreFinalize() println "Imported Grails Application at $basedir - you need to commit this now" } else { println "Import of Grails Application aborted" } } void svn(def arguments) { Ant.exec( executable:"bash") { arg( value: '-c') def cmd = new StringBuffer('svn') arguments.each() { cmd << ' ' << it } arg( value: cmd) } } void svnAdd(dir) { svn(['add', dir]) } void svnRevert(dir, boolean recurse) { def params = ['revert'] if (recurse) { params << '--recursive' } params << dir svn(params) } void svnCheckout(url, dir) { def params = ['checkout'] if (svnRepoUser) { params << '--username' params << svnRepoUser } params << url params << dir svn(params) } void svnIgnore(dir) { println "Adding SVN ignore for $dir" // Store the list for later, there using propedit would be ugly, we'll do a single // propset later def ignoresForDir = svnIgnoresMap[dir.parentFile] if (!ignoresForDir) { ignoresForDir = [] svnIgnoresMap[dir.parentFile] = ignoresForDir } ignoresForDir << dir.name // Now remove this dir from the add list svnRevert(dir, true) } void svnIgnoreFinalize() { svnIgnoresMap.each() { def ignoresList = new StringBuffer() it.value.each() { ignoresList << it << '\n' } svnPropset( "svn:ignore", ignoresList, it.key) } } void svnPropset(propName, value, dir) { svn(['propset', propName, "\"$value\"", dir]) }