optimized code

This commit is contained in:
oppofind 2019-09-25 13:16:08 +08:00
parent cd38219059
commit c76e6d0762
6 changed files with 19 additions and 24 deletions

View File

@ -59,7 +59,7 @@
<dependency> <dependency>
<groupId>com.github.shalousun</groupId> <groupId>com.github.shalousun</groupId>
<artifactId>common-util</artifactId> <artifactId>common-util</artifactId>
<version>1.8.5</version> <version>1.8.6</version>
</dependency> </dependency>
<!--markdown to html--> <!--markdown to html-->
<dependency> <dependency>
@ -84,7 +84,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version> <version>3.8.1</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
@ -95,7 +95,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version> <version>3.1.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -109,7 +109,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version> <version>3.1.1</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>

View File

@ -10,7 +10,6 @@ import com.power.doc.constants.DocTags;
import com.power.doc.model.*; import com.power.doc.model.*;
import com.power.doc.utils.DocClassUtil; import com.power.doc.utils.DocClassUtil;
import com.power.doc.utils.DocUtil; import com.power.doc.utils.DocUtil;
import com.power.doc.utils.PathUtil;
import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.JavaProjectBuilder;
import com.thoughtworks.qdox.model.*; import com.thoughtworks.qdox.model.*;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -93,6 +92,7 @@ public class SourceBuilder {
/** /**
* Get api data * Get api data
*
* @return List of api data * @return List of api data
*/ */
public List<ApiDoc> getControllerApiData() { public List<ApiDoc> getControllerApiData() {
@ -219,7 +219,7 @@ public class SourceBuilder {
url = url.replaceAll("\"", "").trim(); url = url.replaceAll("\"", "").trim();
apiMethodDoc.setType(methodType); apiMethodDoc.setType(methodType);
url = this.appUrl + "/" + baseUrl + "/" + url; url = this.appUrl + "/" + baseUrl + "/" + url;
apiMethodDoc.setUrl(PathUtil.processHttpUrl(url)); apiMethodDoc.setUrl(UrlUtil.simplifyUrl(url));
String comment = getCommentTag(method, "param", cls.getCanonicalName()); String comment = getCommentTag(method, "param", cls.getCanonicalName());
apiMethodDoc.setRequestParams(comment); apiMethodDoc.setRequestParams(comment);
String requestJson = buildReqJson(method, apiMethodDoc); String requestJson = buildReqJson(method, apiMethodDoc);
@ -245,8 +245,11 @@ public class SourceBuilder {
private void loadJavaFiles(List<SourceCodePath> paths) { private void loadJavaFiles(List<SourceCodePath> paths) {
JavaProjectBuilder builder = new JavaProjectBuilder(); JavaProjectBuilder builder = new JavaProjectBuilder();
if (CollectionUtil.isEmpty(paths)) { if (CollectionUtil.isEmpty(paths)) {
builder.addSourceTree(new File("src/main/java")); builder.addSourceTree(new File(DocGlobalConstants.PROJECT_CODE_PATH));
} else { } else {
if (!paths.contains(DocGlobalConstants.PROJECT_CODE_PATH)) {
builder.addSourceTree(new File(DocGlobalConstants.PROJECT_CODE_PATH));
}
for (SourceCodePath path : paths) { for (SourceCodePath path : paths) {
if (null == path) { if (null == path) {
continue; continue;
@ -264,6 +267,7 @@ public class SourceBuilder {
javaFilesMap.put(cls.getFullyQualifiedName(), cls); javaFilesMap.put(cls.getFullyQualifiedName(), cls);
} }
} }
/** /**
* create request headers * create request headers
* *

View File

@ -9,6 +9,8 @@ public class DocGlobalConstants {
public static final String HTML_DOC_OUT_PATH = "src/main/resources/static/doc"; 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 DOC_LANGUAGE = "smart-doc_language";
public static final String API_DOC_TPL = "ApiDoc.btl"; public static final String API_DOC_TPL = "ApiDoc.btl";

View File

@ -114,20 +114,20 @@ public class DocClassUtil {
List<String> classes = new ArrayList<>(); List<String> classes = new ArrayList<>();
List<Integer> indexList = new ArrayList<>(); List<Integer> indexList = new ArrayList<>();
int globIndex = 0; 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) { if (classes.size() > 0) {
int index = classes.size() - 1; int index = classes.size() - 1;
if (!DocUtil.isClassName(classes.get(index))) { if (!DocUtil.isClassName(classes.get(index))) {
globIndex = globIndex + 1; globIndex = globIndex + 1;
if (globIndex < arr.length) { if (globIndex < length) {
indexList.add(globIndex); indexList.add(globIndex);
String className = classes.get(index) + "," + arr[globIndex]; String className = classes.get(index) + "," + arr[globIndex];
classes.set(index, className); classes.set(index, className);
} }
} else { } else {
globIndex = globIndex + 1; globIndex = globIndex + 1;
if (globIndex < arr.length) { if (globIndex < length) {
if (DocUtil.isClassName(arr[globIndex])) { if (DocUtil.isClassName(arr[globIndex])) {
indexList.add(globIndex); indexList.add(globIndex);
classes.add(arr[globIndex]); classes.add(arr[globIndex]);

View File

@ -24,16 +24,4 @@ public class PathUtil {
className = className.replaceAll("\\.", "\\" + File.separator); className = className.replaceAll("\\.", "\\" + File.separator);
return parentDir + className + ".java"; 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();
}
} }

View File

@ -38,8 +38,9 @@ public class ApiDocTest {
config.setAllInOne(false); config.setAllInOne(false);
config.setOutPath("d:\\md2"); config.setOutPath("d:\\md2");
config.setMd5EncryptedHtmlName(true);
//不指定SourcePaths默认加载代码为项目src/main/java下的 //不指定SourcePaths默认加载代码为项目src/main/java下的
config.setSourcePaths( config.setSourceCodePaths(
SourceCodePath.path().setDesc("本项目代码").setPath("src/test/java") SourceCodePath.path().setDesc("本项目代码").setPath("src/test/java")
//SourcePath.path().setPath("F:\\Personal\\project\\smart\\src\\main\\java") //SourcePath.path().setPath("F:\\Personal\\project\\smart\\src\\main\\java")
//SourcePath.path().setDesc("加载项目外代码").setPath("E:\\ApplicationPower\\ApplicationPower\\Common-util\\src\\main\\java") //SourcePath.path().setDesc("加载项目外代码").setPath("E:\\ApplicationPower\\ApplicationPower\\Common-util\\src\\main\\java")