WindowsでPhpStormとXdebugを動かす
少しハマったので整理してみました
環境
最初からこのサイトを見ていたら、すんなり設定出来たかも知れません
Zero-configuration Web Application Debugging with Xdebug and PhpStorm - PhpStorm - Confluence
Apache - PHP連携は省略します、、、
Xdebug
http://xdebug.org/download.php
Vista32bit版&PHP 5.3.25(Thread Safe)を使用しているので、PHP 5.3 VC9 TS (32 bit)を選択
http://www.xdebug.org/files/php_xdebug-2.2.3-5.3-vc9.dll
ダウンロードしたdllをPHPのインストールdir(%PHP_HOME%)のextに移動
C:\Program Files\PHP\ext>ls php_xdebug-2.2.3-5.3-vc9.dll php_xdebug-2.2.3-5.3-vc9.dll
php.ini
設定
以下を追加
xdebug.profiler_output_dirは存在dirであれば何処でも
[xdebug]
zend_extension="C:\Program Files\PHP\ext\php_xdebug-2.2.3-5.3-vc9.dll"
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=1
xdebug.profiler_output_dir=C:\tmp\xdebug
確認
phpinfo();でも出来ますが、コマンドでもいけます
>php -v PHP 5.3.25 (cli) (built: May 8 2013 19:16:49) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
PhpStorm
File→Settings→PHPを選択し、インストールしたPHPをInterpreterを指定
File→Settings→PHP→Debugを選択し、XdebugのDebug portがphp.iniのxdebug.remote_portと一致することを確認後、
画面下部の"Use debugger bookmarklets to initiate debugger from your favorite browser"のリンクを選択
選択後、http://www.jetbrains.com/phpstorm/marklets/に遷移
画面下部のStart debuggerとStop debuggerをブックマーク保存
実行
1. Run→Start Listen PHP Debug Connectionsを選択
ToolbarでもOK
2. ブレイクポイントを設定
3. (対象画面を表示した状態で)ブックマーク保存したStart debuggerを選択
4. 画面操作
止まった!
データベースをDiffするツール liquibase
設計書の突き合せが面倒なので探していたら良いツールがありました
Liquibase | Database Refactoring | Liquibase
ダウンロード
現時点の最新2.0.5を取得
http://github.com/downloads/liquibase/liquibase/liquibase-2.0.5-bin.zip
今回はAntを使って実行しています
こちらからDL出来ます → Apache Ant - Binary Distributions
インストール
%ANT_HOME%\lib下にliquibase.jarとJDBCドライバをコピー(PostgreSQLを使ってます)
$ ls -l -rwx------+ 1 Administrators mkpasswd 920 Apr 3 13:59 build.xml -rwx------+ 1 Administrators mkpasswd 926426 May 2 2012 liquibase.jar -rwx------+ 1 Administrators mkpasswd 579785 Apr 2 10:16 postgresql-9.2-1002.jdbc4.jar
パラメータ(build.xml)
こんな感じです
property要素のvalue属性でDatabaseを指定しています
<?xml version="1.0" encoding="UTF-8"?> <project name="database-diff" default="default" basedir="."> <!-- ver3.3.0とver3.3.2の比較 --> <property name="url"value="jdbc:postgresql://localhost:5434/ver332"/> <property name="referenceeUrl" value="jdbc:postgresql://localhost:5434/ver330"/> <echo message="url is ${url}"/> <echo message="referenceeUrl is ${referenceeUrl}"/> <path id="classpath"> <fileset dir="." includes="*.jar"/> </path> <target name="default"> <taskdef resource="liquibasetasks.properties"> <classpath refid="classpath"/> </taskdef> <diffDatabase driver="org.postgresql.Driver" url="${url}" username="postgres" password="postgres" referenceUrl="${referenceeUrl}" referenceUsername="postgres" referencePassword="postgres" outputFile="outputfile.txt" classpathref="classpath"> </diffDatabase> </target> </project>
実行
build.xmlで指定したoutputfile.txtが作成されてます
$ ant Buildfile: build.xml [echo] url is jdbc:postgresql://localhost:5434/ver332 [echo] referenceeUrl is jdbc:postgresql://localhost:5434/ver314 default: BUILD SUCCESSFUL $ ls -l outputfile.txt -rwx------+ 1 Administrators mkpasswd 29746 4月 4 17:34 outputfile.txt Total time: 20 seconds
結果
Reference Database: postgres @ jdbc:postgresql://localhost:5434/ver314 Target Database: postgres @ jdbc:postgresql://localhost:5434/ver332 Product Name: EQUAL Product Version: EQUAL Missing Tables: AAAAATbl BBBBBTbl CCCCCTbl Unexpected Tables: DDDDDTbl EEEEETbl FFFFFTbl Missing Views: NONE Unexpected Views: NONE Changed Views: NONE Missing Columns: ZZZZZTbl.name ZZZZZTbl.tel Unexpected Columns: YYYYYTbl.zipcode YYYYYTbl.address
おまけ
上記build.xmlは修正済みですが、マニュアル(http://www.liquibase.org/ja/manual/diffdatabase_ant_task)通りに作成するとエラーが発生します
$ ant BUILD FAILED build.xml:27: diffDatabase doesn't support the "baseUrl" attribute
Javadoc(http://www.jarvana.com/jarvana/view/org/liquibase/liquibase-core/2.0-rc5/liquibase-core-2.0-rc5-javadoc.jar!/index.html?liquibase/integration/ant/DiffDatabaseTask.html)を確認したところ、プロパティの名称がbaseXXXからreferenceXXXに変更されてますね、、
Antのマニュアルの修正が漏れているみたいです
Flexible Renamer ファイル名変更 正規表現で
ググっても期待する結果がヒットしなかったので
先頭の文字を変更
例)CT001_00_mlt.jpgをSAMPLE01_00_mlt.jpgに変更
検索 CT001(.*) 置換 SAMPLE02\1
画面
中間の文字を変更
例 SAMPLE02_ct001_01_mlt.jpgをSAMPLE02_BLU_01_mlt.jpgに変更
検索 (.*)ct001(.*) 置換 \1BLU\2
画面
【Groovy/Grails Tool Suite and Git】git pullでエラー
別環境でpushしたソースを始めてpullした際にエラーが発生したのでメモ
git勉強しないとダメだなあ
1. pull。エラー発生
The current branch is not configured for pull No value for key branch.master.merge found in configuration
2. configファイル編集
eclipse 4.2×EGit環境でPush/Pullのハマりどころを回避する | mooappを参考させて頂いた
Window → Open Perspective → Git Repository Exploringを選択
プロジェクトを右クリック → Properties → Openボタンを選択。configファイルが表示される
[core] repositoryformatversion = 0 filemode = false logallrefupdates = true # 以下を追加 [branch "master"] remote = origin merge = refs/heads/master rebase = true
3. 再度pull。またもやエラー
The current branch is not configured for pull No value for key remote.origin.url found in configuration
4. 再度configファイル編集
電脳世界にダイブイン!: GitHub with Eclipseを参考させて頂いた
[core] repositoryformatversion = 0 filemode = false logallrefupdates = true [branch "master"] remote = origin merge = refs/heads/master rebase = true # 以下を追加 [remote "origin"] url = https://github.com/tezu35/grails-ec-admin.git
これでConfigure Fetch from Upstreamメニューが活性状態となる
プロジェクトを右クリック → Team → Remote → Configure Fetch from Upstream → Addボタンを選択
sourceにmを入力、候補が表示されるのでmaster → Finishボタンを選択
Save and Fetchを選択
5. 再再度pull
成功。コンフリクトしてるけど、、
grails-platform-ui-scaffolding Install package-pluginコマンドでzip作成する必要有
mintsource/grails-platform-ui-scaffolding · GitHub
scaffoldで生成するGSPファイルをGrails Plugin: Plugin Platform UI仕様にするプラグイン
platform-uiのタグに変更するの面倒なので助かる
grails install-plugin [name] [version] でインストール不可
Grails central repositoryに登録されてないので、grails install-plugin [name] [version] の指定ではインストール出来ない
http://grails.org/plugins/search?q=grails-platform-ui-scaffolding
GithubのZIPでインストール → 失敗
grails install-plugin [URL/File]でインストール。エラーが発生
$ grails install-plugin https://github.com/mintsource/grails-platform-ui-scaffolding/archive/master.zip
URLはGithubのZIPボタンから取得
これでインスト出来たら楽なんですけどね、、
コンソールログ
| Loading Grails 2.1.1 | Configuring classpath. | Environment set to development..... | Downloading zip https://github.com/mintsource/grails-platform-ui-scaffolding/archive/master.zip. Please wait... | Downloading zip https://github.com/mintsource/grails-platform-ui-scaffolding/archive/master.zip. Please wait.... | Error Zip /var/folders/k6/ntjhf80x3qd5whnvpntvfbzw0000gn/T/master.6589727975340207458.zip is not a valid plugin
ソースコピーでインストール → 失敗
マニュアルを見る限り、ソースコピーでもよさそう
scripts/InstallTemplatesPlatformUIScaffolding.groovyも含めてコピー
Now either:
Manually copy the files from the plugin's /src/templates/scaffolding folder to the root project /src/templates/scaffolding
Or install the grails-platform-ui-scaffolding plugin by referring it via a number of methods described here: http://grails.org/doc/latest/ref/Command%20Line/install-plugin.html
一応、インストールは終わったのでマニュアル通り、プラグインのテンプレートを自作プロジェクトにコピーするコマンドを実行
ファイルを認識しない?
$ grails install-templates-platform-ui-scaffolding | Loading Grails 2.1.1 | Configuring classpath | Running pre-compiled script | Script 'InstallTemplatesPlatformUiScaffolding' not found, did you mean: 1) InstallTemplatesPlatformUIScaffolding 2) InstallTemplates 3) CreateScaffoldController 4) InstallPlugin 5) UninstallPlugin > Please make a selection or enter Q to quit:
マニュアルのtypo。-ui-ではなく-uI-
原因は違うけど再度エラー発生。ソースコピーのインストールは難しそう
$ grails install-templates-platform-uI-scaffolding | Loading Grails 2.1.1 | Configuring classpath. | Environment set to development.... | Error Error executing script InstallTemplatesPlatformUIScaffolding: java.lang.NullPointerException: Cannot invoke method getURI() on null object (Use --stacktrace to see the full trace)
ソース生成したZIPでインストール → 成功
プラグインのソースからZIPを生成してみる。Grailsのverが2.1.2以外だとエラー
$ pwd /Users/tezu/Documents/workspace-ggts-3.1.0.RELEASE/grails-platform-ui-scaffolding $ grails package-plugin | Application expects grails version [2.1.2], but GRAILS_HOME is version [2.1.1] - use the correct Grails version or run 'grails upgrade' if this Grails version is newer than the version your application expects.
Grails2.1.2をダウンロード&インストール後に再度package-plugin実行。成功!
http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.2.zip
$ grails package-plugin | Compiling 11 source files | Compiling 136 source files | Compiling 4 source files… | Plugin packaged grails-grails-platform-ui-scaffolding-0.1.zip
grails install-plugin [URL/File]でインストール。成功!
$ grails install-plugin /Users/tezu/Documents/workspace-ggts-3.1.0.RELEASE/grails-platform-ui-scaffolding/grails-grails-platform-ui-scaffolding-0.1.zip | Loading Grails 2.1.1 | Configuring classpath. | Environment set to development..... | Installing zip grails-grails-platform-ui-scaffolding-0.1.zip..... | Installed plugin grails-platform-ui-scaffolding-0.1 | Resolving plugin JAR dependencies
テンプレートファイルのコピーも成功。grails-ec-adminがアプリケーション
$ grails install-templates-platform-uI-scaffolding | Loading Grails 2.1.1 | Configuring classpath. | Environment set to development.... sourceDir /Users/tezu/.grails/2.1.1/projects/grails-ec-admin/plugins/grails-platform-ui-scaffolding-0.1/.//src/templates/scaffolding targetDir /Users/tezu/Documents/workspace-ggts-3.1.0.RELEASE/grails-ec-admin/src/templates/scaffolding | Environment set to development..... | Platform-UI Scaffolding templates installed successfully $ pwd /Users/tezu/Documents/workspace-ggts-3.1.0.RELEASE/grails-ec-admin/src/templates/scaffolding $ ls -l total 80 -rw-r--r-- 1 tezu36 staff 4059 2 19 14:11 Controller.groovy -rw-r--r-- 1 tezu36 staff 3952 2 19 14:11 Test.groovy -rw-r--r-- 1 tezu36 staff 2189 2 19 14:11 _form.gsp -rw-r--r-- 1 tezu36 staff 989 2 19 14:11 create.gsp -rw-r--r-- 1 tezu36 staff 1519 2 19 14:11 edit.gsp -rw-r--r-- 1 tezu36 staff 2836 2 19 14:11 list.gsp -rw-r--r-- 1 tezu36 staff 11808 2 19 14:11 renderEditor.template -rw-r--r-- 1 tezu36 staff 3591 2 19 14:11 show.gsp
動作確認
Domainを生成後(Member)にgenerate-allコマンドでGSPとControllerを作成
$ grails generate-all jp.gr.java_conf.tezu.grails.ec.Member2 | Loading Grails 2.1.1 | Configuring classpath. | Environment set to development..... | Packaging Grails application.... | Compiling 1 source files | Compiling 1 source files..... | Packaging Grails application..... | Generating views for domain class jp.gr.java_conf.tezu.grails.ec.Member2 | Generating controller for domain class jp.gr.java_conf.tezu.grails.ec.Member2 | Finished generation for domain class jp.gr.java_conf.tezu.grails.ec.Member2
一覧 list.gsp
新規作成 create.gsp
詳細 show.gsp
編集 edit.gspと編集結果
削除結果
これをベースに一覧画面を検索画面に変更するなどのカスタマイズをすれば楽ですね