File tree 6 files changed +53
-13
lines changed
src/main/groovy/net/minecrell/gitpatcher
6 files changed +53
-13
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ plugins {
12
12
}
13
13
14
14
group = ' net.minecrell'
15
- version = ' 0.2 '
15
+ version = ' 0.3 '
16
16
description = ' A Gradle plugin to manage patches for Git repositories'
17
17
18
18
sourceCompatibility = 1.6
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ import static org.eclipse.jgit.revwalk.RevSort.TOPO
27
27
import groovy.transform.stc.ClosureParams
28
28
import groovy.transform.stc.FirstParam
29
29
import groovy.transform.stc.SimpleType
30
- import org.apache.commons.lang.StringUtils
31
30
import org.eclipse.jgit.api.Git
32
31
import org.eclipse.jgit.diff.DiffFormatter
33
32
import org.eclipse.jgit.revwalk.RevCommit
@@ -60,12 +59,6 @@ final class Patcher {
60
59
return walk
61
60
}
62
61
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
-
69
62
static String suggestFileName (RevCommit commit , int num ) {
70
63
def result = new StringBuilder (String . format(" %04d-" , num))
71
64
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 {
27
27
28
28
File repo
29
29
30
+ protected File getIndexFile () {
31
+ return new File (new File (repo, ' .git' ), ' index' )
32
+ }
33
+
30
34
}
Original file line number Diff line number Diff line change @@ -27,12 +27,29 @@ import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD
27
27
import static org.eclipse.jgit.submodule.SubmoduleWalk.getSubmoduleRepository
28
28
29
29
import net.minecrell.gitpatcher.git.MailPatch
30
- import net.minecrell.gitpatcher.git.Patcher
31
30
import 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
32
34
import org.gradle.api.tasks.TaskAction
33
35
34
36
class ApplyPatchesTask extends PatchTask {
35
37
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
+
36
53
@TaskAction
37
54
void applyPatches () {
38
55
File source = null
@@ -73,7 +90,7 @@ class ApplyPatchesTask extends PatchTask {
73
90
if (patchDir. isDirectory()) {
74
91
logger. lifecycle ' Applying patches from {} to {}' , patchDir, repo
75
92
76
- for (def file : Patcher . findPatches(patchDir) ) {
93
+ for (def file : patches ) {
77
94
logger. lifecycle ' Applying: {}' , file. name
78
95
79
96
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
28
28
import net.minecrell.gitpatcher.git.Patcher
29
29
import org.eclipse.jgit.diff.DiffFormatter
30
30
import 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
31
34
import org.gradle.api.tasks.TaskAction
32
35
33
36
class MakePatchesTask extends PatchTask {
34
37
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
+
35
53
@TaskAction
36
54
void makePatches () {
37
55
File [] patches
38
56
if (patchDir. isDirectory()) {
39
- patches = Patcher . findPatches(patchDir)
57
+ patches = this . patches
40
58
} else {
41
59
assert patchDir. mkdirs(), ' Failed to create patch directory'
42
60
patches = null
43
61
}
44
62
45
63
openGit(repo) {
64
+ didWork = false
65
+
46
66
def i = 0
47
67
for (def commit : log(it, ' origin/upstream' )) {
48
68
def out = new File (patchDir, Patcher . suggestFileName(commit, i+1 ))
@@ -90,6 +110,7 @@ class MakePatchesTask extends PatchTask {
90
110
91
111
92
112
logger. lifecycle ' Generating patch: {}' , out. name
113
+ didWork = true
93
114
94
115
out. createNewFile()
95
116
out. withOutputStream {
Original file line number Diff line number Diff line change 22
22
package net.minecrell.gitpatcher.task.patch
23
23
24
24
import net.minecrell.gitpatcher.task.SubmoduleTask
25
- import org.gradle.api.tasks.InputDirectory
25
+ import org.apache.commons.lang.StringUtils
26
26
27
27
abstract class PatchTask extends SubmoduleTask {
28
28
29
29
File root
30
30
31
- @InputDirectory
32
31
File patchDir
33
32
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
+
34
39
}
You can’t perform that action at this time.
0 commit comments