philipWendland / IsoApplet

A Java Card PKI Applet aiming to be ISO 7816 compliant
GNU General Public License v3.0
165 stars 72 forks source link

Use ant-javacard for building the applet. #3

Closed martinpaljak closed 9 years ago

martinpaljak commented 9 years ago

This works on all platforms and all JavaCard SDK versions and is more pleasing to eye.

philipWendland commented 9 years ago

Thank you, I did actually test this on a local branch but got distracted. From the readme of jcpro, the build.xml you provided should work out of the box when JC_HOME is set. However, I get:

[philip@philip-pc IsoApplet]$ echo $JC_HOME
/opt/java/lib/java-card-development-kit
[philip@philip-pc IsoApplet]$ ant
Buildfile: /home/philip/projects/github/IsoApplet/build.xml

dist:

BUILD FAILED
/home/philip/projects/github/IsoApplet/build.xml:8: Must specify JavaCard SDK path

Total time: 0 seconds
[philip@philip-pc IsoApplet]$

Am I wrong? Do you need more debug information?

I know from earlier tests that it does work when specifying the java card SDK manually by:

<javacard jckit="/path/to/jckit_dir1">
  <cap jckit="/path/to/jckit_dir2" (...)
martinpaljak commented 9 years ago

JC_HOME was documented on README but not released as a downloadable JAR. This was fixed before making this pull request, that includes https://github.com/martinpaljak/ant-javacard/releases/tag/v0.8

The warning is correct with both versions:

/Users/martin/projects/IsoApplet/build.xml:8: Must specify JavaCard SDK path or set JC_HOME

philipWendland commented 9 years ago

Nevermind. I had ant-javacard in $ANT_HOME/lib from earlier and ant favored to use the older version located there..

You might have seen this as well:

[compile] /home/philip/projects/github/IsoApplet/src/net/pwendland/javacard/pki/isoapplet/ElementaryFileCyclicFixed.java:68: error: annotations are not supported in -source 1.3
  [compile]     @Override
  [compile]      ^
  [compile]   (use -source 5 or higher to enable annotations)

As far as I remember, the IsoApplet uses features introduced in JC 2.2.2 (getIncomingLength, getOffsetCData etc.) which builds upon Java SDK 1.5 [1]. As there is no possibility to go below JC 2.2.2, compiling the sources with -source 1.5 might make sense.

In the source code of ant-javacard I found:

312         // TODO: detect
313         // 2.2.1 max 1.2
314         // 2.2.2 max 1.3
315         // 3.0.3 max 1.6. Overrides come in 1.5

Where did you get that information from? See the link below, JC 2.2.2 should be JDK 1.5. I am currently using -source 1.5 as well. It's not that having the annotiation is a must for me, I just wanted to note this.

[1] http://www.oracle.com/technetwork/java/javacard/documentation/releasenotes-jcspecspw-2-2-2-142671.html - "Java Card platform language aligned with JDK^TM version 1.5 technology and tools"

martinpaljak commented 9 years ago

Interesting. I really don't remember but it should have come from some empirical tests that are apparently wrong. I'll need to look into this. Thanks for noticing.

philipWendland commented 9 years ago

I'd rather not have the ant-javacard.jar binary in the version control. There are two ways to get around this; either have the user/contributor download ant-javacard.jar himself or

including the ant-javacard source code as git submodule (cd ext && git submodule add https://github.com/martinpaljak/ant-javacard.git) and have ant (recursively) call its build.xml to generate the jar, see below. What do you think of this idea?

Either way, could you please rebase your commit to not include the ant-javacard.jar binary?

diff --git a/build.xml b/build.xml
index 8440e92..051c4d4 100644
--- a/build.xml
+++ b/build.xml
@@ -1,10 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project name="JavaCard PKI isoApplet" default="dist" basedir=".">
+<project name="JavaCard PKI IsoApplet" default="dist" basedir=".">
   <description>Builds the project. </description>
-  <target name="dist" description="generate the distribution">
+
+  <target name="init-ant-javacard" description="build ant-javacard">
+    <tstamp/>
+    <ant antfile="build.xml" dir="ext/ant-javacard" />
+    <taskdef name="javacard" classname="pro.javacard.ant.JavaCard" classpath="ext/ant-javacard/ant-javacard.jar"/>
+  </target>
+
+  <target name="dist" depends="init-ant-javacard" description="generate the distribution">
     <tstamp/>
     <!-- Create the distribution directory -->
-    <taskdef name="javacard" classname="pro.javacard.ant.JavaCard" classpath="ext/ant-javacard.jar"/>
     <javacard>
       <cap aid="f2:76:a2:88:bc:fb:a6:9d:34:f3:10" output="IsoApplet.cap" sources="src" version="1.0">
         <applet class="net.pwendland.javacard.pki.isoapplet.IsoApplet" aid="f2:76:a2:88:bc:fb:a6:9d:34:f3:10:01"/>
martinpaljak commented 9 years ago

What about this ?

philipWendland commented 9 years ago

Perfect, thank you! Applied.