Skip to content

Commit

Permalink
Merge pull request #921 from linwumingshi/refactor/java-doc
Browse files Browse the repository at this point in the history
refactor: update java doc And error log
  • Loading branch information
shalousun authored Sep 15, 2024
2 parents 1bd2587 + 439fda0 commit 5ebbbaa
Show file tree
Hide file tree
Showing 92 changed files with 1,478 additions and 287 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/ly/doc/builder/AdocDocBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@
*/
public class AdocDocBuilder {

/**
* api doc file name
*/
private static final String API_EXTENSION = "Api.adoc";

/**
* index.adoc
*/
private static final String INDEX_DOC = "index.adoc";

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/ly/doc/builder/ApiDataBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.thoughtworks.qdox.JavaProjectBuilder;

/**
* Build Api Data
*
* @author yu 2019/12/7.
* @since 1.7.9
*/
Expand Down Expand Up @@ -56,6 +58,14 @@ public static ApiAllData getApiDataTree(ApiConfig config) {
return getApiData(config, Boolean.TRUE);
}

/**
* Retrieves API data based on the given configuration.
* @param config The API configuration object containing request parameters and data
* source information.
* @param toTree A flag indicating whether to convert the parameter data into a tree
* structure.
* @return An ApiAllData object containing all the API data information.
*/
private static ApiAllData getApiData(ApiConfig config, boolean toTree) {
config.setParamsDataToTree(toTree);
DocBuilderTemplate builderTemplate = new DocBuilderTemplate();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/ly/doc/builder/HtmlApiDocBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,26 @@
import java.util.Objects;

/**
* HTML API Doc Builder
*
* @author yu 2019/9/20.
* @since 1.7+
*/
public class HtmlApiDocBuilder {

/**
* error code html
*/
private static final String ERROR_CODE_HTML = "error.html";

/**
* dict html
*/
private static final String DICT_HTML = "dict.html";

/**
* index html
*/
private static String INDEX_HTML = "index.html";

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/ly/doc/builder/JMeterBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
*/
public class JMeterBuilder {

/**
* Jmeter script extension
*/
private static final String JMETER_SCRIPT_EXTENSION = ".jmx";

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/ly/doc/builder/PostmanJsonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@
import java.util.*;

/**
* Postman Json Builder
*
* @author yu 2019/11/21.
* @since 1.7.8
*/
public class PostmanJsonBuilder {

/**
* Message
*/
private static final String MSG = "Interface name is not set.";

/**
Expand Down
100 changes: 99 additions & 1 deletion src/main/java/com/ly/doc/builder/ProjectDocConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,68 @@
import java.util.logging.Logger;

/**
* ProjectDocConfigBuilder
*
* @author yu 2019/12/21.
* @since 1.8.0
*/
public class ProjectDocConfigBuilder {

/**
* Logger
*/
private static final Logger log = Logger.getLogger(ProjectDocConfigBuilder.class.getName());

/**
* JavaProjectBuilder
*/
private final JavaProjectBuilder javaProjectBuilder;

/**
* classFilesMap
*/
private final Map<String, JavaClass> classFilesMap = new ConcurrentHashMap<>();

/**
* enumClassMap
*/
private final Map<String, Class<? extends Enum<?>>> enumClassMap = new ConcurrentHashMap<>();

/**
* customRespFieldMap
*/
private final Map<CustomField.Key, CustomField> customRespFieldMap = new ConcurrentHashMap<>();

/**
* customReqFieldMap
*/
private final Map<CustomField.Key, CustomField> customReqFieldMap = new ConcurrentHashMap<>();

/**
* replaceClassMap
*/
private final Map<String, String> replaceClassMap = new ConcurrentHashMap<>();

/**
* constantsMap
*/
private final Map<String, String> constantsMap = new ConcurrentHashMap<>();

/**
* serverUrl
*/
private final String serverUrl;

/**
* ApiConfig
*/
private final ApiConfig apiConfig;

/**
* Constructor
* @param apiConfig ApiConfig
* @param javaProjectBuilder JavaProjectBuilder
*/
public ProjectDocConfigBuilder(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder) {
if (null == apiConfig) {
throw new NullPointerException("ApiConfig can't be null.");
Expand Down Expand Up @@ -105,6 +143,10 @@ public ProjectDocConfigBuilder(ApiConfig apiConfig, JavaProjectBuilder javaProje
this.checkBodyAdvice(apiConfig.getResponseBodyAdvice());
}

/**
* Init data dictionary.
* @param apiConfig apiConfig
*/
private void initDict(ApiConfig apiConfig) {
if (enumClassMap.isEmpty()) {
return;
Expand All @@ -129,6 +171,11 @@ private void initDict(ApiConfig apiConfig) {
}
}

/**
* Get enum implements by interface.
* @param enumClass enumClass
* @return enum implements
*/
private Set<Class<? extends Enum<?>>> getEnumImplementsByInterface(Class<?> enumClass) {
if (!enumClass.isInterface()) {
return Collections.emptySet();
Expand All @@ -142,6 +189,11 @@ private Set<Class<? extends Enum<?>>> getEnumImplementsByInterface(Class<?> enum
return set;
}

/**
* Get class by name.
* @param simpleName simpleName
* @return JavaClass
*/
public JavaClass getClassByName(String simpleName) {
JavaClass cls = javaProjectBuilder.getClassByName(simpleName);
List<DocJavaField> fieldList = JavaClassUtil.getFields(cls, 0, new LinkedHashMap<>(), null);
Expand All @@ -158,6 +210,11 @@ public JavaClass getClassByName(String simpleName) {
return cls;
}

/**
* Load java source.
* @param config ApiConfig
* @param builder JavaProjectBuilder
*/
private void loadJavaSource(ApiConfig config, JavaProjectBuilder builder) {
if (CollectionUtil.isNotEmpty(config.getJarSourcePaths())) {
for (SourceCodePath path : config.getJarSourcePaths()) {
Expand All @@ -181,6 +238,11 @@ private void loadJavaSource(ApiConfig config, JavaProjectBuilder builder) {
}
}

/**
* Load jar java source.
* @param strPath path
* @param builder builder
*/
private void loadJavaSource(String strPath, JavaProjectBuilder builder) {
DirectoryScanner scanner = new DirectoryScanner(new File(strPath));
scanner.addFilter(new SuffixFilter(".java"));
Expand All @@ -194,6 +256,11 @@ private void loadJavaSource(String strPath, JavaProjectBuilder builder) {
});
}

/**
* Load jar java source.
* @param path path
* @param builder builder
*/
public void loadJarJavaSource(String path, JavaProjectBuilder builder) {
OutputStream out;
if (!path.endsWith(".jar")) {
Expand Down Expand Up @@ -228,6 +295,10 @@ public void loadJarJavaSource(String path, JavaProjectBuilder builder) {
}
}

/**
* Delete dir.
* @param file file
*/
public static void deleteDir(File file) {
File[] files = file.listFiles();
if (file.isFile() || Objects.isNull(files) || files.length == 0) {
Expand All @@ -241,6 +312,10 @@ public static void deleteDir(File file) {
file.delete();
}

/**
* Init class files map.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void initClassFilesMap() {
Collection<JavaClass> javaClasses = javaProjectBuilder.getClasses();
for (JavaClass cls : javaClasses) {
Expand All @@ -264,6 +339,10 @@ private void initClassFilesMap() {
}
}

/**
* Init custom response fields map.
* @param config config
*/
private void initCustomResponseFieldsMap(ApiConfig config) {
if (CollectionUtil.isNotEmpty(config.getCustomResponseFields())) {
for (CustomField field : config.getCustomResponseFields()) {
Expand All @@ -273,6 +352,10 @@ private void initCustomResponseFieldsMap(ApiConfig config) {
}
}

/**
* Init custom request fields map.
* @param config config
*/
private void initCustomRequestFieldsMap(ApiConfig config) {
if (CollectionUtil.isNotEmpty(config.getCustomRequestFields())) {
for (CustomField field : config.getCustomRequestFields()) {
Expand All @@ -282,6 +365,10 @@ private void initCustomRequestFieldsMap(ApiConfig config) {
}
}

/**
* Init replace class map.
* @param config config
*/
private void initReplaceClassMap(ApiConfig config) {
if (CollectionUtil.isNotEmpty(config.getApiObjectReplacements())) {
for (ApiObjectReplacement replace : config.getApiObjectReplacements()) {
Expand All @@ -290,6 +377,10 @@ private void initReplaceClassMap(ApiConfig config) {
}
}

/**
* Init constants.
* @param config config
*/
private void initConstants(ApiConfig config) {
List<ApiConstant> apiConstants;
if (CollectionUtil.isEmpty(config.getApiConstants())) {
Expand All @@ -311,10 +402,14 @@ private void initConstants(ApiConfig config) {
}
}
catch (ClassNotFoundException | IllegalAccessException e) {
e.printStackTrace();
log.warning(e.getMessage());
}
}

/**
* Check body advice.
* @param bodyAdvice body advice
*/
private void checkBodyAdvice(BodyAdvice bodyAdvice) {
if (Objects.nonNull(bodyAdvice) && StringUtil.isNotEmpty(bodyAdvice.getClassName())) {
if (Objects.nonNull(bodyAdvice.getWrapperClass())) {
Expand All @@ -330,6 +425,9 @@ private void checkBodyAdvice(BodyAdvice bodyAdvice) {
}
}

/**
* Set highlight style.
*/
private void setHighlightStyle() {
String style = apiConfig.getStyle();
if (HighLightJsConstants.HIGH_LIGHT_DEFAULT_STYLE.equals(style)) {
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/ly/doc/builder/WordDocBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@
import java.util.zip.ZipOutputStream;

/**
* Word doc builder
*
* @author <a href="mailto:[email protected]">chenqi</a>
* @version 1.0
* @since 3.0.1
*/
public class WordDocBuilder {

/**
* template docx
*/
private static final String TEMPLATE_DOCX = "template/word/template.docx";

/**
* build docx file name
*/
private static final String BUILD_DOCX = "index.docx";

/**
* build error code docx file name
*/
private static final String BUILD_ERROR_DOCX = "error.docx";

/**
* build directory data docx file name
*/
private static final String BUILD_DICT_DOCX = "dict.docx";

/**
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/ly/doc/builder/javadoc/JavadocAdocBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@

import java.util.List;

/**
* Javadoc Asciidoc Builder
*
* @author chenchuxin
* @since 3.0.5
*/
public class JavadocAdocBuilder {

/**
* api extension
*/
private static final String API_EXTENSION = "JavadocApi.adoc";

/**
* index extension
*/
private static final String INDEX_DOC = "javadoc-index.adoc";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
import com.ly.doc.model.javadoc.JavadocApiAllData;
import com.thoughtworks.qdox.JavaProjectBuilder;

/**
* Javadoc Api Data Builder
*
* @author chenchuxin
* @since 3.0.5
*/
public class JavadocApiDataBuilder {

/**
Expand Down
Loading

0 comments on commit 5ebbbaa

Please sign in to comment.