/** * */ package com.pjaol.gwt.ant; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.Path; import com.google.gwt.dev.GWTCompiler; /** * @author Patrick O'Leary (pjaol@pjaol.com) * * */ public class GWTCompile extends Task { public static class logLevels extends EnumeratedAttribute{ @Override /** * log values for GWTCompiler */ public String[] getValues() { // ide's such as eclipse, xdoclet editor lower case the enumerated values return new String[] {"error", "warn", "info", "trace", "debug", "spam", "all"}; } } public static class styleTypes extends EnumeratedAttribute { @Override public String[] getValues() { return new String[] {"obf", "pretty", "detailed"}; } } private int argpos = 0; private String args[] = new String[8]; private String gen; private String logLevel; private String module; private String out; private String src; private String style; private void addArg(String key, String value) { args[argpos]= key; argpos++; args[argpos]= value; argpos++; } public void execute () { CommandlineJava cmd = new CommandlineJava(); Path cp = cmd.createClasspath(getProject()).concatSystemClasspath(); cmd.setClassname(GWTCompiler.class.getName()); if (gen !=null) { addArg("-gen",gen); } if (out != null) { addArg("-out",out); } if (style != null){ addArg("-style",style); } if(logLevel != null){ addArg("-logLevel", logLevel); } if (module != null) { log("module = " + module +" position = "+argpos, Project.MSG_INFO); args[argpos] = module; argpos++; } cp.add(new Path(getProject(), src)); new TaskUtils().run(getProject(), cp,GWTCompiler.class.getName(), getArgs(), true); } private String[] getArgs() { String[] a = new String[argpos]; for (int x = 0; x< argpos; x++){ a[x] = args[x]; } return a; } public String getGen() { return gen; } public String getLogLevel() { return logLevel; } public String getModule() { return module; } public String getOut() { return out; } public String getSrc() { return src; } public String getStyle() { return style; } public void setGen(String gen) { this.gen = gen; } public void setLogLevel(logLevels logLevel) { this.logLevel = logLevel.getValue().toUpperCase(); } public void setModule(String module) { this.module = module; } public void setOut(String out) { this.out = out; } public void setSrc(String src){ this.src = src; } public void setStyle(styleTypes style) { this.style = style.getValue().toUpperCase(); } }