利用 Topgit 对 Nutch 定制开发进行代码管理(二)

2 篇文章 0 订阅

继 : 利用 Topgit 对 Nutch 定制开发进行代码管理(一)

 

6. 利用 Topgit 对 Nutch 定制开发进行代码管理


了解了 Topgit 的原理和使用方法之后,就可以利用 Topgit 对 Nutch 定制开发进行源代码管理了。

 


6.1 准备版本库


 

● 克隆完整的 Nutch 项目代码


从 github 上克隆完整的 nutch 项目代码:

    
    [devalone@devalone nutch]$ git clone https://github.com/apache/nutch.git

查看版本库配置信息:
    
    [devalone@devalone nutch]$ cat .git/config
    [core]
            repositoryformatversion = 0
            filemode = true
            bare = false
            logallrefupdates = true
    [remote "origin"]
            url = https://github.com/apache/nutch.git
            fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
            remote = origin
            merge = refs/heads/master

定制开发并不向原始的 https://github.com/apache/nutch.git 版本库上提交代码,而是要向一个本地团队开发公用的版本库提交代码,因此修改 "origin" 远程版本库的名称,而将 "origin" 名称留给团队公用版本库使用。将原始版远程本库名称改为 "upstream" 或其它可以表明上游版本库含义的名称:

    [devalone@devalone nutch]$ git remote rename origin upstream


查看分支和远程分支:
    [devalone@devalone nutch]$ git branch
    * master
    [devalone@devalone nutch]$ git branch -r
      upstream/2.1
      upstream/2.x
      upstream/HEAD -> upstream/master
      upstream/NUTCH-2292
      upstream/branch-0.7
      upstream/branch-0.8
      upstream/branch-0.9
      upstream/branch-1.1
      upstream/branch-1.10
      upstream/branch-1.14
      upstream/branch-1.15
      upstream/branch-1.2
      upstream/branch-1.3
      upstream/branch-1.4
      upstream/branch-1.5
      upstream/branch-1.5.1
      upstream/branch-1.6
      upstream/branch-1.7
      upstream/branch-1.8
      upstream/branch-1.9
      upstream/branch-2.2
      upstream/branch-2.2.1
      upstream/branch-2.3
      upstream/branch-2.3.1
      upstream/master
      upstream/nutchbase
      upstream/nutchgora

上游 upstream 远程版本库对定制开发来说,只具有拉取功能,用于更新本地版本库,而不具有推送功能。这对定制开发来说已经足够了,也正是我们所需要的。

 

● 创建 Nutch 2.x 的本地分支
-------------------------------------------------------------------------------------------------------------------------
由于目前 Nutch 在两个代码分支上进行持续开发,分别为 Nutch 1.x 和 Nutch 2.x :

    □ Nutch 1.x :成熟的产品级 web 爬虫,这个分支通过精细的优化配制,充分利用了具有非常强大的批处理能力的Apache Hadoop数据 结构。目前该分支最新版本是 2017 年12月23日发布的 Nutch 1.14,基于 Hadoop 2.7.4 版本开发。
                  
                  通过如下网址访问该版本的发布报告:
                  
                  https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=10680&version=12340218
                        

    □ Nutch 2.x :从 1.x 分离出来的新兴版本,最重要的不同在于:将底层具体的数据存储抽象为存储层,利用 Apache Gora 作为数据中间层来处理对象的持久化映射。这样用户可以实现非常灵活数据模型来存储任何数据到各种类型的 NoSQL 存储方案中, 例如,抓取时间(etch time), 状态(status), 内容(content), 解析的文本(parsed text), 出链(outlinks),入链 ( inlinks) 等等。
                  
                  目前该分支的最新版本是 2016 年1月21日发布的 Nutch 2.3.1。通过如下网址访问该版本的发布报告:

                  https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=10680&version=12329371


克隆下来的 master 分支对应于 Nutch 1.x 分支,而 Nutch 2.x 分支对应于上游版本库 upstream/2.x ,还没有创建对应的本地分支。
如果针对 Nutch 2.x 进行定制开发,则需要手动创建对应的本地分支。方法如下:

    [devalone@devalone nutch]$ git checkout -b nutch-2.x upstream/2.x
    分支 'nutch-2.x' 设置为跟踪来自 'upstream' 的远程分支 '2.x'。
    切换到一个新分支 'nutch-2.x'

