Skip to content

Commit dc10882

Browse files
committed
Merge branch 'develop'
2 parents e592cde + 3241b1c commit dc10882

69 files changed

Lines changed: 1005 additions & 164 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
- 提供gradle快速发布插件[devops-publish-gradle-plugin](./devops-boot-project/devops-boot-tools/devops-publish-gradle-plugin/README.md)
1212
- 提供统一版本依赖管理[devops-boot-dependencies](./devops-boot-project/devops-boot-dependencies/README.md)
1313
- 提供多个开箱即用的starter组件
14-
- [logging日志组件](./devops-boot-project/devops-boot-starters/devops-boot-starter-logging/README.md)
15-
- TODO
14+
- [starter-logging](./devops-boot-project/devops-boot-starters/devops-boot-starter-logging/README.md)
15+
- [starter-api](./devops-boot-project/devops-boot-starters/devops-boot-starter-api/README.md)
16+
- [starter-web](./devops-boot-project/devops-boot-starters/devops-boot-starter-web/README.md)
17+
- [starter-service](./devops-boot-project/devops-boot-starters/devops-boot-starter-service/README.md)
18+
- TODO
1619

1720
## 快速开始
1821
- **gradle.build.kts**
@@ -59,4 +62,3 @@ devops-framework/
5962
## 发行版本
6063
- 0.0.1 2020年10月9日
6164
- 0.0.2 2020年12月22日
62-

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ object Libs {
1010
object MavenBom {
1111
const val SpringBoot = "org.springframework.boot:spring-boot-dependencies:${Versions.SpringBoot}"
1212
const val SpringCloud = "org.springframework.cloud:spring-cloud-dependencies:${Versions.SpringCloud}"
13+
const val DevOpsBoot = ":devops-boot-project:devops-boot-dependencies"
1314
}

devops-boot-project/devops-boot-core/build.gradle.kts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ subprojects {
2020
mavenBom(MavenBom.SpringBoot)
2121
mavenBom(MavenBom.SpringCloud)
2222
}
23+
pomCustomizationSettings.isEnabled = false
2324
}
2425

