forked from jpos/jPOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
150 lines (131 loc) · 4.18 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
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
dependencies {
implementation "commons-cli:commons-cli:1.2"
implementation 'org.apache.felix:org.apache.felix.framework:5.4.0'
// compile( "org.osgi:org.osgi.core:4.3.1" )
}
def archiveJarName="${project.name}-${project.version}.jar"
def jposCopySpec = copySpec {
def cfg = new Properties()
def target = project.hasProperty('target') ? target : 'devel'
cfg.put('jarname', archiveJarName.toString())
cfg.put('target', target.toString())
File cfgFile = file("${target}.properties")
if (cfgFile.exists()) {
cfgFile.withInputStream{
cfg.load(it);
}
}
from(file("src/dist")) {
exclude 'cfg/*.jks'
filter(
org.apache.tools.ant.filters.ReplaceTokens,
tokens: cfg
)
}
from(file("src/dist")) {
include 'cfg/*.jks'
}
from(jar) {
rename archiveJarName, "${cfg.jarname}"
}
into("lib") {
from(configurations.runtimeClasspath)
}
}
task listJars {
doLast {
configurations.testCompile.each { File file -> println file.name }
}
}
jar () {
manifest {
def manifestClasspath = configurations.runtimeClasspath.collect { "lib/" + it.getName() }.join(' ')
attributes 'Implementation-Title': 'jPOS',
'Implementation-Version': project.version,
'Main-Class': 'org.jpos.qnode.QNode',
'Class-Path': manifestClasspath
}
}
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
}
task dist (type: Tar) {
dependsOn 'assemble', 'sourceJar'
compression = Compression.GZIP
includeEmptyDirs true
with jposCopySpec
into "jpos-$project.version"
}
task version (type: JavaExec, dependsOn: classes) {
description = "Display jPOS Version"
main = 'org.jpos.qnode.QNode'
args = "--version".split().toList()
classpath sourceSets.main.runtimeClasspath, configurations.runtime
}
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("version", project.version);
props.put("buildTimestamp", new Date().format("yyyy-MM-dd HH:mm:ss z"));
props.store(new FileOutputStream(outputFile),"Revision Properties")
}
}
task createRevisionPropertyFile(type: GitRevisionTask) {
gitHead = "$rootDir/.git/HEAD" as File
gotHead = gitHead.exists()
if (!gotHead)
gitHead = null;
outputFile = "$sourceSets.main.output.resourcesDir/org/jpos/qnode/revision.properties" as File
}
task createBuildTimestampPropertyFile(type: BuildTimestampTask) {
outputFile = "$sourceSets.main.output.resourcesDir/org/jpos/qnode/buildinfo.properties" as File
}
processResources.dependsOn createBuildTimestampPropertyFile, createRevisionPropertyFile
task installApp(type: Sync) {
description 'Installs jPOS based application'
into { file("${project.buildDir}/install/${project.name}") }
with jposCopySpec
}