-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.gradle
235 lines (197 loc) · 6.66 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
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
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'java'
id 'checkstyle'
id 'groovy'
}
apply plugin: 'java'
// set default properties
// override in command line like: gradle deployPaymentApp -Pjc_version=2.2.2 -Ppaymentapp_cap_aid=A000000123456
if (!project.hasProperty("jc_version")) {
ext.jc_version = "3.0.5"
}
if (!project.hasProperty("paymentapp_cap_aid")) {
ext.paymentapp_cap_aid = "AFFFFFFFFF0000"
}
if (!project.hasProperty("paymentapp_applet_aid")) {
ext.paymentapp_applet_aid = "AFFFFFFFFF1234"
}
// 3.1.0 targeting does not work
/*if (jc_version == "3.1.0") {
// class major version 51
ext.java_version_compatible = 1.7
ext.jc_sdk = "jc310b43_kit"
} else*/ if (jc_version == "3.0.5") {
// class major version 51
ext.java_version_compatible = 1.7
ext.jc_sdk = "jc305u3_kit"
} else if (jc_version == "3.0.4") {
// class major version 50
ext.java_version_compatible = 1.6
ext.jc_sdk = "jc304_kit"
} else if (jc_version == "3.0.1") {
// class major version 50
ext.java_version_compatible = 1.6
ext.jc_sdk = "jc303_kit"
} else if (jc_version == "2.2.2") {
// class major version 49
ext.java_version_compatible = 1.5
ext.jc_sdk = "jc222_kit"
} else if (jc_version == "2.2.1") {
// class major version 46
ext.java_version_compatible = 1.2
ext.jc_sdk = "jc221_kit"
} else {
throw new GradleException("JavaCard version not recognized: ${jc_version}")
}
// Nix-shell pure environment's gradle does not find cargo somehow
// working around via bash/cmd call
ext.cmd_shell = "bash"
ext.cmd_shell_option = "-c"
if (System.properties['os.name'].toLowerCase().contains('windows')) {
ext.cmd_shell = "cmd"
ext.cmd_shell_option = "/c"
}
task buildSimulatorLibrary(type: Exec) {
group "Build"
description "Build Rust simulator library"
workingDir 'src/test/rust/simulator'
commandLine "${cmd_shell}", "${cmd_shell_option}", 'cargo build'
}
tasks.withType(Test) {
systemProperty "java.library.path", "../../rust/simulator/target/debug/"
}
checkstyle {
// Align version with verification-metadata.xml
toolVersion '8.27';
}
checkstyleMain {
source ='src/main/java'
maxWarnings = 0
}
checkstyleTest {
source ='src/test/java'
maxWarnings = 0
}
repositories {
mavenCentral()
}
configurations {
javacardAntTask
}
dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:latest.release'
testImplementation (
'org.junit.jupiter:junit-jupiter-api:latest.release',
'com.klinec:jcardsim:latest.release'
)
implementation (
'com.klinec:jcardsim:latest.release'
)
javacardAntTask 'com.github.martinpaljak:ant-javacard:latest.release'
}
test {
dependsOn buildSimulatorLibrary
workingDir 'src/test/java/emvcardsimulator'
useJUnitPlatform()
testLogging {
outputs.upToDateWhen { false }
events "started", "skipped", "failed"
exceptionFormat "full"
showStandardStreams true
}
failFast = false
}
compileJava {
options.compilerArgs = [
'-Xlint:all',
'-Xlint:-options', //java 13 warns about Java 7 targetting
'-Xlint:-deprecation', // Some Java Card features are deprecated in 3.0.5 but we target earlier versions
'-Werror'
]
sourceCompatibility = java_version_compatible
targetCompatibility = java_version_compatible
// in case need to target for very old Java class major version
if (project.hasProperty("compile_javac_path")) {
options.fork = true
options.forkOptions.executable = "${compile_javac_path}"
}
}
compileTestJava {
options.compilerArgs = [
'-Xlint:all',
'-Xlint:-options', //java 13 warns about Java 7 targetting
'-Werror'
]
// JUnit 5 requires Java 8 or newer
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
task downloadGp {
doLast {
String gpJar = 'gp.jar'
if (!new File(gpJar).exists()) {
String checksumExtension = '.sha512.tmp'
String gpJarTemp = gpJar + checksumExtension
ant.get(src: 'https://github.com/martinpaljak/GlobalPlatformPro/releases/download/v20.07.04/gp.jar', dest:gpJar)
ant.checksum(file: gpJar, algorithm:'SHA-512', fileext: checksumExtension)
String expectedChecksum = "4030c6eb46fb932c167f9a53fdbfab6b1364dbaafad5068b5bfc9779140cc1659e655d5ff53ee20d2823163011ede3ec9c3916632c2173cb6a1e17b84389490a"
String actualChecksum = new File(gpJarTemp).text.trim()
delete gpJarTemp
if (!expectedChecksum.equals(actualChecksum)) {
throw new GradleException("Checksum not valid! file: " + gpJar + ", expected: " + expectedChecksum + ", actual: " + actualChecksum)
}
}
}
}
task cap {
dependsOn assemble
group "Build"
description "Assembles a cap archive containing the main classes."
doLast {
ant.taskdef(name: 'javacard', classname: 'pro.javacard.ant.JavaCard', classpath: configurations.javacardAntTask.asPath)
// 1PAY.SYS.DDF01
ant.javacard(jckit: "oracle_javacard_sdks/${jc_sdk}") {
cap (
package: 'emvcardsimulator',
version: '0.1',
output: 'build/pse.cap',
jca: 'build/pse.jca',
export: 'build',
classes: "build/classes/java/main",
aid: '315041592E000000000000000000') {
applet (class: 'emvcardsimulator.PaymentSystemEnvironment', aid: '315041592E5359532E4444463031')
}
}
ant.javacard(jckit: "oracle_javacard_sdks/${jc_sdk}") {
cap (
package: 'emvcardsimulator',
version: '0.1',
output: 'build/paymentapp.cap',
jca: 'build/paymentapp.jca',
export: 'build',
classes: "build/classes/java/main",
aid: paymentapp_cap_aid) {
applet (class: 'emvcardsimulator.PaymentApplication', aid: paymentapp_applet_aid)
}
}
}
}
// force delete might sometimes be needed?
// java -jar gp.jar --delete A000000003 --force
task deployPse(type: Exec) {
dependsOn downloadGp, cap
group "JavaCard"
description "Deploy PaymentSystemEnvironment applet to JavaCard"
commandLine 'java', '-jar', 'gp.jar', '--force', '--install', 'build/pse.cap'
}
task deployPaymentApp(type: Exec) {
dependsOn downloadGp, cap
group "JavaCard"
description "Deploy payment application applet to JavaCard"
commandLine 'java', '-jar', 'gp.jar', '--force', '--install', 'build/paymentapp.cap'
}