Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit 016c0b6

Browse files
committed
Optimize source code loading performance
1 parent 3e295f2 commit 016c0b6

File tree

6 files changed

+101
-108
lines changed

6 files changed

+101
-108
lines changed

CHANGELOG.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
## smart-doc-gradle-plugin版本
2-
### 版本号:1.0.0
3-
- 更新日期:2020-05-15
4-
- 更新内容:
5-
1. 1.0.0依赖smart-doc 1.8.1
6-
1+
## smart-doc-gradle-plugin版本
2+
### 版本号:1.0.0
3+
- 更新日期:2020-05-15
4+
- 更新内容:
5+
1. 1.0.0依赖smart-doc 1.8.1
6+
### 版本号:1.2.1
7+
- 更新日期:2020-10-24
8+
- 更新内容:
9+
1. Optimize source code loading performance
10+
711

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
group 'com.github.shalousun'
19-
version '1.2.0'
19+
version '1.2.1'
2020

2121
sourceCompatibility = 1.8
2222

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,74 @@
1-
/*
2-
* smart-doc https://github.com/shalousun/smart-doc
3-
*
4-
* Copyright (C) 2018-2020 smart-doc
5-
*
6-
* Licensed to the Apache Software Foundation (ASF) under one
7-
* or more contributor license agreements. See the NOTICE file
8-
* distributed with this work for additional information
9-
* regarding copyright ownership. The ASF licenses this file
10-
* to you under the Apache License, Version 2.0 (the
11-
* "License"); you may not use this file except in compliance
12-
* with the License. You may obtain a copy of the License at
13-
*
14-
* http://www.apache.org/licenses/LICENSE-2.0
15-
*
16-
* Unless required by applicable law or agreed to in writing,
17-
* software distributed under the License is distributed on an
18-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19-
* KIND, either express or implied. See the License for the
20-
* specific language governing permissions and limitations
21-
* under the License.
22-
*/
23-
package com.smartdoc.gradle.chain;
24-
25-
26-
import com.smartdoc.gradle.model.CustomArtifact;
27-
28-
/**
29-
* @author yu 2020/1/13.
30-
*/
31-
public class CommonArtifactFilterChain implements FilterChain {
32-
33-
private FilterChain filterChain;
34-
35-
@Override
36-
public void setNext(FilterChain nextInChain) {
37-
this.filterChain = nextInChain;
38-
}
39-
40-
@Override
41-
public boolean ignoreArtifactById(CustomArtifact artifact) {
42-
String artifactId = artifact.getArtifactId();
43-
switch (artifactId) {
44-
case "bcprov-jdk15on":
45-
case "lombok":
46-
case "jsqlparser":
47-
case "disruptor":
48-
case "commons-codec":
49-
case "snakeyaml":
50-
case "spring-boot-autoconfigure":
51-
case "HikariCP":
52-
case "mysql-connector-java":
53-
case "classmate":
54-
case "commons-lang3":
55-
case "spring-web":
56-
case "spring-webmvc":
57-
case "hibernate-validator":
58-
case "xstream":
59-
case "guava":
60-
case "spring-tx":
61-
case "javassist":
62-
return true;
63-
default:
64-
return this.ignore(filterChain, artifact);
65-
}
66-
}
67-
}
1+
/*
2+
* smart-doc https://github.com/shalousun/smart-doc
3+
*
4+
* Copyright (C) 2018-2020 smart-doc
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one
7+
* or more contributor license agreements. See the NOTICE file
8+
* distributed with this work for additional information
9+
* regarding copyright ownership. The ASF licenses this file
10+
* to you under the Apache License, Version 2.0 (the
11+
* "License"); you may not use this file except in compliance
12+
* with the License. You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing,
17+
* software distributed under the License is distributed on an
18+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19+
* KIND, either express or implied. See the License for the
20+
* specific language governing permissions and limitations
21+
* under the License.
22+
*/
23+
package com.smartdoc.gradle.chain;
24+
25+
26+
import com.smartdoc.gradle.model.CustomArtifact;
27+
28+
/**
29+
* @author yu 2020/1/13.
30+
*/
31+
public class CommonArtifactFilterChain implements FilterChain {
32+
33+
private FilterChain filterChain;
34+
35+
@Override
36+
public void setNext(FilterChain nextInChain) {
37+
this.filterChain = nextInChain;
38+
}
39+
40+
@Override
41+
public boolean ignoreArtifactById(CustomArtifact artifact) {
42+
String artifactId = artifact.getArtifactId();
43+
switch (artifactId) {
44+
case "bcprov-jdk15on":
45+
case "lombok":
46+
case "jsqlparser":
47+
case "disruptor":
48+
case "commons-codec":
49+
case "snakeyaml":
50+
case "spring-boot-autoconfigure":
51+
case "HikariCP":
52+
case "mysql-connector-java":
53+
case "classmate":
54+
case "commons-lang3":
55+
case "spring-web":
56+
case "spring-webmvc":
57+
case "hibernate-validator":
58+
case "xstream":
59+
case "guava":
60+
case "spring-tx":
61+
case "javassist":
62+
case "qdox":
63+
case "smart-doc-gradle-plugin":
64+
case "javafaker":
65+
case "antlr4-runtime":
66+
case "gson":
67+
case "annotations":
68+
case "spring-aop":
69+
return true;
70+
default:
71+
return this.ignore(filterChain, artifact);
72+
}
73+
}
74+
}

