diff --git a/pom.xml b/pom.xml index 41711ca..5ed4563 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ com.github.shalousun common-util - 1.8.5 + 1.8.6 @@ -84,7 +84,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.0 + 3.8.1 1.8 1.8 @@ -95,7 +95,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.1.0 package @@ -109,7 +109,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.0 + 3.1.1 package diff --git a/src/main/java/com/power/doc/builder/SourceBuilder.java b/src/main/java/com/power/doc/builder/SourceBuilder.java index 41764fd..902435e 100644 --- a/src/main/java/com/power/doc/builder/SourceBuilder.java +++ b/src/main/java/com/power/doc/builder/SourceBuilder.java @@ -10,7 +10,6 @@ import com.power.doc.constants.DocTags; import com.power.doc.model.*; import com.power.doc.utils.DocClassUtil; import com.power.doc.utils.DocUtil; -import com.power.doc.utils.PathUtil; import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.*; import org.apache.commons.codec.digest.DigestUtils; @@ -93,6 +92,7 @@ public class SourceBuilder { /** * Get api data + * * @return List of api data */ public List getControllerApiData() { @@ -219,7 +219,7 @@ public class SourceBuilder { url = url.replaceAll("\"", "").trim(); apiMethodDoc.setType(methodType); url = this.appUrl + "/" + baseUrl + "/" + url; - apiMethodDoc.setUrl(PathUtil.processHttpUrl(url)); + apiMethodDoc.setUrl(UrlUtil.simplifyUrl(url)); String comment = getCommentTag(method, "param", cls.getCanonicalName()); apiMethodDoc.setRequestParams(comment); String requestJson = buildReqJson(method, apiMethodDoc); @@ -245,8 +245,11 @@ public class SourceBuilder { private void loadJavaFiles(List paths) { JavaProjectBuilder builder = new JavaProjectBuilder(); if (CollectionUtil.isEmpty(paths)) { - builder.addSourceTree(new File("src/main/java")); + builder.addSourceTree(new File(DocGlobalConstants.PROJECT_CODE_PATH)); } else { + if (!paths.contains(DocGlobalConstants.PROJECT_CODE_PATH)) { + builder.addSourceTree(new File(DocGlobalConstants.PROJECT_CODE_PATH)); + } for (SourceCodePath path : paths) { if (null == path) { continue; @@ -264,6 +267,7 @@ public class SourceBuilder { javaFilesMap.put(cls.getFullyQualifiedName(), cls); } } + /** * create request headers * diff --git a/src/main/java/com/power/doc/constants/DocGlobalConstants.java b/src/main/java/com/power/doc/constants/DocGlobalConstants.java index 68ad2f3..ba9de02 100644 --- a/src/main/java/com/power/doc/constants/DocGlobalConstants.java +++ b/src/main/java/com/power/doc/constants/DocGlobalConstants.java @@ -9,6 +9,8 @@ public class DocGlobalConstants { public static final String HTML_DOC_OUT_PATH = "src/main/resources/static/doc"; + public static final String PROJECT_CODE_PATH = "src/main/java"; + public static final String DOC_LANGUAGE = "smart-doc_language"; public static final String API_DOC_TPL = "ApiDoc.btl"; diff --git a/src/main/java/com/power/doc/utils/DocClassUtil.java b/src/main/java/com/power/doc/utils/DocClassUtil.java index 92a1df8..d396785 100644 --- a/src/main/java/com/power/doc/utils/DocClassUtil.java +++ b/src/main/java/com/power/doc/utils/DocClassUtil.java @@ -114,20 +114,20 @@ public class DocClassUtil { List classes = new ArrayList<>(); List indexList = new ArrayList<>(); int globIndex = 0; - for (int i = 0; i < arr.length; i++) { + int length = arr.length; + for (int i = 0; i < length; i++) { if (classes.size() > 0) { int index = classes.size() - 1; if (!DocUtil.isClassName(classes.get(index))) { globIndex = globIndex + 1; - if (globIndex < arr.length) { + if (globIndex < length) { indexList.add(globIndex); String className = classes.get(index) + "," + arr[globIndex]; classes.set(index, className); } - } else { globIndex = globIndex + 1; - if (globIndex < arr.length) { + if (globIndex < length) { if (DocUtil.isClassName(arr[globIndex])) { indexList.add(globIndex); classes.add(arr[globIndex]); diff --git a/src/main/java/com/power/doc/utils/PathUtil.java b/src/main/java/com/power/doc/utils/PathUtil.java index ca2202b..ad434fe 100644 --- a/src/main/java/com/power/doc/utils/PathUtil.java +++ b/src/main/java/com/power/doc/utils/PathUtil.java @@ -24,16 +24,4 @@ public class PathUtil { className = className.replaceAll("\\.", "\\" + File.separator); return parentDir + className + ".java"; } - - /** - * Replace '//' with '/' in the url. - * @param url url - * @return processed url - */ - public static String processHttpUrl(String url) { - int index = url.indexOf("//"); - String urlHead = url.substring(0, index + 2); - String urlTail = url.substring(index + 2, url.length()).replaceAll("/+", "/"); - return new StringBuilder().append(urlHead).append(urlTail).toString(); - } } diff --git a/src/test/java/com/power/doc/ApiDocTest.java b/src/test/java/com/power/doc/ApiDocTest.java index 1c00b40..ff40b07 100644 --- a/src/test/java/com/power/doc/ApiDocTest.java +++ b/src/test/java/com/power/doc/ApiDocTest.java @@ -38,8 +38,9 @@ public class ApiDocTest { config.setAllInOne(false); config.setOutPath("d:\\md2"); + config.setMd5EncryptedHtmlName(true); //不指定SourcePaths默认加载代码为项目src/main/java下的 - config.setSourcePaths( + config.setSourceCodePaths( SourceCodePath.path().setDesc("本项目代码").setPath("src/test/java") //SourcePath.path().setPath("F:\\Personal\\project\\smart\\src\\main\\java") //SourcePath.path().setDesc("加载项目外代码").setPath("E:\\ApplicationPower\\ApplicationPower\\Common-util\\src\\main\\java")