ページ更新: 2013-03-07 (木) (3614日前)
関連: ソフト/Subversion, Jenkins (2012-09-07 新規作成) OpenGrok は ソースコードを対象とした全文検索エンジンである。 また、バージョン管理システムの情報の一部(変更履歴やannotation) も取り込んで表示することが出来る。 以下の3つで設置してみた。まとめは(まだ)作成していない (2012-09-22)
目次 [編集]情報源 #OpenGrok (ソースコード全文検索エンジン):
Exuberant Ctags (OpenGrokがソースコードを解析する際に必要): JFlex (OpenGrokがソースコードを解析する際に必要):: サーブレットコンテナ/JSPエンジン Winstone (サーブレットコンテナ)+ Jasper (JSPエンジン - Tomcatに同梱) + 足りないライブラリ(Commons Logging):
Tomcat (サーブレットコンテナ/JSPエンジン): GlassFish (サーブレットコンテナ/JSPエンジン):
インストールと設定 #2012-09-12 インデクサがそれなりに動くようになったし、Winstone と GlassFish v3 で動かせた。 いったん、次のように分類しなおして、まとめることにする。
コマンドライン引数 #(2012-09-12) opengrok 0.11.1 C:> java -jar opengrok.jar Usage: opengrok.jar [options] -? Help -A ext:analyzer Files with the named extension should be analyzed with the specified class -a on/off Allow or disallow leading wildcards in a search -B url Base URL of the user Information provider. Default: "http://www.opensolaris.org/viewProfile.jspa?username=" -C Print per project percentage progress information(I/O extensive, since one read through dir structure is made before indexing, needs -v, otherwise it just goes to the log) -c /path/to/ctags Path to Exuberant Ctags from http://ctags.sf.net by default takes the Exuberant Ctags in PATH. -D Store history cache in a database (needs the JDBC driver in the classpath, typically derbyclient.jar or derby.jar) -d /path/to/data/root The directory where OpenGrok stores the generated data -e Economical - consumes less disk space. It does not generate hyper text cross reference files offline, but will do so on demand - which could be sightly slow. -H Generate history cache for all repositories -h /path/to/repository just generate history cache for the specified repos (absolute path from source root) -I pattern Only files matching this pattern will be examined (supports wildcards, example: -I *.java -I *.c) -i pattern Ignore the named files or directories (supports wildcards, example: -i *.so -i *.dll) -j class Name of the JDBC driver class used by the history cache. Can use one of the shorthands "client" (org.apache.derby.jdbc.ClientDriver) or "embedded" (org.apache.derby.jdbc.EmbeddedDriver). Default: "client" -k /path/to/repository Kill the history cache for the given repository and exit. Use '*' to delete the cache for all repositories. -K List all repository pathes and exit. -L path Path to the subdirectory in the web-application containing the requested stylesheet. The following factory-defaults exist: "default", "offwhite" and "polished" -l on/off Turn on/off locking of the Lucene database during index generation -m number The maximum words to index in a file -N /path/to/symlink Allow this symlink to be followed. Option may be repeated. -n Do not generate indexes, but process all other command line options -O on/off Turn on/off the optimization of the index database as part of the indexing step -P Generate a project for each of the top-level directories in source root -p /path/to/default/project This is the path to the project that should be selected by default in the web application(when no other project set either in cookie or in parameter). You should strip off the source root. -Q on/off Turn on/off quick context scan. By default only the first 32k of a file is scanned, and a '[..all..]' link is inserted if the file is bigger. Activating this may slow the server down (Note: this is setting only affects the web application) -q Run as quietly as possible -R /path/to/configuration Read configuration from the specified file -r on/off Turn on/off support for remote SCM systems -S Search for "external" source repositories and add them -s /path/to/source/root The root directory of the source tree -T number The number of threads to use for index generation. By default the number of threads will be set to the number of available CPUs -t number Default tabsize to use (number of spaces per tab character) -U host:port Send the current configuration to the specified address (This is most likely the web-app configured with ConfigAddress) -u url URL to the database that contains the history cache. Default: If -j specifies "embedded", "jdbc:derby:$DATA_ROOT/cachedb;create=true"; otherwise, "jdbc:derby://localhost/cachedb;create=true" -V Print version and quit -v Print progress information as we go along -W /path/to/configuration Write the current configuration to the specified file (so that the web application can use the same configuration -w webapp-context Context of webapp. Default is /source. If you specify a different name, make sure to rename source.war to that name. -X url:suffix URL Suffix for the user Information provider. Default: "" -z number depth of scanning for repositories in directory structure relative to source root[編集] Windows + Winstone #(作業中, 2012-09-08, 2012-09-10, 2012-09-12)
あえてサーブレットコンテナ/JSP にWinstone を使ってみた。 でも Tomcat に含まれる Jasper を使ってるので、Tomcat でいいじゃん、と思ったり。 使用したツール/ライブラリ:
ディレクトリ構成 - opengrok を展開して、ファイルを足す: index_create.cmd (作成 - 後述) index_update.cmd (作成 - 後述) webapp.cmd (作成 - 後述) bin/ ctags.exe (ctags58.zip から) svn.cmd (追加 - 後述) doc/ etc/ (作成) configuration.xml (自動生成) lib/ ant*.jar (Apache Ant 1.8.4 から) commons-logging-*.jar (Commons Logging から) el-api.jar (Tomcat 6 libから) jasper.jar (Tomcat 6 libから) jasper-el.jar (Tomcat 6 libから) jsp-api.jar (Tomcat 6 libから) tomcat-juli.jar (Tomcat 6 binから) JFlex.jar (JFlex から) winstone-0.9.10.jar (Winstone から) man/ data_root/ (作成) src_root/ (作成) webroot/ (opengrok の lib/source.war を展開) WEB-INF/ classes/ (作成: Winstone が警告を出すので) web.xml (configuration.xml のパスを修正) bin/svn.cmd @svn --username USERNAME --password PASSWORD %* index_create.cmd: if exist etc\configuration.xml rmdir /S /Q etc if not exist etc mkdir etc if exist data_root\timestamp rmdir /S /Q data_root if not exist data_root mkdir data_root if not exist src_root mkdir src_root java -jar lib\opengrok.jar ^ -W etc\configuration.xml ^ -c bin\ctags.exe ^ -s src_root ^ -d data_root ^ -H -P -S -r on -T 1 @rem -H Generate history cache for all repositories @rem -P Generate a project for each of the top-level directories in source root @rem -r on/off Turn on/off support for remote SCM systems @rem -S Search for "external" source repositories and add them @rem -T number : The number of threads to use for index generation. By default the number of threads will be set to the number of available CPUs @rem -v Print progress information as we go along index_update.cmd: java -jar lib\opengrok.jar ^ -R etc\configuration.xml ^ -H -P -S -r on -T 1 webroot/WEB-INF/web.xml <web-app> <display-name>OpenGrok</display-name> <description>A wicked fast source browser</description> <context-param> <param-name>CONFIGURATION</param-name> <param-value>/var/opengrok/etc/configuration.xml</param-value> ★この部分を修正 <description>Full path to the configuration file where OpenGrok can read it's configuration</description> </context-param> ... webapp.cmd - 別途、JSPのために環境変数JAVA_HOMEを用意すること。(ex. set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35) rem java -jar lib\winstone-0.9.10.jar ^ rem --javaHome="%JAVA_HOME%" ^ rem --useJasper ^ rem --warfile=lib\source.war java -jar lib\winstone-0.9.10.jar ^ --ajp13Port=-1 ^ --httpPort=10080 ^ --javaHome="%JAVA_HOME%" ^ --useJasper ^ --webroot=webroot 手順 (注意: まだ OpenGrok WebUI の ANNOTATE と HISTORY が動かない):
Windows + GlassFish v3 #(2012-09-12) インデクサは #windows_winstone と同じ。 GlassFish v3 は glassfish-3.1.2.2-web-windows-ml.exe を C:\Java\GlassFish3 に インストールし、 opengrok-0.11.1.tar.gz を展開して lib/source.war を GlassFish の管理画面経由でデプロイして、 C:\java\glassfish3\glassfish\domains\*\applications\source\WEB-INF\web.xml を [#windows_winstone] と同様に書き換えればOK。 管理ポートは 14848 にした (デフォルトは 4848) asadmin の実行例: (注意: 管理ポートを14848にしている場合) C:> c:\java\glassfish3\bin\asadmin.bat --port 14848 list-applications source <web> コマンドlist-applicationsは正常に実行されました。 アプリケーション source の動的再読み込み (OpenGrok でインデックスを更新したときに必要?): echo. > c:\java\glassfish3\glassfish\domains\glassfish3\applications\source\.reload[編集] Ubuntu Server 10.04.4 LTS + Tomcat6 #(作業中, 2012-09-11, 2012-09-12, 2012-09-13) 必要なもの
JavaSE6とAntはインストールしてあるので、他のものを入れる。 補足: 現時点なら、次のようにしてインストールできるはず。動作未確認 (手元のサーバは現時点では sun-java6-* 入れてあるので) $ sudo apt-get install openjdk-6-jdk openjdk-6-jre openjdk-6-jre-headless ant $ sudo apt-get install jflex JFlex はここにインストールされた。 $ dpkg -L jflex | grep jar | xargs ls -l lrwxrwxrwx 1 root root 20 10月 17 2011 /usr/share/ant/lib/jflex.jar -> ../../java/JFlex.jar -rw-r--r-- 1 root root 170448 10月 17 2011 /usr/share/java/JFlex-1.4.3.jar lrwxrwxrwx 1 root root 15 10月 17 2011 /usr/share/java/JFlex.jar -> JFlex-1.4.3.jar (2012-09-13) $ mkdir ~/src/exuberant-ctags-j $ cd ~/src/exuberant-ctags-j/ $ wget http://hp.vector.co.jp/authors/VA025040/ctags/downloads/ctags-5.8j2.tar.gz $ tar zxf ctags-5.8j2.tar.gz $ cd ctags-5.8j2/ $ hg commit -A -m "http://hp.vector.co.jp/authors/VA025040/ctags/downloads/ctags-5.8j2.tar.gz" $ ./configure Exuberant Ctags, version 5.8 ... $ make gcc -I. -I. -DHAVE_CONFIG_H -DKANJI -g -O2 -c args.c ... $ ./ctags --version Exuberant Ctags 5.8J2, Copyright (C) 1996-2009 Darren Hiebert Compiled: Sep 13 2012, 12:42:14 Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net Japanese patch by HIGASHI Hirohito <Twitter: @h_east> http://hp.vector.co.jp/authors/VA025040/ Optional compiled features: +wildcards, +regex, +kanji $ grep ^install Makefile install: install-ctags install-strip: install install-ctags: install-cbin install-cman install-etags: install-ebin install-eman install-bin: install-cbin install-ebin install-lib install-cbin: $(DEST_CTAGS) install-ebin: $(DEST_ETAGS) install-lib: $(DEST_READ_LIB) $(DEST_READ_INC) install-man: install-cman install-eman install-cman: $(DEST_CMAN) install-eman: $(DEST_EMAN) $ sudo aptitude purge exuberant-ctags $ sudo make install cp ctags /usr/local/bin/ctags && chmod 755 /usr/local/bin/ctags ./mkinstalldirs /usr/local/share/man/man1 mkdir /usr/local/share/man/man1 cp ./ctags.1 /usr/local/share/man/man1/ctags.1 && chmod 644 /usr/local/share/man/man1/ctags.1 $ which ctags /usr/local/bin/ctags $ ctags --version Exuberant Ctags 5.8J2, Copyright (C) 1996-2009 Darren Hiebert Compiled: Sep 13 2012, 12:42:14 Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net Japanese patch by HIGASHI Hirohito <Twitter: @h_east> http://hp.vector.co.jp/authors/VA025040/ Optional compiled features: +wildcards, +regex, +kanji $ mkdir -p ~/src/opengrok $ cd ~/src/opengrok $ wget http://hub.opensolaris.org/bin/download/Project+opengrok/files/opengrok-0.11.1.tar.gz $ wget http://hub.opensolaris.org/bin/download/Project+opengrok/files/opengrok-0.11.1-src.tar.gz (念のため) $ tar zxf opengrok-0.11.1.tar.gz $ cd opengrok-0.11.1/ $ hg init $ hg commit -A -m "opengrok-0.11.1.tar.gz" $ ls -F bin/ doc/ lib/ man/ $ ./bin/OpenGrok Usage: OpenGrok <deploy|derby|update|updateQuietly|usage> OpenGrok index [<directory>] Optional environment variables: OPENGROK_CONFIGURATION - location of your configuration e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ./bin/OpenGrok ... See the code for more information on configuration options / variables $ ./bin/OpenGrok usage Loading the default instance configuration ... Options for opengrok.jar: Usage: opengrok.jar [options] -? Help ... $ sudo mkdir /var/opengrok $ sudo mkdir /var/opengrok/src $ cd /var/opengrok/src $ svn co [URL] $ cd .. $ /home/.../src/opengrok/opengrok-0.11.1/bin/OpenGrok index Loading the default instance configuration ... WARNING: OpenGrok generated data path /var/opengrok/data doesn't exist Attempting to create generated data directory ... WARNING: OpenGrok generated etc path /var/opengrok/etc doesn't exist Attempting to create generated etc directory ... Creating default /var/opengrok/logging.properties ... $ ls -F data/ etc/ log/ logging.properties src/ (2012-09-13)
$ sudo cp -a ~/src/opengrok/opengrok-0.11.1 /opt/opengrok $ ls -F /opt/opengrok/ $ sudo chown -R www-data:www-data /var/opengrok/ $ sudo chmod g+w /var/opengrok インデクサを www-data ユーザで実行してみる: $ ls -F /var/opengrok src/ $ sudo -u www-data /opt/opengrok/bin/OpenGrok index Loading the default instance configuration ... WARNING: OpenGrok generated data path /var/opengrok/data doesn't exist Attempting to create generated data directory ... WARNING: OpenGrok generated etc path /var/opengrok/etc doesn't exist Attempting to create generated etc directory ... Creating default /var/opengrok/logging.properties ... $ ls -F /var/opengrok data/ etc/ log/ logging.properties src/ indexer は、デフォルトではCPUコア個数分のスレッドを起動するので、1つにする (-T 1 を指定): /opt/opengrok/bin/OpenGrok への変更点: @@ -718,6 +718,8 @@ StdInvocation() { + THREADS="-T 1" + ${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \ ${LOGGER_PROPERTIES} \ ${JAVA_DEBUG} \ @@ -734,6 +736,7 @@ -W ${XML_CONFIGURATION} \ ${WEBAPP_CONFIG} \ -s ${SRC_ROOT} -d ${DATA_ROOT} \ + ${THREADS} \ "${@}" } $ apt-cache show tomcat6 | grep -i version Version: 6.0.24-2ubuntu1.10 Version: 6.0.24-2ubuntu1 $ sudo apt-get install tomcat6 パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の特別パッケージがインストールされます: authbind libcommons-collections-java libcommons-dbcp-java libcommons-pool-java libecj-java libservlet2.5-java libtomcat6-java tomcat6-common 提案パッケージ: libgeronimo-jta-1.0.1b-spec-java ecj libecj-java-gcj tomcat6-docs tomcat6-admin tomcat6-examples tomcat6-user 以下のパッケージが新たにインストールされます: authbind libcommons-collections-java libcommons-dbcp-java libcommons-pool-java libecj-java libservlet2.5-java libtomcat6-java tomcat6 tomcat6-common アップグレード: 0 個、新規インストール: 9 個、削除: 0 個、保留: 0 個。 5,115kB のアーカイブを取得する必要があります。 この操作後に追加で 8,511kB のディスク容量が消費されます。 続行しますか [Y/n]? ... tomcat6-common (6.0.24-2ubuntu1.10) を設定しています ... tomcat6 (6.0.24-2ubuntu1.10) を設定しています ... システムユーザ `tomcat6' (UID 108) を追加しています... 新しいユーザ `tomcat6' (UID 108) をグループ `tomcat6' に追加しています... ホームディレクトリ `/usr/share/tomcat6' は作成しませんでした. * Starting Tomcat servlet engine tomcat6 [ OK ] authbind (1.2.0build3) を設定しています ... authbind/byuid/108 を追加登録中 cron.daily/tomcat6 を追加登録中 default/tomcat6 を追加登録中 init.d/tomcat6 を追加登録中 rc0.d/K08tomcat6 を追加登録中 rc1.d/K08tomcat6 を追加登録中 rc2.d/S92tomcat6 を追加登録中 rc3.d/S92tomcat6 を追加登録中 rc4.d/S92tomcat6 を追加登録中 rc5.d/S92tomcat6 を追加登録中 rc6.d/K08tomcat6 を追加登録中 tomcat6/Catalina/localhost/ROOT.xml を追加登録中 tomcat6/catalina.properties を追加登録中 tomcat6/context.xml を追加登録中 tomcat6/logging.properties を追加登録中 tomcat6/policy.d/01system.policy を追加登録中 tomcat6/policy.d/02debian.policy を追加登録中 tomcat6/policy.d/03catalina.policy を追加登録中 tomcat6/policy.d/04webapps.policy を追加登録中 tomcat6/policy.d/50local.policy を追加登録中 tomcat6/server.xml を追加登録中 tomcat6/tomcat-users.xml を追加登録中 tomcat6/web.xml を追加登録中 設定ファイルの位置を確認する: $ dpkg -L tomcat6 | grep etc /etc /etc/default /etc/default/tomcat6 /etc/init.d /etc/init.d/tomcat6 /etc/tomcat6 /etc/tomcat6/logging.properties /etc/tomcat6/server.xml /etc/tomcat6/web.xml /etc/tomcat6/catalina.properties /etc/tomcat6/context.xml /etc/tomcat6/Catalina /etc/tomcat6/Catalina/localhost /etc/tomcat6/tomcat-users.xml /etc/tomcat6/policy.d /etc/tomcat6/policy.d/01system.policy /etc/tomcat6/policy.d/02debian.policy /etc/tomcat6/policy.d/03catalina.policy /etc/tomcat6/policy.d/04webapps.policy /etc/tomcat6/policy.d/50local.policy /etc/cron.daily /etc/cron.daily/tomcat6 文書の位置: $ dpkg -L tomcat6 | grep /doc /usr/share/doc /usr/share/doc/tomcat6 /usr/share/doc/tomcat6/copyright /usr/share/doc/tomcat6/changelog.Debian.gz /usr/share/doc/tomcat6/README.Debian.gz $ dpkg -L tomcat6 | grep /var /var /var/log /var/log/tomcat6 /var/cache /var/cache/tomcat6 /var/lib /var/lib/tomcat6 /var/lib/tomcat6/common /var/lib/tomcat6/common/classes /var/lib/tomcat6/server /var/lib/tomcat6/server/classes /var/lib/tomcat6/webapps /var/lib/tomcat6/shared /var/lib/tomcat6/shared/classes /var/lib/tomcat6/work /var/lib/tomcat6/logs /var/lib/tomcat6/conf 設定ファイルの内容を確認する(コメントアウトされている行を除く) $ cat /etc/default/tomcat6 | grep -v ^# | uniq JAVA_OPTS="${JAVA_OPTS} -XX:+UseConcMarkSweepGC" http://ホスト名:8080/ にアクセスし、Tomcat が起動していることを確認する。 管理画面も追加し、設定ファイル /etc/tomcat6/tomcat-users.xml に管理者のアカウントを追加し、Tomcat を再起動する: $ sudo apt-get install tomcat6-admin $ sudo emacs /etc/tomcat6/tomcat-users.xml $ sudo service tomcat6 restart * Stopping Tomcat servlet engine tomcat6 [ OK ] * Starting Tomcat servlet engine tomcat6 [ OK ] http://ホスト名:8080/manager/html にアクセスし、管理者としてログインしてみる。 http://ホスト名:8080/manager/html にアクセスし、「WARファイルの配備」で opengrok の lib/sources.war を指定して配備する。 http://ホスト名:8080/source/ にアクセスして、OpenGrop の画面が表示されて、インデックスを作成したものが表示されればOK。 → UTF-8 で書かれたソースコードが文字化けしていた。ctags日本語対応版 に入れ替えるか、文字コードの指定が必要かも。 Tomcat を Apache の背後に隠して(ProxyPass), 認証を付加する。 方法は ソフト/Continuous Integration/Hudson#mod_proxy + mod_proxy_http でhttpPortで接続する場合 とほぼ同じ。 Tomcat を 127.0.0.1:8080 $ sudo emacs /etc/tomcat6/server.xml /etc/tomcat6/server.xml の変更箇所: @@ -69,6 +69,7 @@ Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector port="8080" protocol="HTTP/1.1" + address="127.0.0.1" connectionTimeout="20000" URIEncoding="UTF-8" redirectPort="8443" /> $ sudo service tomcat6 restart /source → 127.0.0.1:8080 をつなぐ、127.0.0.1 (ホスト内) のアクセスは認証なし、それ以外は Digest認証 を行う (Tracで使ってるアカウントと共用) $ sudo emacs /etc/apache2/sites-available/opengrok /etc/apache2/sites-available/opengrok の内容 (実は Jenkins 用に用意したものをコピーして修正しただけ): BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=On <Location "/source"> AuthType Digest AuthName "development" AuthUserFile "/var/trac/htdigest" Require valid-user Order allow,deny Allow from 127.0.0.1 Satisfy Any ProxyPass http://127.0.0.1:8080/source ProxyPassReverse http://127.0.0.1:8080/source # ProxyPassReverseCookieDomain 127.0.0.1 # ProxyPassReverseCookiePath /source /source <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/css application/javascript application/x-javascript text/x-javascript </IfModule> </Location $ sudo a2ensite opengrok $ sudo service apache2 reload 他のホストから http://ホスト名/source/ にアクセスして、確認すること。 (2012-09-13) Jenkins で実行してみる Jenkins で新規ジョブ opengrok を「フリースタイル」で作成
これで、一回実行して、動作を確認する。 ユーザーanonymousが実行 masterでビルドします。 ワークスペース: /var/opengrok/src Checking out a fresh workspace because /var/opengrok/src/Scratch doesn't exist Cleaning local Directory Scratch Checking out file:///var/svn/sandbox/trunk/Sample A README ... At revision 2907 no revision recorded for file:///var/svn/sandbox/trunk/Sample in the previous build [src] $ /bin/sh -xe /tmp/hudson7806013536709834277.sh + /opt/opengrok/bin/OpenGrok index Loading the default instance configuration ... WARNING: OpenGrok generated data path /var/opengrok/data doesn't exist Attempting to create generated data directory ... WARNING: OpenGrok generated etc path /var/opengrok/etc doesn't exist Attempting to create generated etc directory ... Creating default /var/opengrok/logging.properties ... Finished: SUCCESS[編集] (未着手・調査中) #[編集]multibyte #
ctags へのオプション指定 #(2012-10-02) (職場内SNSでの指摘より) OpenGrok-0.11.1 には無いが、trunk には -o で ctags へのオプションを指定できそうとのこと。 trunk を試すなら、Mercurial でソースコードを入手するのがよさそう [編集]ctags 周りの文字コードの自動判別 #(2012-10-02, 2012-12-09) ソースコードの文字コードが混在している場合に対処するために、文字コードの自動判別(日本語のみ)を行い、 その結果を ctags日本語対応版 の --jcode オプションに渡す wrapper を用意し、OpenGrok の indexer で ctags の代わりに用いるようにしたい。 ためしに、「--jcode=...」オプションを付加する wrapper を、Windows のバッチファイルで作って、「-c ctags_utf8.cmd」で渡してみたけど、途中で止まる。 Sysinternal Process Explorer で見てみたけど、CPUを消費してないので、出力のどこかでブロックしてるようだ。 (失敗) ctags_utf8.cmd - 同じディレクトリ(BASE_DIR)にある ctags.exe に --jcode-utf8 を付けて実行するバッチファイル: @echo off setlocal set BASE_DIR=%~dp0 %BASE_DIR%ctags.exe --jcode=utf8 %* exit /b %ERRORLEVEL% 2012-12-09 文字コードを判別する処理を Python 2.7.x + chardet モジュール で書いてみた: このスクリプトに「ctags を子プロセスとして呼んで、そのときに文字コード名を ctags の文字コード指定オプションに渡す」処理を追加し、このスクリプトを OpenGrok からctagsの代わりに使うようにすれば、インデックスの文字化けは回避できると思う。 [編集]メモ: ctags日本語対応版を自分でビルド #(2012-10-02) ctags 日本語版の文字コードのデフォルト値を変えてみようと思い、 Visual Studio 2008 でビルドしてみた。 (注意: hg は Mercurial なので、無視してよい) http://hp.vector.co.jp/authors/VA025040/ctags/downloads/ec58j2w32.zip をダウンロードして展開し、 次の手順でビルドできた。 C:> hg init C:> hg commit -A -m "ctags58j2" adding COPYING ... C:> "%VS90COMNTOOLS%\vsvars32.bat" Setting environment for using Microsoft Visual Studio 2008 x86 tools. C:> nmake -f mk_mvc.mak Microsoft(R) Program Maintenance Utility Version 9.00.30729.01 Copyright (C) Microsoft Corporation. All rights reserved. echo -DWIN32 -DHAVE_REGCOMP -D__USE_GNU -Dbool=int -Dfalse=0 -Dtrue=1 -D strcasecmp=stricmp -DKANJI > respmvc echo -I. -Ignu_regex >> respmvc echo args.c ant.c asm.c asp.c awk.c basic.c beta.c c.c cobol.c dosbatch.c eiffel.c entry.c erlang.c flex.c fortran.c get.c html.c jscri pt.c keyword.c lisp.c lregex.c lua.c main.c make.c matlab.c ocaml.c opt ions.c parse.c pascal.c perl.c php.c python.c read.c rexx.c routines.c ruby.c scheme.c sh.c slang.c sml.c sort.c sql.c strlist.c tcl.c tex.c verilog.c vhdl.c vim.c yacc.c vstring.c kanji.c >> respmvc echo gnu_regex/regex.c >> respmvc cl /O2 /Fectags.exe @respmvc /link setargv.obj Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. cl -DWIN32 -DHAVE_REGCOMP -D__USE_GNU -Dbool=int -Dfalse=0 -Dtrue=1 -Dstrcasecmp =stricmp -DKANJI -I. -Ignu_regex args.c ant.c asm.c asp.c awk.c basic.c beta.c c.c cobol.c dosbatch.c eiffel.c entry.c erlang.c flex.c fortran.c get.c html.c jscript.c keyword.c lisp.c lrege x.c lua.c main.c make.c matlab.c ocaml.c options.c parse.c pascal.c perl.c php.c python.c read.c rexx.c routines.c ruby.c scheme.c sh.c slang.c sml.c sort.c sql .c strlist.c tcl.c tex.c verilog.c vhdl.c vim.c yacc.c vstring.c kanji.c gnu_regex/regex.c ... (略) 「--jcode」のデフォルト値を変えるには、options.c の以下の部分を修正すればよさそう: optionValues Option = { ...(略) #ifdef KANJI # if defined(WIN32) || defined(MSDOS) || defined(OS2) || defined(__CYGWIN__) || defined(__MACINTOSH__) JCODE_SJIS, /* --jcode */ # else // defined(__linux__) || defined(__APPLE_CC__) JCODE_UTF8, /* --jcode */ # endif #endif ...(略)[編集] メモ: JVM のファイルエンコーディングを変えてみる #(2012-10-03) OpenGrok の これを変更する前に、JVMでエンコーディングを変更できるの、調べてみる。 システムプロパティを全部表示するプログラムを作って、 ファイル ShowSystemProperties.java public final class ShowSystemProperties { public static void main(final String[] args) { final java.util.Properties properties = System.getProperties(); for (final Object key: new java.util.TreeSet<Object>(properties.keySet())) { System.out.println("" + key + "=" + properties.getProperty((String) key)); } } } このプログラムの出力が、-Dfile.encodingの有無で変化するかどうか(プロパティを修正できるか)を確認する。 file.encoding に設定できるエンコーディング名は、以下を参照のこと ためしに、MS932 (Shift_JIS + Microsoft拡張) から、 UTF-8 に切り替えてみる。 実行例 (Windows XP Professional SP2 日本語版, JavaSE 6.0 update 35) → OK。修正できた。 C:> java -showversion ShowSystemProperties | findstr "file.encoding" java version "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10) Java HotSpot(TM) Client VM (build 20.10-b01, mixed mode, sharing) file.encoding=MS932 file.encoding.pkg=sun.io C:> java -Dfile.encoding=UTF-8 ShowSystemProperties | findstr "file.encoding" file.encoding=UTF-8 file.encoding.pkg=sun.io (以下、未確認) OpenGrok の indexer で UTF-8 に固定するなら、 java -Dfile.encodng=UTF-8 -jar lib\opengrok.jar ...(略) どうせなら、indexer を改造して ctags日本語対応版 が出力する 「_TAG_FILE_ENCODING」を indexer が読んで、Java の encoding に変換して、Readerクラスなどの引数に渡せば、 OpenGrok 側では日本語はすべて (Shift-JIS(MS932), EUC-JP, UTF-8) 使えるようになるはず。 あるいは、常にutf-8に変換しつつ処理するindexer, あるいは ctags のwrapper を作った方が楽かな。 |