-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incremental Document Build Based on Git Management #617
Conversation
1. 逻辑流程图2. 接口依赖树文件在 git 仓库的工作目录放置一个隐藏文件夹 以多模块的 maven 项目举例(提供 rest 接口),在项目
如果团队内有公用的接口管理工具(如 Torna),我们建议将 每个模块的配置文件格式如下所示: {
// 最近一次成功构建增量文档时基于的 git commit id
"commitId": "7bc3220f8cc9e7421c6e45511d25acb3ced3653a",
// 模块下的接口依赖树
"dependencyTree": [
{
// 接口所在的类全限定名
"clazz": "org.example.a.controller.TestController",
// 类中所有对外暴露的 api
"apis": [
{
// api 的方法名称
"method": "getUserInfo",
// 方法的参数,全限定名
"args": [
"org.example.a.request.UserRequest"
],
// 方法的返回值,全限定名
"returns": [
"org.example.a.response.ApiResponse",
"org.example.a.response.UserResponse"
]
}
]
}
]
} 3. 增量文档生成3.1 maven 插件新增 Parameter新增参数
<plugin>
<groupId>com.ly.smart-doc</groupId>
<artifactId>smart-doc-maven-plugin</artifactId>
<configuration>
<increment>true</increment>
</configuration>
</plugin>
mvn smart-doc:html -Dfile.encoding=UTF-8 -Dmaven.test.skip=true -Dincrement=true 3.2 改造 IDocBuildTemplate原本的 基于以上考虑,将接口改造为抽象类 public List<T> getApiData(ProjectDocConfigBuilder projectBuilder) {
// 创建 DocHelper,并检测依赖树文件
DocHelper docHelper = DocHelper.create(projectBuilder.getApiConfig());
// 构建文档前置处理
preRender(docHelper);
// 获取项目的全量或增量 class 文件
Collection<JavaClass> candidateClasses = getCandidateClasses(projectBuilder, docHelper);
List<T> apiList = renderApi(projectBuilder, candidateClasses);
// 构建文档后置处理 - 合并新的依赖树
postRender(docHelper, apiList);
return apiList;
} 框架的解析实现类,由原来重写 同时 改造后的 3.3 关于 DocHelper对外提供获取依赖树、构建依赖树、获取增量文件等方法 3.4 检测 candidateClasses3.5 关于 GitHelper基于 JGit 封装的 Git 操作工具类,提供了一些常用的方法 3.6 postRender可用于文件构建后的一些后置处理操作。会在这一步重建依赖树。 private void postRender(DocHelper docHelper, List<T> apiList) {
docHelper.rebuildDependencyTree(apiList);
} 为了便于在多类型文档中提取到公用属性(在构建依赖树时用到的方法参数、返回等),增加了两个接口 构建好本次接口的依赖树后,即会开始合并依赖树。 最后将最新的 commit-id 与合并后的依赖树写入依赖树文件。 4. 还需完善的地方目前只是基于 git 变更的 [文件] 做增量更新,并未解析具体变更代码涉及到的接口方法,因此此方案的增量文档构建有两处不足:
|
这个pr会放11月份来合并,10月主要是过渡期的维护 |
之前提到的 4.2 还需完善的地方,无法从依赖树中剔除已弃用的 class,已经提交了对应的 commit。 为了实现此功能,并且规范文档构建流程,
|
同时,在 dependency-tree文件中新增了 |
@@ -0,0 +1,380 @@ | |||
package com.ly.doc.helper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add license
@@ -41,4 +41,28 @@ public static String formatMockValue(String mock) { | |||
} | |||
return mock.replaceAll("\\\\",""); | |||
} | |||
|
|||
public static List<String> extractQualifiedName(List<ApiParam> paramList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to add unit tests for this method
@@ -0,0 +1,139 @@ | |||
package com.ly.doc.model.dependency; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add license
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||
import org.eclipse.jgit.treewalk.CanonicalTreeParser; | ||
|
||
import javax.annotation.Nullable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not work in a higher version JDK environment, and manual check is recommended.
It is recommended to rebase multiple commit messages into one effective commit message before merging. You can refer this document https://smart-doc-group.github.io/#/zh-cn/community/pull-request-process.md |
5dd8558
to
b9ed9a6
Compare
此 PR 来自于 Discussion #520
有几点需要额外说明:
com.ly.doc
。为了方便本地构建,本次 PR 一并修改了。若不符合 smart-doc 官方规则,我可以再修改;2.8.0-SNAPSHOT
。