optimized code
This commit is contained in:
parent
cd38219059
commit
c76e6d0762
8
pom.xml
8
pom.xml
|
@ -59,7 +59,7 @@
|
|||
<dependency>
|
||||
<groupId>com.github.shalousun</groupId>
|
||||
<artifactId>common-util</artifactId>
|
||||
<version>1.8.5</version>
|
||||
<version>1.8.6</version>
|
||||
</dependency>
|
||||
<!--markdown to html-->
|
||||
<dependency>
|
||||
|
@ -84,7 +84,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
@ -109,7 +109,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
|
|
@ -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<ApiDoc> 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<SourceCodePath> 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
|
||||
*
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -114,20 +114,20 @@ public class DocClassUtil {
|
|||
List<String> classes = new ArrayList<>();
|
||||
List<Integer> 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]);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue