Skip to content

Commit e22df64

Browse files
authored
Merge pull request #41 from wyjsonGo/develop
publish v2.4.7 优化路由路径支持(a-zA-Z0-9_-.#)
2 parents 50979c5 + 9520de6 commit e22df64

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

GoRouter-Compiler/src/main/java/com/wyjson/router/compiler/processor/GenerateRouteModuleProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ private LinkedHashSet<MethodSpec> addRouteGroup(RoundEnvironment roundEnvironmen
211211

212212
for (Map.Entry<String, Set<Element>> entry : routeGroupMap.entrySet()) {
213213
List<RouteModel> routeModelDocList = new ArrayList<>();
214-
String groupName = entry.getKey();
214+
String groupName = entry.getKey()
215+
.replace("-", "_")
216+
.replace(".", "_")
217+
.replace("#", "_");
215218
// 首字母大写
216219
String groupNameToUpperCase = groupName.substring(0, 1).toUpperCase() + groupName.substring(1);
217220
String methodName = String.format(METHOD_NAME_LOAD_ROUTE_FOR_x_GROUP, groupNameToUpperCase);

GoRouter-Gradle-Plugin/src/main/kotlin/com/wyjson/router/gradle_plugin/helper/AssembleGoRouteHelperCode.kt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,31 +218,18 @@ class AssembleGoRouteHelperCode(private val model: RouteHelperModel) {
218218
return projectName
219219
}
220220
var str = projectName
221-
// 去除开头字母是0-9和_的情况
222-
str = str.replace("^[0-9_]+".toRegex(), "")
221+
// 去除开头字母是0-9的情况
222+
str = str.replace("^[0-9]+".toRegex(), "")
223223
str = str.replace("-", "_")
224-
// 首字母小写
225-
str = str.substring(0, 1).lowercase() + str.substring(1)
226-
// 处理大写
227-
val len = str.length
228-
val sb = StringBuilder(len)
229-
for (i in 0 until len) {
230-
val c = str[i]
231-
if (Character.isUpperCase(c)) {
232-
if (str[i - 1] != '_') {
233-
sb.append("_")
234-
}
235-
sb.append(str[i].lowercaseChar())
236-
} else {
237-
sb.append(c)
238-
}
239-
}
240-
return sb.toString()
224+
str = str.lowercase()
225+
return str
241226
}
242227

243228
private fun extractClassNameByPath(path: String): String {
244229
var methodName = ""
245-
val replace = path.replace(".", "").replace("-", "")
230+
val replace = path.replace("-", "_")
231+
.replace(".", "_")
232+
.replace("#", "_")
246233
for (item in replace.split("/")) {
247234
if (item.contains("_")){
248235
for (_item in item.split("_")) {

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dependencyResolutionManagement {
6969
}
7070
7171
dependencies {
72-
api 'com.github.wyjsonGo.GoRouter:GoRouter-Api:2.4.6'
72+
api 'com.github.wyjsonGo.GoRouter:GoRouter-Api:2.4.7'
7373
}
7474
// Kotlin配置参见8-1
7575
```
@@ -89,7 +89,7 @@ android {
8989
}
9090
9191
dependencies {
92-
annotationProcessor 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.6'
92+
annotationProcessor 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.7'
9393
}
9494
```
9595

@@ -157,7 +157,7 @@ pluginManagement {
157157
// 项目根目录下的build.gradle
158158
buildscript {
159159
dependencies {
160-
classpath 'com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:2.4.6'
160+
classpath 'com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:2.4.7'
161161
}
162162
}
163163
```
@@ -894,7 +894,7 @@ kapt {
894894
}
895895

896896
dependencies {
897-
kapt 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.6'
897+
kapt 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.7'
898898
}
899899
```
900900

@@ -906,6 +906,7 @@ module_kotlin模块Demo示例[module_kotlin/build.gradle](https://github.com/wyj
906906

907907
##### 3. 路由中的分组概念
908908

909+
* 路由路径支持(a-zA-Z0-9_-.#)
909910
* SDK中针对所有的路径`/test/1`、`/test/2`进行分组,分组只有在分组中的某一个路径第一次被访问的时候,该分组才会被初始化。分组使用路径中第一段字符串(/*/)作为分组,这里的路径需要注意的是至少需要有两级`/xx/xx`。
910911
* GRouter允许一个module中存在多个分组,也允许多个module中存在相同的分组,但是最好不要在多个module中存在相同的分组,因为在注册路由组时发现存在相同的分组,会立即注册老的路由组里的全部路由,然后更新新的路由组信息。
911912

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
dependencies {
4-
classpath "com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:${VERSION}"
4+
// classpath "com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:${VERSION}"
55
}
66
}
77

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ android.nonTransitiveRClass=true
2525
# org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
2626

2727
GROUP_ID=com.github.wyjsonGo.GoRouter
28-
VERSION=2.4.6
28+
VERSION=2.4.7

settings.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ dependencyResolutionManagement {
1818

1919
rootProject.name = "GoRouter"
2020

21-
include ':app'
22-
include ':module_main'
23-
include ':module_user'
24-
include ':module_kotlin'
25-
include ':module_common'
21+
//include ':app'
22+
//include ':module_main'
23+
//include ':module_user'
24+
//include ':module_kotlin'
25+
//include ':module_common'
2626

2727
include ':GoRouter-Api'
2828
include ':GoRouter-Annotation'

0 commit comments

Comments
 (0)