-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #797 from tuichenchuxin/master
Support @JavaDoc tag for normal service
- Loading branch information
Showing
19 changed files
with
2,253 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/com/ly/doc/builder/javadoc/JavadocAdocBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2018-2024 smart-doc | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.ly.doc.builder.javadoc; | ||
|
||
import com.ly.doc.constants.DocGlobalConstants; | ||
import com.ly.doc.helper.JavaProjectBuilderHelper; | ||
import com.ly.doc.model.ApiConfig; | ||
import com.ly.doc.model.javadoc.JavadocApiDoc; | ||
import com.thoughtworks.qdox.JavaProjectBuilder; | ||
|
||
import java.util.List; | ||
|
||
public class JavadocAdocBuilder { | ||
|
||
private static final String API_EXTENSION = "JavadocApi.adoc"; | ||
|
||
private static final String INDEX_DOC = "javadoc-index.adoc"; | ||
|
||
/** | ||
* build adoc | ||
* | ||
* @param config ApiConfig | ||
*/ | ||
public static void buildApiDoc(ApiConfig config) { | ||
JavaProjectBuilder javaProjectBuilder = JavaProjectBuilderHelper.create(); | ||
buildApiDoc(config, javaProjectBuilder); | ||
} | ||
|
||
/** | ||
* Only for smart-doc maven plugin and gradle plugin. | ||
* | ||
* @param config ApiConfig | ||
* @param javaProjectBuilder ProjectDocConfigBuilder | ||
*/ | ||
public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { | ||
config.setAdoc(true); | ||
JavadocDocBuilderTemplate builderTemplate = new JavadocDocBuilderTemplate(); | ||
builderTemplate.checkAndInit(config,Boolean.TRUE); | ||
List<JavadocApiDoc> apiDocList = builderTemplate.getJavadocApiDoc(config, javaProjectBuilder); | ||
if (config.isAllInOne()) { | ||
String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, ".adoc"); | ||
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DocGlobalConstants.JAVADOC_ALL_IN_ONE_ADOC_TPL, docName); | ||
} else { | ||
builderTemplate.buildApiDoc(apiDocList, config, DocGlobalConstants.JAVADOC_API_DOC_ADOC_TPL, API_EXTENSION); | ||
builderTemplate.buildErrorCodeDoc(config, DocGlobalConstants.ERROR_CODE_LIST_ADOC_TPL, DocGlobalConstants.ERROR_CODE_LIST_ADOC, javaProjectBuilder); | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/ly/doc/builder/javadoc/JavadocApiDataBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2018-2024 smart-doc | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.ly.doc.builder.javadoc; | ||
|
||
import com.ly.doc.constants.FrameworkEnum; | ||
import com.ly.doc.helper.JavaProjectBuilderHelper; | ||
import com.ly.doc.model.ApiConfig; | ||
import com.ly.doc.model.javadoc.JavadocApiAllData; | ||
import com.thoughtworks.qdox.JavaProjectBuilder; | ||
|
||
public class JavadocApiDataBuilder { | ||
|
||
/** | ||
* Get list of ApiDoc | ||
* | ||
* @param config JavadocApiAllData | ||
* @return List of ApiDoc | ||
*/ | ||
public static JavadocApiAllData getApiData(ApiConfig config) { | ||
config.setShowJavaType(true); | ||
config.setFramework(FrameworkEnum.JAVADOC.getFramework()); | ||
JavadocDocBuilderTemplate builderTemplate = new JavadocDocBuilderTemplate(); | ||
builderTemplate.checkAndInitForGetApiData(config); | ||
JavaProjectBuilder javaProjectBuilder = JavaProjectBuilderHelper.create(); | ||
builderTemplate.getApiData(config, javaProjectBuilder); | ||
return builderTemplate.getApiData(config, javaProjectBuilder); | ||
} | ||
} |
215 changes: 215 additions & 0 deletions
215
src/main/java/com/ly/doc/builder/javadoc/JavadocDocBuilderTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
/* | ||
* | ||
* Copyright (C) 2018-2024 smart-doc | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.ly.doc.builder.javadoc; | ||
|
||
import com.ly.doc.builder.BaseDocBuilderTemplate; | ||
import com.ly.doc.builder.ProjectDocConfigBuilder; | ||
import com.ly.doc.constants.DocGlobalConstants; | ||
import com.ly.doc.constants.FrameworkEnum; | ||
import com.ly.doc.constants.TemplateVariable; | ||
import com.ly.doc.factory.BuildTemplateFactory; | ||
import com.ly.doc.model.ApiConfig; | ||
import com.ly.doc.model.ApiDocDict; | ||
import com.ly.doc.model.ApiErrorCode; | ||
import com.ly.doc.model.javadoc.JavadocApiAllData; | ||
import com.ly.doc.model.javadoc.JavadocApiDoc; | ||
import com.ly.doc.template.IDocBuildTemplate; | ||
import com.ly.doc.utils.BeetlTemplateUtil; | ||
import com.ly.doc.utils.DocUtil; | ||
import com.power.common.util.CollectionUtil; | ||
import com.power.common.util.DateTimeUtil; | ||
import com.power.common.util.FileUtil; | ||
import com.thoughtworks.qdox.JavaProjectBuilder; | ||
import org.beetl.core.Template; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class JavadocDocBuilderTemplate extends BaseDocBuilderTemplate { | ||
|
||
private static final String DEPENDENCY_TITLE = "Add dependency"; | ||
private static final long NOW = System.currentTimeMillis(); | ||
|
||
@Override | ||
public void checkAndInit(ApiConfig config, boolean checkOutPath) { | ||
config.setFramework(FrameworkEnum.JAVADOC.getFramework()); | ||
super.checkAndInit(config, checkOutPath); | ||
config.setOutPath(config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + DocGlobalConstants.JAVADOC_OUT_DIR); | ||
} | ||
|
||
/** | ||
* Generate api documentation for all controllers. | ||
* | ||
* @param apiDocList list of api doc | ||
* @param config api config | ||
* @param template template | ||
* @param fileExtension file extension | ||
*/ | ||
public void buildApiDoc(List<JavadocApiDoc> apiDocList, ApiConfig config, String template, String fileExtension) { | ||
FileUtil.mkdirs(config.getOutPath()); | ||
for (JavadocApiDoc apiDoc : apiDocList) { | ||
Template mapper = BeetlTemplateUtil.getByName(template); | ||
mapper.binding(TemplateVariable.DESC.getVariable(), apiDoc.getDesc()); | ||
mapper.binding(TemplateVariable.NAME.getVariable(), apiDoc.getName()); | ||
mapper.binding(TemplateVariable.LIST.getVariable(), apiDoc.getList()); | ||
mapper.binding(TemplateVariable.AUTHOR.getVariable(), apiDoc.getAuthor()); | ||
mapper.binding(TemplateVariable.VERSION.getVariable(), apiDoc.getVersion()); | ||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + apiDoc.getShortName() + fileExtension); | ||
} | ||
} | ||
|
||
/** | ||
* Merge all api doc into one document | ||
* | ||
* @param apiDocList list data of Api doc | ||
* @param config api config | ||
* @param javaProjectBuilder JavaProjectBuilder | ||
* @param template template | ||
* @param outPutFileName output file | ||
*/ | ||
public void buildAllInOne(List<JavadocApiDoc> apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, | ||
String outPutFileName) { | ||
String outPath = config.getOutPath(); | ||
String strTime = DateTimeUtil.long2Str(NOW, DateTimeUtil.DATE_FORMAT_SECOND); | ||
FileUtil.mkdirs(outPath); | ||
List<ApiErrorCode> errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); | ||
Template tpl = BeetlTemplateUtil.getByName(template); | ||
tpl.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList); | ||
tpl.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList); | ||
tpl.binding(TemplateVariable.VERSION_LIST.getVariable(), config.getRevisionLogs()); | ||
tpl.binding(TemplateVariable.VERSION.getVariable(), NOW); | ||
tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); | ||
tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName()); | ||
setDirectoryLanguageVariable(config, tpl); | ||
|
||
List<ApiDocDict> apiDocDictList = DocUtil.buildDictionary(config, javaProjectBuilder); | ||
tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); | ||
|
||
int codeIndex = apiDocList.isEmpty() ? 1 : apiDocDictList.size(); | ||
|
||
if (CollectionUtil.isNotEmpty(errorCodeList)) { | ||
tpl.binding(TemplateVariable.ERROR_CODE_ORDER.getVariable(), ++codeIndex); | ||
} | ||
|
||
if (CollectionUtil.isNotEmpty(apiDocDictList)) { | ||
tpl.binding(TemplateVariable.DICT_ORDER.getVariable(), ++codeIndex); | ||
} | ||
|
||
setCssCDN(config, tpl); | ||
FileUtil.nioWriteFile(tpl.render(), outPath + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); | ||
} | ||
|
||
/** | ||
* Build search js | ||
* | ||
* @param apiDocList list data of Api doc | ||
* @param config api config | ||
* @param javaProjectBuilder projectBuilder | ||
* @param template template | ||
* @param outPutFileName output file | ||
*/ | ||
public void buildSearchJs(List<JavadocApiDoc> apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder | ||
, String template, String outPutFileName) { | ||
List<ApiErrorCode> errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); | ||
Template tpl = BeetlTemplateUtil.getByName(template); | ||
// directory tree | ||
List<JavadocApiDoc> apiDocs = new ArrayList<>(); | ||
JavadocApiDoc apiDoc = new JavadocApiDoc(); | ||
apiDoc.setAlias(DEPENDENCY_TITLE); | ||
apiDoc.setOrder(1); | ||
apiDoc.setDesc(DEPENDENCY_TITLE); | ||
apiDoc.setList(new ArrayList<>(0)); | ||
apiDocs.add(apiDoc); | ||
for (JavadocApiDoc apiDoc1 : apiDocList) { | ||
apiDoc1.setOrder(apiDocs.size() + 1); | ||
apiDocs.add(apiDoc1); | ||
} | ||
Map<String, String> titleMap = setDirectoryLanguageVariable(config, tpl); | ||
if (CollectionUtil.isNotEmpty(errorCodeList)) { | ||
JavadocApiDoc apiDoc1 = new JavadocApiDoc(); | ||
apiDoc1.setOrder(apiDocs.size() + 1); | ||
apiDoc1.setDesc(titleMap.get(TemplateVariable.ERROR_LIST_TITLE.getVariable())); | ||
apiDoc1.setList(new ArrayList<>(0)); | ||
apiDocs.add(apiDoc1); | ||
} | ||
|
||
// set dict list | ||
List<ApiDocDict> apiDocDictList = DocUtil.buildDictionary(config, javaProjectBuilder); | ||
tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); | ||
tpl.binding(TemplateVariable.DIRECTORY_TREE.getVariable(), apiDocs); | ||
FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); | ||
} | ||
|
||
/** | ||
* build error_code adoc | ||
* | ||
* @param config api config | ||
* @param template template | ||
* @param outPutFileName output file | ||
* @param javaProjectBuilder javaProjectBuilder | ||
*/ | ||
public void buildErrorCodeDoc(ApiConfig config, String template, String outPutFileName, JavaProjectBuilder javaProjectBuilder) { | ||
List<ApiErrorCode> errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); | ||
Template mapper = BeetlTemplateUtil.getByName(template); | ||
mapper.binding(TemplateVariable.LIST.getVariable(), errorCodeList); | ||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); | ||
} | ||
|
||
/** | ||
* get all api data | ||
* | ||
* @param config ApiConfig | ||
* @param javaProjectBuilder JavaProjectBuilder | ||
* @return ApiAllData | ||
*/ | ||
public JavadocApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { | ||
JavadocApiAllData apiAllData = new JavadocApiAllData(); | ||
apiAllData.setLanguage(config.getLanguage().getCode()); | ||
apiAllData.setProjectName(config.getProjectName()); | ||
apiAllData.setProjectId(DocUtil.generateId(config.getProjectName())); | ||
apiAllData.setApiDocList(listOfApiData(config, javaProjectBuilder)); | ||
apiAllData.setErrorCodeList(DocUtil.errorCodeDictToList(config, javaProjectBuilder)); | ||
apiAllData.setRevisionLogs(config.getRevisionLogs()); | ||
apiAllData.setApiDocDictList(DocUtil.buildDictionary(config, javaProjectBuilder)); | ||
return apiAllData; | ||
} | ||
|
||
private List<JavadocApiDoc> listOfApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { | ||
this.checkAndInitForGetApiData(config); | ||
config.setMd5EncryptedHtmlName(true); | ||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); | ||
IDocBuildTemplate<JavadocApiDoc> docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework()); | ||
Objects.requireNonNull(docBuildTemplate, "doc build template is null"); | ||
return docBuildTemplate.getApiData(configBuilder); | ||
} | ||
|
||
public List<JavadocApiDoc> getJavadocApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { | ||
config.setShowJavaType(true); | ||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); | ||
IDocBuildTemplate<JavadocApiDoc> docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework()); | ||
Objects.requireNonNull(docBuildTemplate, "doc build template is null"); | ||
return docBuildTemplate.getApiData(configBuilder); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/ly/doc/builder/javadoc/JavadocHtmlBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2018-2024 smart-doc | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.ly.doc.builder.javadoc; | ||
|
||
import com.ly.doc.builder.BaseDocBuilderTemplate; | ||
import com.ly.doc.constants.DocGlobalConstants; | ||
import com.ly.doc.helper.JavaProjectBuilderHelper; | ||
import com.ly.doc.model.ApiConfig; | ||
import com.ly.doc.model.javadoc.JavadocApiDoc; | ||
import com.ly.doc.utils.BeetlTemplateUtil; | ||
import com.power.common.util.FileUtil; | ||
import com.thoughtworks.qdox.JavaProjectBuilder; | ||
import org.beetl.core.Template; | ||
|
||
import java.util.List; | ||
|
||
public class JavadocHtmlBuilder { | ||
|
||
|
||
/** | ||
* build controller api | ||
* | ||
* @param config config | ||
*/ | ||
public static void buildApiDoc(ApiConfig config) { | ||
JavaProjectBuilder javaProjectBuilder = JavaProjectBuilderHelper.create(); | ||
buildApiDoc(config, javaProjectBuilder); | ||
} | ||
|
||
/** | ||
* Only for smart-doc maven plugin and gradle plugin. | ||
* | ||
* @param config ApiConfig | ||
* @param javaProjectBuilder ProjectDocConfigBuilder | ||
*/ | ||
public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { | ||
JavadocDocBuilderTemplate builderTemplate = new JavadocDocBuilderTemplate(); | ||
builderTemplate.checkAndInit(config,Boolean.TRUE); | ||
List<JavadocApiDoc> apiDocList = builderTemplate.getJavadocApiDoc(config, javaProjectBuilder); | ||
Template indexCssTemplate = BeetlTemplateUtil.getByName(DocGlobalConstants.ALL_IN_ONE_CSS); | ||
FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + DocGlobalConstants.ALL_IN_ONE_CSS_OUT); | ||
BaseDocBuilderTemplate.copyJarFile("css/" + DocGlobalConstants.FONT_STYLE, config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + DocGlobalConstants.FONT_STYLE); | ||
BaseDocBuilderTemplate.copyJarFile("js/" + DocGlobalConstants.JQUERY, config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + DocGlobalConstants.JQUERY); | ||
String INDEX_HTML = "javadoc-index.html"; | ||
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DocGlobalConstants.JAVADOC_ALL_IN_ONE_HTML_TPL, INDEX_HTML); | ||
String SEARCH_JS = "search.js"; | ||
builderTemplate.buildSearchJs(apiDocList, config, javaProjectBuilder, DocGlobalConstants.JAVADOC_ALL_IN_ONE_SEARCH_TPL, SEARCH_JS); | ||
} | ||
} |
Oops, something went wrong.