equal
deleted
inserted
replaced
|
1 task sourceArchive { |
|
2 description "Get the source archive of the project" |
|
3 } |
|
4 |
|
5 sourceArchive.doLast { |
|
6 makeSourceArchive(rootProject.name) |
|
7 } |
|
8 |
|
9 project.build.dependsOn sourceArchive |
|
10 |
|
11 def makeSourceArchive(String projectName) { |
|
12 def git = new File(".git") |
|
13 def hg = new File(".hg") |
|
14 def tag |
|
15 if (git.exists()) { |
|
16 tag = getGitSha1() |
|
17 println("Building source archive \"${projectName}-src-${tag}.zip\" from git") |
|
18 exec { |
|
19 workingDir project.rootDir |
|
20 commandLine "git", "archive", "--format=zip", "--prefix=${projectName}-src-${tag}/", "-o", "${projectName}-src-${tag}.zip", "HEAD" |
|
21 } |
|
22 } else if (hg.exists()) { |
|
23 tag = getHgSha1() |
|
24 println("Building source archive \"${projectName}-src-${tag}.zip\" from hg") |
|
25 exec { |
|
26 workingDir project.rootDir |
|
27 commandLine "hg", "archive", "-t", "zip", "-r", tag, "${projectName}-src-${tag}.zip" |
|
28 } |
|
29 } |
|
30 } |
|
31 |
|
32 def getGitSha1() { |
|
33 return 'git rev-parse HEAD'.execute().text.trim() |
|
34 } |
|
35 |
|
36 def getHgSha1() { |
|
37 return 'hg id --debug -i -r .'.execute().text.trim() |
|
38 } |