aboutsummaryrefslogtreecommitdiff
path: root/applet/build.gradle.kts
blob: 091dc09c8754250ce28d8827b53232f55aca3ca3 (plain)
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
// Buildscript configuration for the javacard-gradle plugin.
// Do not modify this particular block. Dependencies for the project are lower.
buildscript {
    repositories {
        mavenCentral()
        maven("https://mvn.javacard.pro/maven")
        maven("https://deadcode.me/mvn")
    }
    dependencies {
        classpath("com.klinec:gradle-javacard:1.8.0")
    }
}

plugins {
    id("com.klinec.gradle.javacard") version "1.8.0"
    id("java")
}

// Common settings, definitions
val rootPath = rootDir.absolutePath
val libs = "$rootPath/ext/libs"
val libsSdk = "$rootPath/ext/sdks"

// Repositories for your project
repositories {
    mavenCentral()
    // mavenLocal() // for local maven repository if needed

    // Repository with JCardSim, Globalplatform, etc, ...
    maven("https://mvn.javacard.pro/maven")
    maven("https://deadcode.me/mvn")

    // Local lib repository
    flatDir {
        dirs(libs)
    }
}

// Dependencies for your project
dependencies {
    jcardsim("com.klinec:jcardsim:3.0.5.11")
    implementation("com.klinec:jcardsim:3.0.5.11")

    testImplementation(platform("org.junit:junit-bom:5.10.2"))
    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")

    // Include plugin as it has bundled GP & other tools.
    // Alternative: include GP manually, but the included
    // version has to be compatible with the plugin.
    runtimeOnly("com.klinec:gradle-javacard:1.8.0") {
        // Exclude old BouncyCastle (we have newer).
        exclude(group = "org.bouncycastle", module="bcpkix-jdk15on")
    }
    runtimeOnly("org.bouncycastle:bcpkix-jdk18on:1.77")
}

java {
    sourceCompatibility = if (JavaVersion.current() == JavaVersion.VERSION_1_8) JavaVersion.VERSION_1_8 else JavaVersion.VERSION_11
}

tasks.named<Test>("test") {
    useJUnitPlatform()
}

// JavaCard SDKs and libraries
val sdks = mapOf(
        "JC211" to Triple("$libsSdk/jc211_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_1_8),
        "JC212" to Triple("$libsSdk/jc212_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_1_8),
        "JC221" to Triple("$libsSdk/jc221_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_1_8),
        "JC222" to Triple("$libsSdk/jc222_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_1_8),
        "JC303" to Triple("$libsSdk/jc303_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_11),
        "JC304" to Triple("$libsSdk/jc304_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_11),
        "JC305u2" to Triple("$libsSdk/jc305u2_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_11),
        "JC305u3" to Triple("$libsSdk/jc305u3_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_11),
        "JC305u4" to Triple("$libsSdk/jc305u4_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_11),
        "JC310b43" to Triple("$libsSdk/jc310b43_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_17),
        "JC310r20210706" to Triple("$libsSdk/jc310r20210706_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_17),
        "JC320v24" to Triple("$libsSdk/jc320v24.0_kit", JavaVersion.VERSION_1_8, JavaVersion.VERSION_17),
)

var pkgAID = "4543546573746572"
var version = "0.3.3"

javacard {
    config {
        // Using custom repo with jcardsim
        debugGpPro(true)
        addImplicitJcardSim(false)
        addImplicitJcardSimJunit(false)

        if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
            /*
            // Exclude for the time being, as the "excludes" param is not properly implemented upstream.
            // https://github.com/ph4r05/javacard-gradle-plugin/pull/11
            cap {
                jckit(sdks["JC221"]!!.first)
                packageName("cz.crcs.ectester.applet")
                version(version)
                aid(pkgAID)
                output("applet221.cap")

                //excludes("ECTesterAppletExtended.*")

                applet {
                    className("cz.crcs.ectester.applet.ECTesterApplet")
                    aid("454354657374657230333320323231")
                }
            }
        */

            cap {
                jckit(sdks["JC222"]!!.first)
                packageName("cz.crcs.ectester.applet")
                version(version)
                aid(pkgAID)
                output("applet222.cap")

                //excludes("ECTesterApplet.*")

                applet {
                    className("cz.crcs.ectester.applet.ECTesterAppletExtended")
                    aid("454354657374657230333320323232")
                }
            }
        }

        if (JavaVersion.current() >= JavaVersion.VERSION_1_8 && JavaVersion.current() <= JavaVersion.VERSION_11) {
            cap {
                jckit(sdks["JC305u4"]!!.first)
                packageName("cz.crcs.ectester.applet")
                version(version)
                aid(pkgAID)
                output("applet305.cap")

                //excludes("ECTesterApplet.*")

                applet {
                    className("cz.crcs.ectester.applet.ECTesterAppletExtended")
                    aid("454354657374657230333320323035")
                }
            }
        }

        if (JavaVersion.current() > JavaVersion.VERSION_11) {
            // This really only works for Java <= 17, but if the check is added, then configuration
            // of the project will not work for Java > 17.
            cap {
                jckit(sdks["JC320v24"]!!.first)
                packageName("cz.crcs.ectester.applet")
                version(version)
                aid(pkgAID)
                output("applet320.cap")

                //excludes("ECTesterApplet.*")

                applet {
                    className("cz.crcs.ectester.applet.ECTesterAppletExtended")
                    aid("454354657374657230333320323230")
                }
            }
        }
    }
}