src/main/java/com/smartdoc/gradle/constant/GlobalConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ public interface GlobalConstants {
5151

5252
String EXTENSION_NAME = "smartdoc";
5353

54-
String SRC_MAIN_JAVA_PATH = "/src/main/java";
54+
String SRC_MAIN_JAVA_PATH = "src/main/java";
5555
}

src/main/java/com/smartdoc/gradle/task/DocBaseTask.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import com.power.common.constants.Charset;
2626
import com.power.common.util.RegexUtil;
27-
import com.power.common.util.StringUtil;
2827
import com.power.doc.model.ApiConfig;
2928
import com.smartdoc.gradle.constant.GlobalConstants;
3029
import com.smartdoc.gradle.extension.SmartDocPluginExtension;
@@ -133,6 +132,9 @@ private void loadSourcesDependencies(JavaProjectBuilder javaDocBuilder, Project
133132
moduleArtifact = CustomArtifact.builder().setGroup(version.getId().getGroup())
134133
.setArtifactId(version.getId().getName())
135134
.setVersion(version.getId().getVersion());
135+
// add local source
136+
String artifactName = moduleArtifact.getGroup() + ":" + moduleArtifact.getArtifactId();
137+
addModuleSourceTree(javaDocBuilder, allModules, artifactName);
136138

137139
}
138140
CustomArtifact artifact = selfModule ? moduleArtifact : CustomArtifact.builder(displayName);
@@ -190,11 +192,11 @@ private void loadSourcesDependency(JavaProjectBuilder javaDocBuilder, DefaultRes
190192
}
191193
}
192194

193-
private void addModuleSourceTree(JavaProjectBuilder javaDocBuilder, TreeMap<String, Project> allModules, String displayName) {
194-
String moduleName = StringUtil.removePrefix(displayName, "project ");
195-
Project module = allModules.getOrDefault(moduleName, null);
195+
private void addModuleSourceTree(JavaProjectBuilder javaDocBuilder, TreeMap<String, Project> allModules, String artifactName) {
196+
Project module = allModules.getOrDefault(artifactName, null);
196197
if (module != null) {
197198
String modelSrc = String.join(File.separator, module.getProjectDir().getAbsolutePath(), GlobalConstants.SRC_MAIN_JAVA_PATH);
199+
getLogger().quiet("The loaded local code path is "+modelSrc);
198200
javaDocBuilder.addSourceTree(new File(modelSrc));
199201
}
200202
}
@@ -205,7 +207,7 @@ private TreeMap<String, Project> getAllModule(Project rootProject) {
205207
return result;
206208
}
207209
if (rootProject.getDepth() != 0) {
208-
result.put(rootProject.getPath(), rootProject);
210+
result.put(rootProject.getGroup() + ":" + rootProject.getName(), rootProject);
209211
}
210212
if (rootProject.getChildProjects().isEmpty()) {
211213
return result;

src/main/java/com/smartdoc/gradle/util/GradleUtil.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@
2828
import com.google.gson.GsonBuilder;
2929
import com.power.common.util.FileUtil;
3030
import com.power.doc.model.*;
31-
import org.apache.commons.lang3.StringUtils;
31+
import org.gradle.api.Project;
32+
import org.gradle.api.logging.Logger;
3233

3334
import java.io.File;
3435
import java.io.FileInputStream;
3536
import java.io.FileNotFoundException;
36-
import java.util.List;
37-
import java.util.Objects;
38-
import java.util.Set;
39-
40-
import org.gradle.api.Project;
41-
import org.gradle.api.logging.Logger;
37+
import java.util.*;
4238

4339
/**
4440
* @author yu 2020/2/16.
@@ -62,12 +58,12 @@ public boolean shouldSkipClass(Class<?> aClass) {
6258
/**
6359
* Build ApiConfig
6460
*
65-
* @param configFile config file
66-
* @param project Project object
67-
* @param log gradle plugin log
61+
* @param configFile config file
62+
* @param project Project object
63+
* @param log gradle plugin log
6864
* @return com.power.doc.model.ApiConfig
6965
*/
70-
public static ApiConfig buildConfig(File configFile, Project project, Logger log) {
66+
public static ApiConfig buildConfig(File configFile, Project project, Logger log) {
7167
try {
7268
ClassLoader classLoader = ClassLoaderUtil.getRuntimeClassLoader(project);
7369
String data = FileUtil.getFileContent(new FileInputStream(configFile));
@@ -125,22 +121,6 @@ public static Class getClassByClassName(String className, ClassLoader classLoade
125121
}
126122

127123
private static void addSourcePaths(Project project, ApiConfig apiConfig, Logger log) {
128-
Set<Project> sourceRoots = project.getAllprojects();
129-
sourceRoots.forEach(s -> {
130-
log.info("path",s.getPath());
131-
apiConfig.setSourceCodePaths(SourceCodePath.path().setPath(s.getPath()));
132-
});
133-
if (Objects.nonNull(project.getParent())) {
134-
Project mavenProject = project.getParent();
135-
if (null != mavenProject) {
136-
log.info("--- parent project name is [" + mavenProject.getName() + "]");
137-
File file = mavenProject.getProjectDir();
138-
if (!Objects.isNull(file)) {
139-
log.info("--- parent project basedir is " + file.getPath());
140-
apiConfig.setSourceCodePaths(SourceCodePath.path().setPath(file.getPath()));
141-
// log.info("--- smart-doc-maven-plugin loaded resource from " + file.getPath());
142-
}
143-
}
144-
}
124+
// do nothing
145125
}
146126
}

0 commit comments

Comments
 (0)