基于OpenGrok搭建Android源码搜索网站 - orangetell/Android-aosp-diss GitHub Wiki

环境准备

  1. ubuntu 16.04

  2. 下载android源码(官网教程

  3. 下载OpenGrok opengrok-1.1-rc1

  4. 下载并安装java8 和 tomcat8

部署opengrok

1. 启动tomcat8

/etc/init.d/tomcat8 start

2. 解压下载好的opengrok到 /opt/opengrok 目录下,并创建源码缓存目录

这里我下载了android-5.0.1_r1, android-6.0.1_r46, android-7.1.2_r36, android-8.1.0_r7, android-9.0.0_r9几个分支源码

那么在/var/opengrok下面分别创建相关目录,并且每个目录下面需要创建 data, etc, log, src 四个子目录

3. 修改/opt/opengrok/bin/OpenGrok脚本

在OPENGROK_INSTANCE_BASE后LOGGER_CONFIG_FILE前添加下面代码

OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:/var/opengrok}"

#添加OPENGROK_WEBAPP_NAME变量
OPENGROK_WEBAPP_NAME="${OPENGROK_WEBAPP_NAME:-source}"
#指定android版本的缓存目录,见第二步创建的
TEMP_NAME_XX="android-5.0.0_r1"
echo "params    ${TEMP_NAME_XX}"
if [ ${TEMP_NAME_XX} ]
then
    OPENGROK_INSTANCE_BASE="/var/opengrok/${TEMP_NAME_XX}"
    **OPENGROK_WEBAPP_NAME="${TEMP_NAME_XX}"
fi

LOGGER_CONFIG_FILE="logging.properties"
echo "OPENGROK_INSTANCE_BASE : ${OPENGROK_INSTANCE_BASE}"
echo "OPENGROK_WEBAPP_NAME : ${OPENGROK_WEBAPP_NAME}"

在StdInvocation下添加代码-w "${OPENGROK_WEBAPP_NAME}"

StdInvocation()
{
    CommonInvocation            \
        -W ${XML_CONFIGURATION} \
        ${SCAN_FOR_REPOSITORY}  \
        ${ENABLE_PROJECTS}      \
        ${WEBAPP_CONFIG}        \
        ${WEBAPP_CONTEXT}       \
        -s "${SRC_ROOT}"        \
        -d "${DATA_ROOT}"       \
        -w "${OPENGROK_WEBAPP_NAME}"    \
        "${@}"
}

4. 执行发布和创建索引命令

# 发布
./OpenGrok deploy

# 链接源码(/home/orange/partp/oaosp目录下是我下载的源码)
ln -s /home/orange/partp/oaosp/android-5.0.1_r1 /var/opengrok/android-5.0.1_r1/src

# 执行索引创建(这个过程需要耗点时间)
./OpenGrok index

5. 部署war包

复制 /opt/opengrok/lib/source.war 到 /var/lib/tomcat8/webapps/目录下,并重命名为android-5.0.1_r1.war

6. 重启tomcat8

/etc/init.d/tomcat8 restart

7. 修改部署好的源码配置

在/var/lib/tomcat8/webapps/目录下面会出现一个android-5.0.1_r1目录,修改android-5.0.1_r1/WEB-INF/web.xml中的CONFIGURATION的param-value值为下面android-5.0.1_r1的缓存配置文件地址,如下

 <context-param>
    <description>Full path to the configuration file where OpenGrok can read its configuration</description>
    <param-name>CONFIGURATION</param-name>
    <param-value>/var/opengrok/android-5.0.1_r1/etc/configuration.xml</param-value>
  </context-param>

8. 使用android-6.0.1_r46重复3-7步骤(7.0、8.0、9.0源码同理)

修改3步骤中的TEMP_NAME_XX="android-5.0.1_r1"值为TEMP_NAME_XX="android-6.0.1_r46",并一次操作上面4-7步骤,即可创建android-6.0.1_r46的索引网站。

9. 全部索引创建完成之后,重启tomcat8

在浏览器中打开网址 http://localhost:8080/android-5.0.1_r1 即可浏览5.0.1的的代码,同理 http://localhost:8080/android-6.0.1_r46 等可以浏览6.0、7.0、8.0、9.0的源码

10. 修改index.html

为了方便,我们可以修改/var/lib/tomcat8/webapps/ROOT目录下的index.html文件,修改为如下内容,我们就可以通过 http://localhost:8080 直接浏览各个版本的源码网站了

