Author: tchemit Date: 2010-05-18 19:58:27 +0200 (Tue, 18 May 2010) New Revision: 1918 Url: http://nuiton.org/repositories/revision/jaxx/1918 Log: improve logs (and prepare form mojo showClassLoading flga) Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java 2010-05-18 12:41:06 UTC (rev 1917) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java 2010-05-18 17:58:27 UTC (rev 1918) @@ -62,6 +62,8 @@ /** Logger */ private static final Log log = LogFactory.getLog(ClassDescriptorHelper.class); + private static boolean SHOW_LOADING = log.isDebugEnabled(); + private static Map<String, ClassDescriptor> descriptors = new HashMap<String, ClassDescriptor>(); @@ -97,6 +99,16 @@ } } + public static URL getURL(ClassLoader classLoader, String className, String clasifier) { + String relativePath = className.replaceAll("\\.", "/"); + String path = relativePath + "." + clasifier; + if (log.isDebugEnabled()) { + log.debug("Path to search : " + path); + } + URL url = classLoader.getResource(path); + return url; + } + public static ClassDescriptor getClassDescriptor( String className, ClassLoader classLoader) throws ClassNotFoundException { @@ -107,12 +119,19 @@ ClassDescriptor result = descriptors.get(className); if (result != null) { + + // found in cache + if (log.isTraceEnabled()) { + log.trace("resolved " + result + " from cache."); + } return result; } JAXXEngine engine = JAXXFactory.isEngineRegistred() ? JAXXFactory.getEngine() : null; + String relativePathPattern = ".*";// + className + ".*"; // used to ensure that the located resource has the right character cases + if (engine != null) { JAXXCompilerFile file = engine.getJAXXCompilerFile(className); @@ -121,6 +140,9 @@ // use the symbole table of this jaxx file on computation + if (SHOW_LOADING) { + log.info("from JAXXFile " + file.getJaxxFile()); + } result = getClassDescriptor0( ClassDescriptorResolverFromJaxxFile.class, className, @@ -128,6 +150,10 @@ classLoader ); + if (log.isDebugEnabled()) { + log.debug("[" + className + "] loaded"); + } + return result; } } @@ -135,12 +161,9 @@ // the class is not in this compile set, try to have it from java // sources or classes. - String relativePath = className.replaceAll("\\.", "/"); - String relativePathPattern = ".*";// + className + ".*"; // used to ensure that the located resource has the right character cases - // find the most recently updated source for the class -- Java source, JAXX source, or compiled class file long javaLastModified = -1; - URL javaFile = classLoader.getResource(relativePath + ".java"); + URL javaFile = getURL(classLoader, className, "java"); if (javaFile != null && javaFile.toString().startsWith("file:") && javaFile.toString().matches(relativePathPattern)) { @@ -151,7 +174,7 @@ } long classLastModified = -1; - URL classFile = classLoader.getResource(relativePath + ".class"); + URL classFile = getURL(classLoader, className, "class"); if (classFile != null && classFile.toString().startsWith("file:") && classFile.toString().matches(relativePathPattern)) { @@ -166,6 +189,10 @@ // java file exist and it is the last modified file, so use it + if (SHOW_LOADING) { + log.info("from JavaFile " + javaFile); + } + result = getClassDescriptor0( ClassDescriptorResolverFromJavaFile.class, className, @@ -173,11 +200,18 @@ classLoader ); + if (log.isDebugEnabled()) { + log.debug("[" + className + "] loaded"); + } return result; } // use the class ... + if (SHOW_LOADING) { + log.info("from class " + className); + } + result = getClassDescriptor0( ClassDescriptorResolverFromJavaClass.class, className, @@ -185,11 +219,14 @@ classLoader ); + if (log.isDebugEnabled()) { + log.debug("[" + className + "] loaded"); + } + if (result != null) { return result; } - // can NOT come here, means could not find result... throw new IllegalStateException(