-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
参考 TransformClassesWithAsmTask 实现对 Jars 的增量构建, 以保证远程构建缓存稳定
- Loading branch information
Showing
2 changed files
with
103 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package tracex | ||
|
||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.work.ChangeType | ||
import org.gradle.work.InputChanges | ||
import java.io.File | ||
|
||
class JarsIdentity( | ||
private val inputJars: ConfigurableFileCollection, | ||
private val inputChanges: InputChanges, | ||
) { | ||
|
||
fun compute(): JarChanges { | ||
val (changed, addedOrRemoved) = inputChanges | ||
.getFileChanges(inputJars) | ||
.partition { it.changeType == ChangeType.MODIFIED } | ||
|
||
val reprocessAll = !inputChanges.isIncremental || addedOrRemoved.isNotEmpty() | ||
val changedFiles = changed.map { it.file }.toSet() | ||
val hasChanged = { file: File -> reprocessAll || (file in changedFiles) } | ||
val jarsInfo = inputJars.files.mapIndexedNotNull { index: Int, file: File -> | ||
if (!hasChanged(file)) null | ||
else FileInfo( | ||
identity = index.toString(), | ||
file = file, | ||
) | ||
} | ||
|
||
return JarChanges(jarsInfo, reprocessAll) | ||
} | ||
|
||
data class JarChanges( | ||
val jarsInfo: List<FileInfo>, | ||
val reprocessAll: Boolean, | ||
) | ||
|
||
data class FileInfo( | ||
val identity: String, | ||
val file: File, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters