Morph開発専用のプラグインを作ってみよう
Grails開発用に、開発支援プラグイン作ってみたよ | ゲンゾウ用ポストイット で取り上げた開発支援用のプラグインですが、 Morph eXchange を使用した開発のニーズが増えてきているようなので、専用プラグインとして作成して見ようと思っています。
Contents
機能
grails deploy-morph コマンド以外は、今回作ってみたものです。
grails deploy-morphコマンド( Morph eXchange にアップロード、デプロイ)grails warコマンド強化機能- war作成時に、 web.xml にメールセッション情報を追加
 - war作成時に、spring管理beanとして mailSession、mailSender ビーンを追加
 
プラグイン名
morph-utilities
morph-plugin
コーディング
DeployMorph.groovy ファイルは、以前のブログで作ったものを利用しました。
MorphUtilitiesGrailsPlugin.groovyMorphPluginGrailsPlugin.groovy ファイルには、以下のように記述しました。
import grails.util.*
import org.codehaus.groovy.grails.commons.*
import org.springframework.mail.*
class MorphPluginGrailsPlugin {
    def version = 0.1
    def dependsOn = [:]
    def author = "genzou"
    def authorEmail = "genzouw@gmail.com"
    def title = "Plugin summary/headline"
    def description = '''
This plugin help you to develop the application on the morph appspace.
'''
    // URL to the plugin's documentation
    def documentation = "http://code.google.com/p/grails-morph-plugin/"
    def doWithSpring = {
        switch (GrailsUtil.environment) {
            case GrailsApplication.ENV_PRODUCTION:
                mailSession(org.springframework.jndi.JndiObjectFactoryBean)
                        {
                            jndiName = 'java:/comp/env/mail/Session'
                        }
                mailSender(org.springframework.mail.javamail.JavaMailSenderImpl)
                        {
                            session = mailSession
                        }
                break
            default:
                break
        }
    }
    def doWithApplicationContext = { applicationContext ->
        // TODO Implement post initialization spring config (optional)
    }
    def doWithWebDescriptor = { xml ->
        switch (GrailsUtil.environment) {
            case GrailsApplication.ENV_PRODUCTION:
                def servlets = xml.'servlet'
                servlets[servlets.size() - 1] + {
                    "resource-ref" {
                        "description"("Morphlabs Mail Session")
                        "res-ref-name"("mail/Session")
                        "res-type"("javax.mail.Session")
                        "res-auth"("Container")
                    }
                }
                break
            default:
                break
        }
    }
    def doWithDynamicMethods = { ctx ->
        // TODO Implement registering dynamic methods to classes (optional)
    }
    def onChange = { event ->
        // TODO Implement code that is executed when any artefact that this plugin is
        // watching is modified and reloaded. The event contains: event.source,
        // event.application, event.manager, event.ctx, and event.plugin.
    }
    def onConfigChange = { event ->
        // TODO Implement code that is executed when the project configuration changes.
        // The event is the same as for 'onChange'.
    }
}
実行時のパラメータによって、web.xml、springに情報を設定するかしないかを判断しています。
これにより、warファイル作成時にのみ実行されるようになります。
課題
これで、プラグインインストール後に Morph Appspace にサーバーをアップした際にメール送信可能になるはずです。でも、なんど試してもうまくいきません。
warファイル解凍後の web.xml にはメール設定が追記されているようなので、問題はspring管理beanに対する情報追加が失敗しているのかな??
完成はまだまだ先みたいです。
どなたか、一緒に作ってみませんか??
追記 2008-10-15
投稿を若干変更しました。Google Codeプロジェクトに配置し、不具合をいくつか修正しました。
ディスカッション
コメント一覧
Morph開発専用プラグインおもしろそうですね。
時間があれば一緒に作ってみたいです。:)
現在、非公式のMorph Pluginってあるみたいですね。
自分はまだ未検証ですが、情報だけ貼っておきます。
http://code.google.com/p/morphplugin/
http://www.nabble.com/Mor.ph-Plugin–td18067929.html
>yamamotoさん
な、なんと!!!
こんな人が僕の日記に・・・びっくりです。
実際に動いているウェブショップのシステムでもAcegi、使わせてもらっています。
Morphプラグイン、あったら便利ですよね。
教えていただいたプラグイン、検証してみますね。