2013/07/04

startup_redmine_plugin_development.sh

Redmine のプラグインを開発するときに最初に行う作業を自動化するスクリプトを書いた。
自動で行なってくれる作業は
  1. 専用ディレクトリの作成
  2. 最新のRedmineを取得
  3. Redmineをローカルにデプロイ
    1. database.ymlを作成
    2. gemのインストール
    3. トークンの作成
    4. マイグレーションの実行
    5. デフォルトデータのロード(デフォルトは日本語)
  4. プラグインの雛形を生成
  5. gitにて初回コミット
惜しむらくは、バージョンとダウンロードURLは都度メンテナンスしていく必要があることかな。

2013/06/22

Redmine プラグインのテストが実行できるまで

Redmineのプラグインのテストが実行できるまでのメモ。意外と苦労した。

環境はこちら。
  • Ruby 2.0.0-p195(use rbenv)
  • Redmine 2.3.1
  • Mac OS X 10.8.4

まずは、公式を参考に実行。

% bundle exec rake test:engines:all
rake aborted! Don't know how to build task 'test:engines:all' ...

タスクが存在していないみたいなので、テストに関連しそうなタスクの一覧を確認。

% bundle exec rake -T | grep test
rake ci # Run the Continous Integration tests for Redmine rake extract_fixtures # Create YAML test fixtures from data in an existing database. rake redmine:email:test[login] # Send a test email to the user with the provided login name rake redmine:plugins:test # Runs the plugins tests. rake redmine:plugins:test:functionals # Run tests for {:functionals=>"db:test:prepare"} rake redmine:plugins:test:integration # Run tests for {:integration=>"db:test:prepare"} rake redmine:plugins:test:units # Run tests for {:units=>"db:test:prepare"} rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins) rake test:coverage # Measures test coverage rake test:rdm_routing # Run tests for rdm_routing / Run the routing tests rake test:recent # Run tests for {:recent=>"test:prepare"} / Test recent changes rake test:scm # Run unit and functional scm tests rake test:scm:functionals # Run tests for {:functionals=>"db:test:prepare"} / Run the scm functional tests rake test:scm:setup:all # Creates all test repositories rake test:scm:setup:bazaar # Creates a test bazaar repository rake test:scm:setup:create_dir # Creates directory for test repositories rake test:scm:setup:cvs # Creates a test cvs repository rake test:scm:setup:darcs # Creates a test darcs repository rake test:scm:setup:filesystem # Creates a test filesystem repository rake test:scm:setup:git # Creates a test git repository rake test:scm:setup:mercurial # Creates a test mercurial repository rake test:scm:setup:subversion # Creates a test subversion repository rake test:scm:units # Run tests for {:units=>"db:test:prepare"} / Run the scm unit tests rake test:scm:update # Updates installed test repositories rake test:single # Run tests for {:single=>"test:prepare"} rake test:ui # Run tests for {:ui=>"db:test:prepare"} / Run the UI tests with Capybara (PhantomJS listening on port 4444 is required) rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Test changes since last checkin (only Subversion and Git)

どうやら、rake redmine:plugins:test{functionals,integration,units}あたりでテストが出来そう。

