org.codehaus.aspectwerkz.compiler
Class AspectWerkzC

java.lang.Object
  extended byorg.codehaus.aspectwerkz.compiler.AspectWerkzC

public class AspectWerkzC
extends java.lang.Object

AspectWerkzC allow for precompilation of class / jar / zip given a class preprocessor.

Usage

 java [-Daspectwerkz.classloader.preprocessor={ClassPreProcessorImpl}] -cp [...] org.codehaus.aspectwerkz.compiler.AspectWerkzC [-verbose] [-haltOnError] [-verify] [-cp {additional cp i}]*  {target 1} .. {target n}
   {ClassPreProcessorImpl} : full qualified name of the ClassPreProcessor implementation (must be in classpath)
      defaults to org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor
   {additional cp i} : additionnal classpath needed at compile time (eg: myaspect.jar)
      use as many -cp options as needed
      supports java classpath syntax for classpath separator: ; on windows, : on others
   {target i} : exploded dir, jar, zip files to compile
   Ant 1.5 must be in the classpath
 

Classpath note

At the beginning of the compilation, all {target i} are added to the classpath automatically.
This is required to support caller side advices.

Error handling

For each target i, a backup copy is written in ./_aspectwerkzc/i/target
Transformation occurs on original target class/dir/jar/zip file
On failure, target backup is restored and stacktrace is given

If -haltOnError was set, compilations ends and a complete rollback occurs on all targets, else a status report is printed at the end of the compilation, indicating SUCCESS or ERROR for each given target.
If -verify was set, all compiled class are verified during the compilation and an error is generated if the compiled class bytecode is corrupted. The error is then handled according to the -haltOnError option.

Manifest.mf update

The Manifest.mf if present is updated wit the following:

Author:
Alexandre Vasseur

Constructor Summary
AspectWerkzC()
          Construct a new Utility, restore the index for backup
 
Method Summary
 void backup(java.io.File source, int index)
          Backup source file in backup_dir/index/file.
 boolean compile(java.io.File source)
          Compile given target.
 void compileClass(java.io.File file, java.lang.String packaging)
          Compiles .class file using fileName as className and given packaging as package name
 void compileJar(java.io.File file)
          Compile all .class encountered in the .jar/.zip file.
 void doCompile(java.io.File sourceFile, java.lang.String prefixPackage)
          Compile sourceFile.
static void doHelp()
          Usage message
 Utility getUtility()
           
static boolean isJarFile(java.io.File source)
          Test if file is a zip/jar file
static void main(java.lang.String[] args)
           
 void postCompile(java.lang.String message)
          Delete backup dir at the end of all compilation
 void restoreBackup()
          Restore the backup registered
 void setCompilationPath(java.io.File[] targets)
          Set up the compilation path by building a URLClassLoader with all targets in
 void setHaltOnError(boolean haltOnError)
           
 void setPreprocessor(java.lang.String preprocessor)
          Sets the ClassPreProcessor implementation to use.
 void setVerbose(boolean verbose)
           
 void setVerify(boolean verify)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AspectWerkzC

public AspectWerkzC()
Construct a new Utility, restore the index for backup

Method Detail

setVerbose

public void setVerbose(boolean verbose)

setHaltOnError

public void setHaltOnError(boolean haltOnError)

setVerify

public void setVerify(boolean verify)

getUtility

public Utility getUtility()

setPreprocessor

public void setPreprocessor(java.lang.String preprocessor)
                     throws CompileException
Sets the ClassPreProcessor implementation to use. The ClassLoader will be set to System ClassLoader when transform(className, byteCode, callerClassLoader) will be called to compile a class.

Throws:
CompileException

backup

public void backup(java.io.File source,
                   int index)
Backup source file in backup_dir/index/file. The backupMap is updated for further rollback


restoreBackup

public void restoreBackup()
Restore the backup registered


postCompile

public void postCompile(java.lang.String message)
Delete backup dir at the end of all compilation


doCompile

public void doCompile(java.io.File sourceFile,
                      java.lang.String prefixPackage)
               throws CompileException
Compile sourceFile. If prefixPackage is not null, assumes it is the class package information. Handles :

Throws:
CompileException

compileClass

public void compileClass(java.io.File file,
                         java.lang.String packaging)
                  throws CompileException
Compiles .class file using fileName as className and given packaging as package name

Throws:
CompileException

compileJar

public void compileJar(java.io.File file)
                throws CompileException
Compile all .class encountered in the .jar/.zip file. The target.jar is compiled in the target.jar.aspectwerkzc and the target.jar.aspectwerkzc then overrides target.jar on success.

Throws:
CompileException

compile

public boolean compile(java.io.File source)
Compile given target.

Returns:
false if process should stop

setCompilationPath

public void setCompilationPath(java.io.File[] targets)
Set up the compilation path by building a URLClassLoader with all targets in

Parameters:
targets - to add to compilationLoader classpath

isJarFile

public static boolean isJarFile(java.io.File source)
Test if file is a zip/jar file


doHelp

public static void doHelp()
Usage message


main

public static void main(java.lang.String[] args)


Copyright (c) 2002-2004 The AspectWerkz Team. All Rights Reserved.