Jun 04 2008
OpenGrok: Can You Dig It?
![]()
Raise your hand if you use OpenGrok.
O.K. you folks are free to leave.
Now raise your hand if you’ve ever read Robert A. Heinlein’s Stranger in a Strange Land.
If you haven’t read the book (and why not?) then you probably don’t know that Heinlein coined the phrase “grok” in his 1961 novel. Grok was used to describe the state of fully understanding someone or something. The entry on Wikipedia states that in the book it “literally means “to drink”, and had a much more profound figurative meaning that is hard for Earthlings to understand because of our assumption of a singular reality. . . The water becomes part of the drinker, and the drinker part of the water. Both grok each other.”
Along those lines OpenGrok, from the gang at OpenSolaris, is a source code search utility that aims to help you search and better “grok” your code base in such a way that after having used it for only a few months I ‘ve found it indispensable for code development. The OpenGrok developers have termed it “wicked fast” and they are spot on in their description.
Simply put OpenGrok allows you to quickly and completely search a code base for text phrases or code snippets with such stunning speed that you’ll never use the search command in you IDE, or the more direct “grep” command at the command line, ever again. No, really, I mean it. Alright I know forever is a long time but ya gotta roll with me on this one. Whatta ya say we just install the software? OpenGrok will run pretty much anywhere you can run OpenSolaris but I’ll focus today on getting it working under Windows XP.
Getting and Installing the Software
You’ll want to point your web browser at http://opensolaris.org/os/project/opengrok/ to read about the latest version of OpenGrok (0.61 at this time) and download the binaries for your platform. Unless you are running on Solaris (I wish) you can download the file named “opengrok-0.6.1.tar.gz.”
In addition you’ll need the Exuberant CTAGS binaries located at http://ctags.sourceforge.net/. Ctags, and I quote their website, “generate(s) an index (or tag) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility.” I feel better already don’t you? The version available works not only for Java but also for Assembler, AWK, ASP, BETA, Bourne/Korn/Zsh Shell, C, C++, COBOL, Eiffel, Fortran, Lisp, Lua, Make, Pascal, Perl, PHP, Python, REXX, Ruby, S-Lang, Scheme, Tcl, Vim, and YACC. (What no Qbasic?)
Now that you have both of these binary packages downloaded extract them to the location of your choice. I chose c:\grok as I am a horrible typist. After you are done extracting the archives you should have a directory structure similar to this:

Please note that the “ec57w32″ directory is the one that has the CTAGS binaries in it.
Now open the “opengrok-0.6.1″ folder and edit the “run.bat” file located there. Then comment out the last exec line for the EFTAR tags unless you know that you need them. If you do use EFTAR tags, and you know who you are, send me $35.00 in unmarked bills or I’m goin’ to the cops.
Next you will need to set the SRC_ROOT to whichever code-base you want to search. e.g. “C:\code\myapp.” Then set the DATA_ROOT to where you want the index files to be. For example “C:\grok\GrokData” like in the screen shot above. If you have multiple branches of source code put them in branch specific subdirectories underneath DATA_ROOT. That way later on you can “grok” multiple branches.
Set the path to the EXUB_CTAGS to where you put ctags.exe. Mine is located at “C:\grok\ec57w32\ctags\ctags.exe.” You will also probably want to change the memory setting for grok. I had to add “-Xms100M -Xmx1000M” as arguments to the java calls to increase the allowed memory size (indexing can suck a bit of memory) Others at our place have noticed that you need to put the memory changes on their own line i.e. “java -Xms100m -Xmx100m” to get this to work.
Now you can run the “run.bat” file and start the indexing process. Go get a cup of coffee and a doughnut as this can take a while.
If you do have multiple branches to index you’ll want to create an xml file, something named “configuration_branchName.xml,” uniquely named for each branch, and put the following lines into it. (for java anyway):

Then you’ll need to create another “run.bat” for each branch you want to index and edit it accordingly to point to the location of the files it is supposed to index. For instance I have a “runbranch1.bat” and a “runBranch2.bat” and so on.
Note the “ctags,” “dataRoot,” and “sourceRoot” info will be specific to your setup. For those of you not using Java you’ll have to go to the OpenGrok and CTAGS websites and check the documentation there. Hey! I can’t please everybody!
Finishing Up
That’s pretty much it. You’ll want to place a soft link or shortcut to the OpenGrok jar file (located at C:\Grok\opengrok-0.6.1\opengrok.jar) somewhere that is easy for you to find so you can launch the app without a lot of trouble. You can see a nice picture of how the GUI looks at: http://www.flickr.com/photos/chandanlog/102978562/ or also here: http://www.flickr.com/photos/chandanlog/71852240/.
There are plug-ins available for both Eclipse and Netbeans. I am using the Netbeans plug-in, which is a little annoying to install but it is tons better than the one for Eclipse. (Which is another reason to use Netbeans!) In the Netbeans version the entire OpenGrok gui appears in a window. The Eclipse version is just not as pretty. But then again neither am I and it has never held me back as least as far as I know.
Other Tips
I set my system up to re-index every night at 3:00 a.m., a time when you should all be home and in bed I hasten to add, by setting up a Scheduled task in Windows. You can do this easier with a cron job on a Mac or a *nix/Solaris box.
Issues You Might Encounter
One thing that I have noticed is that the re-indexing will fail if a “write.lock” file remains in the index folder of your “dataRoot” directory listed in your configuration.xml file. If this is the case your indexing will fail. The fix is to just remove this file if it remains behind after a re-index. You’ll then have to re-index to get you code base up to date.
More info on installing OpenGrok. including other means of deploying the software, can be found here: http://opensolaris.org/os/project/opengrok/manual/installdescription/.
Now get back to work!