% bundle exec rake redmine:plugins:test
rake aborted! undefined method `[]' for nil:NilClass … Tasks: TOP => db:test:load => db:test:purge

RAILS_ENV=test を忘れていた。

% bundle exec rake redmine:plugins:test RAILS_ENV=test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. rake aborted! database configuration does not specify adapter … Tasks: TOP => redmine:plugins:test:units => db:test:prepare => db:abort_if_pending_migrations => environment

テスト用のデータベースの設定がしてない。 config/database.yml を編集して・・・

# config/databse.yml
development:
  adapter: sqlite3
  database: db/redmine.db

# ここから追加
test:
  adapter: sqlite3
  database: db/redmine_test.db

再度実行。

% bundle exec rake redmine:plugins:test RAILS_ENV=test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. You have 221 pending migrations: 1 Setup 2 IssueMove 3 IssueAddNote 4 ExportPdf … Run `rake db:migrate` to update your database then try again.

マイグレーションができていないのね。

% bundle exec rake db:migrate RAILS_ENV=test
== Setup: migrating ========================================================== -- create_table("attachments", {:force=>true}) -> 0.0039s -- create_table("auth_sources", {:force=>true}) -> 0.0011s -- create_table("custom_fields", {:force=>true}) -> 0.0008s -- create_table("custom_fields_projects", {:id=>false, :force=>true}) -> 0.0004s -- create_table("custom_fields_trackers", {:id=>false, :force=>true}) -> 0.0413s -- create_table("custom_values", {:force=>true}) -> 0.0011s -- create_table("documents", {:force=>true}) -> 0.0008s -- add_index("documents", ["project_id"], {:name=>"documents_project_id"}) -> 0.0003s -- create_table("enumerations", {:force=>true}) -> 0.0005s -- create_table("issue_categories", {:force=>true}) -> 0.0005s -- add_index("issue_categories", ["project_id"], {:name=>"issue_categories_project_id"}) -> 0.0002s -- create_table("issue_histories", {:force=>true}) -> 0.0007s -- add_index("issue_histories", ["issue_id"], {:name=>"issue_histories_issue_id"}) -> 0.0002s -- create_table("issue_statuses", {:force=>true}) -> 0.0006s -- create_table("issues", {:force=>true}) -> 0.0011s -- add_index("issues", ["project_id"], {:name=>"issues_project_id"}) -> 0.0002s -- create_table("members", {:force=>true}) -> 0.0006s -- create_table("news", {:force=>true}) -> 0.0007s -- add_index("news", ["project_id"], {:name=>"news_project_id"}) -> 0.0002s -- create_table("permissions", {:force=>true}) -> 0.0007s -- create_table("permissions_roles", {:id=>false, :force=>true}) -> 0.0004s -- add_index("permissions_roles", ["role_id"], {:name=>"permissions_roles_role_id"}) -> 0.0002s -- create_table("projects", {:force=>true}) -> 0.0008s -- create_table("roles", {:force=>true}) -> 0.0004s -- create_table("tokens", {:force=>true}) -> 0.0006s -- create_table("trackers", {:force=>true}) -> 0.0005s -- create_table("users", {:force=>true}) -> 0.0009s -- create_table("versions", {:force=>true}) -> 0.0007s -- add_index("versions", ["project_id"], {:name=>"versions_project_id"}) -> 0.0002s -- create_table("workflows", {:force=>true}) -> 0.0006s == Setup: migrated (0.1067s) ================================================= … == RemoveIssuesDefaultFkValues: migrating ==================================== -- change_column_default(:issues, :tracker_id, nil) -> 0.0257s -- change_column_default(:issues, :project_id, nil) -> 0.0737s -- change_column_default(:issues, :status_id, nil) -> 0.0252s -- change_column_default(:issues, :assigned_to_id, nil) -> 0.0236s -- change_column_default(:issues, :priority_id, nil) -> 0.0245s -- change_column_default(:issues, :author_id, nil) -> 0.0251s == RemoveIssuesDefaultFkValues: migrated (0.1981s) =========================== % bundle exec rake redmine:load_default_data RAILS_ENV=test Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ja ==================================== Default configuration data loaded.

もう一度実行。

% bundle exec rake redmine:plugins:test RAILS_ENV=test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/unit/**/*_test.rb" *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/projects/sample_plugin/redmine-2.3.1/lib/SVG/Graph/Graph.rb:3: warning: class variable access from toplevel Run options: # Running tests: Finished tests in 0.067877s, 132.5928 tests/s, 132.5928 assertions/s. 9 tests, 9 assertions, 0 failures, 0 errors, 0 skips ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0] /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/functional/**/*_test.rb" *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/projects/sample_plugin/redmine-2.3.1/lib/SVG/Graph/Graph.rb:3: warning: class variable access from toplevel Run options: # Running tests: Finished tests in 0.062297s, 16.0521 tests/s, 16.0521 assertions/s. 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0] /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/integration/**/*_test.rb"

成功したみたいなので、失敗させてみる。

# sample_model_test.rb
require File.expand_path('../../test_helper', __FILE__)

class SampleModelTest < ActiveSupport::TestCase

  # Replace this with your real tests.
  def test_truth
    #assert true
    assert false
  end
end
% bundle exec rake redmine:plugins:test:units RAILS_ENV=test
berk redmine:plugins:test:units RAILS_ENV=test (in /Users/pinzolo/projects/sample_plugin/redmine-2.3.1) *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/unit/**/*_test.rb" *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/projects/sample_plugin/redmine-2.3.1/lib/SVG/Graph/Graph.rb:3: warning: class variable access from toplevel Run options: # Running tests: [1/9] SampleModelTest#test_truth = 0.00 s 1) Failure: test_truth(SampleModelTest) [/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/plugins/sample_plugin/test/unit/sample_model_test.rb:8]: Failed assertion, no message given. Finished tests in 0.069086s, 130.2724 tests/s, 130.2724 assertions/s. 9 tests, 9 assertions, 1 failures, 0 errors, 0 skips ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0] rake aborted! Command failed with status (1): [ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/unit/**/*_test.rb" ] … Tasks: TOP => redmine:plugins:test:units

予定通り失敗した。
あとはテストを書いて実行していけばよさそうだ

Ruby2.0.0をインストール

Ruby 2.0 がリリースされてしばらくしたのでそろそろ入れることにした。

% rbenv install 2.0.0-p195
Downloading ruby-2.0.0-p195.tar.gz... -> http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz Installing ruby-2.0.0-p195... BUILD FAILED Inspect or clean up the working tree at /var/folders/1j/hw72brh57jv94vdl9567fr140000gn/T/ruby-build.20130621233411.34289 Results logged to /var/folders/1j/hw72brh57jv94vdl9567fr140000gn/T/ruby-build.20130621233411.34289.log Last 10 log lines: make[2]: *** [readline.o] Error 1 make[1]: *** [ext/readline/all] Error 2 make[1]: *** Waiting for unfinished jobs.... compiling ../.././ext/psych/yaml/reader.c compiling ../.././ext/psych/yaml/scanner.c compiling ../.././ext/psych/yaml/writer.c installing default psych libraries linking shared-object psych.bundle ld: warning: directory not found for option '-L/Users/pinzolo/.rbenv/versions/2.0.0-p195/lib' make: *** [build-ext] Error 2

なんか失敗した。
こちらを参考に再度挑戦。
readline は入っていたので openssl を入れて、`RUBY_CONFIGURE_OPTS`を指定してインストール。

% brew update
% brew install openssl
% brew link openssl --force
% brew install curl-ca-bundle
% brew list curl-ca-bundle
/usr/local/Cellar/curl-ca-bundle/1.87/share/ca-bundle.crt
% cp /usr/local/Cellar/curl-ca-bundle/1.87/share/ca-bundle.crt /usr/local/etc/openssl/cert.pem % RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline` --enable-shared" rbenv install 2.0.0-p195
Downloading ruby-2.0.0-p195.tar.gz... -> http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz Installing ruby-2.0.0-p195... Installed ruby-2.0.0-p195 to /Users/pinzolo/.rbenv/versions/2.0.0-p195

