-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
ApplyRawDiffPatches.kt
71 lines (60 loc) · 2.22 KB
/
ApplyRawDiffPatches.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* paperweight is a Gradle plugin for the PaperMC project.
*
* Copyright (c) 2021 Kyle Wood (DenWav)
* Contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 only, no later versions.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package io.papermc.paperweight.tasks
import io.papermc.paperweight.util.Git
import io.papermc.paperweight.util.copyRecursively
import io.papermc.paperweight.util.defaultOutput
import io.papermc.paperweight.util.path
import io.papermc.paperweight.util.pathOrNull
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
@CacheableTask
abstract class ApplyRawDiffPatches : ZippedTask() {
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val inputDir: DirectoryProperty
@get:Optional
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val patchDir: DirectoryProperty
override fun init() {
super.init()
outputZip.convention(defaultOutput("zip"))
}
override fun run(rootDir: Path) {
val input = inputDir.path
input.copyRecursively(rootDir)
val patches = patchDir.pathOrNull ?: return
val patchSet = patches.useDirectoryEntries("*.patch") { it.toMutableList() }
patchSet.sort()
val git = Git(rootDir)
for (patch in patchSet) {
git("apply", patch.absolutePathString()).executeOut()
}
}
}