1
1
package scripts
2
2
3
+
3
4
import com.google.common.io.Resources
4
5
import groovy.json.JsonBuilder
5
6
import org.apache.commons.io.Charsets
7
+ import org.apache.commons.io.FileUtils
6
8
import org.apache.commons.lang.StringUtils
7
9
import org.jsoup.Jsoup
8
10
import org.jsoup.nodes.Document
@@ -12,12 +14,7 @@ import org.jsoup.select.Elements
12
14
import org.markdown4j.Markdown4jProcessor
13
15
import org.springframework.http.HttpMethod
14
16
import org.zstack.core.Platform
15
- import org.zstack.core.config.GlobalConfig
16
- import org.zstack.core.config.GlobalConfigDef
17
- import org.zstack.core.config.GlobalConfigDefinition
18
- import org.zstack.core.config.GlobalConfigException
19
- import org.zstack.core.config.GlobalConfigValidation
20
- import org.zstack.core.config.GlobalConfigValidatorExtensionPoint
17
+ import org.zstack.core.config.*
21
18
import org.zstack.header.core.NoDoc
22
19
import org.zstack.header.errorcode.ErrorCode
23
20
import org.zstack.header.exception.CloudRuntimeException
@@ -30,9 +27,9 @@ import org.zstack.header.query.APIQueryMessage
30
27
import org.zstack.header.rest.APINoSee
31
28
import org.zstack.header.rest.RestRequest
32
29
import org.zstack.header.rest.RestResponse
30
+ import org.zstack.resourceconfig.BindResourceConfig
33
31
import org.zstack.rest.RestConstants
34
32
import org.zstack.rest.sdk.DocumentGenerator
35
- import org.zstack.resourceconfig.BindResourceConfig
36
33
import org.zstack.utils.*
37
34
import org.zstack.utils.data.StringTemplate
38
35
import org.zstack.utils.gson.JSONObjectUtil
@@ -51,6 +48,7 @@ import java.nio.file.Paths
51
48
import java.util.regex.Matcher
52
49
import java.util.regex.Pattern
53
50
import java.util.stream.Collectors
51
+
54
52
/**
55
53
* Created by xing5 on 2016/12/21.
56
54
*/
@@ -435,6 +433,8 @@ class RestDocumentationGenerator implements DocumentGenerator {
435
433
436
434
String rootPath
437
435
436
+ String projectVersion
437
+
438
438
Map<String , File > sourceFiles = [:]
439
439
440
440
def MUTUAL_FIELDS = [
@@ -505,9 +505,25 @@ class RestDocumentationGenerator implements DocumentGenerator {
505
505
c(emc)
506
506
}
507
507
508
+ void tryInitVersionOfCurrentRepo () {
509
+ def f = new File (" ${ rootPath} /VERSION" )
510
+ if (! f. exists()) {
511
+ println (" missing version file[path: ${ rootPath} /VERSION]" )
512
+ return
513
+ }
514
+
515
+ def versionNumber = []
516
+ FileUtils . readLines(f). each { String line ->
517
+ versionNumber. add(line. split(" =" )[1 ]. trim())
518
+ }
519
+
520
+ projectVersion = versionNumber. join(" ." )
521
+ }
522
+
508
523
@Override
509
524
void generateDocTemplates (String scanPath , DocMode mode ) {
510
525
rootPath = scanPath
526
+ tryInitVersionOfCurrentRepo()
511
527
scanJavaSourceFiles()
512
528
513
529
Set<Class > apiClasses = getRequestRequestApiSet()
@@ -2081,7 +2097,7 @@ ${txt}
2081
2097
\t\t name "${ n} "
2082
2098
\t\t desc "${ desc == null ? "" : desc} "
2083
2099
\t\t type "${ type} "
2084
- \t\t since "0.6"
2100
+ \t\t since "${ projectVersion != null ? projectVersion : " 0.6" } "
2085
2101
\t }"""
2086
2102
}
2087
2103
@@ -2097,7 +2113,7 @@ ${txt}
2097
2113
\t\t path "${ path} "
2098
2114
\t\t desc "${ desc} "${ overrideDesc != null ? ",${overrideDesc}" : ""}
2099
2115
\t\t type "${ type} "
2100
- \t\t since "0.6"
2116
+ \t\t since "${ projectVersion != null ? projectVersion : " 0.6" } "
2101
2117
\t\t clz ${ clz.simpleName} .class
2102
2118
\t }"""
2103
2119
}
@@ -2273,7 +2289,7 @@ ${fieldStr}
2273
2289
\t\t\t\t\t location "${ location} "
2274
2290
\t\t\t\t\t type "${ af.type.simpleName} "
2275
2291
\t\t\t\t\t optional ${ ap == null ? true : !ap.required()}
2276
- \t\t\t\t\t since "0.6"
2292
+ \t\t\t\t\t since "${ projectVersion != null ? projectVersion : " 0.6" } "
2277
2293
""" )
2278
2294
if (values != null ) {
2279
2295
cols. add(" \t\t\t\t\t ${ values} " )
0 commit comments