<!DOCTYPE HTML>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>AndroidXRef</title>
    <!-- you don't need to keep this, but it's cool for stats! -->
    <meta name="generator" content="nanoc 3.4.0">
    <style type="text/css" media="screen">
        * {
        margin: 0;
        padding: 0;
        font-family: 'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace;
        }
        body {
        background: #fff;
        }
        a {
        text-decoration: none;
        }
        a:link,
        a:visited {
        color: #147;
        }
        a:hover {
        color: #ac4;
        }
        #notice {
        position: relative;
        height: 110px;
        }
        #notice_box {
        position: absolute;
        top: 10px;
        left: 20px;
        width: 1020px;
        height: 100px;
        background: #eca;
        }
        #notice_text {
        position: absolute;
        top: 10px;
        left: 20px;
        width: 1020px;
        }
        #notice p {
        font-size: 14px;
        font-weight: normal;
        margin: 12px;
        margin-top: 12px;
        font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
        }
        #web_body {
        position: relative;
        }
        #header {
        position: absolute;
        top: 0px;
        left: 380px;
        margin-top: 10px;
        padding: 10px 10px 0 0;
        width: 500px;
        }
        #split {
        position: absolute;
        top: 70px;
        height:4px;
        width:1020px;
        margin-left:20px;
        margin-right:20px;
        background: #ac4;
        }
        #split_bottom {
        position: absolute;
        top: 770px;
        height:4px;
        width:1020px;
        margin-left:20px;
        margin-right:20px;
        background: #ac4;
        }
        #main {
        position: absolute;
        top: 100px;
        left: 280px;
        width: 500px;
        }
        #main h1 {
        font-size: 40px;
        font-weight: normal;
        line-height: 40px;
        letter-spacing: -1px;
        }
        #main p {
        margin: 20px 0;
        font-size: 15px;
        line-height: 20px;
        }
        #main ul, #main ol {
        margin: 20px;
        }
        #main li {
        font-size: 15px;
        line-height: 20px;
        }
        #main ul li {
        list-style-type: square;
        }
        #sidebar_left {
        position: absolute;
        top: 100px;
        left: 20px;
        width: 200px;
        padding: 20px 20px 0 0;
        text-align: right;
        }
        #sidebar_left h2 {
        text-transform: uppercase;
        font-size: 13px;
        color: #333;
        letter-spacing: 1px;
        line-height: 20px;
        }
        #sidebar_left ul {
        list-style-type: none;
        margin: 20px 0;
        }
        #sidebar_left li {
        font-size: 14px;
        line-height: 20px;
        }
        #index_box {
        position: absolute;
        top: 100px;
        left: 20px;
        width: 220px;
        height: 660px;
        background: #eee;
        }
        #kernel_box {
        position: absolute;
        top: 100px;
        left: 800px;
        width: 170px;
        height: 210px;
        background: #eee;
        }
        #sidebar_right {
        position: absolute;
        top: 100px;
        left: 820px;
        width: 200px;
        padding: 20px 20px 0 0;
        text-align: left;
        }
        #sidebar_right h2 {
        text-transform: uppercase;
        font-size: 13px;
        color: #333;
        letter-spacing: 1px;
        line-height: 20px;
        }
        #sidebar_right ul {
        list-style-type: none;
        margin: 20px 0;
        }
        #sidebar_right li {
        font-size: 14px;
        line-height: 20px;
        }
        #donate_box {
        position: absolute;
        top: 780px;
        left: 20px;
        width: 1020px;
        height: 30px;
        background: #eee;
        }
        #bitcoin_logo {
        position: absolute;
        top: 740px;
        left: 30px;
        width:64px;
        height:32px;
        }
        #bitcoin_addr {
        font-size: 11px;
        font-family: 'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace;
        color: #333;
        letter-spacing: 1px;
        line-height: 20px;
        }
        #ethereum_logo {
        position: absolute;
        top: 780px;
        left: 30px;
        width:30px;
        height:30px;
        }
        #ethereum_addr {
        font-size: 11px;
        font-family: 'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace;
        color: #333;
        letter-spacing: 1px;
        line-height: 20px;
        }
        #bottom_bar {
        position: absolute;
        top: 788px;
        left: 60px;
        width: 1020px;
        height: 40px;
        }
        #donate {
        position: absolute;
        top: 782px;
        left: 850px;
        width: 1020px;
        height: 40px;
        }
        </style>
</head>

<body>
    <div id="web_body">
        <div id="header">
            <h2>Android XRef</h2>
        </div>
        <div id="split"></div>
        <div id="split_bottom"></div>
        <div id="index_box"></div>
        <div id="main">
            <h2 id="news">News</h2>
            <hr />
            <ul>
                <li><b>2018-08-11</b> - New Index: <a href="http://localhost:8080/android-9.0.0_r9/">Pie - 9.0.0_r9</a></li>
                <li><b>2018-06-19</b> - New Index: <a href="http://localhost:8080/android-8.1.0_r7">Oreo - 8.1.0_r7</a></li>
                <li><b>2016-12-22</b> - New Index: <a href="http://localhost:8080/android-7.1.2_r36">Nougat - a712_r36</a></li>
                <li><b>2016-01-08</b> - New Index: <a href="http://localhost:8080/android-6.0.1_r46">Marshmallow - 6.0.1_r46</a></li>
                <li><b>2014-09-06</b> - New Index: <a href="http://localhost:8080/android-5.0.1_r1/">Lollipop - 5.0.1_r1</a></li>
            </ul>
        </div>
        <div id="sidebar_left">
            <h2>Android Source</h2>
            <ul>
                <li><a href="http://localhost:8080/android-9.0.0_r9/">Pie - 9.0.0_r9</a></li>
                <li><a href="http://localhost:8080/android-8.1.0_r7">Oreo - 8.1.0_r7</a></li>
                <li><a href="http://localhost:8080/android-7.1.2_r36">Nougat - a712_r36</a></li>
                <li><a href="http://localhost:8080/android-6.0.1_r46">Marshmallow - 6.0.1_r46</a></li>
                <li><a href="http://localhost:8080/android-5.0.1_r1/">Lollipop - 5.0.1_r1</a></li>
            </ul>
        </div>
    </div>
</body>

</html>
⚠️ **GitHub.com Fallback** ⚠️