いけたみたいなので確認。

% ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]

bundler は入れておかないと。

% gem install bundler
Fetching: bundler-1.3.5.gem (100%) Successfully installed bundler-1.3.5 1 gem installed

バッチリ!お疲れ様でした。

2013/06/20

Redmine から Google Apps のメールを送信する

一人しか使ってないプライベートの Redmine ですが、メール設定しておくのを忘れていたので、メール設定を行った。
GMail の設定は過去に行ったが Google Apps の設定は初めてなのでメモ。
ちなみに環境は Redmine 2.3.1 on Ruby 1.9.3。

とはいっても、Google Apps のメールとはいってもほぼ GMail と同じ。
$REDMINE_HOME/config/configuration.ymlに下記の設定をするだけ。
変更したのは domain を Google Apps で使用しているドメインに設定した。それだけ。

production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      enable_starttls_auto: true
      address: "smtp.gmail.com"
      port: 587
      domain: "mkt-sys.jp"
      authentication: :login
      user_name: "hogefuga@mkt-sys.jp"
      password: "foobarbaz"

2013/06/08

さくらVPSのRedmineを2.0.0から2.3.1にアップデート

ちょっとこれから Redmine のプラグインでも作りたいなと思い、VPSのRedmineをまず最新にした。
やったことはtail -f pinzo.log: Redmine を 1.4.1 から 2.0.0 にアップデートしたの焼き直し。
あと、「Plugin assetsディレクトリに書き込み可能」にビックリマークが出ていたので、解消しておいた。
$REDMINE_HOME/public/plugin_assetsディレクトリを作成して、www-dataにchownしただけ。

2013/06/06

Kyoto.rbに行ってきた

登録はしたものの、引越しとかなんとかで一度も行っていなかったKyoto.rbに初参加してきた。
とはいえ、途中から参加のため自己紹介して軽く発言した程度。
ていうかスーツが俺だけ!?っていうのが驚いた。

引越しとか関西での仕事探しとかですっかりプライベートでの開発熱が下がっていたけど、久しぶりに技術者の集いに参加できたおかげで少しテンションが上がった。
やっぱりモノ作らんといかんよな。

次回の Kyoto.rb は6/20。また参加します。

2013/01/24

macにtreeコマンドをインストール

