From b05f30673dfbe2e842f08f0247151765a5fd579e Mon Sep 17 00:00:00 2001 From: Martin Paljak Date: Tue, 26 Mar 2024 07:33:44 +0200 Subject: [PATCH] Add %J (JDK version) to name template --- Makefile | 6 +++--- README.md | 18 ++++++++++++------ task/src/main/java/pro/javacard/ant/JCCap.java | 5 ++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 690dba3..e5590cd 100644 --- a/Makefile +++ b/Makefile @@ -20,13 +20,13 @@ cap: JAVA_HOME=$(JAVA21) ./mvnw package 8: - JAVA_HOME=$(JAVA8) ant clean test + JAVA_HOME=$(JAVA8) ant test 11: - JAVA_HOME=$(JAVA11) ant clean test + JAVA_HOME=$(JAVA11) ant test 17: - JAVA_HOME=$(JAVA17) ant clean test + JAVA_HOME=$(JAVA17) ant test all: cap 8 11 17 diff --git a/README.md b/README.md index 814d894..ef14eaf 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,12 @@ target: - Targeting JC 3.0.4 or later (modern JavaCard-s) - Use JDK 17 (don't forget to set `$JAVA_HOME`) - Use JavaCard SDK 3.2.0 (`jckit="sdks/jc320v24.0_kit"`) with right target (`targetsdk="3.x.y"`) + - NOTE: depending on your external components, absence of v2.3 export files will force you to stick with JavaCard SDK 3.1 - Targeting JC 2.x.y or 3.0.1 (legacy JavaCard-s) - Use JDK 8 (don't forget to set `$JAVA_HOME`) - Use JavaCard SDK 3.0.5u4 (`jckit="sdks/jc305u4_kit"`) with right target (`targetsdk="sdks/jc222_kit"`) -> Note: ant-javacard will continue to support JavaCard 2 for as long as this is achievable with sane effort. +> Note: ant-javacard will continue to support JavaCard 2 for as long as this is achievable with sane effort ## Syntax Sample: @@ -114,12 +115,17 @@ Notes: * All source files are expected to be UTF-8. It is a sane choice, please use it. ### Output file name variables - * `%h` - 8 character prefix of the SHA-256 Load File Data Block hash of the CAP file - * `%H` - SHA-256 Load File Data Block hash of the CAP file - * `%n` - _common name_ of the entity, either applet class or package + +The default file name template is `%n_%a_%h_%j_%J.cap` which results in a file name similar to `SomeApplet_010203040506_9a037e30_2.2.2_jdk11.cap`. + +Following substitutions are available: + * `%h` - 8 character prefix (hex) of the SHA-256 Load File Data Block hash of the CAP file + * `%H` - SHA-256 Load File Data Block hash (hex) of the CAP file + * `%n` - _common name_ of the entity, either applet class (if only one applet) or package name * `%p` - package name - * `%a` - package AID - * `%j` - targeted JavaCard version + * `%a` - package AID (hex) + * `%j` - targeted JavaCard version (ex: 3.0.5) + * `%J` - used JDK version (ex: jdk11) ### Command line utility (still WIP until [#92](https://github.com/martinpaljak/ant-javacard/issues/92)) `ant-javacard.jar` can be used to dump built .cap file metadata and to re-run off-card verifier. diff --git a/task/src/main/java/pro/javacard/ant/JCCap.java b/task/src/main/java/pro/javacard/ant/JCCap.java index 0ed3f14..4f2893e 100644 --- a/task/src/main/java/pro/javacard/ant/JCCap.java +++ b/task/src/main/java/pro/javacard/ant/JCCap.java @@ -45,6 +45,8 @@ // ... and actual execution of core task. public class JCCap extends Task { + + static final String DEFAULT_CAP_NAME_TEMPLATE = "%n_%a_%h_%j_%J.cap"; // SomeApplet_010203040506_9a037e30_2.2.2_jdk11.cap private final String master_jckit_path; private JavaCardSDK jckit = null; private String classes_path = null; @@ -346,7 +348,7 @@ else if (getProject().resolveFile("src/main/java").isDirectory()) } // Default output name if (output_cap == null) { - output_cap = "%n_%a_%h_%j.cap"; // SomeApplet_010203040506_9a037e30_2.2.2.cap + output_cap = DEFAULT_CAP_NAME_TEMPLATE; } } @@ -777,6 +779,7 @@ private String capFileName(CAPFile cap, String template) { name = name.replace("%a", cap.getPackageAID().toString()); // package AID name = name.replace("%j", cap.guessJavaCardVersion().orElse("unknown")); // JavaCard version name = name.replace("%g", cap.guessGlobalPlatformVersion().orElse("unknown")); // GlobalPlatform version + name = name.replace("%J", String.format("jdk%d", Misc.getCurrentJDKVersion())); // JDK version return name; } }