File tree Expand file tree Collapse file tree 6 files changed +53
-13
lines changed
src/main/groovy/net/minecrell/gitpatcher Expand file tree Collapse file tree 6 files changed +53
-13
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ plugins {
1212}
1313
1414group = ' net.minecrell'
15- version = ' 0.2 '
15+ version = ' 0.3 '
1616description = ' A Gradle plugin to manage patches for Git repositories'
1717
1818sourceCompatibility = 1.6
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ import static org.eclipse.jgit.revwalk.RevSort.TOPO
2727import groovy.transform.stc.ClosureParams
2828import groovy.transform.stc.FirstParam
2929import groovy.transform.stc.SimpleType
30- import org.apache.commons.lang.StringUtils
3130import org.eclipse.jgit.api.Git
3231import org.eclipse.jgit.diff.DiffFormatter
3332import org.eclipse.jgit.revwalk.RevCommit
@@ -60,12 +59,6 @@ final class Patcher {
6059 return walk
6160 }
6261
63- static File [] findPatches (File patchDir ) {
64- return patchDir. listFiles({ dir , name ->
65- name. endsWith(' .patch' ) && StringUtils . isNumeric(name. substring(0 , 4 ))
66- } as FilenameFilter ). sort()
67- }
68-
6962 static String suggestFileName (RevCommit commit , int num ) {
7063 def result = new StringBuilder (String . format(" %04d-" , num))
7164 for (char c : commit. shortMessage. chars) {
Original file line number Diff line number Diff line change @@ -27,4 +27,8 @@ abstract class GitTask extends DefaultTask {
2727
2828 File repo
2929
30+ protected File getIndexFile () {
31+ return new File (new File (repo, ' .git' ), ' index' )
32+ }
33+
3034}
Original file line number Diff line number Diff line change @@ -27,12 +27,29 @@ import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD
2727import static org.eclipse.jgit.submodule.SubmoduleWalk.getSubmoduleRepository
2828
2929import net.minecrell.gitpatcher.git.MailPatch
30- import net.minecrell.gitpatcher.git.Patcher
3130import org.eclipse.jgit.api.Git
31+ import org.gradle.api.tasks.InputFiles
32+ import org.gradle.api.tasks.OutputDirectory
33+ import org.gradle.api.tasks.OutputFile
3234import org.gradle.api.tasks.TaskAction
3335
3436class ApplyPatchesTask extends PatchTask {
3537
38+ @Override @InputFiles
39+ File [] getPatches () {
40+ return super . getPatches()
41+ }
42+
43+ @Override @OutputDirectory
44+ File getRepo () {
45+ return super . getRepo()
46+ }
47+
48+ @Override @OutputFile
49+ File getIndexFile () {
50+ return super . getIndexFile()
51+ }
52+
3653 @TaskAction
3754 void applyPatches () {
3855 File source = null
@@ -73,7 +90,7 @@ class ApplyPatchesTask extends PatchTask {
7390 if (patchDir. isDirectory()) {
7491 logger. lifecycle ' Applying patches from {} to {}' , patchDir, repo
7592
76- for (def file : Patcher . findPatches(patchDir) ) {
93+ for (def file : patches ) {
7794 logger. lifecycle ' Applying: {}' , file. name
7895
7996 def data = new ByteArrayInputStream (file. bytes)
Original file line number Diff line number Diff line change @@ -28,21 +28,41 @@ import net.minecrell.gitpatcher.git.MailPatch
2828import net.minecrell.gitpatcher.git.Patcher
2929import org.eclipse.jgit.diff.DiffFormatter
3030import org.eclipse.jgit.patch.Patch
31+ import org.gradle.api.tasks.InputDirectory
32+ import org.gradle.api.tasks.InputFile
33+ import org.gradle.api.tasks.OutputDirectory
3134import org.gradle.api.tasks.TaskAction
3235
3336class MakePatchesTask extends PatchTask {
3437
38+ @Override @InputDirectory
39+ File getRepo () {
40+ return super . getRepo()
41+ }
42+
43+ @Override @InputFile
44+ File getIndexFile () {
45+ return super . getIndexFile()
46+ }
47+
48+ @Override @OutputDirectory
49+ File getPatchDir () {
50+ return super . getPatchDir()
51+ }
52+
3553 @TaskAction
3654 void makePatches () {
3755 File [] patches
3856 if (patchDir. isDirectory()) {
39- patches = Patcher . findPatches(patchDir)
57+ patches = this . patches
4058 } else {
4159 assert patchDir. mkdirs(), ' Failed to create patch directory'
4260 patches = null
4361 }
4462
4563 openGit(repo) {
64+ didWork = false
65+
4666 def i = 0
4767 for (def commit : log(it, ' origin/upstream' )) {
4868 def out = new File (patchDir, Patcher . suggestFileName(commit, i+1 ))
@@ -90,6 +110,7 @@ class MakePatchesTask extends PatchTask {
90110
91111
92112 logger. lifecycle ' Generating patch: {}' , out. name
113+ didWork = true
93114
94115 out. createNewFile()
95116 out. withOutputStream {
Original file line number Diff line number Diff line change 2222package net.minecrell.gitpatcher.task.patch
2323
2424import net.minecrell.gitpatcher.task.SubmoduleTask
25- import org.gradle.api.tasks.InputDirectory
25+ import org.apache.commons.lang.StringUtils
2626
2727abstract class PatchTask extends SubmoduleTask {
2828
2929 File root
3030
31- @InputDirectory
3231 File patchDir
3332
33+ protected File [] getPatches () {
34+ return patchDir. listFiles({ dir , name ->
35+ name. endsWith(' .patch' ) && StringUtils . isNumeric(name. substring(0 , 4 ))
36+ } as FilenameFilter ). sort()
37+ }
38+
3439}
You can’t perform that action at this time.
0 commit comments