ディレクトリ階層を確認するために便利な tree コマンドを Mac で使用したい。
というわけで Homebrew でさくっとインストール。

% brew install tree
==> Downloading http://mama.indstate.edu/users/ice/tree/src/tree-1.6.0.tgz
######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/tree/1.6.0 MANDIR=/usr/local/Cellar/tree/1.6.0/share/man/man1 CC=cc CFLAGS=-fomit-frame-pointer LDFLAGS= OBJS=tree.o unix.o html.o xml.o hash.o color.o strverscmp.o install
/usr/local/Cellar/tree/1.6.0: 7 files, 120K, built in 4 seconds

簡単です。

使用も簡単です。

% tree
.
├── dir1
│   └── file1-1.txt
├── dir2
│   ├── dir3
│   │   └── file3-1.txt
│   ├── file2-1.txt
│   └── file2-2.txt
└── file1.txt

3 directories, 5 files

ディレクトリ指定。

% tree dir2
dir2
├── dir3
│   └── file3-1.txt
├── file2-1.txt
└── file2-2.txt

1 directory, 3 files

ディレクトリ表示のみ。

% tree -d
.
├── dir1
└── dir2
     └── dir3

3 directories

全ファイル表示。

% tree -a
.
├── .dotdir
│   └── .dotfile2
├── .dotfile
├── dir1
│   └── file1-1.txt
├── dir2
│   ├── dir3
│   │   └── file3-1.txt
│   ├── file2-1.txt
│   └── file2-2.txt
└── file1.txt

4 directories, 7 files

2012/12/07

git config --global push.default simple したら neobundle.vim でエラーになった

git push したらwarningがでた

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

そういえば git の push.default を設定していなかったので、simpleに設定しておいた。

git config --global push.default simple

vimを起動したらwarningがでた

This is old version of neocomplcache-snippets-complete.
This is no longer maintained.
You should use neosnippet plugin instead of it.
https://github.com/Shougo/neosnippet

neocomplcache-snippets-complete は古いから neosnippet 使えよということらしい。
.vimrc から

NeoBundle 'Shougo/neocomplcache-snippet-complete'

を削除して

NeoBundle 'Shougo/neosnippet'

に変更して:NeoBundleInstallを実行した。

エラーになった

/Users/pinzolo/.vim/bundle/neosnippet
error: Malformed value for push.default: simple
error: Must be one of nothing, matching, tracking or current.
fatal: bad config file line 22 in /Users/pinzolo/.gitconfig
Cloning into /Users/pinzolo/.vim/bundle/neosnippet...

simple は push.default の値として不正だからnothing, matching, tracking, currentのどれかにしろと。
普通にgit pullするのは問題ないのになぁ。

simple から currentへ

git config --global push.default current

にして、:NeoBundleInstallしたら成功した。
挙動としては simple の方が好きなんだけど、とりあえず current にしておくか。
neobundle側での原因と対策も調べないとな。

2012/12/06

mac(Mountain Lion)にEclipseをインストールした

これまで事情があって Parallels 上の eclipse で開発していたけど、mac にも eclipse を導入しようと思い立ったので作業メモ。

Eclipseのインストール

  1. Eclipse DownloadからEclipse IDE for Java EE Developers」の「Mac OS X 64bit」をダウンロード
  2. ダウンロードしたファイルを解凍する
  3. 解答してできたeclipseフォルダをアプリケーションフォルダに移動

日本語化

  1. Pleiadesから「64bitのStandard Edition」をダウンロード(JavaだけでいいならJavaを、PythonやPHPの環境が欲しければUltimateを)
  2. ダウンロードしたファイルを解凍する
  3. 解凍したpleiades/eclipse/dropins/MergeDoc/Applications/eclipse/dropins内にコピーする
  4. 下記のコマンドを実行して、eclipse.iniに設定を追加する。

     echo "-javaagent:/Applications/eclipse/dropins/MergeDoc/eclipse/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar" >> /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
    
  5. /Application/eclipse/eclipse -cleanを実行してeclipse起動

これで、macで日本語化したeclipseが使えるようになった。

「'fenc' を空にしてください」エラーが出たら

vimを使っていてこんなエラーが出た。

E513: 書き込みエラー, 変換失敗 (上書きするには 'fenc' を空にしてください)

実際:set fenc=して保存したら保存できたけど、sjis だったのが utf8 になって文字化けしてしまった。
原因は×の代わりに☓(機種依存文字)を使っていたからだった。
このエラーが出たときは、機種依存文字や、現在の文字コードにない文字を使用していないかどうか確認しよう。