Extend -verify to operate on existing class files/jars
Brought to you by:
tarasp
When compiling Java 6 source with -target 1.5, Retrotranslator could be very useful to verify that the generated classes can be loaded with a 1.5 runtime.
It seems that the -verify option is only applied to 'modified' (ie. translated classes). It would be very useful to allow -verify to be used on existing .class files (or jars) to ensure loadability with a different -classpath as specified.
The main thing that this gets us is to be able to support Java 5 users but still use the Java 6 compiler's optimizations and allow the use of @Override annotations on implemented interfaces which helps code correctness.
Retrotranslator should verify any processed input (even if there's nothing to translate) unless you're using -lazy or -uptodatecheck.
Can you give an example of your command line and elaborate on the issue you have?
The problem seems to be that I can't seem to get it to skip the translation step. What I mean to say is:
java -jar retrotranslator-transformer-1.2.9.jar -verbose -target 1.6 -classpath /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -verify -srcjar retrotest.jar
Of course -target 1.6 isn't supported, so instead I enter:
java -jar retrotranslator-transformer-1.2.9.jar -verbose -target 1.5 -classpath /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -verify -srcjar retrotest.jar
Which translates and give these messages:
Processing 2 file(s) in retrotest.jar.
com/oanda/test/RetroTest.class
Transformation
Transformed 1 file(s).
Verifying 2 file(s) in retrotest.jar.
com/oanda/test/RetroTest.class
Verification
com/oanda/test/RetroTest.class
Class not found: net.sf.retrotranslator.runtime.java.lang._String
Method not verified: static boolean net.sf.retrotranslator.runtime.java.lang._String.isEmpty(java.lang.String)
Verified 1 file(s) with 2 warning(s).
Moreover Retrotranslator.run() 1.2.9 reads as:
if (!modified) {
logger.log(new Message(Level.INFO, "Skipped verification of up-to-date file(s)."));
return systemLogger.isReliable();
}
verify(systemLogger);
which to me seems like it won't get to verify() if nothing was modified (which is exactly what I wish to do).
What you need is:
java -jar retrotranslator-transformer-1.2.9.jar -verbose -target 1.5 -classpath /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -verify -srcjar retrotest.jar -destjar throwaway.jar
If you don't specify -lazy every class will be translated (so the "modified" variable will be true). But since you have no backports throwaway.jar will be essentially the same as retrotest.jar.
So even if the verification is done on the throwaway.jar you can safely use the original retrotest.jar.
BTW, I don't understand how you obtain the following output without backports:
Class not found: net.sf.retrotranslator.runtime.java.lang._String
Method not verified: static boolean
net.sf.retrotranslator.runtime.java.lang._String.isEmpty(java.lang.String)
It should be instead:
Method not verified: boolean java.lang.String.isEmpty()
The references to net.sf.retrotranslator confuses me too.
In any case, running the suggested command line results:
$ java -jar retrotranslator-transformer-1.2.9.jar -verbose -target 1.5 -classpath /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -verify -srcjar retrotest.jar -destjar throwaway.jar
Processing 2 file(s) from retrotest.jar to throwaway.jar.
com/oanda/test/RetroTest.class
Transformation
Transformed 1 file(s).
Verifying 2 file(s) in throwaway.jar.
com/oanda/test/RetroTest.class
Verification
com/oanda/test/RetroTest.class
Class not found: net.sf.retrotranslator.runtime.java.lang._String
Method not verified: static boolean net.sf.retrotranslator.runtime.java.lang._String.isEmpty(java.lang.String)
Verified 1 file(s) with 2 warning(s).
$
Thanks for all your help, BTW.
Of course I had to rebulid the retrotest.jar since it was previously -destjar'ed.
$ java -jar retrotranslator-transformer-1.2.9.jar -verbose -target 1.5 -classpath /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -verify -srcjar retrotest.jar -destjar throwaway.jar
Processing 2 file(s) from retrotest.jar to throwaway.jar.
com/oanda/test/RetroTest.class
Transformation
Transformed 1 file(s).
Verifying 2 file(s) in throwaway.jar.
com/oanda/test/RetroTest.class
Verification
com/oanda/test/RetroTest.class
Method not found: boolean java.lang.String.isEmpty()
Verified 1 file(s) with 1 warning(s).
$
Beautiful! Thanks for your help, and a wonderful tool.
Keith