-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpos-app.gradle
executable file
·238 lines (213 loc) · 6.32 KB
/
jpos-app.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
String archiveJarName="${project.name}-${project.version}.jar"
String archiveWarName="${project.name}-${project.version}.war"
String installDir=file("${project.buildDir}/install/${project.name}")
project.ext {
def target = project.hasProperty('target') ? target : 'devel'
targetConfiguration = configure(new Properties()) {
jarname = archiveJarName
warname = archiveWarName
target = target
buildTimestamp = new Date().format("yyyy-MM-dd HH:mm:ss z")
}
File cfgFile = file("${rootProject.projectDir}/${target}.properties")
if (cfgFile.exists()) {
cfgFile.withInputStream{
targetConfiguration.load(it);
}
}
}
// We build a CopySpec for consistency
def jposCopySpec = copySpec {
from(file("src/dist")) {
exclude 'cfg/*.lmk'
exclude 'cfg/*.jks'
exclude 'cfg/*.ks'
exclude 'cfg/*.ser'
exclude 'cfg/authorized_keys'
exclude '**/*.jpg'
exclude '**/*.gif'
exclude '**/*.png'
exclude '**/*.pdf'
exclude '**/*.ico'
exclude '**/*.war'
exclude '**/*.dat'
filter(
org.apache.tools.ant.filters.ReplaceTokens,
tokens: targetConfiguration
)
}
from(file("src/dist")) {
include 'cfg/*.lmk'
include 'cfg/*.ks'
include 'cfg/*.jks'
include 'cfg/*.ser'
include 'cfg/authorized_keys'
fileMode 0600
}
from(file("src/dist")) {
include '**/*.jpg'
include '**/*.gif'
include '**/*.png'
include '**/*.pdf'
include '**/*.ico'
include '**/*.war'
include '**/*.dat'
}
from(jar) {
rename archiveJarName, "${targetConfiguration.jarname}"
}
into("lib") {
from(configurations.runtime)
}
into("webapps") {
from(file("build/libs")) {
include '*.war'
}
}
}
// Create the jar's manifest
jar.manifest {
attributes \
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Main-Class': 'org.jpos.q2.Q2',
'Class-Path': configurations.runtime.collect { "lib/" + it.getName() }.join(' ')
}
task sourceJar( type: Jar ) {
classifier = "sources"
from sourceSets.main.allSource
}
task javadocJar (type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from new File(project.buildDir, 'docs/javadoc')
}
artifacts {
archives sourceJar, javadocJar
}
processResources {
from(sourceSets.main.resources.srcDirs) {
include '**/*.properties'
include '**/*.xml'
include '**/*.cfg'
include '**/*.asc'
filter(
org.apache.tools.ant.filters.ReplaceTokens,
tokens: targetConfiguration
)
}
}
//--------------------------------------------------
// TASKS
//--------------------------------------------------
task version (type: JavaExec, dependsOn: classes) {
description = "Shows jPOS Version"
main = 'org.jpos.q2.Q2'
args = ['--version']
classpath configurations.runtime
}
task dist(type: Tar) {
dependsOn 'assemble', 'sourceJar'
description 'Creates tar distribution'
compression = Compression.GZIP
includeEmptyDirs true
into "$project.name-$version"
with jposCopySpec
extension "tar.gz"
}
task zip(type: Zip) {
dependsOn 'assemble', 'sourceJar'
description 'Creates zip distribution'
includeEmptyDirs true
into "$project.name-$version"
with jposCopySpec
extension "zip"
}
task installApp(type: Sync) {
description 'Installs jPOS based application'
into { installDir }
with jposCopySpec
}
task installResources(dependsOn: 'classes', type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jpos.q2.install.Install'
args = ["--outputDir=src/dist"]
}
task run( dependsOn: 'installApp', type: Exec ) {
workingDir installDir
commandLine 'java','-jar', archiveJarName
}
/*
task genDocker(type: Docker, dependsOn: 'jar') {
def projectName = project.name
applicationName = "${projectName}"
workingDir "/app"
addFile {
into('/app') {
with(jposCopySpec)
}
}
defaultCommand = ["/app/bin/q2"]
}
*/
class GitRevisionTask extends DefaultTask
{
@InputFile @Optional
File gitHead
boolean gotHead
File getRefFile()
{
return new File(gitHead.parent,gitHead.text.replace('ref: ', '').trim())
}
@OutputFile
File outputFile
@TaskAction
public void writeFile()
{
Properties props=new Properties()
if (gotHead) {
File ref=getRefFile()
if (ref.exists()) {
props.put("branch",ref.getName())
props.put("revision",ref.text.substring(0,7))
} else {
props.put("branch", "detached");
props.put("revision", gitHead.text.substring(0,7))
}
} else {
props.put("branch", "unknown");
props.put("revision", "unknown");
}
props.store(new FileOutputStream(outputFile),"Revision Properties")
}
}
class BuildTimestampTask extends DefaultTask {
// We don't want to declare @OutputFile,
// we need a fresh timestamp on every run
File outputFile
@TaskAction
public void writeFile() {
new File(outputFile.parent).mkdirs()
Properties props=new Properties()
props.put("projectName", project.name);
props.put("version", project.version);
props.put("buildTimestamp", new Date().format("yyyy-MM-dd HH:mm:ss z"));
props.store(new FileOutputStream(outputFile),"Revision Properties")
}
}
task createBuildTimestampPropertyFile(type: BuildTimestampTask) {
outputFile = "$sourceSets.main.output.resourcesDir/buildinfo.properties" as File
}
task createRevisionPropertyFile(type: GitRevisionTask) {
gitHead = "$rootDir/.git/HEAD" as File
gotHead = gitHead.exists()
if (!gotHead)
gitHead = null;
outputFile = "$sourceSets.main.output.resourcesDir/revision.properties" as File
}
processResources.dependsOn createBuildTimestampPropertyFile, createRevisionPropertyFile
task viewTests (description: 'Open Test Reports') {
doLast {
Class.forName("java.awt.Desktop").newInstance().browse(
new File("${buildDir}/reports/tests/test", 'index.html').toURI())
}
}