Using code generation under ClearCase
Those of you that know ClearCase also know that it requires the user to check out the file he wishes to edit before any editing can be done; kind of trying to edit a read-only file : you need to remove the read-only flag before anything else. Of course, this doesn't fit well with code generation tools such as Acceleo since the aim of such tools is to edit (or create) a number of files at once.
Until now that is :). Acceleo can now be used in conjunction with ClearCase or other pessimist-locking Version Control Systems (VCS). How does it work?
You might have noticed the "getGenerationStrategy()" method of the Java class we generate for your main mtl files; this is the method that matters for us. You simply need to change it from its default "return super.getGenerationStrategy()" to "return new WorkspaceAwareStrategy()" and you're done! Acceleo will now prompt the users of your generators to check out the files before attempting to modify them.
Two things to note :
You must change the javadoc of "getGenerationStrategy()" so that it doesn't contain "@generated" anymore : delete this tag, change it to "@not-generated", change it to "@generated NOT"... just don't leave this tag as-is or the Acceleo builder will override your change.You cannot use this strategy in standalone mode, its goal is to integrate with the Eclipse workspace and its team providers.The use case with ClearCase or pessimist locking VCSs is obvious, but you might realize that there is more to it that just these. You could be trying to regenerate a file that you set as read only, a file under SVN that requires a lock...
For example, with SVN you can set the property "svn:needs-lock" on a file to prevent any edition without prior locking. If you attempt to regenerate a file with such a property set with Acceleo, here is what you will get :
"java.io.FileNotFoundException: [...]\Library.java (Access denied)"
Pretty mean, huh? If you make use of the WorskpaceAwareStrategy though, you will get this instead :
All you have to do is to tick off the files for which you wish to take the lock. Files you do not check will not be locked for edition.
Until now that is :). Acceleo can now be used in conjunction with ClearCase or other pessimist-locking Version Control Systems (VCS). How does it work?
You might have noticed the "getGenerationStrategy()" method of the Java class we generate for your main mtl files; this is the method that matters for us. You simply need to change it from its default "return super.getGenerationStrategy()" to "return new WorkspaceAwareStrategy()" and you're done! Acceleo will now prompt the users of your generators to check out the files before attempting to modify them.
Two things to note :
You must change the javadoc of "getGenerationStrategy()" so that it doesn't contain "@generated" anymore : delete this tag, change it to "@not-generated", change it to "@generated NOT"... just don't leave this tag as-is or the Acceleo builder will override your change.You cannot use this strategy in standalone mode, its goal is to integrate with the Eclipse workspace and its team providers.The use case with ClearCase or pessimist locking VCSs is obvious, but you might realize that there is more to it that just these. You could be trying to regenerate a file that you set as read only, a file under SVN that requires a lock...
For example, with SVN you can set the property "svn:needs-lock" on a file to prevent any edition without prior locking. If you attempt to regenerate a file with such a property set with Acceleo, here is what you will get :
"java.io.FileNotFoundException: [...]\Library.java (Access denied)"
Pretty mean, huh? If you make use of the WorskpaceAwareStrategy though, you will get this instead :
All you have to do is to tick off the files for which you wish to take the lock. Files you do not check will not be locked for edition.
Auteur d'origine: Laurent