java - How to use offline bytecode writer with Cofoja? -


i'm trying offline instrumentation of code using cofoja (contracts java). cannot seem contracts in compiled class file using offline bytecode writer (this feature briefly mentioned in invocation section of github page). execute resulting class file , purposely fail contract. nothing happens.

here java code... in main like: return divide(10, 0);

  @requires("y != 0")   public static int divide(int x, int y)   {     return x / y;   } 

then following:

i build .java file via ide, intellij , class file.
execute offline bytecode writer this:

java -dcom.google.java.contract.classoutput=cofoja -cp cofoja.asm-1.2-20140817.jar com.google.java.contract.core.agent.premain javatest.class 

this results in "javatest.class" file being generated in "cofoja" directory. however, when execute don't see contract errors.

does know correct steps use "com.google.java.contract.core.agent.premain" generate class files contracts weaved in?

just future reference, went , looked @ source code com.google.java.contract.core.agent.premain. turns out expects contract files , helper files live in same place regular java class files. once include class files along contract files (in same directory) started working.
recap:

java -d {output_dir} -cp {your_classpath} "-acom.google.java.contract.classoutput={output_dir}" "-acom.google.java.contract.classpath={your_classpath}" "-acom.google.java.contract.sourcepath={your_sources_dir}" -processor com.google.java.contract.core.apt.annotationprocessor 

to compile java classes , cofoja contract files. make sure class files go in same directory cofoja contract files.
execute this:

java -dcom.google.java.contract.classoutput={output_dir} -cp cofoja.asm-1.2-20140817.jar com.google.java.contract.core.agent.premain {all .class files separated spaces} 

this command generate single .class files contracts built in can compile jar file. note need have list of of original class files arguments last command , make sure contract files , helper files sitting next corresponding class file.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -