package com.avaje.ebean.enhance.ant; import com.avaje.ebean.enhance.agent.Transformer; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import java.io.File; /** * An ANT task that can enhance entity beans etc for use by Ebean. * <p> * You can use this ANT task as part of your build process to enhance entity * beans etc. * </p> * <p> * The parameters are: * <ul> * <li> <b>classSource</b> This is the root directory where the .class files * are found. </li> * <li> <b>classDestination</b> This is the root directory where the .class * files are written to. If this is left out then this defaults to the * <b>classSource</b>. </li> * <li> <b>packages</b> A comma delimited list of packages that is searched for * classes that need to be enhanced. If the package ends with ** or * then all * subpackages are also searched. </li> * <li> <b>transformArgs</b> Arguments passed to the transformer. Typically a * debug level in the form of debug=1 etc. </li> * </ul> * </p> * * <pre class="code"> * * <taskdef name="ebeanEnhance" classname="com.avaje.ebean.enhance.ant.AntEnhanceTask" classpath="bin" /> * * <target name="enhance" depends="compile"> * <ebeanEnhance * classSource="${bin.dir}" * packages="com.avaje.ebean.meta.**, com.acme.myapp.entity.**" * transformArgs="debug=1" /> * </target> * * </pre> */ public class AntEnhanceTask extends Task { String classpath; String classSource; String classDestination; String transformArgs; String packages; @Override public void execute() throws BuildException { File f = new File(""); System.out.println("Current Directory: "+f.getAbsolutePath()); StringBuilder extraClassPath = new StringBuilder(); extraClassPath.append(classSource); if (classpath != null) { if (!extraClassPath.toString().endsWith(";")) { extraClassPath.append(";"); } extraClassPath.append(classpath); } Transformer t = new Transformer(extraClassPath.toString(), transformArgs); ClassLoader cl = AntEnhanceTask.class.getClassLoader(); OfflineFileTransform ft = new OfflineFileTransform(t, cl, classSource, classDestination); ft.process(packages); } /** * the classpath used to search for e.g. inerited classes */ public String getClasspath() { return classpath; } /** * the classpath used to search for e.g. inerited classes */ public void setClasspath(String classpath) { this.classpath = classpath; } /** * Set the directory holding the class files we want to transform. */ public void setClassSource(String source) { this.classSource = source; } /** * Set the destination directory where we will put the transformed classes. * <p> * This is commonly the same as the classSource directory. * </p> */ public void setClassDestination(String destination) { this.classDestination = destination; } /** * Set the arguments passed to the transformer. */ public void setTransformArgs(String transformArgs) { this.transformArgs = transformArgs; } /** * Set the package name to search for classes to transform. * <p> * If the package name ends in "/**" then this recursively transforms all * sub packages as well. * </p> */ public void setPackages(String packages) { this.packages = packages; } }