RTFSC is an unavoidable lesson for programmers on the way to fight monsters and upgrade, so it is necessary to create a comfortable environment to improve the class experience.
For example, reading AOSP such a large Source Code, what posture to use to read can silky smooth, let F** King Source Code also become less hateful?
Tool selection
I have tried the following types of tools to read source code:
-
IDE
This is my first choice when looking at certain types of projects. For example, it was originally a Visual Studio project, that of course to use Visual Studio to open reading, look at Android App or Library source code, of course, with Android Studio experience better.
-
Editor with plug-ins
For example, Vim + Ctags + Cscope, combined with file blur finder LeaderF and YouCompleteMe, it is very convenient when the source code is not large and easy to open, I am still happy to use them when reading some small projects.
-
Specialized source reading tools
In the case of oversized source code, such as AOSP and Chromium, using the above two solutions may feel weak, this time you need to provide a special source reading tool.
One is commercial software, such as the famous Source Insight under Windows, and Understand across platforms, which are both powerful and good choices. Of course they are expensive.
My protagonist here, OpenGrok, falls into the other category. It’s free, open source, runs smoothly, and features just as well.
If you’re still looking for your own solution, take the time to try out all of the above, and use different tools for different projects, as I did. * OpenGrok is often used as a computer system. It is often used as a computer system. It is often used as a computer system.
OpenGrok features
Translated from the official Wiki.
OpenGrok provides the following features:
-
A fast search engine for code
-
Search for full text, definitions, symbols, file paths, and modification history
-
Search any specified subdirectory (hierarchical search)
-
Incrementally update the index file
-
Support for Google-like query syntax such as path:Makefile defs:target
-
Search for files modified within the date range
-
Support wildcard search, such as * for multiple characters,? Represents a single character
-
Display matching rows in the search results
-
-
A version history viewing interface for a Web – only version
-
File modification log
-
Diff of a file between two versions
-
History of folders
-
-
Cross references are displayed with syntax highlighting, and custom styles can be used with CSS
-
Plug-ins can be developed to support new languages and version control systems
Supported Languages and Formats
Supported Revision Control Systems
Configuration OpenGrok
screenshots
It’s customary to post the picture first, in case you realize at first glance that it’s not your type (screenshot from the website).
Search features and source tree:
Code navigation and version history:
Installation and configuration
Take Windows as an example. Mac OS X and Linux are similar. Brew or APT-get is more convenient for many steps.
-
Install the JDK and configure the JAVA_HOME or JRE_HOME environment variable as the installation directory.
-
Download Tomcat, unzip it to a directory such as D:\Programs\apache-tomcat-8.5.8, and add this directory as the CATALINA_HOME environment variable.
-
Download Universal Ctags for Windows and add the directory where the ctags.exe file resides to the PATH environment variable.
-
Download the latest package of OpenGrok, such as Opengrok-0.13-RC4.zip, and unzip it to a directory such as D:\Programs\ opengroK-0.13-RC4.
-
Configure the data root.
The data root is used to place the generated index files and configuration information. For example, I created a data directory under the OpenGrok directory as the data root, which is D:\Programs\ opengrok-0.13-RC4 \data.
-
Decompress source. War in OpenGrok lib directory to D:\Programs\apache-tomcat-8.5.8\webapps\source, Configure the CONFIGURATION of the web-INF \web. XML file to be configureation.xml in the data directory generated in the previous step, such as my CONFIGURATION:
<display-name>OpenGrok</display-name> <description>A wicked fast source browser</description> <context-param> <description>Full path to the configuration file where OpenGrok can read its configuration</description> <param-name>CONFIGURATION</param-name> <param-value>D: / designed/opengrok - 0.13 - rc4 / data/configuration. The XML</param-value> </context-param>Copy the code
-
Configure source root.
You can make OpenGrok think that each subfolder under source root is a project, so you can use this feature to configure and read multiple project sources.
D:\Programs\opengrok-0.13-rc4\projects D:\Programs\opengrok-0.13-rc4\projects D:\Programs\opengrok-0.13-rc4\projects D:\Programs\opengrok-0.13-rc4\projects
cd/d d :\Programs\opengrok-0.13-rc4\projects mklink /J android d :\sources\android_5.1 mklink /J openjdk7 D:\sources\openjdk7Copy the code
So there is a project called Android, which actually corresponds to D:\sources\android_5.1, and a project called openJDk7, which actually corresponds to D:\sources\ openJDk7.
-
Create an index.
Use opengrok.jar to call ctags to index the source code. The command line:
java -jar /path/to/opengrok.jar -P -S -v -s /path/to/source/root -d /path/to/data/root -W /path/to/configuration.xmlCopy the code
-P generates a project for each level 1 subdirectory in the source root directory.
-s searches for and adds “external” source Repositories.
-v Displays the operation progress.
-s specifies the source root.
-d specifies the data root.
-w indicates that the configuration is written to the file.
More configuration options can be viewed using Java -jar /path/to/opengrok.jar.
Like the full command line I used:
Java-jar D:\Programs\opengrok-0.13-rc4\lib\ opengrok.jp-s-v-s D:\Programs\opengrok-0.13-rc4\projects -d D: \ designed \ opengrok - 0.13 - rc4 \ data - W D: \ designed \ opengrok - 0.13 - rc4 \ data \ configuration XMLCopy the code
It’s not nice to type a long command every time you need to create or update an index. Instead, use the Alias command in doskey or Cmder and change the alias to opengrok-index, or save the command as a bat file.
Indexing large source code can take a long time, and it’s time to do something else.
-
Start Tomcat, happily RTFSC.
D: \ designed \ apache tomcat - 8.5.8 \ bin \ catalina bat startCopy the code
Use your favorite browser open http://localhost:8080/source/, and then can play happily with OpenGrok.
When a new project is added, or an existing project has a source update, the previous command is executed again to incrementally update the index.
Configuring multiple projects
I used to agonize over how to configure multiple projects in OpenGrok — I started with the Source root directory of the Android source code, so OpenGrok divided Android into multiple sub-projects, and I couldn’t add any more projects.
It turns out that creating a dedicated source root and soft-linking the various source root directories is the right way to use OpenGrok to create one item for each symbol level subdirectory under the source root.
For Windows, use mklink /J Android D:\sources\android_5.1. For Mac OS X, use ln -s /path/to/source project_name.
For slasher
Used in Vim
Yes, there is also a plugin that supports using OpenGrok in Vim. If you are a Vim fan, you can give it a try.
- asenac/vim-opengrok
- jdevera/vim-opengrok-search
Anyway like me this kind of intelligence quotient is toss about not to move, reassured in the browser to use.
Make notes in the source code
With the Chrome plugin Diigo, you can tag, comment, and more.
Reference: www.zhihu.com/question/33…
The latter
The ancient people have taught us the wisdom that to do a good job, we must first use sharp tools, but we should not indulge in and wander among various sharp tools. We should choose the one that we feel most comfortable with, use it skillfully, and spend less time on it. After all, it is the right way to invest our limited life in the infinite RTFSC, isn’t it?