2526
dependencies {
27+
implementation(platform(project(MavenBom.DevOpsBoot)))
2628
implementation(Libs.KotlinStdLib)
27-
implementation("org.springframework.boot:spring-boot-starter")
28-
kapt("org.springframework.boot:spring-boot-configuration-processor")
2929
testImplementation("org.springframework.boot:spring-boot-starter-test") {
3030
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
3131
}
@@ -42,11 +42,5 @@ subprojects {
4242
test {
4343
useJUnitPlatform()
4444
}
45-
jar {
46-
manifest {
47-
attributes("Implementation-Title" to (project.description ?: project.name))
48-
attributes("Implementation-Version" to Release.Version)
49-
}
50-
}
5145
}
5246
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description = "DevOps Boot Api"
2+
3+
dependencies {
4+
api("io.swagger:swagger-annotations")
5+
api("io.swagger:swagger-models")
6+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.tencent.devops.api.http
2+
3+
/**
4+
* HTTP Header常量
5+
*/
6+
object HttpHeaders {
7+
const val ACCEPT = "Accept"
8+
const val ACCEPT_CHARSET = "Accept-Charset"
9+
const val ACCEPT_ENCODING = "Accept-Encoding"
10+
const val ACCEPT_LANGUAGE = "Accept-Language"
11+
const val ACCEPT_RANGES = "Accept-Ranges"
12+
const val AGE = "Age"
13+
const val ALLOW = "Allow"
14+
const val AUTHORIZATION = "Authorization"
15+
const val CACHE_CONTROL = "Cache-Control"
16+
const val CONNECTION = "Connection"
17+
const val CONTENT_DISPOSITION = "Content-DISPOSITION"
18+
const val CONTENT_ENCODING = "Content-Encoding"
19+
const val CONTENT_LANGUAGE = "Content-Language"
20+
const val CONTENT_LENGTH = "Content-Length"
21+
const val CONTENT_LOCATION = "Content-Location"
22+
const val CONTENT_MD5 = "Content-MD5"
23+
const val CONTENT_RANGE = "Content-Range"
24+
const val CONTENT_TYPE = "Content-Type"
25+
const val DATE = "Date"
26+
const val DAV = "Dav"
27+
const val DEPTH = "Depth"
28+
const val DESTINATION = "Destination"
29+
const val ETAG = "ETag"
30+
const val EXPECT = "Expect"
31+
const val EXPIRES = "Expires"
32+
const val FROM = "From"
33+
const val HOST = "Host"
34+
const val IF = "If"
35+
const val IF_MATCH = "If-Match"
36+
const val IF_MODIFIED_SINCE = "If-Modified-Since"
37+
const val IF_NONE_MATCH = "If-None-Match"
38+
const val IF_RANGE = "If-Range"
39+
const val IF_UNMODIFIED_SINCE = "If-Unmodified-Since"
40+
const val LAST_MODIFIED = "Last-Modified"
41+
const val LOCATION = "Location"
42+
const val LOCK_TOKEN = "Lock-Token"
43+
const val MAX_FORWARDS = "Max-Forwards"
44+
const val OVERWRITE = "Overwrite"
45+
const val PRAGMA = "Pragma"
46+
const val PROXY_AUTHENTICATE = "Proxy-Authenticate"
47+
const val PROXY_AUTHORIZATION = "Proxy-Authorization"
48+
const val RANGE = "Range"
49+
const val REFERER = "Referer"
50+
const val RETRY_AFTER = "Retry-After"
51+
const val SERVER = "Server"
52+
const val STATUS_URI = "Status-URI"
53+
const val TE = "TE"
54+
const val TIMEOUT = "Timeout"
55+
const val TRAILER = "Trailer"
56+
const val TRANSFER_ENCODING = "Transfer-Encoding"
57+
const val UPGRADE = "Upgrade"
58+
const val USER_AGENT = "User-Agent"
59+
const val VARY = "Vary"
60+
const val VIA = "Via"
61+
const val WARNING = "Warning"
62+
const val WWW_AUTHENTICATE = "WWW-Authenticate"
63+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.tencent.devops.api.http
2+
3+
/**
4+
* HTTP 状态码枚举类
5+
*/
6+
enum class HttpStatus(
7+
val code: Int,
8+
val reasonPhrase: String
9+
) {
10+
CONTINUE(100, "Continue"),
11+
SWITCHING_PROTOCOLS(101, "Switching Protocols"),
12+
PROCESSING(102, "Processing"),
13+
CHECKPOINT(103, "Checkpoint"),
14+
OK(200, "OK"),
15+
CREATED(201, "Created"),
16+
ACCEPTED(202, "Accepted"),
17+
NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
18+
NO_CONTENT(204, "No Content"),
19+
RESET_CONTENT(205, "Reset Content"),
20+
PARTIAL_CONTENT(206, "Partial Content"),
21+
MULTI_STATUS(207, "Multi-Status"),
22+
ALREADY_REPORTED(208, "Already Reported"),
23+
IM_USED(226, "IM Used"), // 3xx Redirection
24+
MULTIPLE_CHOICES(300, "Multiple Choices"),
25+
MOVED_PERMANENTLY(301, "Moved Permanently"),
26+
FOUND(302, "Found"),
27+
MOVED_TEMPORARILY(302, "Moved Temporarily"),
28+
SEE_OTHER(303, "See Other"),
29+
NOT_MODIFIED(304, "Not Modified"),
30+
USE_PROXY(305, "Use Proxy"),
31+
TEMPORARY_REDIRECT(307, "Temporary Redirect"),
32+
PERMANENT_REDIRECT(308, "Permanent Redirect"), // --- 4xx Client Error ---
33+
BAD_REQUEST(400, "Bad Request"),
34+
UNAUTHORIZED(401, "Unauthorized"),
35+
PAYMENT_REQUIRED(402, "Payment Required"),
36+
FORBIDDEN(403, "Forbidden"),
37+
NOT_FOUND(404, "Not Found"),
38+
METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
39+
NOT_ACCEPTABLE(406, "Not Acceptable"),
40+
PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
41+
REQUEST_TIMEOUT(408, "Request Timeout"),
42+
CONFLICT(409, "Conflict"),
43+
GONE(410, "Gone"),
44+
LENGTH_REQUIRED(411, "Length Required"),
45+
PRECONDITION_FAILED(412, "Precondition Failed"),
46+
PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
47+
REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
48+
URI_TOO_LONG(414, "URI Too Long"),
49+
REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),
50+
UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
51+
REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
52+
EXPECTATION_FAILED(417, "Expectation Failed"),
53+
I_AM_A_TEAPOT(418, "I'm a teapot"),
54+
INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"),
55+
METHOD_FAILURE(420, "Method Failure"),
56+
DESTINATION_LOCKED(421, "Destination Locked"),
57+
UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
58+
LOCKED(423, "Locked"),
59+
FAILED_DEPENDENCY(424, "Failed Dependency"),
60+
TOO_EARLY(425, "Too Early"),
61+
UPGRADE_REQUIRED(426, "Upgrade Required"),
62+
PRECONDITION_REQUIRED(428, "Precondition Required"),
63+
TOO_MANY_REQUESTS(429, "Too Many Requests"),
64+
REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),
65+
UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"), // --- 5xx Server Error ---
66+
INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
67+
NOT_IMPLEMENTED(501, "Not Implemented"),
68+
BAD_GATEWAY(502, "Bad Gateway"),
69+
SERVICE_UNAVAILABLE(503, "Service Unavailable"),
70+
GATEWAY_TIMEOUT(504, "Gateway Timeout"),
71+
HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Versio n not supported"),
72+
VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
73+
INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
74+
LOOP_DETECTED(508, "Loop Detected"),
75+
BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
76+
NOT_EXTENDED(510, "Not Extended"),
77+
NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
78+
79+
companion object {
80+
81+
/**
82+
* 根据[code]查询HttpStatus
83+
* 当[code]对应的HttpStatus不存在时抛出[IllegalArgumentException]异常
84+
*/
85+
fun ofCode(code: Int): HttpStatus {
86+
return ofCodeOrNull(code) ?: throw IllegalArgumentException("No matching constant for [$code]")
87+
}
88+
89+
/**
90+
* 根据[code]查询HttpStatus
91+
* 当[code]对应的HttpStatus不存在时返回null
92+
*/
93+
fun ofCodeOrNull(code: Int): HttpStatus? {
94+
for (status in values()) {
95+
if (status.code == code) {
96+
return status
97+
}
98+
}
99+
return null
100+
}
101+
}
102+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.tencent.devops.api.http
2+
3+
/**
4+
* HTTP Media Type常量
5+
*/
6+
object MediaTypes {
7+
const val APPLICATION_OCTET_STREAM = "application/octet-stream"
8+
const val APPLICATION_JSON = "application/json; charset=utf-8"
9+
const val TEXT_HTML = "text/html"
10+
const val APPLICATION_YAML = "application/x-yaml"
11+
const val APPLICATION_TGZ = "application/x-tar"
12+
const val APPLICATION_ICO = "image/x-icon"
13+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.tencent.devops.api.pojo
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore
4+
import io.swagger.annotations.ApiModel
5+
import io.swagger.annotations.ApiModelProperty
6+
7+
@ApiModel("数据返回包装模型")
8+
data class Response<out T>(
9+
@ApiModelProperty("返回码")
10+
val code: Int,
11+
@ApiModelProperty("提示信息")
12+
val message: String? = null,
13+
@ApiModelProperty("数据")
14+
val data: T? = null
15+
) {
16+
/**
17+
* 根据返回码判断是否成功
18+
*/
19+
@JsonIgnore
20+
fun isOk(): Boolean {
21+
return code == SUCCESS
22+
}
23+
24+
/**
25+
* 根据返回码判断是否失败
26+
*/
27+
@JsonIgnore
28+
fun isNotOk(): Boolean {
29+
return !isOk()
30+
}
31+
32+
companion object {
33+
34+
/**
35+
* 成功返回码
36+
*/
37+
private const val SUCCESS = 0
38+
39+
/**
40+
* 成功响应体,返回数据为空
41+
*/
42+
fun success() = Response(SUCCESS, null, null)
43+
44+
/**
45+
* 成功响应体
46+
* @param data 数据
47+
*/
48+
fun <T> success(data: T) = Response(SUCCESS, null, data)
49+
50+
/**
51+
* 错误响应体
52+
* @param code 错误返回码
53+
* @param message 错误提示信息
54+
*/
55+
fun fail(code: Int, message: String) = Response<Void>(code, message, null)
56+
}
57+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
description = "DevOps Boot"
1+
description = "DevOps Boot"
2+
3+
dependencies {
4+
compileOnly("org.springframework.boot:spring-boot")
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.tencent.devops.boot
2+
3+
import org.springframework.boot.SpringApplication
4+
import org.springframework.context.ConfigurableApplicationContext
5+
6+
/**
7+
* SpringBoot 提供的runApplication(vararg args: String)方法使用了kotlin的变长参数传递,会导致detekt提示`SpreadOperator`问题
8+
* 利用数组传递可以避免此问题
9+
*/
10+
inline fun <reified T : Any> runApplication(args: Array<String>): ConfigurableApplicationContext {
11+
return SpringApplication.run(arrayOf(T::class.java), args)
12+
}

0 commit comments

Comments
 (0)