Grails migration issues. DBM-UPDATE include not recursing, fails silently - grails

This is part of an ongoing project... splitting out domain objects so they can be consumed by multiple applications. The database migration files for the domain objects live with the plugin... but we want the apps to be able to reference them during a dbm-update.
I can get the application to recognize the plugin changelog, but after that, the changelog does not perform includes and process them as I expect.
Using GrailsPluginUtils I am able to get the path of the plugin and the plugin changelog, with which I do an include file. If I put the changeSet right in that file I am good, it runs. If I move it to a separate file in the same folder, or in a sub-folder, and reference it via "./someFile.groovy" it seems to FIND it but does not process it. I say it seems to find it because if I do NOT use a relative file path, the migration process throws an error saying it cannot find the file e.g., "someFile.groovy"...
I have workarounds but they are not acceptable because we want to control the order of how the DB migrations occur by using sub-directors with a _changelog.groovy that then includes the actual transformations (changeSets). But they are not being "include"ed.
If I use includeAll, it will grab any and all scripts in that one folder, but again, does not process any other includes referenced therein. I can write a script to scan the folders recursively but again, that requires a lot of coding to parse the _changelogs and grab the appropriate inclusion order, etc.
I really just want "include file:" to work as it does in a given application for its own changelog files.
Has anyone else done this? Am I missing something terribly obvious?
In the app...
databaseChangeLog {
...
include file: "${GrailsPluginUtils.pluginInfos.find { it.name == 'my-plugin' }.pluginDir}/grails-app/migrations/my_plugin_changes"
}
... in the plugin...
databaseChangeLog {
include file: "./someChangeLogChangeSet.groovy"
}
Thank you...

We had also tried adding changelog files to the plugin where our domains live but were unable to access it from the main app. However, if you want to access your files from other location then you could specify this property in your config file and give the folder name here Or even copy all the migrations to the appropriate location to the main app.
grails.plugin.databasemigration.changelogLocation = 'migrations'
If you do find a actual solution to this, please post it.

Related

Where is the default login page for the spring security core plugin?

I have installed the spring security core plugin. I need to modify the login page to look like my existing website. I have searched the entire project and cannot find it. I am running grails 2.4 and spring-security-core:2.0-RC5. Where can this pesky little file be? Can someone who is not a complete greenhorn help a fellow out?
As #Abs points out, the file is at target/work/plugins/spring-security-core-2.0-RC5/grails-app/views/login/auth.gsp but you shouldn't edit plugin files. Other developers on your team won't have access to the modified files and if you delete the target directory you'll lose your changes since the target directory is only a temporary work location.
Instead, copy the file to the same relative location in your application and make changes there. Create grails-app/views/login and copy the file there and make whatever changes you want.
This technique works for most plugin files, not just GSPs. The compilation order and classpath are configured such that application files and classes override plugin files if they're in the same location/package.
You can find the default login page here
targt->work->plugins->spring-security-core-2.0-RC5->grails-app->views->login>auth.gsp

Grails: how to collect all messages

I am new to Grails and I have inherited an existing application. I have a big file message.properties that I would like to prune, in order to remove keys that are no longer used.
In Django there is a command makemessages that goes through all codebase and collects all strings that need translation, adding them to the messages file and commenting out the entries that no longer exist. Is there a similar tool for Grails? If it helps, the project is based on verions 1.3.9.
There is no such tool, but you can create your own gant script. Take a look at getting a list of all i18n properties used in a Grails application and process this list.

Web.config in open source repository

