Offline post-compilation
This document explains the detail of the
offline post-compilation
feature provided by beSee. This mechanism allows to prepare the class files and jars
you are using, instrumenting them thru some command lines calls, and use them or deploy them as usual, without using the beSee
JVM wide hook
architecture.
Supported environmentsbeSee offline compiler has been validated with the following environments:
beSee compiler makes use of Ant libraries to manipulate files and providing complete rollback feature in case an error occurs during the offline transformation of a class file. Usage
beSee compiler is a regular java main class.
java -cp {classpath} com.gnilux.besee.compiler.BeseeC [-verbose] [-haltOnError] {ClassPreProcessorImpl} {target 1} .. {target n}
SamplesThe following runs a compilation on a single jar test.jar and modify all classes (except interface) in order they implement an empty marker interface. You can reproduce this sample by calling the ant target demo.compiler . Both the MarkerInterface and the AddInterfacePreProcessor compiled class will need to be in the classpath during compilation
package demo; /** * Marker interface used to test Besee compiler */ public interface MarkerInterface { } package demo.preprocessor; public class AddInterfacePreProcessor implements ClassPreProcessor { //... (refer to ClassPreProcessor specification) public byte[] preProcess(String klass, byte abyte[], ClassLoader caller) { try { // build the ClassGen ClassParser parser = new ClassParser(new ByteArrayInputStream(abyte), "<generated_"+klass+">"); ClassGen cg = new ClassGen(parser.parse()); // instrument if ( ! cg.isInterface() && ! Arrays.asList(cg.getInterfaceNames()).contains("demo.MarkerInterface") ) cg.addInterface("demo.MarkerInterface"); return cg.getJavaClass().getBytes(); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } // assuming demo.MarkerInterface and demo.AddInterfacePreProcessor are compiled in ./classes/ java -cp besee-2-version.jar;classes;bcel.jar;ant.jar -verbose -haltOnError demo.AddInterfacePreProcessor path/to/test.jar [backup] Copying 1 file to C:\cvs_02\besee_sf\besee2\beseec\1 [backup] Copying C:\cvs_02\besee_sf\besee2\build\test.jar to C:\cvs_02\besee_sf\besee2\beseec\1\test.jar [compilejar] C:\cvs_02\besee_sf\besee2\build\test.jar ... [compilejar] compile test.jar:org/apache/bcel/verifier/Verifier.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame$1.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame$2.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame$3.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame$4.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame$5.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame$6.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierAppFrame.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierFactory.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierFactoryListModel.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifierFactoryObserver.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifyDialog$1.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifyDialog$IvjEventHandler.class [compilejar] compile test.jar:org/apache/bcel/verifier/VerifyDialog.class [backup] removing backup [delete] Deleting 1 files from C:\cvs_02\besee_sf\besee2\beseec [delete] Deleted 1 directories from C:\cvs_02\besee_sf\besee2\beseec ( 2 s ) SUCCESS: build\test.jar Manifest-Version: 1.0 Created-By: Apache Jakarta Maven X-BeseeC-preprocessor: com.gnilux.besee.hook.impl.AddInterfacePreProcessor X-BeseeC-created: 2003-07-09 15:58:23 X-BeseeC-comment: BeseeC - beSee compiler, www.gnilux.com // Decompiled by DJ v3.0.0.63 Copyright 2002 Atanas Neshkov Date: 09/07/2003 16:03:01 // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version! // Decompiler options: packimports(3) // Source File Name: VerifyDialog.java package org.apache.bcel.verifier; import demo.MarkerInterface; .. // Referenced classes of package org.apache.bcel.verifier: // VerifierFactory, Verifier, VerificationResult public class VerifyDialog extends JDialog implements MarkerInterface { .. } |