Browsing Source Code with OpenGrok

“A wicked fast source browser”

{OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It can understand various program file formats and version control histories like Mercurial, Git, SCCS, RCS, CVS, Subversion, Teamware, ClearCase, Perforce, Monotone and Bazaar. In other words it lets you grok (profoundly understand) source code and is developed in the open, hence the name OpenGrok. It is written in Java. OpenGrok is an open source project and is distributed under CDDL. OpenGrok uses software libraries from Apache Software Foundation.

Steps to get OpenGrok on Ubuntu and Browsing your source code

1. Install Java and TomCat 7

  • $sudo apt-get install default-jdk tomcat7

In case old version of tomcat is installed, check and uninstall before installing Tomcat 7

  • $dpkg --get-selections | grep tomcat
  • $sudo apt-get purge tomcat*

2. Check the details about tomcat

  • $cd /usr/share/tomcat7/bin/
  • $./catalina.sh

Output

    Using CATALINA_BASE: /usr/share/tomcat7
    Using CATALINA_HOME: /usr/share/tomcat7
    Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
    Using JRE_HOME: /usr
    Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar

3. Adding export vars
Edit your ~/.bashrc and include using the directory pointed by CATALINA_BASE include the following vars:
export CATALINA_HOME=/usr/share/tomcat7/
export OPENGROK_TOMCAT_BASE=$CATALINA_HOME

4. Run the tomcat and check if it is working:

  • $sudo /etc/init.d/tomcat7

Done!!! installed!!!! Check if it is running now!!! Using your favorite browser type in the web address: http://localhost:8080/
If ok you should see a web page with message “It works!”

    5. Install C tags

    • sudo apt-get install exuberant-ctags

    6. Installing OpenGrok

    • Download opengrok-0.11.1.tar.gz from java.net/projects
    • unpack into /tools
      $sudo mkdir /tools
      $sudo cd /tools
      $sudo tar –xvzf ~/opengrok-0.11.1.tar.gz
      $sudo chmod 777 –Rv /tools
    • Creating OpenGrok working directories
      $sudo mkdir -p /var/opengrok/src
      $sudo mkdir -p /var/opengrok/data
      $sudo mkdir -p /var/opengrok/etc
      $sudo chmod 777 –Rv /var
    • Deploying Opengrok
      /tools/opengrok-0.11.1/bin$sudo ./OpenGrok deploy
      Alternatively, copy OpenGrok all into Tomcat’s webapp folder
      $sudo cp /tools/opengrok-0.11.1/lib/source.war /var/lib/tomcat7/webapps
    • Checking OpenGrok – Visit http://localhost:8080/source/

    7. Specifying Source folder

    • $sudo cd /var/opengrok/src
    • $sudo ln -s /home/<username>/src_base/ src_base

    8. Indexing your source code

    • $sudo /tools/opengrok-0.11.1/bin/OpenGrok index
      Alternatively, You can invoke with path containing your source code.
    • $sudo /tools/opengrok-0.11.1/bin/OpenGrok index /home/<username>/src_base/

    9. Visit http://localhost:8080/source/ and start browsing your code!!

    Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s