Author: tchemit Date: 2009-03-01 12:52:04 +0000 (Sun, 01 Mar 2009) New Revision: 1250 Added: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXProfile.java Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/ClassDescriptorLoader.java jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/MethodDescriptor.java jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java jaxx/trunk/maven-jaxx-plugin/changelog.txt jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java Log: add a profile mode fix some bugs in ClassDescriptorLoader and MethodDescriptor make possible to block $initialize method while internalContext is not set Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt =================================================================== --- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-01 12:52:04 UTC (rev 1250) @@ -1,4 +1,10 @@ 1.3 ??? 200902?? + * 20090229 [chemit] - fix bug in ClassDescriptorLoader when searching for an arrayof primitive type + - add a profile mode + * 20090228 [chemit] - fix bug in MethodDescriptor when no returnType defined (constructor method) in getReturnType method invocation + - generate default constructors only if none defined in script + - add primitive type void in ClassDescriptorLoader + - add a contextInitialized property in JAXX generated file to control JAXXContext initialization * 20090225 [chemit] - add a mecanism to make possible injection of client properties 1.2 letellier 20090225 (release for isis) Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -16,6 +16,7 @@ private boolean keepJavaFiles; private boolean optimize; private boolean verbose; + private boolean profile; /** a flag to enable or disable i18n generation */ private boolean i18nable; @@ -282,4 +283,13 @@ this.defaultDecoratorClass = defaultDecoratorClass; } + public boolean isProfile() { + return profile; + } + + public void setProfile(boolean profile) { + this.profile = profile; + } + + } Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -24,17 +24,14 @@ protected static final Log log = LogFactory.getLog(JAXXCompilerLaunchor.class); protected enum LifeCycle { + init,// state before compilation compile_first_pass, // state when first pass of compilation compile_second_pass, // state when second pass of compilation stylesheet_pass, // state when applygin stylesheet phase after compilation - generate_pass // state when generation phase + generate_pass, // state when generation phase + profile_pass // state when profile } - - protected static final int PASS_1 = 0; - - protected static final int PASS_2 = 1; - /** shared instance of unique launchor at a givne time. */ protected static JAXXCompilerLaunchor singleton; @@ -127,31 +124,24 @@ initializer.initialize(); } } - /** options of the launchor and underlines compilers */ protected CompilerOptions options; /** original list of files to compile */ protected final File[] files; /** original list of classes to compile */ protected final String[] classNames; - /** Files to be treated while compilation. */ protected List<File> jaxxFiles = new ArrayList<File>(); - /** Class names corresponding to the files in the jaxxFiles list. */ protected List<String> jaxxFileClassNames = new ArrayList<String>(); - /** Maps the names of classes being compiled to the compiler instance handling the compilation. */ protected Map<String, JAXXCompiler> compilers = new HashMap<String, JAXXCompiler>(); - /** Maps the names of classes being compiled to their symbol tables (created after the first compiler pass). */ protected Map<File, SymbolTable> symbolTables = new HashMap<File, SymbolTable>(); - protected LifeCycle currentPass; - //protected int currentPass; - protected int errorCount; protected int warningCount; + protected JAXXProfile profiler; protected JAXXCompilerLaunchor(File[] files, String[] classNames, CompilerOptions options) { this.options = options == null ? new CompilerOptions() : options; @@ -160,9 +150,11 @@ if (this.options.isVerbose()) { log.info("files : " + Arrays.toString(files)); } + if (this.options.isProfile()) { + profiler = new JAXXProfile(); + } } - public void init() { // forces static initializer to run if it hasn't yet } @@ -174,7 +166,9 @@ jaxxFileClassNames.clear(); symbolTables.clear(); compilers.clear(); - //CompiledObjectDecorator.reset(); + if (profiler != null) { + profiler.clear(); + } } public String getVersion() { @@ -245,7 +239,9 @@ boolean success = true; // pass 1 - currentPass = LifeCycle.compile_first_pass; + if (!nextStep(LifeCycle.compile_first_pass, success)) { + return false; + } boolean compiled; do { compiled = false; @@ -255,8 +251,8 @@ while (filesIterator.hasNext()) { File file = filesIterator.next(); String className = classNamesIterator.next(); - if (options.isVerbose()) { - log.info("compile first pass for " + className); + if (log.isDebugEnabled()) { + log.debug("compile first pass for " + className); } if (symbolTables.get(file) == null) { compiled = true; @@ -278,8 +274,10 @@ //destDir = file.getParentFile(); } JAXXCompiler compiler = newCompiler(file.getParentFile(), file, className); + addProfileTime(compiler, currentPass.name() + "_start"); compilers.put(className, compiler); compiler.compileFirstPass(); + addProfileTime(compiler, currentPass.name() + "_end"); assert !symbolTables.values().contains(compiler.getSymbolTable()) : "symbolTable is already registered"; symbolTables.put(file, compiler.getSymbolTable()); if (compiler.isFailed()) { @@ -289,34 +287,30 @@ } } while (compiled); - if (!success) { - return report(false); - } // pass 2 - currentPass = LifeCycle.compile_second_pass; + if (!nextStep(LifeCycle.compile_second_pass, success)) { + return false; + } assert jaxxFiles.size() == jaxxFileClassNames.size(); List<File> jaxxFilesClone = new ArrayList<File>(jaxxFiles); for (String className : jaxxFileClassNames) { - JAXXCompiler compiler = compilers.get(className); - if (compiler == null) { - throw new CompilerException("Internal error: could not find compiler for " + className + " during second pass"); + JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass"); + addProfileTime(compiler, currentPass.name() + "_start"); + if (log.isDebugEnabled()) { + log.debug("runInitializers for " + className); } - if (options.isVerbose()) { - - log.info("runInitializers for " + className); - } if (!compiler.isFailed()) { compiler.runInitializers(); } - if (options.isVerbose()) { - - log.info("compile second pass for " + className); + if (log.isDebugEnabled()) { + log.debug("compile second pass for " + className); } compiler.compileSecondPass(); - if (options.isVerbose()) { - log.info("done with result [" + !compiler.isFailed() + "] for " + className); + addProfileTime(compiler, currentPass.name() + "_end"); + if (log.isDebugEnabled()) { + log.debug("done with result [" + !compiler.isFailed() + "] for " + className); } if (compiler.isFailed()) { success = false; @@ -326,58 +320,61 @@ throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + jaxxFiles + ")"); } - if (!success) { - return report(false); - } - // stylesheet application - currentPass = LifeCycle.stylesheet_pass; + if (!nextStep(LifeCycle.stylesheet_pass, success)) { + return false; + } assert jaxxFiles.size() == jaxxFileClassNames.size(); for (String className : jaxxFileClassNames) { - JAXXCompiler compiler = compilers.get(className); - if (compiler == null) { - throw new CompilerException("Internal error: could not find compiler for " + className + " during stylesheet application"); - } + JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application"); + addProfileTime(compiler, currentPass.name() + "_start"); compiler.applyStylesheets(); + addProfileTime(compiler, currentPass.name() + "_end"); if (compiler.isFailed()) { success = false; } } - if (!success) { - return report(false); - } // code generation - currentPass = LifeCycle.generate_pass; + if (!nextStep(LifeCycle.generate_pass, success)) { + return false; + } assert jaxxFiles.size() == jaxxFileClassNames.size(); List<Generator> generators = new ArrayList<Generator>(); for (Generator generator : ServiceLoader.load(Generator.class)) { generators.add(generator); } for (String className : jaxxFileClassNames) { - JAXXCompiler compiler = compilers.get(className); - if (compiler == null) { - throw new CompilerException("Internal error: could not find compiler for " + className + " during code generation"); - } + JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation"); + addProfileTime(compiler, currentPass.name() + "_start"); compiler.generateCode(generators); + addProfileTime(compiler, currentPass.name() + "_end"); //compiler.generateCode(); if (compiler.isFailed()) { success = false; } } + if (options.isProfile()) { + // profile pass (only if succes compile) + if (!nextStep(LifeCycle.profile_pass, success)) { + return false; + } + StringBuilder buffer = profiler.computeProfileReport(); + log.info(buffer.toString()); + } + return report(success); - } - catch (CompilerException e) { + + //FIXME : deal better the exception treatment... + } catch (CompilerException e) { System.err.println(e.getMessage()); e.printStackTrace(); return false; - } - catch (Throwable e) { + } catch (Throwable e) { e.printStackTrace(); return false; - } - finally { + } finally { //TC - 20081018 only reset when no error was detected if (options.isResetAfterCompile() && errorCount == 0) { reset(); @@ -385,6 +382,22 @@ } } + protected JAXXCompiler getCompiler(String className, String message) { + JAXXCompiler compiler = compilers.get(className); + if (compiler == null) { + throw new CompilerException(message); + } + return compiler; + } + + protected boolean nextStep(LifeCycle nextCycle, boolean success) { + if (!success) { + return report(false); + } + currentPass = nextCycle; + return true; + } + protected boolean report(boolean success) { if (warningCount == 1) { System.err.println("1 warning"); @@ -404,6 +417,12 @@ return cons.newInstance(parentFile, file, className, options); } + public static void addProfileTime(JAXXCompiler compiler, String key) { + JAXXProfile p = JAXXCompilerLaunchor.get().profiler; + if (p != null) { + p.addTime(compiler, key); + } + } protected static void showUsage() { System.out.println("Usage: jaxxc <options> <source files>"); @@ -422,68 +441,5 @@ System.out.println(); System.out.println("See http://www.jaxxframework.org/ for full documentation."); } - - public static void main(String[] arg) throws Exception { - //todo make this works again - /*boolean success = true; - - CompilerOptions options = new CompilerOptions(); - List<String> files = new ArrayList<String>(); - for (int i = 0; i < arg.length; i++) { - if (arg[i].endsWith(".jaxx")) { - files.add(arg[i]); - } else if (arg[i].equals("-d")) { - if (++i < arg.length) { - File targetDirectory = new File(arg[i]); - if (!targetDirectory.exists()) { - System.err.println("Error: could not find target directory: " + targetDirectory); - errorCount++; - success = false; - } - options.setTargetDirectory(targetDirectory); - } else { - success = false; - } - } else if (arg[i].equals("-cp") || arg[i].equals("-classpath")) { - if (++i < arg.length) { - options.setClassPath(arg[i]); - } else { - success = false; - } - } else if (arg[i].equals("-javac_opts")) { - if (++i < arg.length) { - options.setJavacOpts(arg[i]); - } else { - success = false; - } - } else if (arg[i].equals("-k") || arg[i].equals("-keep")) { - options.setKeepJavaFiles(true); - } else if (arg[i].equals("-j") || arg[i].equals("-java")) { - options.setKeepJavaFiles(true); - } else if (arg[i].equals("-o") || arg[i].equals("-optimize")) { - options.setOptimize(true); - } else if (arg[i].equals("-version")) { - System.err.println("jaxxc version " + getVersion() + " by Ethan Nicholas"); - System.err.println("http://www.jaxxframework.org/"); - System.exit(0); - } else if (arg[i].equals("-internalDumpVersion")) { // used by ant to extract the version info - System.out.println("jaxx.version=" + getVersion()); - return; - } else { - success = false; - } - } - - success &= (errorCount == 0 && files.size() > 0); - - if (success) { - success = compile(new File("."), files.toArray(new String[files.size()]), options); - } else { - showUsage(); - System.exit(1); - } - - System.exit(success ? 0 : 1);*/ - } - + } Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -4,6 +4,7 @@ import jaxx.CompilerException; import jaxx.reflect.ClassDescriptor; import jaxx.reflect.ClassDescriptorLoader; +import jaxx.reflect.FieldDescriptor; import jaxx.reflect.MethodDescriptor; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; @@ -45,6 +46,9 @@ protected static final JavaField ALL_COMPONENTS_CREATED_FIELD = JavaField.newField(java.lang.reflect.Modifier.PRIVATE, "boolean", "allComponentsCreated" ); + protected static final JavaField CONTEXT_INITIALIZED = JavaField.newField(java.lang.reflect.Modifier.PRIVATE, + "boolean", "contextInitialized","true" + ); protected static final JavaField PREVIOUS_VALUES_FIELD = JavaField.newField(0, "java.util.Map", "$previousValues", "new java.util.HashMap()" ); @@ -247,24 +251,46 @@ } javaFile.addField(ALL_COMPONENTS_CREATED_FIELD); + boolean overrideContextInitialized = false; + FieldDescriptor[] scriptFields = compiler.getScriptFields(); + for (FieldDescriptor f : scriptFields) { + if ("contextInitialized".equals(f.getName())) { + overrideContextInitialized=true; + break; + } + } + if (!overrideContextInitialized) { + javaFile.addField(CONTEXT_INITIALIZED); + } javaFile.addField(createJAXXObjectDescriptorField(compiler, javaFile)); if (compiler.getStylesheet() != null) { javaFile.addField(PREVIOUS_VALUES_FIELD); } - /*for (CompiledObject object : compiler.getObjects().values()) { - List<CompiledObject.ChildRef> refList = object.getChilds(); - if (refList==null || refList.isEmpty()) { - continue; + List<CompiledObject.ChildRef> refList = object.getChilds(); + if (refList==null || refList.isEmpty()) { + continue; + } + for (ChildRef childRef : refList) { + childRef.addToAdditionCode(buffer); + } + }*/ + //TC 20090228 - only generate constructors if not done in scripts + boolean constructorDetected=false; + MethodDescriptor[] methods = compiler.getScriptMethods(); + for (MethodDescriptor m : methods) { + m.getReturnType(); + if (className.equals(m.getName())) { + constructorDetected=true; + break; } - for (ChildRef childRef : refList) { - childRef.addToAdditionCode(buffer); - } - }*/ - javaFile.addMethod(createConstructor(compiler, className, superclassIsJAXXObject)); - javaFile.addMethod(createConstructorWithInitialContext(compiler, className, superclassIsJAXXObject)); - + } + if (!constructorDetected) { + javaFile.addMethod(createConstructor(compiler, className, superclassIsJAXXObject)); + javaFile.addMethod(createConstructorWithInitialContext(compiler, className, superclassIsJAXXObject)); + } + javaFile.addMethod(createInitializer(compiler)); javaFile.addMethod(GET_JAXX_OBJECT_DESCRIPTOR_METHOD); @@ -432,7 +458,7 @@ public JavaMethod createInitializer(JAXXCompiler compiler) throws CompilerException { StringBuffer code = new StringBuffer(); CompiledObject root = compiler.getRootObject(); - code.append("if (allComponentsCreated) {"); + code.append("if (allComponentsCreated || !contextInitialized) {"); code.append(JAXXCompiler.getLineSeparator()); code.append(" return;"); code.append(JAXXCompiler.getLineSeparator()); Added: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXProfile.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXProfile.java (rev 0) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXProfile.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -0,0 +1,238 @@ +package jaxx.compiler; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedMap; +import jaxx.compiler.JAXXCompilerLaunchor.LifeCycle; +import org.codelutin.util.StringUtil; + +/** + * Pour profiler les temps d'execution pendant une compilation. + * + * @author tony + * @since 1.3 + */ +public class JAXXProfile { + + void clear() { + entries.clear(); + compilers.clear(); + } + + protected class CompilerEntry { + + JAXXCompiler compiler; + SortedMap<String, Long> times; + + public CompilerEntry(JAXXCompiler compiler) { + this.compiler = compiler; + times = new java.util.TreeMap<String, Long>(); + } + } + + public static class ProfileResult { + + long min, max, average, total; + Map<JAXXCompiler, Long> delta; + List<Long> times; + + ProfileResult(String label, Map<JAXXCompiler, Long> delta) { + this.delta = delta; + times = new java.util.ArrayList<Long>(delta.values()); + java.util.Collections.sort(times); + min = times.get(0); + max = times.get(times.size() - 1); + total = 0; + average = 0; + for (Long t : times) { + total += t; + } + average = total / times.size(); + } + + public long getTime(JAXXCompiler compiler) { + for (Entry<JAXXCompiler, Long> entry : delta.entrySet()) { + if (entry.getKey().equals(compiler)) { + return entry.getValue(); + } + } + throw new IllegalArgumentException("could not find time for compiler " + compiler); + } + + public void clear() { + times.clear(); + delta.clear(); + } + + public JAXXCompiler getCompiler(Long l) { + for (Entry<JAXXCompiler, Long> entry : delta.entrySet()) { + if (entry.getValue().equals(l)) { + return entry.getKey(); + } + } + throw new IllegalArgumentException("could not find compiler for time " + l); + } + } + SortedMap<Integer, CompilerEntry> entries; + List<JAXXCompiler> compilers; + + public JAXXProfile() { + compilers = new java.util.ArrayList<JAXXCompiler>(); + entries = new java.util.TreeMap<Integer, CompilerEntry>(); + } + + public void addTime(JAXXCompiler compiler, String key) { + CompilerEntry e = getEntry(compiler); + e.times.put(key, System.nanoTime()); + } + + public Map<JAXXCompiler, Long> getDelta(String label, String keyOne, String keyTwo) { + Map<JAXXCompiler, Long> result = new java.util.HashMap<JAXXCompiler, Long>(); + for (java.util.Map.Entry<Integer, CompilerEntry> e : entries.entrySet()) { + JAXXCompiler c = getCompiler(e.getKey()); + CompilerEntry entry = e.getValue(); + Long t0 = entry.times.get(keyOne); + Long t1 = entry.times.get(keyTwo); + if (t0 == null) { + throw new NullPointerException("could not find time for " + keyOne + " on compiler " + c.getOutputClassName()); + } + if (t1 == null) { + throw new NullPointerException("could not find time for " + keyTwo + " on compiler " + c.getOutputClassName()); + } + long delta = t1 - t0; + result.put(c, delta); + } + return result; + } + + public ProfileResult newProfileResult(LifeCycle step) { + ProfileResult result; + String name = step.name(); + Map<JAXXCompiler, Long> delta = getDelta(name, name + "_start", name + "_end"); + result = new ProfileResult(name, delta); + return result; + } + + public ProfileResult newProfileResult(ProfileResult... toCumul) { + ProfileResult result; + Map<JAXXCompiler, Long> delta = new java.util.HashMap<JAXXCompiler, Long>(); + for (JAXXCompiler c : compilers) { + long total = 0; + for (ProfileResult cumul : toCumul) { + long time = cumul.getTime(c); + total += time; + } + delta.put(c, total); + } + result = new ProfileResult("all", delta); + return result; + } + + public StringBuilder computeProfileReport() { + + StringBuilder buffer = new StringBuilder(); + + if (compilers.isEmpty()) { + return buffer.append("no jaxx file treated, no profile report"); + } + + // compute max size of the fqn of a compiled file + int maxLength = 0; + for (JAXXCompiler compiler : compilers) { + int l = compiler.getOutputClassName().length(); + if (l > maxLength) { + maxLength = l; + } + } + + ProfileResult cfp = newProfileResult(LifeCycle.compile_first_pass); + ProfileResult csp = newProfileResult(LifeCycle.compile_second_pass); + ProfileResult ssp = newProfileResult(LifeCycle.stylesheet_pass); + ProfileResult gp = newProfileResult(LifeCycle.generate_pass); + ProfileResult total = newProfileResult(cfp, csp, ssp, gp); + + String reportPattern = "\n|%1$-" + maxLength + "s|%2$15s|%3$15s|%4$15s|%5$15s|%6$15s|"; + + char[] tmpC = new char[maxLength]; + Arrays.fill(tmpC, '-'); + String line = String.format(reportPattern, + new String(tmpC), + "---------------", + "---------------", + "---------------", + "---------------", + "---------------"); + + buffer.append(line); + + buffer.append(String.format(reportPattern, + "(files / stats) \\ passes", + "compile round 1", "compile round 2", "stylesheet", "generation", "all passes")); + + buffer.append(line); + + // affiche les temps de tous les fichiers en temp total croissant + for (Long l : total.times) { + JAXXCompiler c = total.getCompiler(l); + printReportLine(buffer, reportPattern, c.getOutputClassName(), cfp.getTime(c), csp.getTime(c), ssp.getTime(c), gp.getTime(c), total.getTime(c)); + } + + buffer.append(line); + + printReportLine(buffer, reportPattern, "total (" + compilers.size() + " files)", cfp.total, csp.total, ssp.total, gp.total, total.total); + + buffer.append(line); + printReportLine2(buffer, reportPattern, "min", cfp.min, csp.min, ssp.min, gp.min, total.min); + printReportLine2(buffer, reportPattern, "max", cfp.max, csp.max, ssp.max, gp.max, total.max); + printReportLine(buffer, reportPattern, "average", cfp.average, csp.average, ssp.average, gp.average, total.average); + buffer.append(line); + + cfp.clear(); + csp.clear(); + ssp.clear(); + gp.clear(); + total.clear(); + + return buffer; + } + public static final String TIME_PATTERN = "%1$9s - %2$2d%%"; + + protected void printReportLine(StringBuilder buffer, String reportPattern, String label, long firstPassCounter, long secondPassCounter, long cssCounter, long generatorCounter, long totalCounter) { + float percentCFP = ((float) firstPassCounter / totalCounter) * 100; + float percentCSP = ((float) secondPassCounter / totalCounter) * 100; + float percentCSSP = ((float) cssCounter / totalCounter) * 100; + float percentGP = ((float) generatorCounter / totalCounter) * 100; + String strCFP = String.format(TIME_PATTERN, StringUtil.convertTime(firstPassCounter), (int) percentCFP); + String strCSP = String.format(TIME_PATTERN, StringUtil.convertTime(secondPassCounter), (int) percentCSP); + String strCSSP = String.format(TIME_PATTERN, StringUtil.convertTime(cssCounter), (int) percentCSSP); + String strGP = String.format(TIME_PATTERN, StringUtil.convertTime(generatorCounter), (int) percentGP); + + buffer.append(String.format(reportPattern, label, strCFP, strCSP, strCSSP, strGP, StringUtil.convertTime(totalCounter))); + } + + protected void printReportLine2(StringBuilder buffer, String reportPattern, String label, long firstPassCounter, long secondPassCounter, long cssCounter, long generatorCounter, long totalCounter) { + buffer.append(String.format(reportPattern, label, StringUtil.convertTime(firstPassCounter), StringUtil.convertTime(secondPassCounter), StringUtil.convertTime(cssCounter), StringUtil.convertTime(generatorCounter), StringUtil.convertTime(totalCounter))); + } + + protected CompilerEntry getEntry(JAXXCompiler compiler) { + int key = compiler.getOutputClassName().hashCode(); + CompilerEntry result = entries.get(key); + if (result == null) { + result = new CompilerEntry(compiler); + entries.put(key, result); + compilers.add(compiler); + } + return result; + } + + protected JAXXCompiler getCompiler(int hasCode) { + for (JAXXCompiler c : compilers) { + if (hasCode == c.getOutputClassName().hashCode()) { + return c; + } + } + return null; + } +} Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/ClassDescriptorLoader.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/ClassDescriptorLoader.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/ClassDescriptorLoader.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -121,8 +121,39 @@ } } - public static Class getClass(String className, ClassLoader classLoader) throws ClassNotFoundException { + public static Class getPrimitiveBoxedClass(String className) throws ClassNotFoundException { if (className.equals("boolean")) { + return Boolean.class; + } + if (className.equals("byte")) { + return Byte.class; + } + if (className.equals("short")) { + return Short.class; + } + if (className.equals("int")) { + return Integer.class; + } + if (className.equals("long")) { + return Long.class; + } + if (className.equals("float")) { + return Float.class; + } + if (className.equals("double")) { + return Double.class; + } + if (className.equals("char")) { + return Character.class; + } + if (className.equals("void")) { + return Void.class; + } + return null; + } + + public static Class getPrimitiveClass(String className) throws ClassNotFoundException { + if (className.equals("boolean")) { return boolean.class; } if (className.equals("byte")) { @@ -146,18 +177,57 @@ if (className.equals("char")) { return char.class; } + if (className.equals("void")) { + return void.class; + } + // detect arrays int arrayCount = 0; while (className.endsWith("[]")) { arrayCount++; className = className.substring(0, className.length() - 2); } + Class klass=null; if (arrayCount > 0) { + klass = getPrimitiveClass(className); + if (klass==null) { + // none primitive array + return null; + } + // must take the boxed class, other it does not works + // to make a Class.forName("[Lchar;"); but works + // with Class.forName("[LCharacter;"); ... + klass =getPrimitiveBoxedClass(className); + className=klass.getName(); + className = "L" + className + ";"; while (arrayCount > 0) { className = "[" + className; arrayCount--; } + System.out.println("primitive array class "+className); + return Class.forName(className); } + return null; + } + + public static Class getClass(String className, ClassLoader classLoader) throws ClassNotFoundException { + Class klass = getPrimitiveClass(className); + if (klass!=null) { + return klass; + } + // try an array of none primitive classes + int arrayCount = 0; + while (className.endsWith("[]")) { + arrayCount++; + className = className.substring(0, className.length() - 2); + } + if (arrayCount > 0) { + className = "L" + className + ";"; + while (arrayCount > 0) { + className = "[" + className; + arrayCount--; + } + } try { return classLoader != null ? Class.forName(className, true, classLoader) : Class.forName(className); } catch (ClassNotFoundException e) { @@ -185,7 +255,6 @@ } } - private static MethodDescriptor createMethodDescriptor(Method javaMethod, ClassLoader classLoader) { String methodName = javaMethod.getName(); int modifiers = javaMethod.getModifiers(); @@ -206,7 +275,6 @@ return new FieldDescriptor(fieldName, modifiers, type, classLoader); } - private static JAXXObjectDescriptor getJAXXObjectDescriptor(Class<?> jaxxClass) { if (!JAXXObject.class.isAssignableFrom(jaxxClass) || jaxxClass == JAXXObject.class) { return null; @@ -226,7 +294,6 @@ } } - private static ClassDescriptor createClassDescriptorFromJavaSource(URL javaSource, ClassLoader classLoader) throws ClassNotFoundException { try { InputStream in = javaSource.openStream(); @@ -240,7 +307,6 @@ } } - private static ClassDescriptor createClassDescriptorFromSymbolTable(String className, ClassLoader classLoader) throws ClassNotFoundException { final JAXXCompiler compiler = JAXXCompilerLaunchor.get().getJAXXCompiler(className); final SymbolTable symbolTable = JAXXCompilerLaunchor.get().getSymbolTable(className); @@ -280,6 +346,7 @@ (String[]) interfaces.toArray(new String[interfaces.size()]), false, false, null, null, classLoader, (MethodDescriptor[]) publicMethods.toArray(new MethodDescriptor[publicMethods.size()]), (FieldDescriptor[]) publicFields.toArray(new FieldDescriptor[publicFields.size()])) { + @Override public FieldDescriptor getDeclaredFieldDescriptor(String name) throws NoSuchFieldException { String type = symbolTable.getClassTagIds().get(name); if (type != null) { @@ -288,7 +355,7 @@ throw new NoSuchFieldException(name); } - + @Override public MethodDescriptor getDeclaredMethodDescriptor(String name, ClassDescriptor... parameterTypes) throws NoSuchMethodException { throw new NoSuchMethodException(name); } @@ -328,10 +395,12 @@ fields[i] = createFieldDescriptor(javaFields[i], javaClass.getClassLoader()); } return new ClassDescriptor(name, packageName, superclassName, interfaceNames, isInterface, isArray, componentTypeName, jaxxObjectDescriptor, classLoader, methods, fields) { + @Override public FieldDescriptor getDeclaredFieldDescriptor(String name) throws NoSuchFieldException { return createFieldDescriptor(javaClass.getDeclaredField(name), javaClass.getClassLoader()); } + @Override public MethodDescriptor getDeclaredMethodDescriptor(String name, ClassDescriptor... parameterTypes) throws NoSuchMethodException { try { Class[] parameterTypeClasses = new Class[parameterTypes.length]; Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/MethodDescriptor.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/MethodDescriptor.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/reflect/MethodDescriptor.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -24,11 +24,15 @@ public ClassDescriptor getReturnType() { - try { + try { + //TC 20090228 : fix bug when no return type defined (constructor method) + if (returnType == null) { + return null; + } return ClassDescriptorLoader.getClassDescriptor(returnType); } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new RuntimeException("could not find return type " + returnType, e); } } @@ -44,7 +48,7 @@ return result; } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new RuntimeException("could not find the parameter types " + java.util.Arrays.toString(parameterTypes), e); } } } \ No newline at end of file Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -268,6 +268,7 @@ * @throws IllegalArgumentException if the property is an enumeration, but the value is not valid * @throws NumberFormatException if the property is not an enumeration */ + @Override protected int constantValue(String key, String value) { if ((key.equals("mnemonic") || key.equals("displayedMnemonic"))) { if (value.length() == 1) { Modified: jaxx/trunk/maven-jaxx-plugin/changelog.txt =================================================================== --- jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-01 12:52:04 UTC (rev 1250) @@ -1,3 +1,8 @@ +1.3 ??? 200903?? + * 20090301 [chemit] - add a profile mode (-Djaxx.profile) + +1.2 letelier 2009022? + 1.1 chemit 20090220 * 20090203 [chemit] - mojo's property src is now by default in src/main/java * 20090202 [chemit] - introduce a property validatorClass to specify the validator implementation Modified: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java =================================================================== --- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-02-25 16:18:04 UTC (rev 1249) +++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-03-01 12:52:04 UTC (rev 1250) @@ -256,6 +256,14 @@ * @parameter expression="${jaxx.useUIManagerForIcon}" default-value="false" */ protected boolean useUIManagerForIcon; + /** + * flag to activate profile mode. + * <p/> + * By default, not active. + * + * @parameter expression="${jaxx.profile}" default-value="false" + */ + protected boolean profile; protected String[] files; @@ -377,6 +385,7 @@ result.setVerbose(verbose); result.setI18nable(i18nable); result.setAddLogger(addLogger); + result.setProfile(profile); result.setResetAfterCompile(resetAfterCompile); result.setJaxxContextImplementorClass(jaxxContextImplementorClass); result.setExtraImports(extraImports); @@ -431,18 +440,21 @@ JAXXCompilerLaunchor launchor = JAXXCompilerLaunchor.newLaunchor(src, files, options); if (!launchor.compile()) { - throw new MojoFailureException("Aborting due to errors reported by jaxxc"); + throw new MojoExecutionException("Aborting due to errors reported by jaxxc"); } + } catch (MojoExecutionException e) { + getLog().error(e); + throw e; } catch (Exception e) { - getLog().error(e); + //getLog().error(e); Throwable e2 = e; while (e2.getCause() != null) { e2 = e.getCause(); } getLog().error(e2); - throw new MojoExecutionException(e.getMessage(), e); + throw new MojoExecutionException(e2.getMessage(), e2); } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org