forked from thelegendmink/Orchid
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.gradle
115 lines (101 loc) · 3.19 KB
/
build.gradle
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
//sourceCompatibility = 10
//targetCompatibility = 10
repositories {
mavenCentral()
// jcenter()
//if https doesn't work
// jcenter {url "http://jcenter.bintray.com" }
}
dependencies {
//sync with versions included in Debian sid, if possible
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.jsoup', name: 'jsoup', version: '1.10.2'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
// compile group: 'net.sf.proguard', name: 'proguard-base', version: '6.0.1'
// compile group: 'net.sf.proguard', name: 'proguard-gradle', version: '6.0.1'
compile group: 'org.apache.xmlrpc', name: 'xmlrpc-common', version: '3.1.3'
compile group: 'org.apache.xmlrpc', name: 'xmlrpc-client', version: '3.1.3'
// compile fileTree(dir: 'lib', include: '*.jar')
}
sourceSets {
main {
java {
srcDirs = ['src/main','opt']
}
}
}
jar {
manifest {
attributes 'Main-Class': 'com.subgraph.orchid.TorClient'
}
}
//gradle clean fatJar
task fatJar(type: Jar) {
baseName = rootProject.name
manifest {
attributes 'Main-Class': 'com.subgraph.orchid.TorClient'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
//https://gist.github.com/JonasGroeger/7620911
def getGitSha() {
def gitFolder = "$projectDir/.git/"
def takeFromHash = 12
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
// def isRef = head.length > 1 // ref: refs/heads/master
if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb
def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
refHead.text.trim().take takeFromHash
}
def getReleaseTag() {
def gitTagStdOut = new ByteArrayOutputStream()
try{
exec {
commandLine "git", "describe", "--abbrev=0", "--tags"
standardOutput = gitTagStdOut
}
return gitTagStdOut.toString().trim()
} catch(all){
return '0.0.0'
}
}
version = getReleaseTag()
processResources {
def replacer = { replaceMap ->
return { line ->
def newLine = line
replaceMap.each { regex, replaceStr ->
if (line =~ regex) {
println "Replacing $line with $replaceStr"
newLine = replaceStr
}
}
return newLine
}
}
def fileName = rootProject.name+"-"+version+".jar"
def gitSha = getGitSha()
def releaseDate = new Date()
filesMatching('*.properties', { file ->
switch(file.name) {
case 'application.properties':
//Modify app.version and revision
file.filter(replacer([
/file\.name=.*/ : "file.name=$fileName",
/git\.sha=.*/ : "git.sha=$gitSha",
/release\.date=.*/ : "release.date=$releaseDate"
]))
break
}
})
}