新创建的本地分支 'nutch-2.x' 设置为跟踪来自 'upstream' 的远程分支 '2.x'。并且切换到了新分支 'nutch-2.x' 上。显然,当前我们
有了两个分支:

    [devalone@devalone nutch]$ git branch
      master
    * nutch-2.x

查看 git 配置的变化:

    [devalone@devalone nutch]$ cat .git/config
    [core]
            repositoryformatversion = 0
            filemode = true
            bare = false
            logallrefupdates = true
    [remote "upstream"]
            url = https://github.com/apache/nutch.git
            fetch = +refs/heads/*:refs/remotes/upstream/*
    [branch "master"]
            remote = upstream
            merge = refs/heads/master
    [branch "nutch-2.x"]
            remote = upstream
            merge = refs/heads/2.x

        

● 建立定制开发团队公用的开发版本库
-------------------------------------------------------------------------------------------------------------------------
上游版本库准备好了,下一步要建立开发团队内部使用的公用版本库,用于各团队成员向其推送提交,称之为 "团队版本库" 。

建立团队开发版本库的方法很多,最简单的方法就是克隆一个裸版本库到一个团队成员都能访问的公用服务器上。版本库间的通信协议也很多,一般使用 ssh 通信比较方便。这里不再赘述,使用环境内已存在的 gitolite 建立公用版本库,URL 为:

    repo.sansovo.org:scm/vnutch


● 将团队开发版本库添加为远程版本库
-------------------------------------------------------------------------------------------------------------------------
将建立好的团队开发版本库 URL 注册名称为 "origin" 的远程版本库:

    [devalone@devalone nutch]$ cat .git/config
    [core]
            repositoryformatversion = 0
            filemode = true
            bare = false
            logallrefupdates = true
    [remote "upstream"]
            url = https://github.com/apache/nutch.git
            fetch = +refs/heads/*:refs/remotes/upstream/*
    [branch "master"]
            remote = upstream
            merge = refs/heads/master
    [branch "nutch-2.x"]
            remote = upstream
            merge = refs/heads/2.x
    [remote "origin"]
            url = repo.sansovo.org:scm/vnutch
            fetch = +refs/heads/*:refs/remotes/origin/*

 

● 将本地版本库推送到团队版本库
-------------------------------------------------------------------------------------------------------------------------

    [devalone@devalone nutch]$ git branch
    * master
      nutch-2.x

    [devalone@devalone nutch]$ git push origin master
    枚举对象: 46738, 完成.
    对象计数中: 100% (46738/46738), 完成.
    Delta compression using up to 4 threads.
    压缩对象中: 100% (10657/10657), 完成.
    写入对象中: 100% (46738/46738), 127.94 MiB | 375.00 KiB/s, 完成.
    Total 46738 (delta 22886), reused 46735 (delta 22886)
    To repo.sansovo.org:scm/vnutch
     * [new branch]        master -> master

    [devalone@devalone nutch]$ git push origin nutch-2.x
    枚举对象: 10338, 完成.
    对象计数中: 100% (10337/10337), 完成.
    Delta compression using up to 4 threads.
    压缩对象中: 100% (2842/2842), 完成.
    写入对象中: 100% (9880/9880), 1.94 MiB | 42.24 MiB/s, 完成.
    Total 9880 (delta 4685), reused 9197 (delta 4078)
    To repo.sansovo.org:scm/vnutch
     * [new branch]        nutch-2.x -> nutch-2.x

    

6.2 建立 TopGit 特性版本
-------------------------------------------------------------------------------------------------------------------------
准备好版本仓库之后,创建 Nutch 1.x 和 Nutch 2.x 的特性分支。

 

● 创建依赖于 master 的 Nutch 1.x 特性分支 t/vnutch-1.x
-------------------------------------------------------------------------------------------------------------------------
    [devalone@devalone nutch]$ tg create t/vnutch-1.x master
    tg: creating t/vnutch-1.x base from master...
    切换到一个新分支 't/vnutch-1.x'
    [t/vnutch-1.x c95f855a] tg create t/vnutch-1.x
     2 files changed, 5 insertions(+)
     create mode 100644 .topdeps
     create mode 100644 .topmsg
    tg: Topic branch t/vnutch-1.x created.

 

● 创建依赖于 Nutch-2.x 的 Nutch 2.x 特性分支 t/vnutch-2.x
-------------------------------------------------------------------------------------------------------------------------
    [devalone@devalone nutch]$ tg create t/vnutch-2.x nutch-2.x
    tg: creating t/vnutch-2.x base from nutch-2.x...
    切换到一个新分支 't/vnutch-2.x'
    [t/vnutch-2.x b3bd8d1a] tg create t/vnutch-2.x
     2 files changed, 5 insertions(+)
     create mode 100644 .topdeps
     create mode 100644 .topmsg
    tg: Topic branch t/vnutch-2.x created.

 

● 查看特性分支信息
-------------------------------------------------------------------------------------------------------------------------
    [devalone@devalone nutch]$ git branch
      master
      nutch-2.x
      t/vnutch-1.x
    * t/vnutch-2.x

    [devalone@devalone nutch]$ tg info
    Topic Branch: t/vnutch-2.x (1/1 commit)
    Subject: [PATCH] t/vnutch-2.x
    Base: c43c2c85
    Depends: nutch-2.x
    Up-to-date.

    [devalone@devalone nutch]$ tg checkout t/vnutch-1.x
    切换到分支 't/vnutch-1.x'
    [devalone@devalone nutch]$ tg info
    Topic Branch: t/vnutch-1.x (1/1 commit)
    Subject: [PATCH] t/vnutch-1.x
    Base: aaf85cad
    Depends: master
    Up-to-date.

    [devalone@devalone nutch]$ tg summary
    >0       t/vnutch-1.x                   [PATCH] t/vnutch-1.x
     0       t/vnutch-2.x                   [PATCH] t/vnutch-2.x


    
● 设置 TopGit 远程分支信息
-------------------------------------------------------------------------------------------------------------------------
    [devalone@devalone nutch]$ tg remote --populate origin
    tg: Remote origin can now follow TopGit topic branches.
    tg: Populating local topic branches from remote 'origin'...
    tg: The remote 'origin' is now the default source of topic branches.

查看 git 配置信息变化:

    [devalone@devalone nutch]$ cat .git/config
    [core]
            repositoryformatversion = 0
            filemode = true
            bare = false
            logallrefupdates = true
    [remote "upstream"]
            url = https://github.com/apache/nutch.git
            fetch = +refs/heads/*:refs/remotes/upstream/*
    [branch "master"]
            remote = upstream
            merge = refs/heads/master
    [branch "nutch-2.x"]
            remote = upstream
            merge = refs/heads/2.x
    [remote "origin"]
            url = repo.sansovo.org:scm/vnutch
            fetch = +refs/heads/*:refs/remotes/origin/*
            fetch = +refs/top-bases/*:refs/remotes/origin/top-bases/*
    [merge "ours"]
            name = \"always keep ours\" merge driver
            driver = touch %A
    [topgit]
            remote = origin


● 将 TopGit 分支推送到远程版本库
-------------------------------------------------------------------------------------------------------------------------
查看特性分支状态信息:
    
    [devalone@devalone nutch]$ tg summary
    >0l      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
     0l      t/vnutch-2.x                   [PATCH] t/vnutch-2.x


TopGit 特性分支只存在于本地版本库,还没有推送到远程版本库

运行 tg push --all | -a 命令,将所有的 TopGit 分支推送到远程版本库:

    [devalone@devalone nutch]$ tg push --all
    Enumerating objects: 10, done.
    Counting objects: 100% (10/10), done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (6/6), done.
    Writing objects: 100% (8/8), 932 bytes | 932.00 KiB/s, done.
    Total 8 (delta 2), reused 0 (delta 0)
    To repo.sansovo.org:scm/vnutch
     * [new branch]        t/vnutch-1.x -> t/vnutch-1.x
     * [new branch]        t/vnutch-2.x -> t/vnutch-2.x
     * [new branch]        refs/top-bases/t/vnutch-1.x -> refs/top-bases/t/vnutch-1.x
     * [new branch]        refs/top-bases/t/vnutch-2.x -> refs/top-bases/t/vnutch-2.x
    
    [devalone@devalone nutch]$ tg summary
    >0r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
     0r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x


OK. 本地版本库与团队开发版本库同步一致。

 


6.3 日常开发维护工作
-------------------------------------------------------------------------------------------------------------------------
特性分支及团队开发版本库设置完成之后,日后的定制开发工作就是在所创建的两个 Nutch 特性分支上进行,t/vnutch-1.x 分支基于
Nutch 1.x,t/vnutch-2.x 基于 Nutch 2.x, 可以随意在任何一条分支线上工作。日常工作与原生 Git 类似:

    git add ...
    git commit ...
    tg summary
    tg push ...
    
    需要时可以建立里程碑:
    tg tag ...
    
    
    
当上游版本库 https://github.com/apache/nutch.git 有足够多的提交需要合并到定制开发分支中时,执行下面操作过程:

    git pull upstream
    git push origin master
    git push origin nutch-2.x

    tg info
    tg summary
    tg update ...
    tg info
    
    可能发生冲突的过程,冲突解决,执行: tg update --continue
    
    tg summary
    ...


    NOTE:
    ---------------------------------------------------------------------------------------------------------------------
    使用 TopGit 管理定制开发,要始终在特性分支上执行提交和推送操作,不要在依赖的分支上操作,例如,本案例中的 master 和 nutch-2.x 分支。依赖分支用于跟踪上游分支的更新,以便特性分支进行 update 操作。定制开发日常真正开发工作的提交和推送都  是在各自的特性分支上进行,如本案例的 t/vnutch-1.x 和 t/vnutch-2.x 分支。
    
    
示例:

    下面是几天以后的一次更新操作,https://github.com/apache/nutch.git 的 master 分支上有了 2 个新的提交,执行:
    
    [devalone@devalone nutch]$ git pull upstream
    来自 https://github.com/apache/nutch
       aaf85cad..f02110f4  master     -> upstream/master
    更新 aaf85cad..f02110f4
    Fast-forward
    ...
    
    [devalone@devalone nutch]$ git push origin master
    枚举对象: 702, 完成.
    对象计数中: 100% (702/702), 完成.
    Delta compression using up to 4 threads.
    压缩对象中: 100% (83/83), 完成.
    写入对象中: 100% (443/443), 71.89 KiB | 71.89 MiB/s, 完成.
    Total 443 (delta 144), reused 442 (delta 143)
    To repo.sansovo.org:scm/vnutch
       aaf85cad..f02110f4  master -> master
    
    [devalone@devalone nutch]$ git push origin nutch-2.x
    Everything up-to-date
    
    [devalone@devalone nutch]$ tg checkout t/vnutch-1.x
    切换到分支 't/vnutch-1.x'

    [devalone@devalone nutch]$ tg info
    Topic Branch: t/vnutch-1.x (2/2 commits)
    Subject: [PATCH] t/vnutch-1.x
    Base: aaf85cad
    Remote Mate: origin/t/vnutch-1.x
    Depends: master
    Needs update from:
            master (2/2 commits)
            
    [devalone@devalone nutch]$ tg summary
    > r D    t/vnutch-1.x                   [PATCH] t/vnutch-1.x
      r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x
      
    (注:新提交发生在 master 分支上,而 nutch-2.x 分支上并没有新的提交,因此 t/vnutch-1.x 状态发生变化,而 t/vnutch-2.x
    分支没有变化)

    [devalone@devalone nutch]$ tg update
    tg: Updating t/vnutch-1.x base with master changes...
    Fast-forward (no commit created)
    tg: The t/vnutch-1.x head is up-to-date wrt. its remote branch.
    tg: Updating t/vnutch-1.x against new base...
    Merge made by the 'trivial aggressive' strategy.
     99 files changed, 291 insertions(+), 256 deletions(-)
    
    [devalone@devalone nutch]$ tg summary
    > rL     t/vnutch-1.x                   [PATCH] t/vnutch-1.x
      r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x

    [devalone@devalone nutch]$ tg update t/vnutch-2.x
    tg: The base is up-to-date.
    tg: The t/vnutch-2.x head is up-to-date wrt. its remote branch.
    tg: The t/vnutch-2.x head is up-to-date wrt. the base.

    [devalone@devalone nutch]$ tg summary
    > rL     t/vnutch-1.x                   [PATCH] t/vnutch-1.x
      r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x
    
    
    最后执行 tg push 操作:
    
    [devalone@devalone nutch]$ tg push -a
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 362 bytes | 362.00 KiB/s, done.
    Total 2 (delta 1), reused 0 (delta 0)
    To repo.sansovo.org:scm/vnutch
       fe6aba3d..30b0cdac  t/vnutch-1.x -> t/vnutch-1.x
       aaf85cad..f02110f4  refs/top-bases/t/vnutch-1.x -> refs/top-bases/t/vnutch-1.x

    查看状态:
    [devalone@devalone nutch]$ tg summary
    > r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
      r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x
      
    OK. 依赖更新完毕。

    
    下面是最近的 2 个新提交和上次 clone 时的最后一个提交:
    
    [devalone@devalone nutch]$ git log --oneline -3
    f02110f4 (HEAD -> master, refs/top-bases/t/vnutch-1.x, upstream/master, upstream/HEAD, origin/top-bases/t/vnutch-1.x,\
    origin/master) NUTCH-2633 Fix deprecation warnings when building Nutch master branch under JDK 10.0.2+13 (#374)
    01c5d6ea Prepare for new development after release of 1.15 - bump version number (1.15-SNAPSHOT -> 1.16-SNAPSHOT) - \
    add 1.15 changes / release notes
    aaf85cad Merge pull request #366 from sebastian-nagel/NUTCH-2622-unbundle-lgpl-licensed-jars


7. 将 Nutch 项目代码导入到 Eclipse 中
-------------------------------------------------------------------------------------------------------------------------
有了完备的代码管理,再将项目代码导入到 Eclipse 中,定制开发工作就可以愉快地展开了。

 

    NOTE: sonar-ant-task-2.2.jar
    ---------------------------------------------------------------------------------------------------------------------
    nutch 源码 ant 任务依赖 sonar-ant-task-2.2.jar 任务包,但 ivy 无法加载该包的资源定义 org/sonar/ant/antlib.xml,需要
    手动下载,否则出现如下错误:
    [taskdef] Could not load definitions from resource org/sonar/ant/antlib.xml. It could not be found.
    ivy-download:
    [taskdef] Could not load definitions from resource org/sonar/ant/antlib.xml. It could not be found.

    下载地址:
        https://download.csdn.net/download/devalone/10554266

    将下载解压的 sonar-ant-task-2.2.jar 包文件复制到 ant/lib/ 目录下:
        [devalone@nutch ant]$ sudo cp ~/sonar-ant-task-2.2.jar ant/lib/
    
    
    

7.1 Nutch 1.x 分支导入
-------------------------------------------------------------------------------------------------------------------------
① Nutch 1.x 分支对应已建好的 TopGit 特性分支 t/vnutch-1.x,因此确保当前在 t/vnutch-1.x 分支上:
    
    [devalone@devalone nutch]$ tg summary
    >0r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
     0r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x
    

② 编辑项目根目录下的 ivy/ivysettings.xml 文件,将其中的 3 个依赖仓库 URL 修改为本地区较快的镜像仓库,例如:
-------------------------------------------------------------------------------------------------------------------------
    http://maven.aliyun.com/nexus/content/groups/public/
    http://maven.aliyun.com/nexus/content/repositories/central/
    http://maven.aliyun.com/nexus/content/repositories/apache-snapshots/
    

    本例使用本地网络环境内配置好的 maven 仓库:
    <property name="oss.sonatype.org"
    value="http://repo.sansovo.org:8081/nexus/content/groups/public/"
    override="false"/>
    <property name="repo.maven.org"
    value="http://repo.sansovo.org:8081/nexus/content/groups/public/"
    override="false"/>
    <property name="repository.apache.org"
    value="http://repo.sansovo.org:8081/nexus/content/groups/public-snapshot/"
    override="false"/>

    
③ 在工作区根目录下执行 ant 的 eclipse 任务:
-------------------------------------------------------------------------------------------------------------------------
    [devalone@devalone nutch]$ ant eclipse
    Buildfile: /home/devalone/workspaces/nutch/nutch/build.xml
    Trying to override old definition of task javac

    clean-build:
       [delete] Deleting directory /home/devalone/workspaces/nutch/nutch/build

    clean-default-lib:

    clean-test-lib:

    clean-lib:

    clean-dist:

    clean-eclipse:

    ivy-probe-antlib:

    ivy-download:

    ivy-download-unchecked:

    ivy-init-antlib:

    ivy-init:

    init:
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build

    ...
    
    eclipse:
      [eclipse] There were no settings found.
      [eclipse] Writing the project definition in the mode "java".
      [eclipse] Writing the classpath definition.

    BUILD SUCCESSFUL
    Total time: 12 minutes 0 seconds
    
    

    首次执行时间取决于本地网速和所选的镜像仓库速度,以后再次执行 ant 任务时,很快就会完成。
    
    
④ 导入 Eclipse workspace:
-------------------------------------------------------------------------------------------------------------------------
启动 Eclipse,单击 File -> Import

在打开的 Import 向导对话框内展开 General 组,选择 Existing Projects into Workspace ,然后单击 Next 按钮

在 Import 向导的下一对话框内,选择 "Select root directory" ,然后通过 "Browse..." 按钮定位到 nutch 项目的根目录,单击 OK
按钮,返回到对话框。
    
单击 "Finish" 按钮完成导入。

项目名称显示为:

    nutch [nutch t/vnutch-1.x]
    
表明当前处于 t/vnutch-1.x 特性分支上。

OK. 导入 Eclipse 项目完成。


⑤ 将 t/vnutch-1.x 分支对 ivy/ivysettings 的修改提交并推送到团队开发版本库:
-------------------------------------------------------------------------------------------------------------------------
使用原生 Git 命令提交:
    [devalone@devalone nutch]$ git add ivy/ivysettings.xml
    [devalone@devalone nutch]$ git commit -m "修改 ivy 依赖仓库为本地仓库,以提升 ant 任务下载速度。"

查看当前状态信息:
    [devalone@devalone nutch]$ tg summary
    > rL     t/vnutch-1.x                   [PATCH] t/vnutch-1.x
     0r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x

将特性分支提交推送的团队版本库:
    [devalone@devalone nutch]$ tg push
    Enumerating objects: 7, done.
    Counting objects: 100% (7/7), done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 557 bytes | 557.00 KiB/s, done.
    Total 4 (delta 3), reused 0 (delta 0)
    To repo.sansovo.org:scm/vnutch
       c95f855a..fe6aba3d  t/vnutch-1.x -> t/vnutch-1.x
    

再次查看状态信息:
    [devalone@devalone nutch]$ tg summary
    > r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
     0r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x    

OK.


7.2 Nutch 2.x 分支导入
-------------------------------------------------------------------------------------------------------------------------
① 与 Nutch 1.x 分支导入类似,首先切换到 t/vnutch-2 特性分支:


切换分支:
    [devalone@devalone nutch]$ tg checkout t/vnutch-2.x
    切换到分支 't/vnutch-2.x'
    [devalone@devalone nutch]$ git branch
      master
      nutch-2.x
      t/vnutch-1.x
    * t/vnutch-2.x
    


② 编辑项目根目录下的 ivy/ivysettings.xml 文件,将其中的 3 个依赖仓库 URL 修改为本地区较快的镜像仓库
-------------------------------------------------------------------------------------------------------------------------
    同 t/vnutch-1.x 分支设置。
    
    
③ 在工作区根目录下执行 ant 的 eclipse 任务:
-------------------------------------------------------------------------------------------------------------------------
    [devalone@devalone nutch]$ ant eclipse
    Buildfile: /home/devalone/workspaces/nutch/nutch/build.xml
    Trying to override old definition of task javac

    clean-build:
       [delete] Deleting directory /home/devalone/workspaces/nutch/nutch/build

    clean-lib:

    clean-dist:

    clean-eclipse:

    ivy-probe-antlib:

    ivy-download:

    ivy-download-unchecked:
          [get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar
          [get] To: /home/devalone/workspaces/nutch/nutch/ivy/ivy-2.3.0.jar

    ivy-init-antlib:

    ivy-init:

    init:
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build/lib
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build/classes
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build/release
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build/test
        [mkdir] Created dir: /home/devalone/workspaces/nutch/nutch/build/test/classes
         [copy] Copying 1 file to /home/devalone/workspaces/nutch/nutch/conf

    ...
    
    eclipse:
    [eclipse] There were no settings found.
    [eclipse] Writing the project definition in the mode "java".
    [eclipse] Writing the classpath definition.

    BUILD SUCCESSFUL
    Total time: 21 minutes 24 seconds


④ 导入 Eclipse workspace:    
-------------------------------------------------------------------------------------------------------------------------
导入过程与 t/vnutch-1.x 分支导入过程相同。
   
如果已经按照上述方法导入了 t/vnutch-1.x 分支,则不需要再次将 t/vnutch-2.x 分支导入到 Eclipse,打开 Eclipse 即会直接切换到
t/vnutch-2.x 分支下工作。

在 t/vnutch-2.x 分支下工作时, Eclipse 中项目名称显示为:

    nutch [nutch t/vnutch-2.x]
    
表明当前处于处于 t/vnutch-2.x 特性分支中。

 

⑤ 将 t/vnutch-2.x 分支对 ivy/ivysettings 的修改提交并推送到团队开发版本库:
-------------------------------------------------------------------------------------------------------------------------
使用原生 Git 命令提交:
    [devalone@devalone nutch]$ git add ivy/ivysettings.xml
    [devalone@devalone nutch]$ git commit -m "修改 ivy 依赖仓库为本地仓库,以提升 ant 任务下载速度。"

查看当前状态信息:
    [devalone@devalone nutch]$ tg summary
      r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
    > rL     t/vnutch-2.x                   [PATCH] t/vnutch-2.x


将提交推送到团队版本库:
    [devalone@devalone nutch]$ tg push
    Enumerating objects: 7, done.
    Counting objects: 100% (7/7), done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 535 bytes | 535.00 KiB/s, done.
    Total 4 (delta 3), reused 0 (delta 0)
    To repo.sansovo.org:scm/vnutch
       b3bd8d1a..dec79976  t/vnutch-2.x -> t/vnutch-2.x

再次查看特性分支状态信息:  
    [devalone@devalone nutch]$ tg summary
      r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
    > r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x

OK.


7.3 小问题处理
-------------------------------------------------------------------------------------------------------------------------
执行 ant eclipse 任务之后,会在当前分支根目录下产生几个没有被跟踪的文件:

    [devalone@devalone nutch]$ git status
    位于分支 t/vnutch-2.x
    未跟踪的文件:
      (使用 "git add <文件>..." 以包含要提交的内容)

            .classpath
            .project
            ivy/ivy-2.3.0.jar
            ivy/ivy-2.4.0.jar

前两个隐藏文件 .classpath 和 .project 是 eclipse 的类路径列表文件和项目文件,是由 ant eclipse 执行过程中产生的,用于
eclipse 管理项目。后面两个是 ivy 两个版本的 jar 文件,也是 ant 任务执行期间下载的文件,ivy/ivy-2.3.0.jar 是 nutch 1.x 下载
的,ivy/ivy-2.4.0.jar 是 nutch 2.x 任务下载的。

这 4 个文件与项目代码无关,而且自动由工具产生和修改。为了保持代码库干净,可以将它们加入到项目根目录下的 .gitignore 文件中,
使其被 Git 忽略。

[devalone@devalone nutch]$ vi .gitignore

加入:

.classpath
.project
ivy/ivy-2.3.0.jar
ivy/ivy-2.4.0.jar

保存退出。

由于修改了 .gitignore 文件,它是由 Git 管理的文件,因此需要再次提交推送:

    [devalone@devalone nutch]$ git status
    位于分支 t/vnutch-2.x
    尚未暂存以备提交的变更:
      (使用 "git add <文件>..." 更新要提交的内容)
      (使用 "git checkout -- <文件>..." 丢弃工作区的改动)

            修改:     .gitignore

    修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

    [devalone@devalone nutch]$ git add .gitignore
    [devalone@devalone nutch]$ git commit -m "修改 .gitignore 文件,保持代码库干净、整洁。"
    [t/vnutch-2.x 1c8c3123] 修改 .gitignore 文件,保持代码库干净、整洁。
     1 file changed, 4 insertions(+), 1 deletion(-)
 
    [devalone@devalone nutch]$ tg summary
      r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
    > rL     t/vnutch-2.x                   [PATCH] t/vnutch-2.x

    [devalone@devalone nutch]$ tg push
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 427 bytes | 427.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    To repo.sansovo.org:scm/vnutch
       dec79976..1c8c3123  t/vnutch-2.x -> t/vnutch-2.x
   
再次查看特性分支状态信息:
    [devalone@devalone nutch]$ tg summary
      r      t/vnutch-1.x                   [PATCH] t/vnutch-1.x
    > r      t/vnutch-2.x                   [PATCH] t/vnutch-2.x

    [devalone@devalone nutch]$ git status
    位于分支 t/vnutch-2.x
    无文件要提交,干净的工作区

OK.

同样的方法处理 t/vnutch-1.x 分支。

 

                                                         (本篇完)

 

系列目录:

利用 Topgit 对 Nutch 定制开发进行代码管理(一)

利用 Topgit 对 Nutch 定制开发进行代码管理(二)

 

-------------------------------------------------------------------------------------------------------------------------
参考:

    https://github.com/mackyle/topgit
    https://wiki.apache.org/nutch/RunNutchInEclipse

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值