tezu memo blog

日々行った作業をメモしていきます

WindowsでPhpStormとXdebugを動かす

少しハマったので整理してみました

環境

  • WindowsVista(32bit版)
  • Apache 2.2.11
  • PHP 5.3.25(Thread Safe)
  • PhpStorm 6.0.2


最初からこのサイトを見ていたら、すんなり設定出来たかも知れません
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

f:id:tezu35:20130531140642j:plain


ダウンロードした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を選択し、インストールしたPHPInterpreterを指定
f:id:tezu35:20130531140632j:plain
 
File→Settings→PHP→Debugを選択し、XdebugのDebug portがphp.iniのxdebug.remote_portと一致することを確認後、
画面下部の"Use debugger bookmarklets to initiate debugger from your favorite browser"のリンクを選択
f:id:tezu35:20130531140636j:plain
 
選択後、http://www.jetbrains.com/phpstorm/marklets/に遷移
画面下部のStart debuggerとStop debuggerをブックマーク保存
f:id:tezu35:20130531140639j:plain
 
 

実行

1. Run→Start Listen PHP Debug Connectionsを選択
ToolbarでもOK
f:id:tezu35:20130531141646j:plain
2. ブレイクポイントを設定 
3. (対象画面を表示した状態で)ブックマーク保存したStart debuggerを選択
4. 画面操作
止まった!
f:id:tezu35:20130531142835j:plain

データベースを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

Javadochttp://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

画面
f:id:tezu35:20130305135253j:plain

 

中間の文字を変更

例 SAMPLE02_ct001_01_mlt.jpgをSAMPLE02_BLU_01_mlt.jpgに変更

検索 (.*)ct001(.*)
置換 \1BLU\2

画面
f:id:tezu35:20130305135258j:plain

【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

f:id:tezu35:20130222181109j:plain
 

2. configファイル編集
eclipse 4.2×EGit環境でPush/Pullのハマりどころを回避する | mooappを参考させて頂いた

Window → Open Perspective → Git Repository Exploringを選択
プロジェクトを右クリック → Properties → Openボタンを選択。configファイルが表示される
f:id:tezu35:20130222181243j:plain

[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

f:id:tezu35:20130222181750j:plain


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ボタンを選択
f:id:tezu35:20130222182442j:plain

sourceにmを入力、候補が表示されるのでmaster → Finishボタンを選択
f:id:tezu35:20130222182506j:plain

Save and Fetchを選択
f:id:tezu35:20130222183342j:plain
f:id:tezu35:20130222183408j:plain

 
5. 再再度pull
成功。コンフリクトしてるけど、、
f:id:tezu35:20130222185249j:plain

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
f:id:tezu35:20130219164736p:plain
 

GithubのZIPでインストール → 失敗

grails install-plugin [URL/File]でインストール。エラーが発生

$ grails install-plugin https://github.com/mintsource/grails-platform-ui-scaffolding/archive/master.zip

URLはGithubのZIPボタンから取得
f:id:tezu35:20130219163046p:plain

これでインスト出来たら楽なんですけどね、、

コンソールログ

| 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
f:id:tezu35:20130219143923p:plain

新規作成 create.gsp
f:id:tezu35:20130219143929p:plain

詳細 show.gsp
f:id:tezu35:20130219143936p:plain

編集 edit.gspと編集結果
f:id:tezu35:20130219143945p:plain
f:id:tezu35:20130219143949p:plain

削除結果
f:id:tezu35:20130219143956p:plain

これをベースに一覧画面を検索画面に変更するなどのカスタマイズをすれば楽ですね