1 OpenGrok - a wicked fast source browser 2 --------------------------------------- 3 4 OpenGrok is a fast and usable source code search and cross reference 5 engine, written in Java. It helps you search, cross-reference and navigate 6 your source tree. It can understand various program file formats and 7 version control histories like SCCS, RCS, CVS, Subversion and Mercurial. 8 9 OpenGrok is the tool used for the OpenSolaris Source Browser. 10 11 Requirements 12 ------------ 13 * Latest Java http://java.sun.com/ (At least 1.5) 14 * A servlet container like Tomcat (5.x or later) 15 http://tomcat.apache.org/ 16 supporting Servlet 2.4 and JSP 2.0 17 * Exuberant Ctags http://ctags.sourceforge.net/ 18 * Subversion 1.3.0 or later if SVN support is needed 19 http://subversion.tigris.org/ 20 * Mercurial 0.9.3 or later if Mercurial support is needed 21 http://www.selenic.com/mercurial/wiki/ 22 * JFlex Ant task (If you want to build OpenGrok) 23 http://www.jflex.org/ 24 25 26 Usage 27 ----- 28 SRC_ROOT refers to the directory containing your source tree. 29 OpenGrok analyzes the source tree and builds a search index along with 30 cross-referenced hypertext versions of the source files. These generated 31 data files will be stored in DATA_ROOT directory. 32 33 OpenGrok setup Step.0 - Setting up the Sources. 34 ---------------------------------------------- 35 Source base must be available locally for OpenGrok to work efficiently. No 36 changes are required to your source tree. If the code is under source control 37 management (SCM) OpenGrok requires the checked out source tree under SRC_ROOT. 38 It is possible for some SCM systems to use a remote repository (Subversion), 39 but this is not recommended due to the performance penalty. CVS must have a 40 local repository. 41 Note that OpenGrok ignores symbolic links. 42 43 --------------------------------------------------- 44 Using command line interface. 45 --------------------------------------------------- 46 47 Step.1 - Populate DATA_ROOT Directory 48 ===================================== 49 Option 1. OpenGrok: There is a sample shell script OpenGrok that is suitable 50 for using in a cronjob to run regularly. Modify the variables in the script 51 to point appropriate directories, or as the code suggests factor your local 52 configuration into a seperate file and simplify future upgrades. 53 54 Option 2. opengrok.jar: You can also directly use the Java application. If 55 the sources are all located in a directory SRC_ROOT and the data and 56 hypertext files generated by OpenGrok are to be stored in DATA_ROOT, run 57 58 $ java -jar opengrok.jar -s SRC_ROOT -d DATA_ROOT 59 60 See opengrok.jar manual below for more details. 61 62 Step.2 - Configure and Deploy source.war Webapp 63 =============================================== 64 To configure the webapp source.war, look into the parameters defined in 65 web.xml of source.war file and change them (see note1) appropriately. 66 67 * HEADER: is the fragment of HTML that will be used to display title or 68 logo of your project 69 * SRC_ROOT: the absolute path name of the root directory of your source tree 70 * DATA_ROOT: absolute path of the directory where OpenGrok data 71 files are stored 72 73 74 Optional Step.3 - Path Descriptions 75 ----------------------------------- 76 OpenGrok uses path descriptions in various places (For eg. while showing 77 directory listings or search results) Example descriptions are in paths.tsv 78 file. You can list descriptions for directories one per line tab separated 79 format path tab description. Refer to example 4 below. 80 81 Note 1 - Changing webapp parameters: web.xml is the deployment descriptor 82 for the web application. It is in a Jar file named source.war, you can 83 change the : 84 85 * Option 1: Unzip the file to TOMCAT/webapps/source/ directory and 86 change the source/WEB-INF/web.xml and other static html files like 87 index.html to customize to your project. 88 89 * Option 2: Extract the web.xml file from source.war file 90 91 $ unzip source.war WEB-INF/web.xml 92 93 edit web.xml and re-package the jar file. 94 95 $ zip -u source.war WEB-INF/web.xml 96 97 Then copy the war files to <i>TOMCAT</i>/webapps directory. 98 99 * Option 3: Edit the Context container element for the webapp 100 101 Copy source.war to TOMCAT/webapps 102 103 When invoking OpenGrok to build the index, use -w <webapp> to set the 104 context. 105 106 After the index is built, there's a couple different ways to set the 107 Context for the servlet container: 108 - Add the Context inside a Host element in TOMCAT/conf/server.xml 109 110 <Context path="/<webapp>" docBase="source.war"> 111 <Parameter name="DATA_ROOT" value="/path/to/data/root" override="false" /> 112 <Parameter name="SRC_ROOT" value="/path/to/src/root" override="false" /> 113 <Parameter name="HEADER" value='...' override="false" /> 114 <Parameter name="SCAN_REPOS" value="false" override="false" /> 115 </Context> 116 117 - Create a Context file for the webapp 118 119 This file will be named `<webapp>.xml'. 120 121 For Tomcat, the file will be located at: 122 `TOMCAT/conf/<engine_name>/<hostname>', where <engine_name> 123 is the Engine that is processing requests and <hostname> is a Host 124 associated with that Engine. By default, this path is 125 'TOMCAT/conf/Catalina/localhost' or 'TOMCAT/conf/Standalone/localhost'. 126 127 This file will contain something like the Context described above. 128 129 Optional Step 4 -- Subversion setup 130 ----------------------------------- 131 Some additional setup is needed if you are using Subversion. OpenGrok uses 132 the Subversion javahl bindings, which must be installed separately. 133 134 svn-javahl.jar must be inserted in OpenGrok's classpath (you may do 135 this by copying the file into the lib-subdirectory in your OpenGrok 136 installation). 137 svn-javahl.jar is also needed by the web application, and you may 138 either copy the jar-file into WEB-INF/lib-directory or insert it into the 139 common directory for all web applications (For Tomcat 5.x, this is 140 `TOMCAT/common/lib/svn-javahl.jar') 141 142 The path to the native library svnjavahl needs to be added to 143 java.library.path for both the OpenGrok application and the OpenGrok 144 web application. 145 146 ex: 147 java -Djava.library.path=/usr/lib/svn -jar opengrok.jar .... 148 or, by using LD_LIBRARY_PATH 149 LD_LIBRARY_PATH=/usr/lib/svn java -jar opengrok.jar ... 150 151 --------------------------------------------------- 152 Using Standalone Swing GUI 153 --------------------------------------------------- 154 opengrok.jar when invoked without any arguments, opens up the GUI search window. 155 The interface is similar to cscope. 156 157 To create an index, first select the browse button for "Search" drop down list. 158 Choose a directory to store the index (DATA_ROOT), and select the source tree 159 (SRC_ROOT). You may have to also select path to ctags in the Advanced Options, 160 if exuberant ctags can not be found in the PATH. 161 162 Clicking "Update" will create or update the search index. 163 164 The index can be searched using the cscope like GUI, which lets you customize 165 your favorite editor to open the matching files. 166 167 --------------------------------------------------- 168 Using Findbugs 169 --------------------------------------------------- 170 If you want to run Findbugs (http://findbugs.sourceforge.net/) on OpenGrok, 171 you have to download Findbugs to your machine, and install it where you have 172 checked out your OpenGrok source code, under the lib/findbugs directory, 173 like this: 174 175 cd opengrok/trunk/lib 176 wget http://..../findbugs-x.y.z.tar.gz 177 gtar -xf findbugs-x.y.z.tar.gz 178 mv findbugs-x.y.z findbugs 179 180 You can now run ant with the findbugs target: 181 182 ant findbugs 183 ... 184 findbugs: 185 [findbugs] Executing findbugs from ant task 186 [findbugs] Running FindBugs... 187 [findbugs] Warnings generated: nnn 188 [findbugs] Output saved to findbugs/findbugs.html 189 190 Now, open findbugs/findbugs.html in a web-browser, and start fixing bugs! 191 192 --------------------------------------------------- 193 Using Emma 194 --------------------------------------------------- 195 If you want to check test coverage on OpenGrok, download Emma from 196 http://emma.sourceforge.net/. Place emma.jar and emma-ant.jar in the 197 opengrok/trunk/lib directory. 198 199 Now you can instrument your classes, and create a jar file: 200 201 ant emma-instrument 202 203 If you are using NetBeans, select File - "opengrok" Properties 204 - libraries - Compile tab. Press the "Add JAR/Folder" and select 205 lib/emma.jar and lib/emma_ant.jar 206 207 If you are not using netbeans, you have to edit the file 208 nbproject/project.properties, and add "lib/emma.jar" and 209 "lib/emma_ant.jar" to the javac.classpath inside it. 210 211 Now you can put the classes into jars and generate distributables: 212 213 ant dist 214 215 The classes inside opengrok.jar should now be instrumented. 216 If you use opengrok.jar for your own set of tests, you need 217 emma.jar in the classpath.If you want to specify where to store 218 the run time analysis, use these properties: 219 220 emma.coverage.out.file=path/coverage.ec 221 emma.coverage.out.merge=true 222 223 The coverage.ec file should be placed in the opengrok/trunk/coverage 224 directory for easy analyzation. 225 226 If you want to test the coverage of the unit tests, you can 227 run the tests: 228 229 ant test (Or Alt+F6 in NetBeans) 230 231 Now you should get some output saying that Emma is placing runtime 232 coverage data into coverage.ec. 233 234 To generate reports, run ant again: 235 236 ant emma-report 237 238 Look at coverage/coverage.txt, coverage/coverage.xml and 239 coverage/coverage.html to see how complete your tests are. 240 241 AUTHORS 242 ------- 243 Chandan B.N, Sun Microsystems. https://blogs.sun.com/chandan 244 Trond Norbye, norbye.org 245 Knut Pape, eBriefkasten.de 246 Martin Englund, Sun Microsystems 247 Knut Anders Hatlen, Sun Microsystems 248