I am creating web application in C# using ASP.NET MVC and I am using MSSQL server installed on my machine.
Also I wanted to publish application as open source project, and run it on production server.
Should I add web.config file to source code repository? If i should, how I should track "open source version" (pointing on MsSQL installed on localhost) and production version (pointing on my hosting of web.config (I am using Mercurial).
The recommended way to do this is as follows:
Create a copy of the public version of the file you'd like people to use as a starting point, and name it something other than the actual usable file. In your case, it could be web.config.template. Make sure the file would be usable if you just renamed it.
Instruct Mercurial to ignore the actual file, ie. web.config
If possible, make the build process figure out if the actual file is present, and if not, make a copy from the template file into the actual file
If step 3 is not possible, a batch file to make the actual file is the next best thing, or simple instructions on how to make it.
This ensures that:
There is a simple way of getting the actual configuration file
You can edit your local actual configuration file without worrying about committing it (it is ignored)
If step 3 was possible, this is largely transparent unless you need to make modifications to the file
Step 3 can be handled with a pre-build event for your project, something like:
if not exist web.config copy web.config.template web.config
You could commit a generic version to your repository, probably on the initial load only (so that the project will build for those who don't know how to create their own), and then add an ignore rule later so that you can add your connection strings and whatnot.

How to access files in the Project Directory with Grails

I needed some templates to render some code for users to paste. I put these into
/project-dir/grails-app/resources/templates/quickInstallCode.html
Then I tried accessing them using their relative path (grails-app/resources/templates/quickInstallCode.html), and it worked great.
When we then deployed the application to a Tomcat Server, using a .war file, the paths began pointing to a wrong location.
ERROR call, Template file /var/lib/tomcat6/grails-app/resources/templates/quickInstallCode.html not found.
I assumed, that Grails, giving good defaults for everything would handle this mess for me, but it seems like it does not.
I also tried this call, and it seemed to work great, but when deployed, the BuildSettingsHolder did not contain build Settings, which resulted in a fatal error.
BuildSettingsHolder.settings.baseDir.toString()
http://grails.org/doc/latest/api/grails/util/BuildSettingsHolder.html
http://grails.org/doc/latest/api/grails/util/BuildSettings.html
I am pretty frustrated that I cannot get this easy task to work, but the reason that this is so complicated seems to be that all Files are encapsuled in a WAR and not unpacked on the Server.
So the Questions are:
Where in your Project would you put
Files like this?
How to get a
reliable and stable way to access
this files? I just need a stable path to a base directory, without having to hardcode something in the configuration ... This cannot be so hard.
I have 2 solution to propose for this situation:
Save the template in the database, in a setting table. This way guarantees that nothing can go wrong.
You can consider using the resource folder like Sachin & Nirmal has proposed. About security, I think you can configure SpringSecurity Plugin to protect the specific resources, so that it can only be accessed by the site user.
Take a look at this link and try to use the getResource that spring provides. Its way more flexible and configurable.
def filePath = "resources/file.txt"
def appHolder=ApplicationHolder.application.parentContext.getResource("classpath:$filePath")
By the way Conf is on the root of the classpath, you can stick the files in src/java or src/groovy.
I keep my static resources in web-app folder and access them like this
ApplicationHolder.application.parentContext.servletContext.getRealPath("quickInstallCode.html")
// quickInstallCode.html should be in web-app folder.

How to rename an existing Grails application

Does anybody know how to (easily) "rename" an existing grails application? I'm running into this because my PaaS provider does not allow me to delete a subscription... So I want to deploy my application under a different name.
Of course, I can do this manually, but I think it might be a useful 'top-level' script (i.e. "grails rename-app newappname")
Manual hints:
When I do a "grails create-app myappname" I can see the myappname exists in the following files (and filenames)... Of course this is done by the create-app script, which replaces #...# tokens in the template. I guess once they are replaced, it's not trivial to do a rename.
./.project: <name>myappname</name>
./application.properties:app.name=myappname
./build.xml:<project xmlns:ivy="antlib:org.apache.ivy.ant" name="myappname" default="test">
./ivy.xml: <info organisation="org.example" module="myappname"/>
./myappname-test.launch:<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="myappname"/>
./myappname.launch:<listEntry value="/myappname"/>
./myappname.launch:<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="myappname" path="1" type="4"/> "/>
./myappname.launch:<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="myappname"/>
./myappname.launch:<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dbase.dir="${project_loc:myappname}" -Dserver.port=8080 -Dgrails.env=development"/>
./myappname.tmproj: <string>myappname.launch</string>
And of course... the top-level directory name is "myappname"
Any hints, or information about ongoing initiatives in this area are welcome
Greetz,
Johan
I had to do this, I renamed my project top level directory to the new name and
edited the application.properties file. There is a line app.name=youroldappname which should be changed.
Actually, you do not even have to rename the directory. You could have a different web-app name.
Hmm, I know it doesn't look fun, but it shouldn't be difficult (just boring) to rename the project directory, then all the files with your project name in them (you can ignore .tmproj unless you use TextMate). Finally, a quick search through all the files for your old project name to replace and you should have it.
Oh! First, if you're using an IDE, you'll want to remove the project from the IDE, then re-import it once you've completed your renaming procedure.
As far as I know, nothing project-specific is stored anywhere except the project directory and below, so it's a very finite set to search, and you only have to do this once (I hope).
Not very elegant, I know, but brute force does have its uses.
I used the brute force Method and it worked for me. Took 5-10 minutes to find all files with the name in it and replace it with the new one. Also Netbeans was ok afterwards. The only thing that changed was the port number which I had to change again.
Just renaming works except when you are using plugins. They will be stored in the $USER_HOME/.grails/$GRAILS_VERSION/projects/OLDNAME folder.
So after renaming your project you "lost" your plugins. I haven't tried renaming the plugin's folder however just installing all your plugin works as well (at least with Google App Engine and gorm-jpa).
If only changing the web app name isn't enough you can try the rough way - make a backup before.
(In workspace folder)
zip -r oldname.zip oldname/
Then, in eclipse/ggts, use
Disable project, Build automatically
Search, File, Containing text : "oldname", Search
Right click on search results, Replace all, ... "newname"
Exit eclipse and rename all folders to the new project name. On Unix/Mac run
find . -name "oldname"
and mv the handful of results to properly reflect the new names.
For me it worked like a charm, but make sure your project name is not a keyword and reasonably unique.

Resources