History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-552
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Graeme Rocher
Reporter: Marc Palmer
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails

"grails upgrade" trashes CSS, layouts/main.gsp, error.gsp and taglibs

Created: 03/Jan/07 09:55 AM   Updated: 30/Jan/07 02:06 PM
Component/s: None
Affects Version/s: 0.4
Fix Version/s: 0.4

Time Tracking:
Not Specified


 Description  « Hide
This appears to be an ANT "copy" task problem rather than a Gant/Grails problem. From the ANT docs:

"By default, files are only copied if the source file is newer than the destination file, or when the destination file does not exist. However, you can explicitly overwrite files with the overwrite attribute."

This implies that you cannot actually force it to NEVER overwrite if there is another file. One workaround may be to "touch" all the files in the project at the point of upgrade, but this might affect version control negatively?



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Marc Palmer - 03/Jan/07 10:28 AM
We need to use the ANT <present> selector to make it copy only if the file exists only in the src tree.

Here is an example of the converted Upgrade.groovy however note that from my reading of the docs <present> is only valid as a child of <fileset> and as such I have commented out the copy commands that use toFile as these are not going to work, and also the workaround for these seems unclear currently.

/*
 * Copyright 2004-2005 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 upgrading of a Grails applications
 * 
 * @author Graeme Rocher
 *
 * @since 0.4
 */    
import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU

Ant.property(environment:"env")       
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"   

includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" )

task( upgrade: "main upgrade task") {
	depends( createStructure )    
	
	Ant.sequential {  
        delete(dir:"${basedir}/tmp", failonerror:false)
		copy(todir:"${basedir}/web-app") {
			fileset(dir:"${grailsHome}/src/war") {
				include(name:"**/**")
				exclude(name:"WEB-INF/**")
                present(present:"srconly", targetdir="${basedir}/web-app")
			} 
		}
		copy(file:"${grailsHome}/src/war/WEB-INF/sitemesh.xml",
			 tofile:"${basedir}/web-app/WEB-INF/sitemesh.xml", overwrite:true)
		copy(file:"${grailsHome}/src/war/WEB-INF/applicationContext.xml",
			 tofile:"${basedir}/web-app/WEB-INF/applicationContext.xml", overwrite:true)		
		copy(file:"${grailsHome}/src/war/WEB-INF/log4j.properties",
			 tofile:"${basedir}/grails-app/conf/log4j.development.properties") {
            //present(present:"srconly", targetdir="${basedir}/grails-app/conf")
        }
		copy(file:"${grailsHome}/src/war/WEB-INF/log4j.properties",
			 tofile:"${basedir}/grails-app/conf/log4j.test.properties") {
            //present(present:"srconly", targetdir="${basedir}/grails-app/conf")
        }
		copy(file:"${grailsHome}/src/war/WEB-INF/log4j.properties",
			 tofile:"${basedir}/grails-app/conf/log4j.production.properties") {
            //present(present:"srconly", targetdir="${basedir}/grails-app/conf")
        }
			
		copy(todir:"${basedir}/grails-app") {
			fileset(dir:"${grailsHome}/src/grails/grails-app") {
                present(present:"srconly", targetdir="${basedir}/grails-app")
            }
		}

		copy(todir:"${basedir}/grails-app/taglib") {
			fileset(dir:"${grailsHome}/src/grails/grails-app/taglib") {
                present(present:"srconly", targetdir="${basedir}/grails-app/taglib")
            }
		}
						   	 
		copy(file:"${grailsHome}/src/war/WEB-INF/web${servletVersion}.template.xml", 
			 tofile:"${basedir}/web-app/WEB-INF/web.template.xml") {
            //present(present:"srconly", targetdir="${basedir}/web-app/WEB-INF")
        }

		if(servletVersion != "2.3") {
			replace(file:"${basedir}/web-app/index.jsp", token:"http://java.sun.com/jstl/core",
					value:"http://java.sun.com/jsp/jstl/core")
		}  
		
		copy(todir:"${basedir}/web-app/WEB-INF/tld", overwrite:true) {
			fileset(dir:"${grailsHome}/src/war/WEB-INF/tld/${servletVersion}")	
			fileset(dir:"${grailsHome}/src/war/WEB-INF/tld", includes:"spring.tld")
			fileset(dir:"${grailsHome}/src/war/WEB-INF/tld", includes:"grails.tld")			
		}	 
		copy(todir:"${basedir}/spring") {
			fileset(dir:"${grailsHome}/src/war/WEB-INF/spring") {
				include(name:"*.xml")
				include(name:"*.groovy")    				
			}
		}  
		touch(file:"${basedir}/grails-app/i18n/messages.properties") 
	}
}

task("default": "Upgrades a Grails application from a previous version of Grails") {
	depends( upgrade )
}

Marc Palmer - 03/Jan/07 11:16 AM
Committed fix for this but log files still a problem.