diff --git a/README.en.md b/README.en.md index 1b641b79..5428758c 100644 --- a/README.en.md +++ b/README.en.md @@ -1,6 +1,8 @@ [![CI](https://github.com/jinganix/guess/actions/workflows/ci.yml/badge.svg)](https://github.com/jinganix/guess/actions/workflows/ci.yml) [![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) +[中文版本](README.md) + # Guess The source code of the 'Guess Who I Am' Wechat miniprogram, you can [scan to experience](#qr-code) the miniprogram diff --git a/README.md b/README.md index 2a767486..0888433c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ [![CI](https://github.com/jinganix/guess/actions/workflows/ci.yml/badge.svg)](https://github.com/jinganix/guess/actions/workflows/ci.yml) [![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) +[English Version](README.en.md) + # 猜我是谁 本仓库是《猜我是谁》微信小程序的源码,你可以[扫码体验](#qr-code)此小程序 @@ -44,7 +46,7 @@ docker-compose up - spring.datasource.username: 数据库用户名 - spring.datasource.password: 数据库密码 -以下命令可以在`Linux`或`MacOd`系统中启动后端服务 +以下命令可以在`Linux`或`MacOS`系统中启动后端服务 ```shell ./gradlew service:guess:bootRun diff --git a/aggregation/build.gradle.kts b/aggregation/build.gradle.kts deleted file mode 100644 index d0e2a910..00000000 --- a/aggregation/build.gradle.kts +++ /dev/null @@ -1,82 +0,0 @@ -import utils.Props -import utils.createConfiguration -import utils.extractDependencies - -plugins { - id("jacoco.aggregation") -} - -repositories { - gradlePluginPortal() -} - -val buildSrcDependencies = extractDependencies(file("${rootDir}/buildSrc/build.gradle.kts")) - -configurations.implementation.get().dependencies.forEach { - if (it is ModuleDependency) { - it.isTransitive = false - } -} - -val incomingClassDirs = createConfiguration("incomingClassDirs", "classDirs") { - extendsFrom(configurations.implementation.get()) - isCanBeResolved = true - isCanBeConsumed = false -} - -val incomingSourceDirs = createConfiguration("incomingSourceDirs", "sourceDirs") { - extendsFrom(configurations.implementation.get()) - isCanBeResolved = true - isCanBeConsumed = false -} - -val incomingCoverageData = createConfiguration("incomingCoverageData", "coverageData") { - extendsFrom(configurations.implementation.get()) - isCanBeResolved = true - isCanBeConsumed = false -} - -fun updateJacocoReport(base: JacocoReportBase) { - base.additionalClassDirs(incomingClassDirs.incoming.artifactView { - lenient(true) - }.files.asFileTree.matching { - }) - base.additionalSourceDirs(incomingSourceDirs.incoming.artifactView { lenient(true) }.files) - base.executionData(incomingCoverageData.incoming.artifactView { lenient(true) }.files.filter { it.exists() }) -} - -val coverageVerification by tasks.registering(JacocoCoverageVerification::class) { - enabled = Props.coverage - updateJacocoReport(this) - - violationRules { - rule { limit { minimum = BigDecimal.valueOf(Props.jacocoMinCoverage) } } - } -} - -val coverage by tasks.registering(JacocoReport::class) { - enabled = Props.coverage - updateJacocoReport(this) - - reports { - xml.required.set(true) - html.required.set(true) - } -} - -val configCoveralls by tasks.registering(DefaultTask::class) { - coveralls { - sourceDirs = incomingSourceDirs.incoming.artifactView { lenient(true) }.files.map { - it.absolutePath - } - jacocoReportPath = "build/reports/jacoco/coverage/coverage.xml" - } -} - -tasks.coveralls { - dependsOn(configCoveralls) -} - -tasks.check { - dependsOn(coverageVerification) -} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index e352e93e..61317809 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -6,8 +6,22 @@ plugins { `maven-publish` } +val javaVersion = JavaVersion.VERSION_21 + +java { + sourceCompatibility = javaVersion + targetCompatibility = javaVersion +} + +tasks.compileKotlin { + kotlinOptions { + jvmTarget = javaVersion.toString() + } +} + repositories { gradlePluginPortal() + mavenCentral() } val properties = Properties() diff --git a/buildSrc/src/main/kotlin/conventions.common.gradle.kts b/buildSrc/src/main/kotlin/conventions.common.gradle.kts index 1ce1e742..c2f87051 100644 --- a/buildSrc/src/main/kotlin/conventions.common.gradle.kts +++ b/buildSrc/src/main/kotlin/conventions.common.gradle.kts @@ -10,6 +10,5 @@ Props.initialize(project) Vers.initialize(project) repositories { - mavenLocal() mavenCentral() } diff --git a/buildSrc/src/main/kotlin/jacoco.aggregation.gradle.kts b/buildSrc/src/main/kotlin/jacoco.aggregation.gradle.kts deleted file mode 100644 index f9f10fd0..00000000 --- a/buildSrc/src/main/kotlin/jacoco.aggregation.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("com.github.kt3k.coveralls") - id("conventions.common") - jacoco - java -} - -repositories { - mavenLocal() - mavenCentral() -} diff --git a/buildSrc/src/main/kotlin/java.application.gradle.kts b/buildSrc/src/main/kotlin/java.application.gradle.kts deleted file mode 100644 index 9e6917f3..00000000 --- a/buildSrc/src/main/kotlin/java.application.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -import utils.Vers.versionCommonsLang3 -import utils.Vers.versionJupiter - -plugins { - `maven-publish` - application - id("java.common") - id("org.springframework.boot") - java - signing -} - -dependencies { - implementation("org.apache.commons:commons-lang3:${versionCommonsLang3}") - testImplementation("org.junit.jupiter:junit-jupiter-api:${versionJupiter}") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versionJupiter}") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") -} diff --git a/buildSrc/src/main/kotlin/java.common.gradle.kts b/buildSrc/src/main/kotlin/java.common.gradle.kts deleted file mode 100644 index a34a8bb3..00000000 --- a/buildSrc/src/main/kotlin/java.common.gradle.kts +++ /dev/null @@ -1,80 +0,0 @@ -import utils.Vers -import utils.Vers.versionAssertj -import utils.Vers.versionJakartaXml -import utils.Vers.versionLombok -import utils.Vers.versionMockitoCore -import utils.Vers.versionMockitoInline -import utils.createConfiguration - -plugins { - id("com.diffplug.spotless") - id("conventions.common") - jacoco - java -} - -java { - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 -} - -dependencies { - annotationProcessor("org.projectlombok:lombok:${versionLombok}") - compileOnly("jakarta.xml.bind:jakarta.xml.bind-api:${versionJakartaXml}") - compileOnly("org.projectlombok:lombok:${versionLombok}") - testAnnotationProcessor("org.projectlombok:lombok:${versionLombok}") - testCompileOnly("org.projectlombok:lombok:${versionLombok}") - testImplementation("org.assertj:assertj-core:${versionAssertj}") - testImplementation("org.mockito:mockito-core:${versionMockitoCore}") - testImplementation("org.mockito:mockito-inline:${versionMockitoInline}") -} - -tasks.test { - useJUnitPlatform() -} - -spotless { - java { - targetExclude("build/**/*") - googleJavaFormat() - } -} - -tasks.check { - dependsOn(tasks.spotlessApply) -} - -jacoco { - toolVersion = Vers.versionJacocoAgent -} - -tasks.jacocoTestReport { - enabled = false -} - -createConfiguration("outgoingClassDirs", "classDirs") { - extendsFrom(configurations.implementation.get()) - isCanBeResolved = false - isCanBeConsumed = true - sourceSets.main.get().output.forEach { - outgoing.artifact(it) - } -} - -createConfiguration("outgoingSourceDirs", "sourceDirs") { - extendsFrom(configurations.implementation.get()) - isCanBeResolved = false - isCanBeConsumed = true - sourceSets.main.get().java.srcDirs.forEach { - outgoing.artifact(it) - } -} - -createConfiguration("outgoingCoverageData", "coverageData") { - extendsFrom(configurations.implementation.get()) - isCanBeResolved = false - isCanBeConsumed = true - outgoing.artifact(tasks.test.map { - it.extensions.getByType().destinationFile!! - }) -} diff --git a/buildSrc/src/main/kotlin/java.library.gradle.kts b/buildSrc/src/main/kotlin/java.library.gradle.kts deleted file mode 100644 index 4e3dbdbc..00000000 --- a/buildSrc/src/main/kotlin/java.library.gradle.kts +++ /dev/null @@ -1,22 +0,0 @@ -import utils.Props -import utils.Vers.versionJupiter - -plugins { - `java-library` - `maven-publish` - id("java.common") - signing -} - -if (Props.javaDocs) { - java { - withJavadocJar() - withSourcesJar() - } -} - -dependencies { - testImplementation("org.junit.jupiter:junit-jupiter-api:${versionJupiter}") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versionJupiter}") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") -} diff --git a/buildSrc/src/main/kotlin/java.service.gradle.kts b/buildSrc/src/main/kotlin/java.service.gradle.kts deleted file mode 100644 index 5518d045..00000000 --- a/buildSrc/src/main/kotlin/java.service.gradle.kts +++ /dev/null @@ -1,53 +0,0 @@ -import com.google.protobuf.gradle.id -import com.google.protobuf.gradle.remove -import utils.Vers.versionProtobuf -import utils.Vers.versionWebpb - -plugins { - `maven-publish` - application - id("com.google.protobuf") - id("io.spring.dependency-management") - id("java.common") - id("org.springframework.boot") - java - signing -} - -dependencies { -} - -tasks.withType { - options.encoding = "UTF-8" - options.compilerArgs.addAll( - arrayOf( - "-Xlint:deprecation", - "-Xlint:unchecked", - "-Amapstruct.unmappedTargetPolicy=IGNORE" - ) - ) -} - -protobuf { - protoc { - artifact = "com.google.protobuf:protoc:${versionProtobuf}" - } - plugins { - id("webpb") { - artifact = "io.github.jinganix.webpb:webpb-protoc-java:${versionWebpb}:all@jar" - } - } - generateProtoTasks { - ofSourceSet("main").forEach { - it.doFirst { - delete(it.outputBaseDir) - } - it.builtins { - remove("java") - } - it.plugins { - id("webpb") - } - } - } -} diff --git a/buildSrc/src/main/kotlin/proto.common.gradle.kts b/buildSrc/src/main/kotlin/proto.common.gradle.kts deleted file mode 100644 index fad0cd7d..00000000 --- a/buildSrc/src/main/kotlin/proto.common.gradle.kts +++ /dev/null @@ -1,23 +0,0 @@ -import utils.Props -import utils.Vers -import utils.Vers.versionWebpb -import utils.hierarchicalGroup - -plugins { - id("conventions.common") - java -} - -Props.initialize(project) -Vers.initialize(project) - -group = hierarchicalGroup() - -repositories { - mavenLocal() - mavenCentral() -} - -dependencies { - compileOnly("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") -} diff --git a/buildSrc/src/main/kotlin/ts.frontend.gradle.kts b/buildSrc/src/main/kotlin/ts.frontend.gradle.kts deleted file mode 100644 index c98820bf..00000000 --- a/buildSrc/src/main/kotlin/ts.frontend.gradle.kts +++ /dev/null @@ -1,48 +0,0 @@ -import com.google.protobuf.gradle.id -import com.google.protobuf.gradle.remove -import utils.Props -import utils.Vers -import utils.Vers.versionProtobuf -import utils.Vers.versionWebpb - -plugins { - id("com.google.protobuf") - id("conventions.versioning") - java -} - -Props.initialize(project) -Vers.initialize(project) - -repositories { - mavenLocal() - mavenCentral() -} - -dependencies { - implementation("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") -} - -protobuf { - protoc { - artifact = "com.google.protobuf:protoc:${versionProtobuf}" - } - plugins { - id("ts") { - artifact = "io.github.jinganix.webpb:webpb-protoc-ts:${versionWebpb}:all@jar" - } - } - generateProtoTasks { - ofSourceSet("main").forEach { - it.doFirst { - delete(it.outputBaseDir) - } - it.builtins { - remove("java") - } - it.plugins { - id("ts") - } - } - } -} diff --git a/buildSrc/src/main/kotlin/utils/Props.kt b/buildSrc/src/main/kotlin/utils/Props.kt index 72eb88f7..b2c7e2e3 100644 --- a/buildSrc/src/main/kotlin/utils/Props.kt +++ b/buildSrc/src/main/kotlin/utils/Props.kt @@ -9,11 +9,9 @@ object Props { lateinit var group: String lateinit var version: String - var javaDocs: Boolean = true - var coverage: Boolean = true + var verifyJavaDocs: Boolean = true + var verifyCoverage: Boolean = true var jacocoMinCoverage: Double = 1.0 - var releaseRepo: String = "" - var snapshotRepo: String = "" fun initialize(project: Project) { if (initialized) { diff --git a/buildSrc/src/main/kotlin/utils/Vers.kt b/buildSrc/src/main/kotlin/utils/Vers.kt index b35d5f85..97d2c6ee 100644 --- a/buildSrc/src/main/kotlin/utils/Vers.kt +++ b/buildSrc/src/main/kotlin/utils/Vers.kt @@ -19,17 +19,14 @@ object Vers { lateinit var versionFlyway: String lateinit var versionFreemarker: String lateinit var versionGradleVersionsPlugin: String - lateinit var versionGuava: String lateinit var versionJackson: String lateinit var versionJacocoAgent: String lateinit var versionJakartaXml: String - lateinit var versionJupiter: String lateinit var versionJwt: String lateinit var versionLombok: String lateinit var versionMapstruct: String lateinit var versionMockitoCore: String lateinit var versionMockitoInline: String - lateinit var versionModelMapper: String lateinit var versionMysqlConnector: String lateinit var versionNetty: String lateinit var versionPeashooter: String diff --git a/buildSrc/src/main/kotlin/utils/utils.kt b/buildSrc/src/main/kotlin/utils/utils.kt index 68008ae1..cba6af0a 100644 --- a/buildSrc/src/main/kotlin/utils/utils.kt +++ b/buildSrc/src/main/kotlin/utils/utils.kt @@ -7,7 +7,6 @@ import org.gradle.api.attributes.Category import org.gradle.api.attributes.DocsType import org.gradle.api.attributes.Usage import org.gradle.kotlin.dsl.named -import java.io.File fun Project.hierarchicalGroup(): String { var suffix = "" @@ -35,18 +34,3 @@ fun Project.createConfiguration( configuration.execute(conf) return conf } - -fun Project.extractDependencies(file: File): List { - val text = file.readText() - val versionRegex = "(.*)\\$\\{?([\\w+]*)}?".toRegex() - return "(implementation|testImplementation)\\(\"(.*)\"\\)".toRegex() - .findAll(text) - .map { it.groupValues[2] } - .map { - val matchResult = versionRegex.find(it) ?: return@map it - val artifact = matchResult.groupValues[1] - val property = matchResult.groupValues[2] - "$artifact${project.property(property) as String}" - } - .toList() -} diff --git a/frontend/weapp/build.gradle.kts b/frontend/weapp/build.gradle.kts index 7cdf85d9..745ccd55 100644 --- a/frontend/weapp/build.gradle.kts +++ b/frontend/weapp/build.gradle.kts @@ -1,13 +1,13 @@ -import com.google.protobuf.gradle.protobuf +import com.google.protobuf.gradle.id +import com.google.protobuf.gradle.remove import org.apache.tools.ant.taskdefs.condition.Os +import utils.Vers.versionProtobuf +import utils.Vers.versionWebpb plugins { - id("ts.frontend") -} - -dependencies { - protobuf(project(":proto:service")) - protobuf(project(":proto:imports")) + id("com.google.protobuf") + id("conventions.common") + java } val npm = if (Os.isFamily(Os.FAMILY_WINDOWS)) "npm.cmd" else "npm" @@ -21,16 +21,54 @@ task("npmInstall") { } } +task("npmStart") { + commandLine(npm, "run", "dev") + + dependsOn("npmInstall") +} + task("npmCheck") { commandLine(npm, "run", "lint") commandLine(npm, "run", "test") commandLine(npm, "run", "build") dependsOn("npmInstall") - dependsOn("generateProto") } tasks.check { dependsOn("npmCheck") } +dependencies { + implementation("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") + protobuf(project(":proto:imports")) + protobuf(project(":proto:service")) +} + +tasks.clean { + enabled = false +} + +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:$versionProtobuf" + } + plugins { + id("ts") { + artifact = "io.github.jinganix.webpb:webpb-protoc-ts:$versionWebpb:all@jar" + } + } + generateProtoTasks { + ofSourceSet("main").forEach { + it.doFirst { + delete(it.outputBaseDir) + } + it.builtins { + remove("java") + } + it.plugins { + id("ts") + } + } + } +} diff --git a/gradle.properties b/gradle.properties index 76741059..53fa61de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,9 @@ group = io.github.jinganix.guess version = 0.0.1-SNAPSHOT -javaDocs = false -coverage = false +verifyJavaDocs = false +verifyCoverage = false jacocoMinCoverage = 0 -releaseRepo = https://s01.oss.sonatype.org/service/local/staging/deploy/maven2 -snapshotRepo = https://s01.oss.sonatype.org/content/repositories/snapshots versionAssertj = 3.25.2 versionAuthorizationServer = 1.2.1 @@ -19,18 +17,15 @@ versionDependencyManagementPlugin = 1.1.4 versionFlyway = 10.6.0 versionFreemarker = 2.3.32 versionGradleVersionsPlugin = 0.51.0 -versionGuava = 33.0.0-jre versionJackson = 2.16.1 versionJacocoAgent = 0.8.11 versionJakartaServletApi = 6.0.0 versionJakartaXml = 4.0.1 -versionJupiter = 5.10.1 versionJwt = 4.4.0 versionLombok = 1.18.30 versionMapstruct = 1.5.5.Final versionMockitoCore = 5.10.0 versionMockitoInline = 5.2.0 -versionModelMapper = 3.2.0 versionMysqlConnector = 8.0.33 versionNetty = 4.1.106.Final versionPeashooter = 0.0.3 diff --git a/lib/proto/build.gradle.kts b/lib/proto/build.gradle.kts deleted file mode 100644 index 759762bc..00000000 --- a/lib/proto/build.gradle.kts +++ /dev/null @@ -1,53 +0,0 @@ -import com.google.protobuf.gradle.* -import utils.Vers.versionJackson -import utils.Vers.versionMapstruct -import utils.Vers.versionProtobuf -import utils.Vers.versionWebpb - -plugins { - id("com.google.protobuf") - id("io.spring.dependency-management") - id("java.library") - id("org.springframework.boot") -} - -dependencies { - api("io.github.jinganix.webpb:webpb-runtime:${versionWebpb}") - compileOnly("org.mapstruct:mapstruct:${versionMapstruct}") - implementation("com.fasterxml.jackson.core:jackson-databind:${versionJackson}") - implementation("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") - implementation("org.springframework.boot:spring-boot-autoconfigure") - implementation("org.springframework.boot:spring-boot-starter-validation") - implementation("org.springframework.data:spring-data-commons") - implementation("org.springframework:spring-web") - protobuf(project(":proto:imports")) -} - -tasks.bootJar { - enabled = false -} - -tasks.jar { - enabled = true -} - -protobuf { - protoc { - artifact = "com.google.protobuf:protoc:${versionProtobuf}" - } - plugins { - id("webpb") { - artifact = "io.github.jinganix.webpb:webpb-protoc-java:${versionWebpb}:all@jar" - } - } - generateProtoTasks { - ofSourceSet("main").forEach { - it.builtins { - remove("java") - } - it.plugins { - id("webpb") - } - } - } -} diff --git a/lib/proto/src/main/java/io/github/jinganix/guess/proto/converter/PbEnumConverter.java b/lib/proto/src/main/java/io/github/jinganix/guess/proto/converter/PbEnumConverter.java deleted file mode 100644 index 900175f6..00000000 --- a/lib/proto/src/main/java/io/github/jinganix/guess/proto/converter/PbEnumConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2020 jinganix@gmail.com, All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * https://github.com/jinganix/guess - */ - -package io.github.jinganix.guess.proto.converter; - -import com.fasterxml.jackson.databind.util.StdConverter; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -/** Mapping between integer value and enumeration. */ -public class PbEnumConverter extends StdConverter { - - private static final Map, Optional> enumValueGetterMap = - new ConcurrentHashMap<>(); - - /** - * Convert an enum to integer value. - * - * @param value enum object - * @return value - */ - @Override - public Integer convert(Object value) { - Optional optional = getValueGetter(value.getClass()); - if (optional.isPresent()) { - try { - return (Integer) optional.get().invoke(value); - } catch (Exception e) { - e.printStackTrace(); - } - } - return null; - } - - private static Optional getValueGetter(Class type) { - return enumValueGetterMap.computeIfAbsent( - type, key -> Optional.ofNullable(resolveValueGetter(key))); - } - - private static Method resolveValueGetter(Class type) { - for (Method method : type.getDeclaredMethods()) { - if (!Modifier.isPublic(method.getModifiers())) { - continue; - } - if (method.getReturnType() != Integer.class && method.getReturnType() != int.class) { - continue; - } - if (method.getParameterCount() != 0) { - continue; - } - return method; - } - return null; - } -} diff --git a/lib/proto/src/main/java/io/github/jinganix/guess/proto/mapstruct/GeneralProtoMapper.java b/lib/proto/src/main/java/io/github/jinganix/guess/proto/mapstruct/GeneralProtoMapper.java deleted file mode 100644 index 45dbba74..00000000 --- a/lib/proto/src/main/java/io/github/jinganix/guess/proto/mapstruct/GeneralProtoMapper.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2020 jinganix@gmail.com, All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * https://github.com/jinganix/guess - */ - -package io.github.jinganix.guess.proto.mapstruct; - -import io.github.jinganix.guess.proto.imports.common.PageablePb; -import io.github.jinganix.guess.proto.imports.common.PagingPb; -import lombok.RequiredArgsConstructor; -import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -/** General mapstruct mapper. */ -@RequiredArgsConstructor -public class GeneralProtoMapper { - - private final SpringDataWebProperties dataWebProperties; - - /** - * {@link PagingPb} mapper. - * - * @param page {@link Page} - * @return {@link PagingPb} - */ - public PagingPb pagingPb(Page page) { - if (page.getPageable().isPaged()) { - return new PagingPb() - .setPage( - dataWebProperties.getPageable().isOneIndexedParameters() - ? page.getNumber() + 1 - : page.getNumber()) - .setSize(page.getSize()) - .setTotalCount((int) page.getTotalElements()) - .setTotalPage(page.getTotalPages()); - } - return null; - } - - /** - * {@link PageablePb} mapper. - * - * @param pageable {@link Pageable} - * @return {@link PageablePb} - */ - public PageablePb pageablePb(Pageable pageable) { - if (pageable == null) { - return null; - } - return new PageablePb() - .setPage(pageable.getPageNumber()) - .setSize(pageable.getPageSize()) - .setPagination(true) - .setSort(pageable.getSort().toString()); - } -} diff --git a/proto/imports/build.gradle.kts b/proto/imports/build.gradle.kts index 83397c5c..3b7098ca 100644 --- a/proto/imports/build.gradle.kts +++ b/proto/imports/build.gradle.kts @@ -1,3 +1,13 @@ +import utils.Vers.versionWebpb + plugins { - id("proto.common") + java +} + +repositories { + mavenCentral() +} + +dependencies { + compileOnly("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") } diff --git a/proto/imports/src/main/resources/imports/Common.proto b/proto/imports/src/main/resources/imports/Common.proto deleted file mode 100644 index b6bf64df..00000000 --- a/proto/imports/src/main/resources/imports/Common.proto +++ /dev/null @@ -1,37 +0,0 @@ -syntax = "proto2"; - -package CommonProto; - -option java_package = "io.github.jinganix.guess.proto.imports.common"; - -import "imports/WebpbOptions.proto"; -import "webpb/WebpbExtend.proto"; - -message PageablePb { - optional bool pagination = 1; - optional int32 page = 2; - optional int32 size = 3; - optional string sort = 4; -} - -message PagingPb { - required int32 page = 1; - required int32 size = 2; - required int32 totalCount = 3; - required int32 totalPage = 4; -} - -message HeaderTypesPb { - repeated int32 types = 1; -} - -message AssetPb { - required string thumb = 1; - required string url = 2; -} - -message CursorLongPb { - required int64 time = 1; - required int64 key = 2 [(opts).ts = {as_string: true}]; - required bool desc = 3; -} diff --git a/proto/imports/src/main/resources/imports/Oauth2.proto b/proto/imports/src/main/resources/imports/Oauth2.proto deleted file mode 100644 index 2c5318dd..00000000 --- a/proto/imports/src/main/resources/imports/Oauth2.proto +++ /dev/null @@ -1,94 +0,0 @@ -syntax = "proto2"; - -package Oauth2Proto; - -option java_package = "io.github.jinganix.guess.proto.imports.oauth2"; - -import "imports/WebpbOptions.proto"; -import "webpb/WebpbExtend.proto"; - -enum ResponseType { - CODE = 0 [(v_opts).opt = {value: 'code'}]; -} - -enum GrantType { - AUTHORIZATION_CODE = 0 [(v_opts).opt = {value: 'authorization_code'}]; - REFRESH_TOKEN = 1 [(v_opts).opt = {value: 'refresh_token'}]; - CLIENT_CREDENTIALS = 2 [(v_opts).opt = {value: 'client_credentials'}]; - WEAPP = 3 [(v_opts).opt = {value: 'weapp'}]; -} - -enum TokenType { - BEARER = 0 [(v_opts).opt = {value: 'Bearer'}]; -} - -message Oauth2LoginRequest { - option (m_opts).opt = { - method: "GET" - path: "/oauth2/login" - }; - - required string username = 1; - required string password = 2; -} - -message Oauth2AuthorizeRequest { - option (m_opts).opt = { - method: "GET" - path: "/oauth2/authorize?response_type={type}&client_id={clientId}&scope={scope}&redirect_uri={redirectUri}&state={state}" - }; - - required ResponseType type = 1 [(opts).opt = {in_query: true}]; - required string clientId = 2 [(opts).opt = {in_query: true}]; - required string scope = 3 [(opts).opt = {in_query: true}]; - required string redirectUri = 4 [(opts).opt = {in_query: true}]; - required string state = 5 [(opts).opt = {in_query: true}]; -} - -message Oauth2TokenRequest { - option (m_opts).opt = { - method: "POST" - path: "/oauth2/token" - }; - - required GrantType grantType = 1 [(opts).ts = {alias: 'grant_type'}]; - required string clientId = 2 [(opts).ts = {alias: 'client_id'}]; - optional string redirectUri = 3 [(opts).ts = {alias: 'redirect_uri'}]; - optional string code = 4; - optional string refreshToken = 5 [(opts).ts = {alias: 'refresh_token'}]; - optional string scope = 6; -} - -message Oauth2TokenResponse { - required string accessToken = 1 [(opts).ts = {alias: 'access_token'}]; - required int64 expiresIn = 2 [(opts).ts = {alias: 'expires_in'}]; - required string refreshToken = 3 [(opts).ts = {alias: 'refresh_token'}]; - required string tokenType = 4 [(opts).ts = {alias: 'token_type'}]; - required string scope = 5; -} - -message Oauth2LogoutRequest { - option (m_opts).opt = { - method: "GET" - path: "/oauth2/logout" - }; -} - -message Oauth2ConsentRequest { - option (m_opts).opt = { - method: "GET" - path: "/oauth2/consent?client_id={clientId}&scope={scope}&state={state}" - }; - - required string clientId = 1 [(opts).opt = {in_query: true}, (opts).java = {annotation: '@NotNull'}]; - required string scope = 2 [(opts).opt = {in_query: true}, (opts).java = {annotation: '@NotNull'}]; - required string state = 3 [(opts).opt = {in_query: true}, (opts).java = {annotation: '@NotNull'}]; -} - -message Oauth2ConsentResponse { - required string clientId = 1; - required string principalName = 2; - required string state = 3; - repeated string scopes = 4; - repeated string approvedScopes = 5; -} diff --git a/proto/internal/build.gradle.kts b/proto/internal/build.gradle.kts index d9dddaf3..994ed2b8 100644 --- a/proto/internal/build.gradle.kts +++ b/proto/internal/build.gradle.kts @@ -1,7 +1,14 @@ +import utils.Vers.versionWebpb + plugins { - id("proto.common") + java +} + +repositories { + mavenCentral() } dependencies { - compileOnly(project(":proto:imports")) + compileOnly("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") + compileOnly(project(":proto:imports")) } diff --git a/proto/service/build.gradle.kts b/proto/service/build.gradle.kts index d9dddaf3..994ed2b8 100644 --- a/proto/service/build.gradle.kts +++ b/proto/service/build.gradle.kts @@ -1,7 +1,14 @@ +import utils.Vers.versionWebpb + plugins { - id("proto.common") + java +} + +repositories { + mavenCentral() } dependencies { - compileOnly(project(":proto:imports")) + compileOnly("io.github.jinganix.webpb:webpb-proto:${versionWebpb}") + compileOnly(project(":proto:imports")) } diff --git a/proto/service/src/main/resources/service/Comment.proto b/proto/service/src/main/resources/service/Comment.proto index d15b5618..d371ee55 100644 --- a/proto/service/src/main/resources/service/Comment.proto +++ b/proto/service/src/main/resources/service/Comment.proto @@ -4,7 +4,6 @@ package CommentProto; option java_package = "io.github.jinganix.guess.proto.service.comment"; -import "imports/Common.proto"; import "imports/WebpbOptions.proto"; import "webpb/WebpbExtend.proto"; import "service/User.proto"; diff --git a/proto/service/src/main/resources/service/Moment.proto b/proto/service/src/main/resources/service/Moment.proto index 9a96bd3e..edd32c00 100644 --- a/proto/service/src/main/resources/service/Moment.proto +++ b/proto/service/src/main/resources/service/Moment.proto @@ -5,7 +5,6 @@ package MomentProto; option java_package = "io.github.jinganix.guess.proto.service.moment"; import "imports/WebpbOptions.proto"; -import "imports/Common.proto"; import "webpb/WebpbExtend.proto"; enum MomentCategory { diff --git a/proto/service/src/main/resources/service/Puzzle.proto b/proto/service/src/main/resources/service/Puzzle.proto index 325bc7c9..c7b6d03a 100644 --- a/proto/service/src/main/resources/service/Puzzle.proto +++ b/proto/service/src/main/resources/service/Puzzle.proto @@ -4,7 +4,6 @@ package PuzzleProto; option java_package = "io.github.jinganix.guess.proto.service.puzzle"; -import "imports/Common.proto"; import "imports/WebpbOptions.proto"; import "webpb/WebpbExtend.proto"; diff --git a/proto/service/src/main/resources/service/User.proto b/proto/service/src/main/resources/service/User.proto index 59de15d1..b2445566 100644 --- a/proto/service/src/main/resources/service/User.proto +++ b/proto/service/src/main/resources/service/User.proto @@ -4,7 +4,6 @@ package UserProto; option java_package = "io.github.jinganix.guess.proto.service.user"; -import "imports/Common.proto"; import "imports/WebpbOptions.proto"; import "webpb/WebpbExtend.proto"; diff --git a/service/guess/build.gradle.kts b/service/guess/build.gradle.kts index ef73a452..7a98ef0b 100644 --- a/service/guess/build.gradle.kts +++ b/service/guess/build.gradle.kts @@ -1,13 +1,17 @@ +import com.google.protobuf.gradle.id import com.google.protobuf.gradle.protobuf +import com.google.protobuf.gradle.remove +import utils.Props +import utils.Vers import utils.Vers.versionAuthorizationServer import utils.Vers.versionBcpkix import utils.Vers.versionCaffeine import utils.Vers.versionCommonsCodec import utils.Vers.versionCommonsLang3 import utils.Vers.versionFlyway +import utils.Vers.versionJackson import utils.Vers.versionJwt import utils.Vers.versionMapstruct -import utils.Vers.versionJackson import utils.Vers.versionMysqlConnector import utils.Vers.versionNetty import utils.Vers.versionPeashooter @@ -16,12 +20,28 @@ import utils.Vers.versionTestContainers import utils.Vers.versionWebpb plugins { - id("java.service") + id("com.diffplug.spotless") + id("com.github.kt3k.coveralls") + id("com.google.protobuf") + id("conventions.common") + id("io.spring.dependency-management") + id("org.springframework.boot") + jacoco + java +} + +group = "io.github.jinganix.ddz" +version = "${versionWebpb}-SNAPSHOT" + +java { + sourceCompatibility = JavaVersion.VERSION_21 } dependencies { annotationProcessor("io.github.jinganix.webpb:webpb-processor:${versionWebpb}") + annotationProcessor("org.projectlombok:lombok:${Vers.versionLombok}") annotationProcessor("org.mapstruct:mapstruct-processor:${versionMapstruct}") + compileOnly("org.projectlombok:lombok:${Vers.versionLombok}") implementation("com.auth0:java-jwt:${versionJwt}") implementation("com.fasterxml.jackson.core:jackson-databind:${versionJackson}") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${versionJackson}") @@ -49,27 +69,95 @@ dependencies { implementation("org.testcontainers:junit-jupiter:${versionTestContainers}") implementation("org.testcontainers:mysql:${versionTestContainers}") implementation("org.testcontainers:testcontainers:${versionTestContainers}") - implementation(project(":lib:proto")) + protobuf(project(":proto:imports")) protobuf(project(":proto:internal")) protobuf(project(":proto:service")) runtimeOnly("mysql:mysql-connector-java:${versionMysqlConnector}") + testAnnotationProcessor("org.projectlombok:lombok:${Vers.versionLombok}") testAnnotationProcessor("org.mapstruct:mapstruct-processor:${versionMapstruct}") + testCompileOnly("org.projectlombok:lombok:${Vers.versionLombok}") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.security:spring-security-test") testImplementation("org.testcontainers:junit-jupiter:${versionTestContainers}") testImplementation("org.testcontainers:testcontainers:${versionTestContainers}") } -tasks.withType { - options.compilerArgs.add("--enable-preview") +tasks.withType { + useJUnitPlatform() } tasks.test { - useJUnitPlatform() - jvmArgs("--enable-preview") + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + html.required.set(true) + xml.required.set(true) + } +} + +tasks.jacocoTestCoverageVerification { + enabled = Props.verifyCoverage + dependsOn(tasks.jacocoTestReport) + violationRules { + rule { + limit { + minimum = Props.jacocoMinCoverage.toBigDecimal() + } + } + } +} + +tasks.check { + dependsOn(tasks.jacocoTestCoverageVerification) +} + +jacoco { + toolVersion = Vers.versionJacocoAgent +} + +if (Props.verifyJavaDocs) { + java { + withJavadocJar() + withSourcesJar() + } +} + +spotless { + java { + googleJavaFormat() + + targetExclude("build/**/*.java") + } +} + +tasks.check { + dependsOn(tasks.spotlessCheck) } -tasks.bootJar { - archiveFileName.set("guess-service.jar") - launchScript() +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:${Vers.versionProtobuf}" + } + plugins { + id("webpb") { + artifact = "io.github.jinganix.webpb:webpb-protoc-java:${versionWebpb}:all@jar" + } + } + generateProtoTasks { + ofSourceSet("main").forEach { + it.doFirst { + delete(it.outputBaseDir) + } + it.builtins { + remove("java") + } + it.plugins { + id("webpb") + } + } + } } diff --git a/settings.gradle.kts b/settings.gradle.kts index ae9c35e0..e6f441e5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,9 @@ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + rootProject.name = "guess" -include(":aggregation") include(":frontend:weapp") -include(":lib:proto") include(":proto:imports") include(":proto:internal") include(":proto:service")