Skip to content

Commit

Permalink
Add %J (JDK version) to name template
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Mar 26, 2024
1 parent fbb33a9 commit b05f306
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion task/src/main/java/pro/javacard/ant/JCCap.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

// <cap ...>...</cap> 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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit b05f306

Please sign in to comment.