From a2d455d6b78f6f8f8856845a26b48982a72b5612 Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Tue, 1 Sep 2020 23:17:58 +0800 Subject: [PATCH] add travis ci config --- .travis.yml | 10 ++++ .../doc/template/RpcDocBuildTemplate.java | 29 +++++----- .../template/SpringBootDocBuildTemplate.java | 54 +++++++++---------- 3 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..588ffee --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: java +jdk: + - oraclejdk8 +install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true +script: mvn test +after_success: + - mvn clean cobertura:cobertura coveralls:report +env: + global: + secure: xxx diff --git a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java index 8759a0d..dc10764 100644 --- a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java @@ -79,7 +79,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate { return null; } - public boolean ignoreReturnObject(String typeName,List ignoreParams) { + public boolean ignoreReturnObject(String typeName, List ignoreParams) { return false; } @@ -131,7 +131,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate { } apiMethodDoc.setDeprecated(deprecated); // build request params - List requestParams = requestParams(method, DocTags.PARAM, projectBuilder); + List requestParams = requestParams(method, projectBuilder); apiMethodDoc.setRequestParams(requestParams); // build response params List responseParams = buildReturnApiParams(method, projectBuilder); @@ -142,18 +142,17 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate { return methodDocList; } - private List requestParams(final JavaMethod javaMethod, final String tagName, ProjectDocConfigBuilder builder) { + private List requestParams(final JavaMethod javaMethod, ProjectDocConfigBuilder builder) { boolean isStrict = builder.getApiConfig().isStrict(); boolean isShowJavaType = builder.getApiConfig().getShowJavaType(); Map responseFieldMap = new HashMap<>(); String className = javaMethod.getDeclaringClass().getCanonicalName(); - Map paramTagMap = DocUtil.getParamsComments(javaMethod, tagName, className); + Map paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className); List parameterList = javaMethod.getParameters(); if (parameterList.size() < 1) { return null; } List paramList = new ArrayList<>(); - out: for (JavaParameter parameter : parameterList) { String paramName = parameter.getName(); String typeName = parameter.getType().getGenericCanonicalName(); @@ -168,8 +167,6 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate { JavaClass javaClass = builder.getJavaProjectBuilder().getClassByName(fullTypeName); List annotations = parameter.getAnnotations(); List groupClasses = JavaClassUtil.getParamGroupJavaClass(annotations); - String strRequired = "true"; - Boolean required = Boolean.parseBoolean(strRequired); if (JavaClassValidateUtil.isCollection(fullTypeName) || JavaClassValidateUtil.isArray(fullTypeName)) { String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName); String gicName = gicNameArr[0]; @@ -183,28 +180,28 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate { .setType(processedType); paramList.add(param); } else { - paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses,0)); + paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0)); } } else if (JavaClassValidateUtil.isPrimitive(fullTypeName)) { ApiParam param = ApiParam.of().setField(paramName) .setType(JavaClassUtil.getClassSimpleName(typeName)) - .setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION); + .setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION); paramList.add(param); } else if (JavaClassValidateUtil.isMap(fullTypeName)) { if (DocGlobalConstants.JAVA_MAP_FULLY.equals(typeName)) { ApiParam apiParam = ApiParam.of().setField(paramName).setType(typeName) - .setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION); + .setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION); paramList.add(apiParam); - continue out; + continue; } String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName); - paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses,0)); + paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0)); } else if (javaClass.isEnum()) { ApiParam param = ApiParam.of().setField(paramName) - .setType("Enum").setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION); + .setType("Enum").setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION); paramList.add(param); } else { - paramList.addAll(ParamsBuildHelper.buildParams(typeName, paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses,0)); + paramList.addAll(ParamsBuildHelper.buildParams(typeName, paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0)); } } return paramList; @@ -272,8 +269,8 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate { returnClass = returnClass.replace(simpleReturn, JavaClassUtil.getClassSimpleName(simpleReturn)); String[] arrays = DocClassUtil.getSimpleGicName(returnClass); for (String str : arrays) { - if(str.contains("[")){ - str = str.substring(0,str.indexOf("[")); + if (str.contains("[")) { + str = str.substring(0, str.indexOf("[")); } String[] generics = str.split("<"); for (String generic : generics) { diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java index 284b3cd..2f1db72 100644 --- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java @@ -129,8 +129,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { methodOrder++; ApiMethodDoc apiMethodDoc = new ApiMethodDoc(); apiMethodDoc.setOrder(methodOrder); - apiMethodDoc.setDesc(method.getComment()); apiMethodDoc.setName(method.getName()); + apiMethodDoc.setDesc(method.getComment()); String methodUid = DocUtil.generateId(clazName + method.getName()); apiMethodDoc.setMethodId(methodUid); String apiNoteValue = DocUtil.getNormalTagComments(method, DocTags.API_NOTE, cls.getName()); @@ -162,7 +162,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { apiMethodDoc.setPath(requestMapping.getShortUrl()); apiMethodDoc.setDeprecated(requestMapping.isDeprecated()); // build request params - List requestParams = requestParams(method, DocTags.PARAM, projectBuilder); + List requestParams = requestParams(method, projectBuilder); if (paramsDataToTree) { requestParams = ApiParamTreeUtil.apiParamToTree(requestParams); } @@ -228,18 +228,13 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { String paramName = parameter.getName(); String typeName = javaType.getFullyQualifiedName(); String gicTypeName = javaType.getGenericCanonicalName(); - String rewriteClassName = null; + String commentClass = paramsComments.get(paramName); //ignore request params if (Objects.nonNull(commentClass) && commentClass.contains(IGNORE)) { continue; } - if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) { - String[] comments = commentClass.split("\\|"); - rewriteClassName = comments[comments.length - 1]; - } else { - rewriteClassName = replacementMap.get(typeName); - } + String rewriteClassName = this.getRewriteClassName(replacementMap, typeName, commentClass); // rewrite class if (DocUtil.isClassName(rewriteClassName)) { gicTypeName = rewriteClassName; @@ -391,14 +386,14 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { String format = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, header.toString(), url); if (requestExample.isJson()) { if (StringUtil.isNotEmpty(requestExample.getJsonBody())) { - exampleBody = String.format(DocGlobalConstants.CURL_POST_PUT_JSON, methodType,header.toString(), url, + exampleBody = String.format(DocGlobalConstants.CURL_POST_PUT_JSON, methodType, header.toString(), url, requestExample.getJsonBody()); } else { exampleBody = format; } } else { if (StringUtil.isNotEmpty(body)) { - exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE_DATA, methodType,header.toString(), url, body); + exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE_DATA, methodType, header.toString(), url, body); } else { exampleBody = format; } @@ -412,7 +407,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { url = StringUtil.removeQuotes(url); url = apiMethodDoc.getServerUrl() + "/" + url; url = UrlUtil.simplifyUrl(url); - exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType,header.toString(), url); + exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, header.toString(), url); requestExample.setExampleBody(exampleBody) .setJsonBody(DocGlobalConstants.EMPTY) .setUrl(url); @@ -420,13 +415,12 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { return requestExample; } - private List requestParams(final JavaMethod javaMethod, final String tagName, ProjectDocConfigBuilder builder) { + private List requestParams(final JavaMethod javaMethod, ProjectDocConfigBuilder builder) { boolean isStrict = builder.getApiConfig().isStrict(); Map responseFieldMap = new HashMap<>(); - - Map replacementMap = builder.getReplaceClassMap(); String className = javaMethod.getDeclaringClass().getCanonicalName(); - Map paramTagMap = DocUtil.getParamsComments(javaMethod, tagName, className); + Map replacementMap = builder.getReplaceClassMap(); + Map paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className); List parameterList = javaMethod.getParameters(); if (parameterList.size() < 1) { return null; @@ -441,21 +435,16 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { String typeName = parameter.getType().getGenericCanonicalName(); String simpleName = parameter.getType().getValue().toLowerCase(); String fullTypeName = parameter.getType().getFullyQualifiedName(); - String rewriteClassName = null; + String commentClass = paramTagMap.get(paramName); - if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) { - String[] comments = commentClass.split("\\|"); - rewriteClassName = comments[comments.length - 1]; - } else { - rewriteClassName = replacementMap.get(fullTypeName); - } + String rewriteClassName = getRewriteClassName(replacementMap, fullTypeName, commentClass); // rewrite class if (DocUtil.isClassName(rewriteClassName)) { typeName = rewriteClassName; fullTypeName = DocClassUtil.getSimpleName(rewriteClassName); } if (JavaClassValidateUtil.isMvcIgnoreParams(typeName, builder.getApiConfig().getIgnoreRequestParams())) { - continue out; + continue; } fullTypeName = DocClassUtil.rewriteRequestParam(fullTypeName); typeName = DocClassUtil.rewriteRequestParam(typeName); @@ -473,7 +462,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { .setId(paramList.size() + 1) .setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION); paramList.add(param); - continue out; + continue; } JavaClass javaClass = builder.getJavaProjectBuilder().getClassByName(fullTypeName); List annotations = parameter.getAnnotations(); @@ -512,7 +501,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { requestBodyCounter++; } } - Boolean required = Boolean.parseBoolean(strRequired); + boolean required = Boolean.parseBoolean(strRequired); if (isPathVariable) { comment = comment + " (This is path param)"; } @@ -554,7 +543,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { .setPathParams(isPathVariable) .setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION); paramList.add(apiParam); - continue out; + continue; } String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName); paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], DocGlobalConstants.EMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0)); @@ -605,4 +594,15 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { } return false; } + + private String getRewriteClassName(Map replacementMap, String fullTypeName, String commentClass) { + String rewriteClassName; + if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) { + String[] comments = commentClass.split("\\|"); + rewriteClassName = comments[comments.length - 1]; + } else { + rewriteClassName = replacementMap.get(fullTypeName); + } + return rewriteClassName; + } }