Skip to content

Commit

Permalink
Merge pull request #6 from godfather1103/dev
Browse files Browse the repository at this point in the history
feat(ProcessResources): 优化ProcessResources任务支持通过方法控制是否缓存相关数据
  • Loading branch information
godfather1103 authored Jul 10, 2021
2 parents 538550d + 1f75110 commit 56b7836
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

### 1.4.2
1. 修复数据获取异常

### 1.5
1. 优化ProcessResources任务支持通过方法控制是否缓存相关数据
2 changes: 1 addition & 1 deletion gradle-base-plugin-main/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("com.gradle.plugin-publish") version "0.14.0"
id("com.gradle.plugin-publish") version "0.15.0"
`java-gradle-plugin`
`maven-publish`
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class GradleBasePlugin : Plugin<Project> {

target.tasks.withType(ProcessResources::class.java) { task ->
run {
task.outputs.upToDateWhen {
extension.getCacheProcessResources()
}
task.doFirst {
val p = extension.getFilterParams()
if (p.isNotEmpty()) {
Expand All @@ -61,16 +64,16 @@ class GradleBasePlugin : Plugin<Project> {
org.apache.tools.ant.filters.ReplaceTokens::class.java
)
} else {
if (extension.getExcludeFilterPatterns().getOrElse(HashSet()).isNotEmpty()) {
task.filesNotMatching(extension.getExcludeFilterPatterns().getOrElse(HashSet())) {
if (extension.getExcludeFilterPatterns().isNotEmpty()) {
task.filesNotMatching(extension.getExcludeFilterPatterns()) {
it.filter(
mapOf("tokens" to p),
org.apache.tools.ant.filters.ReplaceTokens::class.java
)
}
}
if (extension.getIncludeFilterPatterns().getOrElse(HashSet()).isNotEmpty()) {
task.filesMatching(extension.getIncludeFilterPatterns().getOrElse(HashSet())) {
if (extension.getIncludeFilterPatterns().isNotEmpty()) {
task.filesMatching(extension.getIncludeFilterPatterns()) {
it.filter(
mapOf("tokens" to p),
org.apache.tools.ant.filters.ReplaceTokens::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,49 @@ open class BasePluginExtension(project: Project) {
* */
private val excludeFilterPatterns: SetProperty<String> = project.objects.setProperty(String::class.java)

fun getExcludeFilterPatterns(): SetProperty<String> {
return excludeFilterPatterns
}
fun getExcludeFilterPatterns(): Set<String> = excludeFilterPatterns.orNull ?: HashSet<String>()

/**
* 需要进行filter的资源文件的Pattern
* */
private val includeFilterPatterns: SetProperty<String> = project.objects.setProperty(String::class.java)

fun getIncludeFilterPatterns(): SetProperty<String> {
return includeFilterPatterns
}
fun getIncludeFilterPatterns(): Set<String> = includeFilterPatterns.orNull ?: HashSet<String>()

/**
* ProcessResources任务是否需要缓存
* */
private val cacheProcessResources: Property<Boolean> = project.objects.property(Boolean::class.java)


/**
* 设置ProcessResources任务是否需要缓存的标识<BR>
*
* @param b 标识
* @author 作者: chu.chuanbao E-mail: chu.chuanbao@trs.com.cn
* 创建时间:2021/7/6 16:42
*/
fun cacheProcessResources(b: () -> Boolean) = cacheProcessResources.set(b())


/**
* 设置ProcessResources任务是否需要缓存的标识<BR>
*
* @param b 标识
* @author 作者: chu.chuanbao E-mail: chu.chuanbao@trs.com.cn
* 创建时间:2021/7/6 16:42
*/
fun cacheProcessResources(b: Boolean) = cacheProcessResources.set(b)


/**
* 获取ProcessResources任务是否需要缓存的标识(默认不缓存)<BR>
*
* @return 标识
* @author 作者: chu.chuanbao E-mail: chu.chuanbao@trs.com.cn
* 创建时间:2021/7/6 16:41
*/
fun getCacheProcessResources(): Boolean = cacheProcessResources.getOrElse(false)

/**
* 获取filter对应的参数值对<BR>
Expand Down
3 changes: 3 additions & 0 deletions gradle-base-plugin-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ configure<com.github.godfather1103.ext.BasePluginExtension> {
if (System.getProperty("env") == "ccb") {
addFilterParam("two", "2")
}
cacheProcessResources {
false
}
setFilterParamFile(project.projectDir.absolutePath + "/filters/a.properties")
excludeFilter("*.txt")
excludeFilter("**/*.docx")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugin.groupId=io.github.godfather1103
# \u63D2\u4EF6ID
plugin.artifactId=gradle-base-plugin
# \u63D2\u4EF6\u7248\u672C
plugin.version=1.4.2
plugin.version=1.5
# \u6D4B\u8BD5\u63D2\u4EF6\u7248\u672C
test.plugin.version=1.4.2
test.plugin.version=1.5
# \u63D2\u4EF6\u663E\u793A\u540D\u79F0
plugin.displayName=Gradle Base Plugin
# \u63D2\u4EF6\u63CF\u8FF0
Expand Down

0 comments on commit 56b7836

Please sign in to comment.