-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3188afd
commit 5def8a3
Showing
4 changed files
with
85 additions
and
64 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
43 changes: 0 additions & 43 deletions
43
paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/mache/ApplyMachePatches.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,33 +2,60 @@ package io.papermc.paperweight.tasks.mache | |
|
||
import io.papermc.paperweight.tasks.* | ||
import io.papermc.paperweight.util.* | ||
import io.papermc.paperweight.util.patches.* | ||
import io.papermc.paperweight.util.patches.JavaPatcher | ||
import io.papermc.paperweight.util.patches.NativePatcher | ||
import io.papermc.paperweight.util.patches.Patcher | ||
import java.nio.file.Path | ||
import java.util.function.Predicate | ||
import javax.inject.Inject | ||
import kotlin.io.path.* | ||
import org.eclipse.jgit.api.Git | ||
import org.eclipse.jgit.lib.PersonIdent | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.ProjectLayout | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.CacheableTask | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.tasks.UntrackedTask | ||
import org.gradle.api.tasks.* | ||
import org.gradle.process.ExecOperations | ||
|
||
@CacheableTask | ||
abstract class SetupVanilla : BaseTask() { | ||
|
||
@get:PathSensitive(PathSensitivity.NONE) | ||
@get:InputFile | ||
abstract val inputFile: RegularFileProperty | ||
|
||
@get:Internal | ||
@get:Input | ||
abstract val predicate: Property<Predicate<Path>> | ||
|
||
@get:OutputDirectory | ||
abstract val outputDir: DirectoryProperty | ||
|
||
@get:Internal | ||
abstract val patches: DirectoryProperty | ||
|
||
@get:Optional | ||
@get:Classpath | ||
abstract val mache: ConfigurableFileCollection | ||
|
||
@get:Internal | ||
abstract val useNativeDiff: Property<Boolean> | ||
|
||
@get:Internal | ||
abstract val patchExecutable: Property<String> | ||
|
||
@get:Inject | ||
abstract val exec: ExecOperations | ||
|
||
init { | ||
run { | ||
useNativeDiff.convention(false) | ||
patchExecutable.convention("patch") | ||
} | ||
} | ||
|
||
@TaskAction | ||
fun run() { | ||
val path = outputDir.convertToPath().ensureClean() | ||
|
@@ -56,5 +83,44 @@ abstract class SetupVanilla : BaseTask() { | |
.setSign(false) | ||
.call() | ||
git.tag().setName("vanilla").setTagger(vanillaIdent).setSigned(false).call() | ||
|
||
if (patches.isPresent()) { | ||
// prepare for patches for patching | ||
val patchesFolder = patches.convertToPath().ensureClean() | ||
|
||
mache.singleFile.toPath().openZip().use { zip -> | ||
zip.getPath("patches").copyRecursivelyTo(patchesFolder) | ||
} | ||
|
||
// patch | ||
val result = createPatcher().applyPatches(path, patches.convertToPath(), path, path) | ||
|
||
val macheIdent = PersonIdent("Mache", "[email protected]") | ||
git.add().addFilepattern(".").call() | ||
git.tag().setName("mache").setTagger(macheIdent).setSigned(false).call() | ||
git.commit() | ||
.setMessage("Mache") | ||
.setAuthor(macheIdent) | ||
.setSign(false) | ||
.call() | ||
|
||
if (result is PatchFailure) { | ||
result.failures | ||
.map { "Patch failed: ${it.patch.relativeTo(patches.get().path)}: ${it.details}" } | ||
.forEach { logger.error(it) } | ||
git.close() | ||
throw Exception("Failed to apply ${result.failures.size} patches") | ||
} | ||
} | ||
|
||
git.close() | ||
} | ||
|
||
internal open fun createPatcher(): Patcher { | ||
return if (useNativeDiff.get()) { | ||
NativePatcher(exec, patchExecutable.get()) | ||
} else { | ||
JavaPatcher() | ||
} | ||
} | ||
} |
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