在Ubuntu 12.04.2 LTS上安裝OpenGrok瀏覽Android源碼

http://opengrok.github.io/OpenGrok/

OpenGrok is a fastand usable source code search and cross reference engine. It helps you search,cross-reference and navigate your source tree. It can understand variousprogram file formats and version control histories like Mercurial, Git, SCCS,RCS, CVS, Subversion, Teamware, ClearCase, Perforce, Monotone and Bazaar. Inother words it lets you grok (profoundly understand) source code and isdeveloped in the open, hence the name OpenGrok. It is written in Java.

 

  1. Install ctags

If you cannot run ctags command, install it.

apt-getinstall exuberant-ctags

 

  1. Install Tomcat

sudoapt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin

/etc/init.d/tomcat7 restart

sudo vim /etc/tomcat7/tomcat-users.xml   // add below change password before </tomcat-users>

<role rolename="manager-gui"/>

<role rolename="admin-gui"/>

<user username="admin" password="root123" roles="manager-gui,admin-gui"/>

sudo /etc/init.d/tomcat7 restart

Directories:

/etc/tomcat7 - Global configurations

   /usr/share/tomcat7/ - Program

  /etc/tomcat7/Catalina/localhost/ - local Catalina configures

    /var/lib/tomcat7/ - tomcat home

  /var/lib/tomcat7/webapps - applications

  /var/lib/tomcat7/work - dynamic directory, such as dynamic compiled.jsp

 

 

Another way:

From http://tomcat.apache.org/ download Tomcat binary package. (apache-tomcat-7.0.42.tar.gz)

cd /opt

tar xvzf apache-tomcat-7.0.42.tar.gz

cd apache-tomcat-7.0.42/bin

./startup.sh     (use ./shutdown.sh to stoptomcat)

Visit: http://localhost:8080/

 

  1. Install OpenGrok

From http://opengrok.github.io/OpenGrok/  download binaray file (opengrok-0.11.1.tar.gz).

cd /opt

tarxvzf opengrok-0.11.1.tar.gz

ln -s opengrok-0.11.1   opengrok

copy /opt/opengrok/lib/source.war to  /var/lib/tomcat6/webapps  or /opt/apache-tomcat-7.0.42/webapps/)

Visit http://localhost:8080/source/to confirm OpenGrok is installed OK.

 

  1. Configure OpenGrok

add below line to /etc/profile.d/hansel.sh

exportOPENGROK_INSTANCE_BASE=/opt/opengrok

 

Modify /opt/apache-tomcat-7.0.42/webapps/source/WEB-INF/web.xml, change the path of opengrok.

<context-param> 

  <param-name>CONFIGURATION</param-name> 

   <param-value>/opt/opengrok/etc/configuration.xml</param-value> 

   <description>Full path to theconfiguration file where OpenGrok can read it'sconfiguration</description> 

 </context-param>

 

Setup password for using opengrok web page:

add role name to /etc/tomcat7/tomcat-users.xml

<rolerolename="opengrok"/>

<user username="opengrok" password="1234" roles="opengrok"/>

modify /var/lib/tomcat7/webapps/source/WEB-INF/web.xml, add below tothe bottom before "</web-app>":

  <security-constraint>

    <web-resource-collection>

      <web-resource-name>OpenGrokWeb</web-resource-name>

      <url-pattern>/*</url-pattern>

    </web-resource-collection>

    <auth-constraint>

      <role-name>opengrok</role-name>

    </auth-constraint>

  </security-constraint>

  <login-config>

   <auth-method>BASIC</auth-method>

   <realm-name>OpenGrok</realm-name>

  </login-config>

 

  1. Create Index of source code

cd /opt/opengrok

mkdir data src

cd src

ln -s  <your sourcecode>  <project name>

cd ../bin

OPENGROK_VERBOSE=true  ./OpenGrok index

chown tomcat7:tomcat7 * -R

 

  1. Create symbol link

To avoid OpenGrok complain about not found /var/opengrok/ when doindex using root.

mkdir -p /var/opengrok/etc/

ln -s /opt/opengrok/etc/configuration.xml/var/opengrok/etc/configuration.xml

 

  1. Update index automatically

add execute /opt/opengrok/bin/OpenGrok to system crontab.

sudo vim /etc/cron.daily/opengrok

#!/bin/sh

/opt/opengrok/bin/OpenGrokindex

sudo chmod +x /etc/cron.daily/opengrok


上文轉自:http://blog.csdn.net/hansel/article/details/9798257


修改/opengrok/bin/OpenGrok


vi ./OpenGrok
修改:
103行:將OPENGROK_INSTANCE_BASE改爲你放置opengrok的目錄,例如我的是/opt/opengrok,那麼這裏就是
OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/opt/opengrok}"
126行:SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"將SRC_ROOT改爲你的src路徑,可以是相對路徑或者絕對路徑,因爲我們上面將src目錄創建於opengrok目錄下,也就是OPENGROK_INSTANCE_BASE,所以無須修改。
131行:DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"以及後面的
PATH_DESC="${OPENGROK_INSTANCE_BASE}/etc/paths.tsv"和
XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
無須手動創建,如果不存在,opengrok會自動創建(參見601行CreateRuntimeRequirements函數)
349行: Linux:*)    commandName="ctags" ;;
因爲linux下默認的是ctags,不是ctags-ex~
376行:將你的jvm目錄的路徑添加進去
434行:加入你的tomcat6的webapps目錄,本機是/usr/share/tomcat6/webapps,也可能是/var/lib/tomcat6/webapps,根據tomcat6的具體安裝路徑選擇
修改完成後,根用戶權限執行:
OpenGrok deploy
一般情況下,此時應該不會出錯了,打印指導信息,啓動tomcat6,然後輸入:
http://127.0.0.1:8080/source就可以看到OpenGrok的默認主頁了,如果還是出錯,根據具體說明排查,一般都可以通過vi OpenGrok得到解決

然後將你需要瀏覽的代碼拷貝到Opengrok安裝路徑下的src目錄中,根權限執行:
OpenGrok index
如果代碼不是很多的話,很快就可以索引結束,刷新OpenGrok的默認主頁就可以看到右邊的項目選擇框了。
如果你的代碼是從svn上下載的,或者代碼中有不符合規範的xml文件的話會報錯:
10:09:53 SEVERE: An error occurred while parsing the xml output
org.xml.sax.SAXParseException: XML document structures must start and end within the same entity.
或者:
10:09:53 WARNING: An error occured while creating cache for /var/opengrok/src/vss2 (SubversionRepository)
或者:
11:02:21 WARNING: An error occurred while reading history: 
org.opensolaris.opengrok.history.HistoryException: Failed to get history for: "/var/opengrok/src/vss2/APICommonCode/SDPSourceInfo.cpp" Exit code: 1
忽略即可,不影響使用。
Enjoy !

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章