user icon

OpenGrokをCentOS5にインストール

MOONGIFTさん経由で知ったのですが、OpenGrokはSCM(Subversion、Git、Mercurial等)上のソースコードを関数名、変数名その他で検索できるエンジンで、CDDLでオープンソースとして公開されています。この検索エンジンを使用する状況としては、「この関数ってどんな使い方?」、「某言語の某関数にバグがあるみたいなんだけど、うちのコードで使ってなかった?」といった時が考えられます。便利そうでしたのでCentOS5にインストールしてみました。

OpenGrokの動作に必要なctags、tomcat等をインストール

yum install ctags tomcat5 tomcat5-webapps
chkconfig tomcat5 on

OpenGrok用ディレクトリを作成

mkdir /var/opengrok/
mkdir /var/opengrok/bin
mkdir /var/opengrok/src #ここに解析対象のソースを置くことに
mkdir /var/opengrok/data
mkdir /var/opengrok/etc

OpenGrokをダウンロード・展開

mkdir work
cd work
wget
tar xzvf opengrok-0.9-rc1.tar.gz
mv opengrok-0.9-rc1/* /var/opengrok/

source.warを一度展開し、web.xmlを編集する

mkdir source
cd source
unzip /var/opengrok/lib/source.war
vi WEB-INF/web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#下記を追加
<web-app>
  ...
  <context-param>
    <param-name>DATA_ROOT</param-name>
    <param-value>/var/opengrok/data</param-value>
    <description>REQUIRED: Full path of the directory where data files generated by OpenGrok are stored</description>
  </context-param>
 
  <context-param>
    <param-name>SRC_ROOT</param-name>
    <param-value>/var/opengrok/src</param-value>
    <description>REQUIRED: Full path to source tree</description>
  </context-param>
 
  <context-param>
    <param-name>SCAN_REPOS</param-name>
    <param-value>false</param-value>
    <description>Set this variable to true if you would like the web application to scan for external repositories (Mercurial)</description>
   </context-param>
   ...
</web-app>
zip -r source.war ./
mv source.war /var/opengrok/lib/
cp /var/opengrok/lib/source.war /var/lib/tomcat5/webapps/

何かソースを取得しておく

cd /var/opengrok/src
svn co file:///home/svn/project #何かチェックアウトしてみる

インデックス作成用スクリプトの編集

vi /var/opengrok/doc/run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
 
#変更
PROGDIR=/var/opengrok
 
# REQUIRED The root of your source tree
#変更
SRC_ROOT=${PROGDIR}/src
 
# REQUIRED  The directory where the data files like
# Lucene index and hypertext cross-references are stored
#変更
DATA_ROOT=${PROGDIR}/data
 
# OPTIONAL A tab separated files that contains small
# descriptions for paths in the source tree
PATH_DESC=${PROGDIR}/doc/paths.tsv
 
# A modern Exubrant Ctags program
# from http://ctags.sf.net
#変更
EXUB_CTAGS=/usr/bin/ctags
 
# If you need to set properties (Ex. override the mercurial binary)
#PROPERTIES=-Dorg.opensolaris.opengrok.history.Mercurial=/home/trond/bin/hg
 
# Uncomment the following line if your source contains Mercurial repositories.
# SCAN_FOR_REPOS="-S"
 
# You might want to add more available memory, and perhaps use a server jvm?
#JAVA_OPTS="-server -Xmx1024m"
 
LOGGER="-Djava.util.logging.config.file=logging.properties"
 
#変更
java ${JAVA_OPTS} ${PROPERTIES} ${LOGGER} -jar ${PROGDIR}/lib/opengrok.jar ${SCAN_FOR_REPOS} -c ${EXUB_CTAGS} -W ${PROGDIR}/etc/configuration.xml -P -S -v -s ${SRC_ROOT} -d ${DATA_ROOT}
 
# OPTIONAL
java ${LOGGER} -classpath ${PROGDIR}/lib/opengrok.jar org.opensolaris.opengrok.web.EftarFile ${PATH_DESC} ${DATA_ROOT}/index/dtags.eftar
chmod +x /var/opengrok/doc/run.sh

インデックス作成スクリプトの実行

/var/opengrok/doc/run.sh #このスクリプトをcron等で定期実行する

Tomcatの起動

/etc/rc.d/init.d/tomcat5 start

http://hostname:8080/source/ にアクセスし確認

Popularity: 33% [?]

タグ: ,

名前
E-mail
URL
コメント